123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- 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.RepairStatusEnum;
- 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.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.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;
- @Autowired
- RepairSupplyService repairSupplyService;
- /**
- * 售后工程师
- * statusParam 0 待接单,1待跟进,2已完结
- * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
- * * 80待支付(已完结),90待回收,100待发货,110已发货
- */
- public PageInfo saleOrderList(RepairParam param) {
- List<Integer> repairStatus = StatusUtil.getSaleStatus(param.getStatusParam());
- param.setStatusList(repairStatus);
- Page<RepairerVo> voPage = repairService.saleOrderList(param);
- sysUserService.setSaleNameAndRepairManName(voPage.getRecords());
- BigDecimal payAmount;
- for (RepairerVo record : voPage.getRecords()) {
- if(record.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status())){
- payAmount = priceListService.getRobAmountByRepairId(record.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().equals(RepairStatusEnum.TO_BE_RECEIVED.status())){
- 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(), RepairStatusEnum.TO_BE_CHECK.status(),"客服接单");
- }
- 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<Repair> 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);
- }
- }
- }
- CameraDetail cameraDetail = cameraService.getCameraTypeByCameraId(camera.getId());
- Integer cameraType = null;
- switch (cameraDetail.getType()){
- case 9: cameraType = 1;break;
- case 10: cameraType = 2;break;
- default: cameraType = 0; break;
- }
- Date outTime = cameraDetail.getOutTime() == null ? cameraDetail.getCreateTime() : cameraDetail.getOutTime();
- Date date = DateUtil.dateAddOneYear(outTime, 1);
- date = DateUtil.dateAddOne(date, 7);
- String date1 = DateUtil.getDate(DateUtil.dayFmt, date) +" 23:59:59";
- Repair repair = new Repair();
- BeanUtils.copyProperties(param,repair);
- repair.setRepairId(DateUtil.getDate(DateUtil.repairIdFmt));
- repair.setReceiverType(receiverType);
- repair.setCameraType(cameraType);
- repair.setSysUserId(userId);
- repair.setWarrantyDate(date1);
- repair.setWarrantyType(2);
- if(DateUtil.getDateByStr(date1).getTime() >= new Date().getTime()){
- repair.setWarrantyType(0);
- }
- 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(),RepairStatusEnum.TO_BE_RECEIVED.status(),"报修");
- }
- 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().equals(RepairStatusEnum.TO_BE_QUOTED.status())
- && !repair.getStatus().equals(RepairStatusEnum.TO_BE_CONFIRMED.status())){
- throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
- }
- HashMap<Integer,Part> partMap = partService.getHashMap();
- HashMap<Integer,LaborCost> laborMap = laborCostService.getHashMap();
- List<PriceList> priceListList = priceListService.getByRepairId(repair.getRepairId());
- HashMap<Integer,PriceList> priceListHashMap = new HashMap<>();
- priceListList.forEach(entity -> priceListHashMap.put(entity.getPriceListId(),entity));
- priceListService.delNoCm(repair.getRepairId());
- 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.getDiscount() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Part part = partMap.get(priceList.getPartId());
- priceList.setPrice(part.getPartPrice());
- priceList.setPriceDiscount(part.getPartPriceDiscount());
- 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.setPriceListId(null);
- }
- priceList.setRepairId(param.getRepairId());
- if(priceList.getPriceListId() != null){
- PriceList priceList1 = priceListHashMap.get(priceList.getPriceListId());
- if(priceList1 != null){
- priceList.setStatus(priceList1.getStatus());
- }
- priceList.setPriceListId(null);
- priceListService.save(priceList);
- }else {
- priceListService.save(priceList);
- }
- }
- repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_CONFIRMED.status(),"维修报价");
- }
- public PriceListVo getPriceList(String repairId) {
- if(StringUtils.isBlank(repairId)){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- List<PriceList> priceLists = priceListService.getByRepairId(repairId);
- List<RepairLog> repairLogs = repairLogService.getByRepairIdAndStatus(repairId, RepairStatusEnum.TO_BE_CONFIRMED.status());
- 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().equals(RepairStatusEnum.TO_BE_CANCELED.status()) && !repair.getStatus().equals(RepairStatusEnum.TO_BE_PAID.status())){
- throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
- }
- BigDecimal payAmount;
- if(repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status())){
- 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);
- List<RepairRegisterPartVo> partVoList = repairSupplyService.partInfo(repairPay.getRepairId(), 1);
- if(partVoList.size() >0){
- repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_RECOVERED.status(), "付款登记");
- }else {
- repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_SHIPPED.status(), "付款登记");
- }
- }
- 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().equals(RepairStatusEnum.TO_BE_SHIPPED.status())){
- throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
- }
- customerAddressService.setTrackingNumByRepairId(repair.getRepairId(),param.getGetType(),param.getTrackingNum());
- repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.OVER_SHIPPED.status(),"发货登记");
- }
- }
|