RepairSupplyService.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.fdkankan.sale.service.impl;
  2. import java.math.BigDecimal;
  3. import java.util.Date;
  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.sale.common.PageInfo;
  8. import com.fdkankan.sale.common.RepairStatusEnum;
  9. import com.fdkankan.sale.common.ResultCode;
  10. import com.fdkankan.sale.entity.*;
  11. import com.fdkankan.sale.exception.BusinessException;
  12. import com.fdkankan.sale.service.*;
  13. import com.fdkankan.sale.util.DateUtil;
  14. import com.fdkankan.sale.util.StatusUtil;
  15. import com.fdkankan.sale.vo.request.CheckRegisterParam;
  16. import com.fdkankan.sale.vo.request.OrderReceivingParam;
  17. import com.fdkankan.sale.vo.request.RecordingParam;
  18. import com.fdkankan.sale.vo.request.RepairParam;
  19. import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
  20. import com.fdkankan.sale.vo.response.RepairerVo;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.springframework.beans.BeanUtils;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.stereotype.Service;
  25. import java.util.ArrayList;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. @Service
  29. public class RepairSupplyService {
  30. @Autowired
  31. IRepairService repairService;
  32. @Autowired
  33. IRepairLogService repairLogService;
  34. @Autowired
  35. IOrderReceivingService orderReceivingService;
  36. @Autowired
  37. ICustomerService customerService;
  38. @Autowired
  39. ICustomerAddressService customerAddressService;
  40. @Autowired
  41. ICameraService cameraService;
  42. @Autowired
  43. ISysUserService sysUserService;
  44. @Autowired
  45. IRepairRegisterService repairRegisterService;
  46. @Autowired
  47. IRepairRegisterPartService repairRegisterPartService;
  48. @Autowired
  49. IPartService partService;
  50. @Autowired
  51. IPriceListService priceListService;
  52. @Autowired
  53. IPartLogService partLogService;
  54. /**
  55. * 维修备件管理 供应链
  56. * statusParam 0 待备料,1已备料,2待回收
  57. * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
  58. * * 80待支付(已完结),90待回收,100待发货,110已发货
  59. */
  60. public Object supplyOrderList(RepairParam param) {
  61. List<Integer> repairStatus = StatusUtil.getSupplyStatus(param.getStatusParam());
  62. param.setStatusList(repairStatus);
  63. Page<RepairerVo> voPage = repairService.supplyOrderList(param);
  64. sysUserService.setSaleNameAndRepairManName(voPage.getRecords());
  65. return PageInfo.PageInfo(voPage);
  66. }
  67. public List<RepairRegisterPartVo> partInfo(String repairId,Integer type) {
  68. LambdaQueryWrapper<PriceList> wrapper = new LambdaQueryWrapper<>();
  69. wrapper.eq(PriceList::getRepairId,repairId);
  70. wrapper.in(PriceList::getStatus,1);
  71. wrapper.eq(PriceList::getType,0);
  72. List<PriceList> list = priceListService.list(wrapper);
  73. LambdaQueryWrapper<PartLog> wrapper2 = new LambdaQueryWrapper<>();
  74. wrapper2.eq(PartLog::getRepairId,repairId);
  75. if(type == 0 ){ //出库
  76. wrapper2.eq(PartLog::getStatus,1);
  77. }
  78. if(type == 1){ //回收
  79. wrapper2.eq(PartLog::getStatus,2);
  80. }
  81. HashMap<Integer,PartLog> map = new HashMap<>();
  82. if(type != 2){
  83. List<PartLog> partLogs = partLogService.list(wrapper2);
  84. partLogs.forEach(entity -> map.put(entity.getPartId(),entity));
  85. }
  86. HashMap<Integer,Integer> partPriceListMap = new HashMap<>();
  87. for (PriceList priceList : list) {
  88. partPriceListMap.merge(priceList.getPartId(), priceList.getCount(), Integer::sum);
  89. }
  90. List<RepairRegisterPartVo> parts = new ArrayList<>();
  91. for (Integer partId : partPriceListMap.keySet()) {
  92. Part part = partService.getById(partId);
  93. if(part == null){
  94. continue;
  95. }
  96. RepairRegisterPartVo vo = new RepairRegisterPartVo();
  97. vo.setPartId(partId);
  98. vo.setPartName(part.getPartName());
  99. vo.setPartCount(partPriceListMap.get(partId));
  100. vo.setPartNum(part.getPartNum());
  101. if(type != 2){
  102. PartLog partLog = map.get(part.getPartId());
  103. if(partLog != null){
  104. Integer count = partLog.getCount();
  105. vo.setPartCount(vo.getPartCount() - count);
  106. }
  107. if(vo.getPartCount() <=0){
  108. continue;
  109. }
  110. }
  111. parts.add(vo);
  112. }
  113. return parts;
  114. }
  115. public void partOut(Repair param, Long userId) {
  116. if(StringUtils.isBlank(param.getRepairId())){
  117. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  118. }
  119. Repair repair = repairService.getById(param.getRepairId());
  120. if(repair == null){
  121. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  122. }
  123. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_PREPARED.status())){
  124. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  125. }
  126. List<RepairRegisterPartVo> partVoList = this.partInfo(param.getRepairId(),0);
  127. for (RepairRegisterPartVo partVo : partVoList) {
  128. partService.outStockCheck(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId());
  129. }
  130. for (RepairRegisterPartVo partVo : partVoList) {
  131. partService.outStock(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId());
  132. }
  133. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"备件出库");
  134. }
  135. public void partRecovery(Repair param, Long userId) {
  136. if(StringUtils.isBlank(param.getRepairId())){
  137. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  138. }
  139. Repair repair = repairService.getById(param.getRepairId());
  140. if(repair == null){
  141. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  142. }
  143. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_RECOVERED.status())
  144. && !repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED_RECOVERED.status())){
  145. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  146. }
  147. List<RepairRegisterPartVo> partVoList = this.partInfo(param.getRepairId(),1);
  148. for (RepairRegisterPartVo partVo : partVoList) {
  149. partService.recovery(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId(),repair.getStatus());
  150. }
  151. String remark = null;
  152. if(StringUtils.isNotBlank(param.getRemark())){
  153. remark = "回收备注:"+param.getRemark();
  154. }
  155. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_SHIPPED.status(),repair.getStatus(),"备件回收",remark);
  156. }
  157. }