RepairSupplyService.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. if(type == 0){ //获取备件出库单
  69. HashMap<Integer,PriceList> priceMap = new HashMap<>();
  70. List<RepairRegisterPartVo> parts = new ArrayList<>();
  71. List<PriceList> priceListList = priceListService.getByRepairId(repairId);
  72. for (PriceList priceList : priceListList) {
  73. if(priceList.getStatus() == 1){
  74. if(priceList.getPartId() != null && priceList.getType() == 0){
  75. if(priceMap.get(priceList.getPartId()) == null){
  76. priceMap.put(priceList.getPartId(),priceList);
  77. }else {
  78. PriceList priceList1 = priceMap.get(priceList.getPartId());
  79. priceList1.setCount(priceList1.getCount() + priceList.getCount());
  80. }
  81. }
  82. }
  83. }
  84. for (Integer partId : priceMap.keySet()) {
  85. RepairRegisterPartVo vo = new RepairRegisterPartVo();
  86. vo.setPartId(partId);
  87. vo.setPartName(priceMap.get(partId).getName());
  88. vo.setPartCount(priceMap.get(partId).getCount());
  89. Part part = partService.getById(partId);
  90. if(part != null){
  91. vo.setPartNum(part.getPartNum());
  92. }
  93. parts.add(vo);
  94. }
  95. return parts;
  96. }
  97. LambdaQueryWrapper<PartLog> wrapper2 = new LambdaQueryWrapper<>();
  98. wrapper2.eq(PartLog::getRepairId,repairId);
  99. wrapper2.eq(PartLog::getStatus,1);
  100. List<PartLog> partLogs = partLogService.list(wrapper2);
  101. HashMap<Integer,PartLog> map = new HashMap<>();
  102. for (PartLog partLog : partLogs) {
  103. if(map.get(partLog.getPartId()) != null){
  104. PartLog partLog1 = map.get(partLog.getPartId());
  105. partLog1.setCount(partLog1.getCount() + partLog.getCount());
  106. }else {
  107. map.put(partLog.getPartId(),partLog);
  108. }
  109. }
  110. List<RepairRegisterPartVo> parts = new ArrayList<>();
  111. for (Integer partId : map.keySet()) {
  112. Part part = partService.getById(partId);
  113. if(part == null){
  114. continue;
  115. }
  116. RepairRegisterPartVo vo = new RepairRegisterPartVo();
  117. vo.setPartId(partId);
  118. vo.setPartName(part.getPartName());
  119. vo.setPartCount(map.get(partId).getCount());
  120. vo.setPartNum(part.getPartNum());
  121. parts.add(vo);
  122. }
  123. return parts;
  124. }
  125. public void partOut(Repair param, Long userId) {
  126. if(StringUtils.isBlank(param.getRepairId())){
  127. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  128. }
  129. Repair repair = repairService.getById(param.getRepairId());
  130. if(repair == null){
  131. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  132. }
  133. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_PREPARED.status())){
  134. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  135. }
  136. List<RepairRegisterPartVo> partVoList = this.partInfo(param.getRepairId(),0);
  137. for (RepairRegisterPartVo partVo : partVoList) {
  138. partService.outStockCheck(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId());
  139. }
  140. for (RepairRegisterPartVo partVo : partVoList) {
  141. partService.outStock(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId());
  142. }
  143. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"备件出库");
  144. }
  145. public void partRecovery(Repair param, Long userId) {
  146. if(StringUtils.isBlank(param.getRepairId())){
  147. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  148. }
  149. Repair repair = repairService.getById(param.getRepairId());
  150. if(repair == null){
  151. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  152. }
  153. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_RECOVERED.status())
  154. && !repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED_RECOVERED.status())){
  155. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  156. }
  157. List<RepairRegisterPartVo> partVoList = this.partInfo(param.getRepairId(),1);
  158. for (RepairRegisterPartVo partVo : partVoList) {
  159. partService.recovery(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId(),repair.getStatus());
  160. }
  161. String remark = null;
  162. if(StringUtils.isNotBlank(param.getRemark())){
  163. remark = "回收备注:"+param.getRemark();
  164. }
  165. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_SHIPPED.status(),repair.getStatus(),"备件回收",remark);
  166. }
  167. }