@Transactional(readOnly = false)
public ServiceResponse createAgent(BaseAgent agent,Long id) {
// 检查loginCode 是否存在
BaseAgent agentFromDb = baseAgentDao.findAgentByLoginCode(agent.getAgentLoginCode());
if (agentFromDb != null) {
return ServiceResponse.fail(Error.USER_USERNAME_EXIST);
}
String password = agent.getAgentLoginPwd();
SimpleHash simpleHash = new SimpleHash("SHA-256", password, Constants.Shiro.salt, 1);
String hashedPwd = simpleHash.toHex();
agent.setAgentLoginPwd(hashedPwd);
agent.setRegTime(new Date());
agent.setStatus(Constants.Status.Agent.ENABLE.id);
agent.setId(id);
BaseAgent a = baseAgentDao.insert(agent, FieldFilter.create(BaseAgent.class, FieldMatcher.create(false)));
return ServiceResponse.success();
}