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 repairStatus = StatusUtil.getSupplyStatus(param.getStatusParam()); param.setStatusList(repairStatus); Page voPage = repairService.supplyOrderList(param); sysUserService.setSaleNameAndRepairManName(voPage.getRecords()); return PageInfo.PageInfo(voPage); } public List partInfo(String repairId,Integer type) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(PriceList::getRepairId,repairId); wrapper.in(PriceList::getStatus,1); wrapper.eq(PriceList::getType,0); List list = priceListService.list(wrapper); LambdaQueryWrapper 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 map = new HashMap<>(); if(type != 2){ List partLogs = partLogService.list(wrapper2); partLogs.forEach(entity -> map.put(entity.getPartId(),entity)); } HashMap partPriceListMap = new HashMap<>(); for (PriceList priceList : list) { partPriceListMap.merge(priceList.getPartId(), priceList.getCount(), Integer::sum); } List 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 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 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); } }