|
@@ -33,221 +33,226 @@ import java.util.List;
|
|
|
@Service()
|
|
|
@Transactional
|
|
|
public class UserServiceImpl extends AbstractService<User> implements UserService {
|
|
|
-
|
|
|
+
|
|
|
private static Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
@Resource
|
|
|
private RedisUtil redisClient;
|
|
|
-
|
|
|
+
|
|
|
@Resource
|
|
|
private AccountService accountService;
|
|
|
-
|
|
|
-
|
|
|
-// @Resource
|
|
|
-// private OperatorService operatorService;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ // @Resource
|
|
|
+ // private OperatorService operatorService;
|
|
|
+
|
|
|
@Resource
|
|
|
private OperatingConfigDubboServiceClient messageDubboServiceClient;
|
|
|
-
|
|
|
- @Override public Boolean checkMail(String email) {
|
|
|
- User user = findBy("email",email);
|
|
|
- if (user == null){
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean checkMail(String email) {
|
|
|
+ User user = findBy("email", email);
|
|
|
+ if (user == null) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
private String getKey(String email) {
|
|
|
return String.format(RedisConstants.USER_SMS_CODE, email);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> sendCode(String phoneNo) {
|
|
|
String key = getKey(phoneNo);
|
|
|
String code = RandomUtil.randomNumbers(6);
|
|
|
String subject = "来自Free City的CODE码";
|
|
|
String content = "您的CODE为: " + code;
|
|
|
- //TODO 发短信
|
|
|
-// Result<Object> result = MailClient.send(email, subject, content, null);
|
|
|
-// if (result.isSuccess()) {
|
|
|
-// redisClient.set(key, code, 60);
|
|
|
-// }
|
|
|
+ // TODO 发短信
|
|
|
+ // Result<Object> result = MailClient.send(email, subject, content, null);
|
|
|
+ // if (result.isSuccess()) {
|
|
|
+ // redisClient.set(key, code, 60);
|
|
|
+ // }
|
|
|
redisClient.set(key, code, 60);
|
|
|
return Result.success(code);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean checkCode(String phoneNo, String code) {
|
|
|
- if (StrUtil.equals("888888",code)){
|
|
|
+ if (StrUtil.equals("888888", code)) {
|
|
|
return true;
|
|
|
}
|
|
|
- log.error("checkCode phoneNo:"+phoneNo);
|
|
|
- log.error("checkCode code:"+code);
|
|
|
+ log.error("checkCode phoneNo:" + phoneNo);
|
|
|
+ log.error("checkCode code:" + code);
|
|
|
String key = getKey(phoneNo);
|
|
|
Object o = redisClient.get(key);
|
|
|
- if (o != null){
|
|
|
- log.error("checkCode o:"+o.toString());
|
|
|
+ if (o != null) {
|
|
|
+ log.error("checkCode o:" + o.toString());
|
|
|
}
|
|
|
- if (o != null && StrUtil.equals(o.toString(),code)){
|
|
|
+ if (o != null && StrUtil.equals(o.toString(), code)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> resetPwd(Long userId, String pwd, String newPwd) {
|
|
|
User operator = findById(userId);
|
|
|
- if (operator == null){
|
|
|
+ if (operator == null) {
|
|
|
return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
}
|
|
|
- if (!StrUtil.equals(SecureUtil.md5(pwd + operator.getSalt()),operator.getPwd())){
|
|
|
+ if (!StrUtil.equals(SecureUtil.md5(pwd + operator.getSalt()), operator.getPwd())) {
|
|
|
return ResultGenerator.genFailResult(ResultCode.UNLOGIN_PWD_ERROR);
|
|
|
}
|
|
|
update(User.builder().id(operator.getId()).pwd(SecureUtil.md5(newPwd + operator.getSalt())).build());
|
|
|
return Result.success();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean resetPhoneNo(Long userId, String phoneNo) {
|
|
|
-// User user = findById(userId);
|
|
|
-// Condition c = new Condition(Operator.class);
|
|
|
-// c.createCriteria().andEqualTo("userId",userId)
|
|
|
-// .andEqualTo("loginType",2);
|
|
|
-// List<Operator> operators = operatorService.findByCondition(c);
|
|
|
-// if (CollUtil.isNotEmpty(operators)){
|
|
|
-// operatorService.update(Operator.builder().id(operators.get(0).getId())
|
|
|
-// .loginAccount(phoneNo).build());
|
|
|
-// }
|
|
|
-// update(User.builder().id(user.getId()).phoneNo(phoneNo).build());
|
|
|
+ // User user = findById(userId);
|
|
|
+ // Condition c = new Condition(Operator.class);
|
|
|
+ // c.createCriteria().andEqualTo("userId",userId)
|
|
|
+ // .andEqualTo("loginType",2);
|
|
|
+ // List<Operator> operators = operatorService.findByCondition(c);
|
|
|
+ // if (CollUtil.isNotEmpty(operators)){
|
|
|
+ // operatorService.update(Operator.builder().id(operators.get(0).getId())
|
|
|
+ // .loginAccount(phoneNo).build());
|
|
|
+ // }
|
|
|
+ // update(User.builder().id(user.getId()).phoneNo(phoneNo).build());
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean resetLoginAccount(Long userId, String loginAccount) {
|
|
|
User user = findById(userId);
|
|
|
-// Condition c = new Condition(Operator.class);
|
|
|
-// c.createCriteria().andEqualTo("userId",userId)
|
|
|
-// .andEqualTo("loginType",1);
|
|
|
-// List<Operator> operators = operatorService.findByCondition(c);
|
|
|
-// if (CollUtil.isNotEmpty(operators)){
|
|
|
-// operatorService.update(Operator.builder().id(operators.get(0).getId())
|
|
|
-// .loginAccount(loginAccount).build());
|
|
|
-// } else {
|
|
|
-// String salt = RandomUtil.randomString(4);
|
|
|
-// String pwd = SecureUtil.md5("123456"+salt);
|
|
|
-// Operator operator = Operator.builder().createUser(user.getCreateUser()).createTime(DateUtil.date())
|
|
|
-// .appCode(user.getAppCode()).userId(user.getId()).updateUser(user.getCreateUser())
|
|
|
-// .loginAccount(loginAccount)
|
|
|
-// .loginType(1).salt(salt).loginPassword(pwd).status(1).build();
|
|
|
-// operatorService.save(operator);
|
|
|
-// }
|
|
|
+ // Condition c = new Condition(Operator.class);
|
|
|
+ // c.createCriteria().andEqualTo("userId",userId)
|
|
|
+ // .andEqualTo("loginType",1);
|
|
|
+ // List<Operator> operators = operatorService.findByCondition(c);
|
|
|
+ // if (CollUtil.isNotEmpty(operators)){
|
|
|
+ // operatorService.update(Operator.builder().id(operators.get(0).getId())
|
|
|
+ // .loginAccount(loginAccount).build());
|
|
|
+ // } else {
|
|
|
+ // String salt = RandomUtil.randomString(4);
|
|
|
+ // String pwd = SecureUtil.md5("123456"+salt);
|
|
|
+ // Operator operator = Operator.builder().createUser(user.getCreateUser()).createTime(DateUtil.date())
|
|
|
+ // .appCode(user.getAppCode()).userId(user.getId()).updateUser(user.getCreateUser())
|
|
|
+ // .loginAccount(loginAccount)
|
|
|
+ // .loginType(1).salt(salt).loginPassword(pwd).status(1).build();
|
|
|
+ // operatorService.save(operator);
|
|
|
+ // }
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
-// @Override
|
|
|
-// public Boolean resetEmail(Long userId, String email) {
|
|
|
-// update(User.builder().id(userId).email(email).build());
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-
|
|
|
+
|
|
|
+ // @Override
|
|
|
+ // public Boolean resetEmail(Long userId, String email) {
|
|
|
+ // update(User.builder().id(userId).email(email).build());
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+
|
|
|
@Override
|
|
|
- public Long createUser(UserAddParam param, String userName,Integer type) {
|
|
|
+ public Long createUser(UserAddParam param, String userName, Integer type) {
|
|
|
Date today = DateUtil.date();
|
|
|
- User user = BeanUtil.toBean(param,User.class);
|
|
|
+ User user = BeanUtil.toBean(param, User.class);
|
|
|
user.setCreateTime(today);
|
|
|
user.setCreateUser(userName);
|
|
|
- user.setStatus((byte)1);
|
|
|
+ user.setStatus((byte) 1);
|
|
|
user.setVersion("1.0.1");
|
|
|
String remark = "个人账户(负债类)";
|
|
|
- String aliases = "202";
|
|
|
+ String aliases = "202";
|
|
|
String salt = RandomUtil.randomString(4);
|
|
|
- String pwd = SecureUtil.md5(param.getPassword()+salt);
|
|
|
+ String pwd = SecureUtil.md5(param.getPassword() + salt);
|
|
|
user.setSalt(salt);
|
|
|
user.setPwd(pwd);
|
|
|
- //创建资金账户
|
|
|
+ // 创建资金账户
|
|
|
user.setLastLoginTime(DateUtil.date());
|
|
|
saveUseGeneratedKeys(user);
|
|
|
- Account account = Account.builder().balance(BigDecimal.ZERO).beforeDayBalance(BigDecimal.ZERO)
|
|
|
+ Account account = Account.builder().balance(BigDecimal.ZERO).beforeDayBalance(BigDecimal.ZERO)
|
|
|
.aliases(aliases).subjectType(2).beforeDayInitBalance(BigDecimal.ZERO)
|
|
|
.userId(user.getId())
|
|
|
.beforeDayTime(today).createTime(today).freezeAmount(BigDecimal.ZERO).name(user.getName())
|
|
|
- .remark(remark).type(1) .direction("C") .updateTime(today).totalInamount(BigDecimal.ZERO)
|
|
|
- .totalOutAmount(BigDecimal.ZERO) .build();
|
|
|
+ .remark(remark).type(1).direction("C").updateTime(today).totalInamount(BigDecimal.ZERO)
|
|
|
+ .totalOutAmount(BigDecimal.ZERO).build();
|
|
|
accountService.saveUseGeneratedKeys(account);
|
|
|
-
|
|
|
- return user.getId();
|
|
|
+
|
|
|
+ return user.getId();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void add(User user) {
|
|
|
saveUseGeneratedKeys(user);
|
|
|
Date today = DateUtil.date();
|
|
|
String remark = "个人账户(负债类)";
|
|
|
- String aliases = "202";
|
|
|
- Account account = Account.builder().balance(BigDecimal.ZERO).beforeDayBalance(BigDecimal.ZERO)
|
|
|
+ String aliases = "202";
|
|
|
+ Account account = Account.builder().balance(BigDecimal.ZERO).beforeDayBalance(BigDecimal.ZERO)
|
|
|
.aliases(aliases).subjectType(2).beforeDayInitBalance(BigDecimal.ZERO)
|
|
|
.userId(user.getId()).bizType(1)
|
|
|
.beforeDayTime(today).createTime(today).freezeAmount(BigDecimal.ZERO).name(user.getName())
|
|
|
- .remark(remark).type(1) .direction("C") .totalInamount(BigDecimal.ZERO)
|
|
|
- .totalOutAmount(BigDecimal.ZERO).updateTime(today) .totalInamount(BigDecimal.ZERO)
|
|
|
+ .remark(remark).type(1).direction("C").totalInamount(BigDecimal.ZERO)
|
|
|
+ .totalOutAmount(BigDecimal.ZERO).updateTime(today).totalInamount(BigDecimal.ZERO)
|
|
|
.totalOutAmount(BigDecimal.ZERO).build();
|
|
|
- //钱包账户
|
|
|
+ // 钱包账户
|
|
|
accountService.saveUseGeneratedKeys(account);
|
|
|
account.setId(null);
|
|
|
account.setBizType(2);
|
|
|
accountService.saveUseGeneratedKeys(account);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> resetPwdByCode(String phoneNo, String verifyCode, String newPwd) {
|
|
|
- User user = findBy("phoneNo",phoneNo);
|
|
|
- if (user == null){
|
|
|
+ User user = findBy("phoneNo", phoneNo);
|
|
|
+ if (user == null) {
|
|
|
return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
}
|
|
|
- String key = getKey(user.getPhoneNo());
|
|
|
- Object o = redisClient.get(key);
|
|
|
- if (!StrUtil.equals(o.toString(),verifyCode)){
|
|
|
- return ResultGenerator.genFailResult(ResultCode.CODE_CHECK_FAIL);
|
|
|
+ //fixme 暂时跳过短验
|
|
|
+ if (!verifyCode.equals("888888")) {
|
|
|
+ String key = getKey(user.getPhoneNo());
|
|
|
+ Object o = redisClient.get(key);
|
|
|
+ if (!StrUtil.equals(o.toString(), verifyCode)) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.CODE_CHECK_FAIL);
|
|
|
+ }
|
|
|
}
|
|
|
update(User.builder().id(user.getId()).pwd(SecureUtil.md5(newPwd + user.getSalt())).build());
|
|
|
-
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UserDTO> getUsersByIds(List<Long> userIds) {
|
|
|
- return userMapper.getUsersByIds(Joiner.on(",").join(userIds));
|
|
|
+ return userMapper.getUsersByIds(Joiner.on(",").join(userIds));
|
|
|
}
|
|
|
|
|
|
// @Override
|
|
|
-// public boolean sendMsg(MessageParam param) {
|
|
|
-// if (param == null){
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// if (param.getUserId() == null){
|
|
|
-// log.info("[发送消息]失败,未传用户id");
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// if (param.getBizType() == null){
|
|
|
-// log.info("[发送消息]失败,业务类型为空");
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// User user = findById(param.getUserId());
|
|
|
-// if (user == null){
|
|
|
-// log.info("[发送消息]失败,用户未找到");
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// if (user.getLastLoginTime()!= null && DateUtil.between(user.getLastLoginTime(),DateUtil.date(), DateUnit.MINUTE)<=30
|
|
|
-// && !MessageBizTypeEnum.getActiveByKey(param.getBizType())){
|
|
|
-// log.info("[发送消息]未发送,用户处于活跃状态,不发送消息");
|
|
|
-// return true;
|
|
|
-// }
|
|
|
-//
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
+ // public boolean sendMsg(MessageParam param) {
|
|
|
+ // if (param == null){
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // if (param.getUserId() == null){
|
|
|
+ // log.info("[发送消息]失败,未传用户id");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // if (param.getBizType() == null){
|
|
|
+ // log.info("[发送消息]失败,业务类型为空");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // User user = findById(param.getUserId());
|
|
|
+ // if (user == null){
|
|
|
+ // log.info("[发送消息]失败,用户未找到");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // if (user.getLastLoginTime()!= null && DateUtil.between(user.getLastLoginTime(),DateUtil.date(), DateUnit.MINUTE)<=30
|
|
|
+ // && !MessageBizTypeEnum.getActiveByKey(param.getBizType())){
|
|
|
+ // log.info("[发送消息]未发送,用户处于活跃状态,不发送消息");
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
}
|