RepairSupplyService.java 8.4 KB

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