<commit_before>package selling.sunshine.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import selling.sunshine.dao.AgentDao;
import selling.sunshine.model.Agent;
import selling.sunshine.pagination.DataTableParam;
import selling.sunshine.service.AgentService;
import selling.sunshine.utils.Encryption;
import selling.sunshine.utils.ResponseCode;
import selling.sunshine.utils.ResultData;

import java.util.Map;

/**
 * Created by sunshine on 4/8/16.
 */
@Service
public class AgentServiceImpl implements AgentService {
    private Logger logger = LoggerFactory.getLogger(AgentServiceImpl.class);

    @Autowired
    private AgentDao agentDao;

    @Override
    public ResultData fetchAgent(Map<String, Object> condition) {
        ResultData result = new ResultData();
        ResultData queryResponse = agentDao.queryAgent(condition);
        result.setResponseCode(queryResponse.getResponseCode());
        if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(queryResponse.getData());
        } else if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_ERROR) {
            result.setDescription(queryResponse.getDescription());
        }
        return result;
    }

    @Override
    public ResultData createAgent(Agent agent) {
        ResultData result = new ResultData();
        agent.setPassword(Encryption.md5(agent.getPassword()));
        ResultData insertResponse = agentDao.insertAgent(agent);
        result.setResponseCode(insertResponse.getResponseCode());
        if (insertResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(insertResponse.getData());
        } else {
            result.setDescription(insertResponse.getDescription());
        }
        return result;
    }

    @Override
    public ResultData fetchAgent(Map<String, Object> condition, DataTableParam param) {
        ResultData result = new ResultData();
        ResultData queryResponse = agentDao.queryAgentByPage(condition, param);
        result.setResponseCode(queryResponse.getResponseCode());
        if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(queryResponse.getData());
        } else if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_ERROR) {
            result.setDescription(queryResponse.getDescription());
        }
        return result;
    }

	@Override
	public ResultData placeOrder(Map<String, Object> conditon) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultData updateAgent(Agent agent) {
		 ResultData result = new ResultData();
	        ResultData updateResponse = agentDao.updateAgent(agent);
	        result.setResponseCode(updateResponse.getResponseCode());
	        if (updateResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
	            result.setData(updateResponse.getData());
	        } else {
	            result.setDescription(updateResponse.getDescription());
	        }
	        return result;
	}

	@Override
	public ResultData consume(Agent agent, double money) {
		// TODO Auto-generated method stub
		return null;
	}
}<commit_msg>implementation of agent service consume method<commit_after>package selling.sunshine.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import selling.sunshine.dao.AgentDao;
import selling.sunshine.model.Agent;
import selling.sunshine.pagination.DataTableParam;
import selling.sunshine.service.AgentService;
import selling.sunshine.utils.Encryption;
import selling.sunshine.utils.ResponseCode;
import selling.sunshine.utils.ResultData;

import java.util.Map;

/**
 * Created by sunshine on 4/8/16.
 */
@Service
public class AgentServiceImpl implements AgentService {
    private Logger logger = LoggerFactory.getLogger(AgentServiceImpl.class);

    @Autowired
    private AgentDao agentDao;

    @Override
    public ResultData fetchAgent(Map<String, Object> condition) {
        ResultData result = new ResultData();
        ResultData queryResponse = agentDao.queryAgent(condition);
        result.setResponseCode(queryResponse.getResponseCode());
        if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(queryResponse.getData());
        } else if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_ERROR) {
            result.setDescription(queryResponse.getDescription());
        }
        return result;
    }

    @Override
    public ResultData createAgent(Agent agent) {
        ResultData result = new ResultData();
        agent.setPassword(<PASSWORD>(agent.getPassword()));
        ResultData insertResponse = agentDao.insertAgent(agent);
        result.setResponseCode(insertResponse.getResponseCode());
        if (insertResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(insertResponse.getData());
        } else {
            result.setDescription(insertResponse.getDescription());
        }
        return result;
    }

    @Override
    public ResultData fetchAgent(Map<String, Object> condition, DataTableParam param) {
        ResultData result = new ResultData();
        ResultData queryResponse = agentDao.queryAgentByPage(condition, param);
        result.setResponseCode(queryResponse.getResponseCode());
        if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(queryResponse.getData());
        } else if (queryResponse.getResponseCode() == ResponseCode.RESPONSE_ERROR) {
            result.setDescription(queryResponse.getDescription());
        }
        return result;
    }

    @Override
    public ResultData placeOrder(Map<String, Object> conditon) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ResultData updateAgent(Agent agent) {
        ResultData result = new ResultData();
        ResultData updateResponse = agentDao.updateAgent(agent);
        result.setResponseCode(updateResponse.getResponseCode());
        if (updateResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(updateResponse.getData());
        } else {
            result.setDescription(updateResponse.getDescription());
        }
        return result;
    }

    @Override
    public ResultData consume(Agent agent, double money) {
        ResultData result = new ResultData();
        if (agent.getCoffer() < money) {
            result.setResponseCode(ResponseCode.RESPONSE_ERROR);
            result.setDescription("账户余额不足");
        }
        agent.setCoffer(agent.getCoffer() - money);
        ResultData updateResponse = updateAgent(agent);
        if (updateResponse.getResponseCode() == ResponseCode.RESPONSE_OK) {
            result.setData(updateResponse.getData());
        } else {
            result.setDescription(updateResponse.getDescription());
        }
        return result;
    }
}
{'fraction_non_alphanumeric': 0.09848697114037545, 'fraction_numerical': 0.0018212384421406557, 'mean_word_length': 3.3878303626306083, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1792352', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1882, 'n_words': 353}