123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- 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.common.util.SecurityUtil;
- 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);
- //保外转保内
- if(repair.getWarrantyType() !=0 && param.getConvertWarranty() == 1){
- repairService.updateWarrantyType(repair.getRepairId(),3);
- }
- repairLogService.saveBySysUser(sysUserId,param.getRepairId(), RepairStatusEnum.TO_BE_CHECK.status(),repair.getStatus(),"售后接单");
- }
- 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;
- case 11: cameraType = 3;break;
- default: cameraType = 0; break;
- }
- Date outTime = cameraDetail.getBuyDate() == null ? cameraDetail.getCreateTime() : DateUtil.getDateByStr2(cameraDetail.getBuyDate());
- 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(),repair.getStatus(),"报修");
- }
- 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);
- }
- if(param.getConvertWarranty() == 1){ //保外转保内
- repairService.updateWarrantyType(repair.getRepairId(),3);
- }
- 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());
- Integer status = RepairStatusEnum.TO_BE_CONFIRMED.status();
- for (PriceList priceList : param.getPriceLists()) {
- if(priceList.getType() == null){
- throw new BusinessException(ResultCode.PRICE_TYPE_NOT);
- }
- if(priceList.getCount() == null){
- throw new BusinessException(ResultCode.PRICE_COUNT_NOT);
- }
- if(priceList.getCount() <= 0){
- throw new BusinessException(ResultCode.PRICE_COUNT_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(param.getConvertWarranty() == 1){
- status = RepairStatusEnum.TO_BE_PREPARED.status();
- }
- }
- 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());
- }
- if(priceList.getType() == 2){ //自定义费用
- if(StringUtils.isBlank(priceList.getName()) || priceList.getPrice() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- }
- priceList.setRepairId(param.getRepairId());
- if(priceList.getPriceListId() != null){
- PriceList priceList1 = priceListHashMap.get(priceList.getPriceListId());
- if(priceList1 != null){
- priceList.setStatus(priceList1.getStatus());
- priceList.setRemark(priceList1.getRemark());
- }
- priceList.setPriceListId(null);
- }
- if(param.getConvertWarranty() == 1){
- priceList.setStatus(1);
- }
- priceListService.save(priceList);
- }
- if(param.getConvertWarranty() == 1 && !status.equals(RepairStatusEnum.TO_BE_PREPARED.status())){
- status = RepairStatusEnum.TO_BE_REPAIRED.status();
- }
- repairLogService.saveBySysUser(userId,param.getRepairId(),status,repair.getStatus(),"维修报价");
- }
- public PriceListVo getPriceList(String repairId,Integer isRest) {
- if(StringUtils.isBlank(repairId)){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(isRest == 1){
- return repairRegisterService.getPriceList(repairId);
- }
- List<PriceList> priceLists = priceListService.getByRepairId(repairId);
- Set<Integer> collect = priceLists.stream().map(PriceList::getPartId).collect(Collectors.toSet());
- HashMap<Integer,Part> partHashMap = new HashMap<>();
- if(collect.size() >0){
- List<Part> parts = partService.listByIds(collect);
- parts.forEach(entity -> partHashMap.put(entity.getPartId(),entity));
- }
- for (PriceList priceList : priceLists) {
- if(priceList.getType() == 0 && priceList.getPartId() != null && partHashMap.get(priceList.getPartId()) !=null) {
- priceList.setPartUnit(partHashMap.get(priceList.getPartId()).getPartUnit());
- }
- }
- 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);
- }
- RepairPay byRepairId = repairPayService.getByRepairId(repair.getRepairId(), 1);
- if(byRepairId != null){
- throw new BusinessException(ResultCode.ORDER_PAY_ERROR);
- }
- BigDecimal payAmount;
- String orderSn = null;
- Integer status = null;
- Integer orderType = null;
- if(repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status())){
- payAmount = priceListService.getRobAmountByRepairId(repair.getRepairId());
- orderSn = "c"+DateUtil.getDate(DateUtil.repairIdFmt);
- //status = RepairStatusEnum.TO_BE_CANCELED_RECOVERED.status();
- orderType = 1;
- }else {
- payAmount = priceListService.getAmountByRepairId(repair.getRepairId());
- orderSn = "s"+DateUtil.getDate(DateUtil.repairIdFmt);
- //status = RepairStatusEnum.TO_BE_RECOVERED.status();
- orderType = 0;
- }
- 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(orderType);
- repairPay.setOrderSn(orderSn);
- repairPay.setRemark(param.getRemark());
- repairPayService.save(repairPay);
- repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_PAID_OVER.status(),repair.getStatus(), "付款登记");
- }
- 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(),repair.getStatus(),"发货登记");
- }
- public void signFor(PayRegisterParam param, Long userId) {
- if(StringUtils.isBlank(param.getRepairId()) || param.getTrackingImg() == null || param.getTrackingImg().isEmpty()){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Repair repair = repairService.getById(param.getRepairId());
- if(repair == null){
- throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
- }
- customerAddressService.setTrackingImgByRepairId(repair.getRepairId(),param.getTrackingImg(),userId);
- }
- }
|