AgentNewServiceImpl.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.fdkankan.agent.service.impl;
  2. import java.util.Date;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  5. import com.fdkankan.agent.entity.AgentNew;
  6. import com.fdkankan.agent.entity.AgentNewLog;
  7. import com.fdkankan.agent.entity.IncrementType;
  8. import com.fdkankan.agent.mapper.IAgentNewMapper;
  9. import com.fdkankan.agent.response.AgentNewVo;
  10. import com.fdkankan.agent.service.IAgentNewLogService;
  11. import com.fdkankan.agent.service.IAgentNewService;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. /**
  19. * <p>
  20. * 服务实现类
  21. * </p>
  22. *
  23. * @author
  24. * @since 2022-11-09
  25. */
  26. @Service
  27. public class AgentNewServiceImpl extends ServiceImpl<IAgentNewMapper, AgentNew> implements IAgentNewService {
  28. @Autowired
  29. IAgentNewLogService agentNewLogService;
  30. @Override
  31. public AgentNewVo getByUserName(String phoneNum) {
  32. LambdaQueryWrapper<AgentNew> wrapper = new LambdaQueryWrapper<>();
  33. wrapper.eq(AgentNew::getUserName,phoneNum);
  34. List<AgentNew> list = this.list(wrapper);
  35. if(list == null || list.size() <=0){
  36. return null;
  37. }
  38. List<AgentNewVo> listVo = new ArrayList<>();
  39. for (AgentNew agentNew : list) {
  40. AgentNewVo vo = new AgentNewVo();
  41. BeanUtils.copyProperties(agentNew,vo);
  42. vo.setDownSubNum(vo.getDownTotalNum() - vo.getDownUseNum());
  43. vo.setHighSubNum(vo.getHighTotalNum() - vo.getHighUseNum());
  44. vo.setMajorSubNum(vo.getMajorTotalNum() - vo.getMajorUseNum());
  45. listVo.add(vo);
  46. }
  47. return listVo.get(0);
  48. }
  49. @Override
  50. public void subNum(AgentNewVo agentNewVo, Long userId,IncrementType incrementType, Integer count,Integer addType) {
  51. if(count == null || count <=0){
  52. return;
  53. }
  54. AgentNewLog agentNewLog = new AgentNewLog();
  55. agentNewLog.setAgentId(agentNewVo.getId());
  56. agentNewLog.setUserId(userId);
  57. agentNewLog.setCount(count);
  58. agentNewLog.setGiveType(addType);
  59. LambdaUpdateWrapper<AgentNew> wrapper = new LambdaUpdateWrapper<>();
  60. wrapper.eq(AgentNew::getId,agentNewVo.getId());
  61. if(incrementType != null && incrementType.getValidTimeType() == 0){
  62. agentNewLog.setType(0);
  63. wrapper.set(AgentNew::getMajorUseNum,agentNewVo.getMajorUseNum() + count);
  64. }
  65. if(incrementType != null && incrementType.getValidTimeType() == 1){
  66. agentNewLog.setType(1);
  67. wrapper.set(AgentNew::getHighUseNum,agentNewVo.getHighUseNum() + count);
  68. }
  69. if(incrementType == null){
  70. agentNewLog.setType(2);
  71. wrapper.set(AgentNew::getDownUseNum,agentNewVo.getDownUseNum() + count);
  72. }
  73. this.update(wrapper);
  74. agentNewLogService.save(agentNewLog);
  75. }
  76. }