AgentNewServiceImpl.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.fdkankan.manage.service.impl;
  2. import com.alibaba.excel.EasyExcel;
  3. import com.alibaba.excel.ExcelWriter;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.fdkankan.manage.common.PageInfo;
  8. import com.fdkankan.manage.common.CacheUtil;
  9. import com.fdkankan.manage.common.ResultCode;
  10. import com.fdkankan.manage.entity.*;
  11. import com.fdkankan.manage.exception.BusinessException;
  12. import com.fdkankan.manage.mapper.IAgentNewMapper;
  13. import com.fdkankan.manage.service.*;
  14. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  15. import com.fdkankan.manage.vo.request.AgentAddIncrementParam;
  16. import com.fdkankan.manage.vo.request.AgentNewLogParam;
  17. import com.fdkankan.manage.vo.request.AgentParam;
  18. import com.fdkankan.manage.vo.request.OrderParam;
  19. import com.fdkankan.manage.vo.response.AgentNewLogVo;
  20. import com.fdkankan.manage.vo.response.AgentVo;
  21. import com.fdkankan.manage.vo.response.OrderVo;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.springframework.beans.BeanUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.util.ArrayList;
  29. import java.util.HashMap;
  30. import java.util.List;
  31. /**
  32. * <p>
  33. * 服务实现类
  34. * </p>
  35. *
  36. * @author
  37. * @since 2022-11-08
  38. */
  39. @Service
  40. public class AgentNewServiceImpl extends ServiceImpl<IAgentNewMapper, AgentNew> implements IAgentNewService {
  41. @Autowired
  42. ISysUserService sysUserService;
  43. @Autowired
  44. IIncrementTypeService incrementTypeService;
  45. @Autowired
  46. IAgentNewLogService agentNewLogService;
  47. @Autowired
  48. IExcelService excelService;
  49. @Override
  50. public Object pageList(AgentParam agentParam) {
  51. LambdaQueryWrapper<AgentNew> wrapper = new LambdaQueryWrapper<>();
  52. if(StringUtils.isNotBlank(agentParam.getName())){
  53. wrapper.like(AgentNew::getName,agentParam.getName());
  54. }
  55. wrapper.orderByDesc(AgentNew::getCreateTime);
  56. Page<AgentNew> page = this.page(new Page<>(agentParam.getPageNum(), agentParam.getPageSize()), wrapper);
  57. List<AgentVo> voList = new ArrayList<>();
  58. for (AgentNew record : page.getRecords()) {
  59. AgentVo vo = new AgentVo();
  60. BeanUtils.copyProperties(record,vo);
  61. SysUser sysUser = sysUserService.getById(vo.getSysUserId());
  62. if(sysUser != null){
  63. vo.setSysUserName(sysUser.getNickName());
  64. }
  65. voList.add(vo);
  66. }
  67. Page<AgentVo> voPage = new Page<>(agentParam.getPageNum(), agentParam.getPageSize());
  68. voPage.setTotal(page.getTotal());
  69. voPage.setRecords(voList);
  70. return PageInfo.PageInfo(voPage);
  71. }
  72. @Override
  73. public void addIncrementNum(AgentAddIncrementParam param) {
  74. if(param.getId() == null ){
  75. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  76. }
  77. AgentNew agentNew = this.getById(param.getId());
  78. if(agentNew == null){
  79. throw new BusinessException(ResultCode.AGENT_NEW_EMPTY);
  80. }
  81. if(param.getDownAddNum() <=0 || param.getMajorAddNum() <=0 || param.getHighAddNum() <=0 ){
  82. return;
  83. }
  84. LambdaUpdateWrapper<AgentNew> wrapper = new LambdaUpdateWrapper<>();
  85. wrapper.eq(AgentNew::getId,param.getId());
  86. if( param.getDownAddNum() >0){
  87. wrapper.set(AgentNew::getDownTotalNum,agentNew.getDownTotalNum() + param.getDownAddNum());
  88. }
  89. if(param.getHighAddNum() >0){
  90. wrapper.set(AgentNew::getHighTotalNum,agentNew.getHighTotalNum() + param.getHighAddNum());
  91. }
  92. if( param.getMajorAddNum() >0){
  93. wrapper.set(AgentNew::getMajorTotalNum,agentNew.getMajorTotalNum() + param.getMajorAddNum());
  94. }
  95. this.update(wrapper);
  96. }
  97. @Override
  98. public Object logList(AgentNewLogParam param) {
  99. CacheUtil.agentParam = param;
  100. return agentNewLogService.getVoList(param);
  101. }
  102. @Override
  103. public void export(HttpServletRequest req, HttpServletResponse resp) {
  104. AgentNewLogParam param = CacheUtil.agentParam;
  105. List<AgentNewLogVo> voList = agentNewLogService.getVoList(param);
  106. ExcelWriter excelWriter = null;
  107. try {
  108. excelWriter = EasyExcel.write(resp.getOutputStream(),AgentNewLogVo.class).build();
  109. excelService.commonExport(req,resp,"经销商结算统计",voList,excelWriter);
  110. }catch (Exception e){
  111. e.printStackTrace();
  112. }finally {
  113. if(excelWriter != null){
  114. excelWriter.finish();
  115. }
  116. }
  117. }
  118. }