123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package com.fdkankan.sale.service.impl;
- import java.math.BigDecimal;
- import java.util.Date;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.sale.common.PageInfo;
- import com.fdkankan.sale.common.RepairStatusEnum;
- import com.fdkankan.sale.common.ResultCode;
- import com.fdkankan.sale.entity.*;
- import com.fdkankan.sale.exception.BusinessException;
- import com.fdkankan.sale.service.*;
- import com.fdkankan.sale.util.DateUtil;
- import com.fdkankan.sale.util.StatusUtil;
- import com.fdkankan.sale.vo.request.CheckRegisterParam;
- import com.fdkankan.sale.vo.request.OrderReceivingParam;
- import com.fdkankan.sale.vo.request.RecordingParam;
- import com.fdkankan.sale.vo.request.RepairParam;
- import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
- import com.fdkankan.sale.vo.response.RepairerVo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- @Service
- public class RepairSupplyService {
- @Autowired
- IRepairService repairService;
- @Autowired
- IRepairLogService repairLogService;
- @Autowired
- IOrderReceivingService orderReceivingService;
- @Autowired
- ICustomerService customerService;
- @Autowired
- ICustomerAddressService customerAddressService;
- @Autowired
- ICameraService cameraService;
- @Autowired
- ISysUserService sysUserService;
- @Autowired
- IRepairRegisterService repairRegisterService;
- @Autowired
- IRepairRegisterPartService repairRegisterPartService;
- @Autowired
- IPartService partService;
- @Autowired
- IPriceListService priceListService;
- @Autowired
- IPartLogService partLogService;
- /**
- * 维修备件管理 供应链
- * statusParam 0 待备料,1已备料,2待回收
- * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
- * * 80待支付(已完结),90待回收,100待发货,110已发货
- */
- public Object supplyOrderList(RepairParam param) {
- List<Integer> repairStatus = StatusUtil.getSupplyStatus(param.getStatusParam());
- param.setStatusList(repairStatus);
- Page<RepairerVo> voPage = repairService.supplyOrderList(param);
- sysUserService.setSaleNameAndRepairManName(voPage.getRecords());
- return PageInfo.PageInfo(voPage);
- }
- public List<RepairRegisterPartVo> partInfo(String repairId,Integer type) {
- LambdaQueryWrapper<PriceList> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(PriceList::getRepairId,repairId);
- wrapper.in(PriceList::getStatus,1);
- wrapper.eq(PriceList::getType,0);
- List<PriceList> list = priceListService.list(wrapper);
- LambdaQueryWrapper<PartLog> wrapper2 = new LambdaQueryWrapper<>();
- wrapper2.eq(PartLog::getRepairId,repairId);
- if(type == 0 ){ //出库
- wrapper2.eq(PartLog::getStatus,1);
- }
- if(type == 1){ //回收
- wrapper2.eq(PartLog::getStatus,2);
- }
- HashMap<Integer,PartLog> map = new HashMap<>();
- if(type != 2){
- List<PartLog> partLogs = partLogService.list(wrapper2);
- partLogs.forEach(entity -> map.put(entity.getPartId(),entity));
- }
- HashMap<Integer,Integer> partPriceListMap = new HashMap<>();
- for (PriceList priceList : list) {
- partPriceListMap.merge(priceList.getPartId(), priceList.getCount(), Integer::sum);
- }
- List<RepairRegisterPartVo> parts = new ArrayList<>();
- for (Integer partId : partPriceListMap.keySet()) {
- Part part = partService.getById(partId);
- if(part == null){
- continue;
- }
- RepairRegisterPartVo vo = new RepairRegisterPartVo();
- vo.setPartId(partId);
- vo.setPartName(part.getPartName());
- vo.setPartCount(partPriceListMap.get(partId));
- vo.setPartNum(part.getPartNum());
- if(type != 2){
- PartLog partLog = map.get(part.getPartId());
- if(partLog != null){
- Integer count = partLog.getCount();
- vo.setPartCount(vo.getPartCount() - count);
- }
- if(vo.getPartCount() <=0){
- continue;
- }
- }
- parts.add(vo);
- }
- return parts;
- }
- public void partOut(Repair param, Long userId) {
- if(StringUtils.isBlank(param.getRepairId())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Repair repair = repairService.getById(param.getRepairId());
- if(repair == null){
- throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
- }
- if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_PREPARED.status())){
- throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
- }
- List<RepairRegisterPartVo> partVoList = this.partInfo(param.getRepairId(),0);
- for (RepairRegisterPartVo partVo : partVoList) {
- partService.outStockCheck(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId());
- }
- for (RepairRegisterPartVo partVo : partVoList) {
- partService.outStock(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId());
- }
- repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"备件出库");
- }
- public void partRecovery(Repair param, Long userId) {
- if(StringUtils.isBlank(param.getRepairId())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Repair repair = repairService.getById(param.getRepairId());
- if(repair == null){
- throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
- }
- if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_RECOVERED.status())
- && !repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED_RECOVERED.status())){
- throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
- }
- List<RepairRegisterPartVo> partVoList = this.partInfo(param.getRepairId(),1);
- for (RepairRegisterPartVo partVo : partVoList) {
- partService.recovery(partVo.getPartId(),partVo.getPartCount(),userId,repair.getRepairId(),repair.getStatus());
- }
- String remark = null;
- if(StringUtils.isNotBlank(param.getRemark())){
- remark = "回收备注:"+param.getRemark();
- }
- repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_SHIPPED.status(),repair.getStatus(),"备件回收",remark);
- }
- }
|