package com.fdkankan.sale.service.impl; import java.math.BigDecimal; import java.util.*; import com.alibaba.fastjson.JSONObject; 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.ResultCode; import com.fdkankan.sale.common.ResultData; 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.*; import com.fdkankan.sale.vo.response.PriceListVo; 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.stream.Collectors; @Service public class RepairSaleService { @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 IPriceListService priceListService; @Autowired IRepairPayService repairPayService; @Autowired IPartService partService; @Autowired ILaborCostService laborCostService; /** * 售后工程师 * statusParam 0 待接单,1待跟进,2已完结 * status 0待接单,1待检测,2待报价,3待确认,4已取消,5待备料,6待回收,7维修中,8待测试, * 9待支付(已完结),10待发货,11已发货,12已评价 */ public PageInfo saleOrderList(RepairParam param) { List repairStatus = StatusUtil.getSaleStatus(param.getStatusParam()); param.setStatusList(repairStatus); Page voPage = repairService.saleOrderList(param); sysUserService.setSaleNameAndRepairManName(voPage.getRecords()); BigDecimal payAmount; for (RepairerVo record : voPage.getRecords()) { if(record.getStatus() == 4){ payAmount = priceListService.getRobAmountByRepairId(param.getRepairId()); }else { payAmount = priceListService.getAmountByRepairId(record.getRepairId()); } record.setPayAmount(payAmount); } return PageInfo.PageInfo(voPage); } public void orderReceiving(OrderReceivingParam param, Long sysUserId ) { if(param.getRepairId() == null){ 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() !=0 ){ throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS); } param.setSysUserId(sysUserId); param.setOrderFaultMsg(param.getCameraFaultInfo()); param.setOrderFaultImg(param.getImageUrl()); orderReceivingService.save(param); repairLogService.saveBySysUser(sysUserId,param.getRepairId(),1,"接单"); } public void recording(RecordingParam param, Long userId,Integer receiverType) { if(StringUtils.isBlank(param.getCameraSnCode())){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } Camera camera = cameraService.getBySnCode(param.getCameraSnCode()); if(camera == null){ throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXITS); } List repairList = repairService.getBySnCode(camera.getSnCode()); if(repairList.size() >0){ for (Repair repair : repairList) { if(!StatusUtil.overStatusList.contains(repair.getStatus())){ throw new BusinessException(ResultCode.REPAIR_SN_EXITS); } } } Integer cameraType = cameraService.getCameraTypeByCameraId(camera.getId()); Repair repair = new Repair(); BeanUtils.copyProperties(param,repair); repair.setRepairId(DateUtil.getDate(DateUtil.repairIdFmt)); repair.setReceiverType(receiverType); repair.setCameraType(cameraType); repair.setSysUserId(userId); Customer customer = new Customer(); BeanUtils.copyProperties(param,customer); customer.setRepairId(repair.getRepairId()); customerService.save(customer); CustomerAddress customerAddress = new CustomerAddress(); BeanUtils.copyProperties(param,customerAddress); customerAddress.setCustomerId(customer.getCustomerId()); customerAddress.setRepairId(repair.getRepairId()); customerAddressService.save(customerAddress); repairService.save(repair); repairLogService.saveBySysUser(userId,repair.getRepairId(),0,"录单"); //自动接单 if(receiverType == 0){ OrderReceiving orderReceiving = new OrderReceiving(); BeanUtils.copyProperties(param,orderReceiving); orderReceiving.setOrderFaultImg(param.getFaultImg()); orderReceiving.setOrderFaultMsg(param.getFaultMsg()); orderReceiving.setSysUserId(userId); orderReceiving.setRepairId(repair.getRepairId()); orderReceivingService.save(orderReceiving); repairLogService.saveBySysUser(userId,repair.getRepairId(),1,"接单"); } } public void addOrUpdatePriceList(PriceListParam param, Long userId) { if(StringUtils.isBlank(param.getRepairId()) || param.getPriceLists() == null || param.getPriceLists().size() <=0){ 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() !=2 && repair.getStatus() !=3){ throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS); } HashMap partMap = partService.getHashMap(); HashMap laborMap = laborCostService.getHashMap(); for (PriceList priceList : param.getPriceLists()) { if(priceList.getType() == null){ throw new BusinessException(ResultCode.PRICE_TYPE_NOT); } if(priceList.getType() == 0){ if(priceList.getPartId() == null || partMap.get(priceList.getPartId()) == null || priceList.getPriceListId() == null){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } Part part = partMap.get(priceList.getPartId()); priceList.setPrice(part.getPartPrice()); priceList.setName(part.getPartName()); } if(priceList.getType() == 1){ if(priceList.getLaborId() == null || laborMap.get(priceList.getLaborId()) == null){ throw new BusinessException(ResultCode.LABOR_ID_EMPTY); } LaborCost laborCost = laborMap.get(priceList.getLaborId()); priceList.setPrice(laborCost.getPrice()); priceList.setName(laborCost.getName()); } priceList.setRepairId(param.getRepairId()); if(priceList.getPriceListId() != null){ PriceList dbPriceList = priceListService.getById(priceList.getPriceListId()); if(dbPriceList.getStatus() != 1){ priceListService.updateById(priceList); } }else { priceListService.save(priceList); } } repairLogService.saveBySysUser(userId,param.getRepairId(),3,"维修报价"); } public PriceListVo getPriceList(String repairId) { if(StringUtils.isBlank(repairId)){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } List priceLists = priceListService.getByRepairId(repairId); List repairLogs = repairLogService.getByRepairIdAndStatus(repairId, 3); PriceListVo priceListVo = new PriceListVo(); priceListVo.setPriceLists(priceLists); priceListVo.setCount(repairLogs.size() +1); return priceListVo; } public void payRegister(PayRegisterParam param,Long userId) { if(StringUtils.isBlank(param.getRepairId()) || param.getPayType() == null || param.getPayImg() == null){ 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() != 4 && repair.getStatus() !=9){ throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS); } BigDecimal payAmount; if(repair.getStatus() == 4){ payAmount = priceListService.getRobAmountByRepairId(repair.getRepairId()); }else { payAmount = priceListService.getAmountByRepairId(repair.getRepairId()); } RepairPay repairPay = new RepairPay(); repairPay.setRepairId(repair.getRepairId()); repairPay.setPayType(param.getPayType()); repairPay.setPayImg(param.getPayImg()); repairPay.setPayStatus(1); repairPay.setSysUserId(userId); repairPay.setPayAmount(payAmount); repairPay.setPayTime(DateUtil.getDate()); repairPay.setOrderType(0); repairPay.setOrderSn("se_s"+DateUtil.getDate(DateUtil.repairIdFmt)); repairPayService.save(repairPay); repairLogService.saveBySysUser(userId,param.getRepairId(),10,"付款登记"); } public void sendRegister(PayRegisterParam param,Long userId) { if(StringUtils.isBlank(param.getRepairId()) || param.getGetType() == null){ 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() !=10){ throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS); } customerAddressService.setTrackingNumByRepairId(repair.getRepairId(),param.getGetType(),param.getTrackingNum()); repairLogService.saveBySysUser(userId,param.getRepairId(),11,"发货登记"); } }