diff --git a/src/main/java/com/bonus/gzcar/business/backstage/service/CarPlanAuditServiceImpl.java b/src/main/java/com/bonus/gzcar/business/backstage/service/CarPlanAuditServiceImpl.java index 5d50235..02157f7 100644 --- a/src/main/java/com/bonus/gzcar/business/backstage/service/CarPlanAuditServiceImpl.java +++ b/src/main/java/com/bonus/gzcar/business/backstage/service/CarPlanAuditServiceImpl.java @@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -79,80 +80,95 @@ public class CarPlanAuditServiceImpl implements CarPlanAuditService{ */ @Override public ServerResponse auditInfo(AuditInfoDataVo data) { - try{ - String userId= Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); - CarNeedPlanVo carNeedPlanVo=new CarNeedPlanVo(); + try { + String userId = Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); + String userName = Objects.requireNonNull(UserUtil.getLoginUser()).getRoleName(); + // 查询当前计划详情 + CarNeedPlanVo carNeedPlanVo = new CarNeedPlanVo(); carNeedPlanVo.setId(data.getId()); - CarNeedPlanVo vo=mapper.getCarAuditDetails(carNeedPlanVo); - int status=vo.getStatus(); - int statusType=vo.getStatusType(); + CarNeedPlanVo vo = mapper.getCarAuditDetails(carNeedPlanVo); + int status = vo.getStatus(); + int statusType = vo.getStatusType(); vo.setCreator(userId); - int nums =mapper.getAuditNumByUser(vo); - if(nums>0){ - return ServerResponse.createErroe("您已审核通过,请等待其他用户审核"); + + // 判断是否已审核过 + int nums = mapper.getAuditNumByUser(vo); + if (nums > 0) { + return ServerResponse.createErroe("您已审核,请勿重复提交,请等待其他用户审核"); } - if(1==statusType){ - return ServerResponse.createErroe("该数据已被审核请刷新后重试"); + if (statusType == 1 || status == 2) { + return ServerResponse.createErroe("该数据已被审核,请刷新后重试"); } - if(2==status){ - return ServerResponse.createErroe("该数据已被审核请刷新后重试"); + + // 权限校验 + if (!hasAuditPermission(statusType, userName)) { + return ServerResponse.createErroe("该账号无权限审核当前节点"); } - //查询用户是否有审核权限 - boolean isPermission=sysAuditService.getUserPermission("car_plan",statusType); - //查询 审核 类型 - if(!isPermission){ - return ServerResponse.createErroe("该账号无权限审核"); - } - //1 会签 2 或签 - int auditType=sysAuditService.getAuditType("car_plan",statusType); - //审核 通过 - String upTimes=recordService.getUpTimes(data.getId(),vo.getStatusType(),data.getStatus()); - if(2==data.getStatus()){ - //添加审核记录 - recordService.addRecord(data.getId(),data.getStatus()+"",vo.getStatusType()+"","3",data.getRemark(),upTimes); - //或签 - if(2==auditType){ - //更新状态 - if(vo.getStatusType()==3){ - data.setNextStatus(1); - }else { - data.setStatus(1); - data.setNextStatus(vo.getStatusType()+1); - } - int num= mapper.updatePlanAudit(data); - if(num>0){ - return ServerResponse.createBySuccessMsg("审核通过成功"); - } - }else{ - // 会签 ->查询是否 所设置的人已全部审核 - boolean isNext=sysAuditService.getNextAuditStatus(data.getId(),"car_plan",statusType); - //进入下一个节点则更新 - if(isNext){ - if(vo.getStatusType()==3){ - data.setNextStatus(1); - }else { - data.setStatus(1); - data.setNextStatus(vo.getStatusType()+1); - } - int num= mapper.updatePlanAudit(data); - if(num>0){ - return ServerResponse.createBySuccessMsg("审核通过成功"); - } - }else{ - return ServerResponse.createBySuccessMsg("审核成功,等待其他人继续审核"); - } + + String upTimes = recordService.getUpTimes(data.getId(), vo.getStatusType(), data.getStatus()); + /* int auditType = sysAuditService.getAuditType("car_plan", statusType);*/ + + // 审核通过 + if (data.getStatus() == 2) { + recordService.addRecord(data.getId(), String.valueOf(data.getStatus()), + String.valueOf(vo.getStatusType()), "3", data.getRemark(), upTimes); + + data.setStatus(1); + data.setNextStatus(getNextStatusType(statusType)); + + if (mapper.updatePlanAudit(data) > 0) { + return ServerResponse.createBySuccessMsg("审核通过成功"); } - } else{ - recordService.addRecord(data.getId(),data.getStatus()+"",vo.getStatusType()+"","3",data.getRemark(),upTimes); - int num= mapper.updatePlanAudit(data); - if(num>0){ + } else { // 驳回 + recordService.addRecord(data.getId(), String.valueOf(data.getStatus()), + String.valueOf(vo.getStatusType()), "3", data.getRemark(), upTimes); + if (mapper.updatePlanAudit(data) > 0) { return ServerResponse.createBySuccessMsg("审核驳回成功"); } } - }catch (Exception e){ - log.error(e.toString()); + } catch (Exception e) { + log.error("审核异常", e); } return ServerResponse.createErroe("审核失败"); } + + /** + * 审核节点定义 + */ + public static class AuditNode { + public static final int PLAN_DEPT = 1; // 计划项目部 + public static final int MGMT_CENTER = 2; // 项目管理中心 + public static final int EQUIP_DEPT = 3; // 智联装备云控公司机具部(王伟) + public static final int LIFT_TEAM = 4; // 放线吊车班(或签) + } + + /** + * 获取下一个状态类型 + */ + private int getNextStatusType(int currentStatusType) { + switch (currentStatusType) { + case AuditNode.PLAN_DEPT: return AuditNode.MGMT_CENTER; + case AuditNode.MGMT_CENTER: return AuditNode.EQUIP_DEPT; + case AuditNode.EQUIP_DEPT: return AuditNode.LIFT_TEAM; + case AuditNode.LIFT_TEAM: return 1; // 审核结束或流程回到初始 + default: return 1; + } + } + + /** + * 判断用户是否有当前节点的权限 + */ + private boolean hasAuditPermission(int statusType, String userName) { + if (statusType == AuditNode.PLAN_DEPT || statusType == AuditNode.MGMT_CENTER) { + return sysAuditService.getUserPermission("car_plan", statusType); + } else if (statusType == AuditNode.EQUIP_DEPT) { + return "王炜".equals(userName); + } else if (statusType == AuditNode.LIFT_TEAM) { + List liftTeamUsers = Arrays.asList("雷治明", "黄廉飞", "刘晓", "张杰"); + return liftTeamUsers.contains(userName); + } + return false; + } + } diff --git a/src/main/java/com/bonus/gzcar/business/backstage/service/DispatchCarServiceImpl.java b/src/main/java/com/bonus/gzcar/business/backstage/service/DispatchCarServiceImpl.java index bb3a179..1b95282 100644 --- a/src/main/java/com/bonus/gzcar/business/backstage/service/DispatchCarServiceImpl.java +++ b/src/main/java/com/bonus/gzcar/business/backstage/service/DispatchCarServiceImpl.java @@ -233,95 +233,71 @@ public class DispatchCarServiceImpl implements DispatchCarService{ } public void deleteData(CarNeedPlanVo data){ - mapper.deleteOutData(data); - mapper.deleteOutDetails(data); - mapper.deleteOutDataRecord(data); - mapper.deleteOutDetailsRecord(data); + mapper.deleteOutData(data); + mapper.deleteOutDetails(data); + mapper.deleteOutDataRecord(data); + mapper.deleteOutDetailsRecord(data); } - /** - * 车辆配送=-审核 - * @param data - * @return - * 2025-05-16增加分管领导审核 - */ @Override public ServerResponse dispatchAudit(CarPlanOutVo data) { try { - //获取用户信息 SelfUserEntity loginUser = UserUtil.getLoginUser(); - String status = data.getStatus(); + String roleName = loginUser.getRoleName(); + String status = data.getStatus(); // 前端传入:2=驳回,其它=通过 String remark = data.getRemark(); - CarPlanOutVo vo = mapper.getCarPlanOut(data); - CarNeedPlanVo carNeedPlanVo = mapper.getPlanInfo(data); - if ("娄强".equals(loginUser.getRoleName())) { - if (!"3".equals(vo.getStatus())) { - return ServerResponse.createErroe("还未到您审核,请刷新后重试"); - } else { - if ("2".equals(status)) { - //驳回 - int num = mapper.updateDispatchData(data); - if (num > 0) { - List list = mapper.getAuditList(data); - if (ListHelpUtil.isEmpty(list)) { - carNeedPlanVo.setStatus(2); - } else { - carNeedPlanVo.setStatus(0); - } - //更新计划状态 - mapper.updatePlanInfo(carNeedPlanVo); - } - } else { - //通过 - int num = mapper.updateDispatchData(data); - if (num > 0) { - List list = mapper.getAuditList(data); - int dispatchNum = carNeedPlanVo.getDispatchNum(); - carNeedPlanVo.setDispatchDay(DateTimeHelper.getNowDay()); - carNeedPlanVo.setDispatchNum(dispatchNum + vo.getDispatchNum()); - if (ListHelpUtil.isEmpty(list)) { - carNeedPlanVo.setStatus(1); - } else { - carNeedPlanVo.setStatus(2); - } - //更新计划信息 - mapper.updateCarPlanInfo(carNeedPlanVo); - } - } - } - } else { - if (!"0".equals(vo.getStatus())) { - return ServerResponse.createErroe("待分管领导审核,请刷新后重试"); - } else { - if ("2".equals(status)) { - //驳回 - int num = mapper.updateDispatchData(data); - if (num > 0) { - List list = mapper.getAuditList(data); - if (ListHelpUtil.isEmpty(list)) { - carNeedPlanVo.setStatus(2); - } else { - carNeedPlanVo.setStatus(0); - } - //更新计划状态 - mapper.updatePlanInfo(carNeedPlanVo); - } - } else { - //通过,只修改状态 - data.setStatus("3"); - int num = mapper.updateDispatchData(data); - } - } + + CarPlanOutVo vo = mapper.getCarPlanOut(data); // 当前记录 + String currentStatus = vo.getStatus(); + + // 计算审核后的目标状态 + String targetStatus = determineNextStatus(roleName, currentStatus, status); + if (targetStatus == null) { + return ServerResponse.createErroe("无权审核或状态不匹配,请刷新后重试"); } - String uptime = recordService.getUpTimes("out-" + data.getId(), Integer.parseInt(status)); - recordService.addRecord("out-" + data.getId(), status, "2", "3", remark, uptime); + + // 更新数据 + data.setStatus(targetStatus); + int updated = mapper.updateDispatchData(data); + if (updated <= 0) { + return ServerResponse.createErroe("审核操作失败,请稍后重试"); + } + + // 写操作记录 + String uptime = recordService.getUpTimes("out-" + data.getId(), Integer.parseInt(targetStatus)); + recordService.addRecord("out-" + data.getId(), targetStatus, "2", "3", remark, uptime); + return ServerResponse.createBySuccessMsg("审核成功"); } catch (Exception e) { - log.error(e.toString(), e); + log.error("dispatchAudit 异常: {}", e.toString(), e); + return ServerResponse.createErroe("审核失败,请稍后重试"); } - return ServerResponse.createErroe("审核失败,请稍后重试"); } + private String determineNextStatus(String roleName, String currentStatus, String actionStatus) { + if ("2".equals(actionStatus)) { + // 驳回统一到状态9 + if (isSecondLevelApprover(roleName) && "1".equals(currentStatus)) return "9"; + if (isThirdLevelApprover(roleName) && "2".equals(currentStatus)) return "9"; + } else { + // 通过流转到下一状态 + if (isSecondLevelApprover(roleName) && "0".equals(currentStatus)) return "1"; + if (isThirdLevelApprover(roleName) && "1".equals(currentStatus)) return "2"; + } + return null; // 不符合条件 + } + + + private boolean isSecondLevelApprover(String roleName) { + return "雷治明".equals(roleName) || "黄廉飞".equals(roleName) + || "刘晓".equals(roleName) || "张杰".equals(roleName); + } + + private boolean isThirdLevelApprover(String roleName) { + return "娄强".equals(roleName); + } + + /** * @param data diff --git a/src/main/java/com/bonus/gzcar/business/backstage/service/SupDispatchCarServiceImpl.java b/src/main/java/com/bonus/gzcar/business/backstage/service/SupDispatchCarServiceImpl.java index 46866a1..0bb83ad 100644 --- a/src/main/java/com/bonus/gzcar/business/backstage/service/SupDispatchCarServiceImpl.java +++ b/src/main/java/com/bonus/gzcar/business/backstage/service/SupDispatchCarServiceImpl.java @@ -32,11 +32,12 @@ import java.util.Objects; /** * 供应商 派车录入业务层 + * * @author 黑子 */ @Slf4j @Service -public class SupDispatchCarServiceImpl implements SupDispatchCarService{ +public class SupDispatchCarServiceImpl implements SupDispatchCarService { @Autowired private SupDispatchCarMapper mapper; @@ -49,21 +50,21 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ @Override public List getPlanListBySup(CarNeedPlanVo data) { - try{ + try { return mapper.getPlanListBySup(data); - }catch (Exception e){ - log.error(e.toString(),e); + } catch (Exception e) { + log.error(e.toString(), e); } return new ArrayList<>(); } @Override public ServerResponse getDetailsList(CarNeedPlanVo data) { - List list=new ArrayList<>(); + List list = new ArrayList<>(); try { - list=mapper.getDetailsList(data); - }catch (Exception e){ + list = mapper.getDetailsList(data); + } catch (Exception e) { log.error(e.toString()); } return ServerResponse.createSuccess(list); @@ -71,85 +72,86 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ /** * 新增派车信息 + * * @param request * @param files * @return */ @Override - public ServerResponse addDispatchCarData(HttpServletRequest request, MultipartFile[] files,String[] types) { - try{ - String params=request.getParameter("params"); - if(StringHelper.isEmpty(params)){ - return ServerResponse.createErroe("请求参数缺失"); + public ServerResponse addDispatchCarData(HttpServletRequest request, MultipartFile[] files, String[] types) { + try { + String params = request.getParameter("params"); + if (StringHelper.isEmpty(params)) { + return ServerResponse.createErroe("请求参数缺失"); } - if(files==null || files.length<1 || types==null || files.length!=types.length){ - return ServerResponse.createErroe("请先上传文件"); + if (files == null || files.length < 1 || types == null || files.length != types.length) { + return ServerResponse.createErroe("请先上传文件"); } - String userId= Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); + String userId = Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); CarPlanOutVo outVo = JSON.parseObject(params, CarPlanOutVo.class); - Integer jsNum=mapper.validateSltNum(outVo); - if(jsNum!=null && jsNum>0){ - return ServerResponse.createErroe("该计划已被结算,不允许修改"); + Integer jsNum = mapper.validateSltNum(outVo); + if (jsNum != null && jsNum > 0) { + return ServerResponse.createErroe("该计划已被结算,不允许修改"); } //文件进行分类存储 - Map> fileMaps= Maps.newHashMap(); + Map> fileMaps = Maps.newHashMap(); for (int i = 0; i < types.length; i++) { - String key=types[i]; - MultipartFile file=files[i]; - if(fileMaps.containsKey(key)){ - List multipartFiles=fileMaps.get(key); - multipartFiles.add(file); - fileMaps.put(key,multipartFiles); - }else{ - List fileList=new ArrayList<>(); - fileList.add(file); - fileMaps.put(key,fileList); - } + String key = types[i]; + MultipartFile file = files[i]; + if (fileMaps.containsKey(key)) { + List multipartFiles = fileMaps.get(key); + multipartFiles.add(file); + fileMaps.put(key, multipartFiles); + } else { + List fileList = new ArrayList<>(); + fileList.add(file); + fileMaps.put(key, fileList); + } } outVo.setCreator(userId); outVo.setUpdater(userId); - int planType=outVo.getPlanType(); - List detailsVoList=outVo.getDetailsVoList(); - String msg=getContractMoney(detailsVoList,planType,outVo); + int planType = outVo.getPlanType(); + List detailsVoList = outVo.getDetailsVoList(); + String msg = getContractMoney(detailsVoList, planType, outVo); //校验及计算 - if(StringHelper.isNotEmpty(msg)){ + if (StringHelper.isNotEmpty(msg)) { return ServerResponse.createErroe(msg); } outVo.setDispatchNum(detailsVoList.size()); - int num=mapper.addDispatchCarData(outVo); - mapper.addDispatchCarDataRecord(outVo); - if(num>0){ - List basic=fileMaps.get("basic"); - if(basic==null || basic.isEmpty()){ - return ServerResponse.createErroe("请上传基础文件"); - }else{ + int num = mapper.addDispatchCarData(outVo); + mapper.addDispatchCarDataRecord(outVo); + if (num > 0) { + List basic = fileMaps.get("basic"); + if (basic == null || basic.isEmpty()) { + return ServerResponse.createErroe("请上传基础文件"); + } else { MultipartFile[] basicfile = basic.toArray(new MultipartFile[0]); - uploadService.uploadImage(basicfile,outVo.getId(),"car_plan_out","派车附件"); + uploadService.uploadImage(basicfile, outVo.getId(), "car_plan_out", "派车附件"); } - for (CarPlanOutVoDetailsVo detailsVo:detailsVoList){ + for (CarPlanOutVoDetailsVo detailsVo : detailsVoList) { detailsVo.setPlanId(outVo.getPlanId()); detailsVo.setOutId(outVo.getId()); detailsVo.setSupId(outVo.getSupId()); - int success= mapper.addDispatchCarDetailsData(detailsVo); - detailsVo.setRelId(outVo.getOutId()); - mapper.addDispatchCarDetailsDataRecord(detailsVo); - if(success>0){ - List modelFile=fileMaps.get(detailsVo.getFileType()); - if(modelFile!=null && !modelFile.isEmpty()){ + int success = mapper.addDispatchCarDetailsData(detailsVo); + detailsVo.setRelId(outVo.getOutId()); + mapper.addDispatchCarDetailsDataRecord(detailsVo); + if (success > 0) { + List modelFile = fileMaps.get(detailsVo.getFileType()); + if (modelFile != null && !modelFile.isEmpty()) { MultipartFile[] modelFiles = modelFile.toArray(new MultipartFile[0]); - uploadService.uploadImage(modelFiles,detailsVo.getId(),"car_plan_out_details","导航截图"); + uploadService.uploadImage(modelFiles, detailsVo.getId(), "car_plan_out_details", "导航截图"); } - }else{ + } else { return ServerResponse.createErroe("新增派车失败"); } } } mapper.updatePlanInfo(outVo); - recordService.addRecord("out-"+outVo.getId(),"0","1","2","派车提交","0"); + recordService.addRecord("out-" + outVo.getId(), "0", "1", "2", "派车提交", "0"); return ServerResponse.createBySuccessMsg("派车成功"); - }catch (Exception e){ - log.error(e.toString(),e); + } catch (Exception e) { + log.error(e.toString(), e); } return ServerResponse.createErroe("新增派车失败"); @@ -157,197 +159,197 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ /** * 车辆修改前回显 + * * @param data * @return */ @Override public ServerResponse getDispatchCarData(CarPlanOutVo data) { - try{ - CarPlanOutVo vo=mapper.getDispatchCarData(data); - if(vo!=null){ - List fileList=uploadService.getFileList(data.getId(),"car_plan_out",""); + try { + CarPlanOutVo vo = mapper.getDispatchCarData(data); + if (vo != null) { + List fileList = uploadService.getFileList(data.getId(), "car_plan_out", ""); vo.setFileList(fileList); - List list=mapper.getDispatchCarDetailsList(data); - for (CarPlanOutVoDetailsVo detailsVo:list){ - List fileList2=uploadService.getFileList(detailsVo.getId(),"car_plan_out_details",""); + List list = mapper.getDispatchCarDetailsList(data); + for (CarPlanOutVoDetailsVo detailsVo : list) { + List fileList2 = uploadService.getFileList(detailsVo.getId(), "car_plan_out_details", ""); detailsVo.setFileList(fileList2); - List carImage=uploadService.getFileList(detailsVo.getCarId(),"car_supplier_info",""); + List carImage = uploadService.getFileList(detailsVo.getCarId(), "car_supplier_info", ""); detailsVo.setCarImage(carImage); - List driverUserImage=uploadService.getFileList(detailsVo.getDriverUserId(),"car_driver_info",""); + List driverUserImage = uploadService.getFileList(detailsVo.getDriverUserId(), "car_driver_info", ""); detailsVo.setDriverUserImage(driverUserImage); - List operaImage=uploadService.getFileList(detailsVo.getOperaUserId(),"car_driver_info",""); + List operaImage = uploadService.getFileList(detailsVo.getOperaUserId(), "car_driver_info", ""); detailsVo.setOperaImage(operaImage); } - List record= recordService.getRecordList("out-"+data.getId()); + List record = recordService.getRecordList("out-" + data.getId()); vo.setRecordList(record); vo.setDetailsVoList(list); } - return ServerResponse.createSuccess("查询成功",vo); - }catch (Exception e){ - log.error(e.toString(),e); + return ServerResponse.createSuccess("查询成功", vo); + } catch (Exception e) { + log.error(e.toString(), e); } - return ServerResponse.createSuccess("查询失败",new CarPlanOutVo()); + return ServerResponse.createSuccess("查询失败", new CarPlanOutVo()); } + /** * 修改计划 + * * @param request * @param files * @return */ @Override - public ServerResponse updateDispatchCarData(HttpServletRequest request, MultipartFile[] files,String[] types) { - try{ - String params=request.getParameter("params"); - if(StringHelper.isEmpty(params)){ - return ServerResponse.createErroe("请求参数缺失"); + public ServerResponse updateDispatchCarData(HttpServletRequest request, MultipartFile[] files, String[] types) { + try { + String params = request.getParameter("params"); + if (StringHelper.isEmpty(params)) { + return ServerResponse.createErroe("请求参数缺失"); } //文件进行分类存储 - Map> fileMaps= Maps.newHashMap(); - if(files!=null && files.length>0 && types!=null && types.length>0 ){ + Map> fileMaps = Maps.newHashMap(); + if (files != null && files.length > 0 && types != null && types.length > 0) { for (int i = 0; i < types.length; i++) { - String key=types[i]; - MultipartFile file=files[i]; - if(fileMaps.containsKey(key)){ - List multipartFiles=fileMaps.get(key); + String key = types[i]; + MultipartFile file = files[i]; + if (fileMaps.containsKey(key)) { + List multipartFiles = fileMaps.get(key); multipartFiles.add(file); - fileMaps.put(key,multipartFiles); - }else{ - List fileList=new ArrayList<>(); + fileMaps.put(key, multipartFiles); + } else { + List fileList = new ArrayList<>(); fileList.add(file); - fileMaps.put(key,fileList); + fileMaps.put(key, fileList); } } } - - - String userId= Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); + String userId = Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); CarPlanOutVo outVo = JSON.parseObject(params, CarPlanOutVo.class); - int sltNum=mapper.getSltNumByPlan(outVo); - if(sltNum>0){ - return ServerResponse.createErroe("当前计划已结算,不允许修改"); + int sltNum = mapper.getSltNumByPlan(outVo); + if (sltNum > 0) { + return ServerResponse.createErroe("当前计划已结算,不允许修改"); } - int planType=outVo.getPlanType(); + int planType = outVo.getPlanType(); outVo.setUpdater(userId); - List detailsVoList=outVo.getDetailsVoList(); - String msg=getContractMoney(detailsVoList,planType,outVo); + List detailsVoList = outVo.getDetailsVoList(); + String msg = getContractMoney(detailsVoList, planType, outVo); //校验及计算 - if(StringHelper.isNotEmpty(msg)){ + if (StringHelper.isNotEmpty(msg)) { return ServerResponse.createErroe(msg); } outVo.setDispatchNum(detailsVoList.size()); - int num=mapper.updateDispatchCarData(outVo); - if(StringHelper.isNotEmpty(outVo.getStatus())){ + int num = mapper.updateDispatchCarData(outVo); + if (StringHelper.isNotEmpty(outVo.getStatus())) { mapper.updatePlanInfo(outVo); } - if(num>0){ - if(StringHelper.isNotEmpty(outVo.getDelFileId())){ + if (num > 0) { + if (StringHelper.isNotEmpty(outVo.getDelFileId())) { uploadService.deleteFile(outVo.getDelFileId()); } - List basic=fileMaps.get("basic"); - if(ListHelpUtil.isNotEmpty(basic)){ + List basic = fileMaps.get("basic"); + if (ListHelpUtil.isNotEmpty(basic)) { MultipartFile[] basicfile = basic.toArray(new MultipartFile[0]); - uploadService.uploadImage(basicfile,outVo.getId(),"car_plan_out","派车附件"); + uploadService.uploadImage(basicfile, outVo.getId(), "car_plan_out", "派车附件"); } - if("0".equals(outVo.getStatus())){ - outVo.setResource("1"); - }else{ - outVo.setResource("0"); + if ("0".equals(outVo.getStatus())) { + outVo.setResource("1"); + } else { + outVo.setResource("0"); + } + mapper.addDispatchCarDataRecord(outVo); + for (CarPlanOutVoDetailsVo detailsVo : detailsVoList) { + CarPlanOutVoDetailsVo hisDetails = mapper.getCarPlanOutVoDetailsVo(detailsVo); + //修改车辆详情 + mapper.updateDispatchCarDetailsData(detailsVo); + List modelFile = fileMaps.get(detailsVo.getFileType()); + if (ListHelpUtil.isNotEmpty(modelFile)) { + MultipartFile[] modelFiles = modelFile.toArray(new MultipartFile[0]); + uploadService.uploadImage(modelFiles, detailsVo.getId(), "car_plan_out_details", "导航截图"); + } + if (planType == 1) { + if (!detailsVo.getCarId().equals(hisDetails.getCarId())) { + detailsVo.setUpdateCar("1"); + } + } else { + if (!detailsVo.getCarNum().equals(hisDetails.getCarNum())) { + detailsVo.setUpdateCar("1"); + } + } + if (planType == 1) { + if (!detailsVo.getGls().equals(hisDetails.getGls())) { + detailsVo.setUpdateGls("1"); + } + if (!detailsVo.getStartAddress().equals(hisDetails.getStartAddress())) { + detailsVo.setUpdateStartAddress("1"); + } + if (!detailsVo.getEndAddress().equals(hisDetails.getEndAddress())) { + detailsVo.setUpdateEndAddress("1"); + } + } else { + if (detailsVo.getPlanDay() != hisDetails.getPlanDay()) { + detailsVo.setUpdateDay("1"); + } + if (StringHelper.isNotEmpty(detailsVo.getJcMoney())) { + if (!detailsVo.getJcMoney().equals(hisDetails.getJcMoney())) { + detailsVo.setUpdateCcGls("1"); + } } - mapper.addDispatchCarDataRecord(outVo); - for (CarPlanOutVoDetailsVo detailsVo:detailsVoList){ - CarPlanOutVoDetailsVo hisDetails=mapper.getCarPlanOutVoDetailsVo(detailsVo); - //修改车辆详情 - mapper.updateDispatchCarDetailsData(detailsVo); - List modelFile=fileMaps.get(detailsVo.getFileType()); - if(ListHelpUtil.isNotEmpty(modelFile)){ - MultipartFile[] modelFiles = modelFile.toArray(new MultipartFile[0]); - uploadService.uploadImage(modelFiles,detailsVo.getId(),"car_plan_out_details","导航截图"); - } - if(planType==1) { - if (!detailsVo.getCarId().equals(hisDetails.getCarId())) { - detailsVo.setUpdateCar("1"); - } - }else{ - if (!detailsVo.getCarNum().equals(hisDetails.getCarNum())) { - detailsVo.setUpdateCar("1"); - } - } - if(planType==1){ - if(!detailsVo.getGls().equals(hisDetails.getGls())){ - detailsVo.setUpdateGls("1"); - } - if(!detailsVo.getStartAddress().equals(hisDetails.getStartAddress())){ - detailsVo.setUpdateStartAddress("1"); - } - if(!detailsVo.getEndAddress().equals(hisDetails.getEndAddress())){ - detailsVo.setUpdateEndAddress("1"); - } - }else{ - if(detailsVo.getPlanDay()!=hisDetails.getPlanDay()){ - detailsVo.setUpdateDay("1"); - } - if(StringHelper.isNotEmpty(detailsVo.getJcMoney())){ - if(!detailsVo.getJcMoney().equals(hisDetails.getJcMoney())){ - detailsVo.setUpdateCcGls("1"); - } - } - } - detailsVo.setPlanId(outVo.getPlanId()); - detailsVo.setOutId(outVo.getId()); - detailsVo.setRelId(outVo.getOutId()); - mapper.addDispatchCarDetailsDataRecord(detailsVo); + } + detailsVo.setPlanId(outVo.getPlanId()); + detailsVo.setOutId(outVo.getId()); + detailsVo.setRelId(outVo.getOutId()); + mapper.addDispatchCarDetailsDataRecord(detailsVo); - } + } } return ServerResponse.createBySuccessMsg("修改成功"); - }catch (Exception e){ - log.error(e.toString(),e); + } catch (Exception e) { + log.error(e.toString(), e); } return ServerResponse.createErroe("修改派车失败"); } - - @Override public ServerResponse getAllOutList(CarPlanOutVo data) { - List list=new ArrayList<>(); - try { - list=mapper.getAllOutList(data); - }catch (Exception e){ - log.error(e.toString()); - } + List list = new ArrayList<>(); + try { + list = mapper.getAllOutList(data); + } catch (Exception e) { + log.error(e.toString()); + } return ServerResponse.createSuccess(list); } /** * 到货确认单查询 + * * @param data * @return */ @Override public List getOutPageList(CarNeedPlanVo data) { - List list=new ArrayList<>(); + List list = new ArrayList<>(); try { - String userId= Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); + String userId = Objects.requireNonNull(UserUtil.getLoginUser()).getUserId().toString(); data.setCreator(userId); data.setUserId(userId); - list=mapper.getOutPageList(data); - for (CarNeedPlanVo carNeedPlanVo:list){ - if(carNeedPlanVo.getFileNum()>0){ - List fileList= uploadService.getFileList(carNeedPlanVo.getId()+"-dh","car_plan_out","到货确认单"); + list = mapper.getOutPageList(data); + for (CarNeedPlanVo carNeedPlanVo : list) { + if (carNeedPlanVo.getFileNum() > 0) { + List fileList = uploadService.getFileList(carNeedPlanVo.getId() + "-dh", "car_plan_out", "到货确认单"); carNeedPlanVo.setFileList(fileList); } } - }catch (Exception e){ + } catch (Exception e) { log.error(e.toString()); } return list; @@ -355,6 +357,7 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ /** * 到货确认单 + * * @param request * @param files * @return @@ -362,60 +365,60 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ @Override public ServerResponse uploadFile(HttpServletRequest request, MultipartFile[] files) { try { - String params=request.getParameter("params"); + String params = request.getParameter("params"); - if(StringHelper.isEmpty(params)){ - return ServerResponse.createErroe("请求参数缺失"); - } - JSONObject json=JSON.parseObject(params); - params=json.get("id").toString(); - uploadService.uploadImage(files,params+"-dh","car_plan_out","到货确认单"); - return ServerResponse.createBySuccessMsg("上传成功"); - }catch (Exception e){ - log.error(e.toString()); + if (StringHelper.isEmpty(params)) { + return ServerResponse.createErroe("请求参数缺失"); } - return ServerResponse.createErroe("上传失败"); + JSONObject json = JSON.parseObject(params); + params = json.get("id").toString(); + uploadService.uploadImage(files, params + "-dh", "car_plan_out", "到货确认单"); + return ServerResponse.createBySuccessMsg("上传成功"); + } catch (Exception e) { + log.error(e.toString()); + } + return ServerResponse.createErroe("上传失败"); } @Override public ServerResponse getDispatchCarData2(CarPlanOutVo data) { - try{ - CarPlanOutVo vo=mapper.getDispatchCarData(data); - if(vo!=null){ - List fileList=uploadService.getFileList(data.getId(),"car_plan_out",""); - List fileList0=uploadService.getFileList(data.getId()+"-dh","car_plan_out",""); - if(ListHelpUtil.isNotEmpty(fileList0) && ListHelpUtil.isNotEmpty(fileList)){ + try { + CarPlanOutVo vo = mapper.getDispatchCarData(data); + if (vo != null) { + List fileList = uploadService.getFileList(data.getId(), "car_plan_out", ""); + List fileList0 = uploadService.getFileList(data.getId() + "-dh", "car_plan_out", ""); + if (ListHelpUtil.isNotEmpty(fileList0) && ListHelpUtil.isNotEmpty(fileList)) { fileList.addAll(fileList0); } vo.setFileList(fileList); - List list=mapper.getDispatchCarDetailsList(data); - for (CarPlanOutVoDetailsVo detailsVo:list){ - List fileList2=uploadService.getFileList(detailsVo.getId(),"car_plan_out_details",""); + List list = mapper.getDispatchCarDetailsList(data); + for (CarPlanOutVoDetailsVo detailsVo : list) { + List fileList2 = uploadService.getFileList(detailsVo.getId(), "car_plan_out_details", ""); detailsVo.setFileList(fileList2); - List carImage=uploadService.getFileList(detailsVo.getCarId(),"car_supplier_info",""); + List carImage = uploadService.getFileList(detailsVo.getCarId(), "car_supplier_info", ""); detailsVo.setCarImage(carImage); - List driverUserImage=uploadService.getFileList(detailsVo.getDriverUserId(),"car_driver_info",""); + List driverUserImage = uploadService.getFileList(detailsVo.getDriverUserId(), "car_driver_info", ""); detailsVo.setDriverUserImage(driverUserImage); - List operaImage=uploadService.getFileList(detailsVo.getOperaUserId(),"car_driver_info",""); + List operaImage = uploadService.getFileList(detailsVo.getOperaUserId(), "car_driver_info", ""); detailsVo.setOperaImage(operaImage); } - List record= recordService.getRecordList("out-"+data.getId()); + List record = recordService.getRecordList("out-" + data.getId()); vo.setRecordList(record); vo.setDetailsVoList(list); } - return ServerResponse.createSuccess("查询成功",vo); - }catch (Exception e){ - log.error(e.toString(),e); + return ServerResponse.createSuccess("查询成功", vo); + } catch (Exception e) { + log.error(e.toString(), e); } - return ServerResponse.createSuccess("查询失败",new CarPlanOutVo()); + return ServerResponse.createSuccess("查询失败", new CarPlanOutVo()); } @Override public ServerResponse getDispatchCarListData(CarPlanOutVo data) { - List list=new ArrayList<>(); + List list = new ArrayList<>(); try { - list=mapper.getDispatchCarListData(data); - }catch (Exception e){ + list = mapper.getDispatchCarListData(data); + } catch (Exception e) { log.error(e.toString()); } return ServerResponse.createSuccess(list); @@ -424,106 +427,109 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ /** * 校验价格 + * * @return */ - private String getContractMoney(List list,int planType,CarPlanOutVo outVo){ - BigDecimal allMoney=new BigDecimal(0); - for (CarPlanOutVoDetailsVo vo:list){ - StringBuilder sb=new StringBuilder(); - BigDecimal cost=new BigDecimal(0); - if(StringHelper.isEmpty(outVo.getContractId())){ + private String getContractMoney(List list, int planType, CarPlanOutVo outVo) { + BigDecimal allMoney = new BigDecimal(0); + for (CarPlanOutVoDetailsVo vo : list) { + StringBuilder sb = new StringBuilder(); + BigDecimal cost = new BigDecimal(0); + if (StringHelper.isEmpty(outVo.getContractId())) { outVo.setContractId(vo.getContractId()); } - if(StringHelper.isEmpty(vo.getSupId())){ + if (StringHelper.isEmpty(vo.getSupId())) { vo.setSupId(outVo.getSupId()); } //车辆 - if(planType==1){ + if (planType == 1) { //公里数必填 - String gls=vo.getGls(); - try{ - PriceVo priceVo=getMoney(vo.getContractId(),null,vo.getSupId(),gls); + String gls = vo.getGls(); + try { + PriceVo priceVo = getMoney(vo.getContractId(), null, vo.getSupId(), gls); sb.append("依据:").append(priceVo.getGlsStart()).append("-").append(priceVo.getGlsEnd()); sb.append("公里:").append(priceVo.getPrice()).append("元"); vo.setRemark(sb.toString()); vo.setPriceId(priceVo.getId()); vo.setGlsPrice(priceVo.getPrice()); - BigDecimal nowGls=new BigDecimal(gls); - BigDecimal price=new BigDecimal(priceVo.getPrice()); - BigDecimal glsMoney=nowGls.multiply(price); - allMoney=allMoney.add(glsMoney); + BigDecimal ton = new BigDecimal(vo.getTon()); + BigDecimal nowGls = new BigDecimal(gls); + BigDecimal price = new BigDecimal(priceVo.getPrice()); + // 公里*每公里*吨位 + BigDecimal glsMoney = nowGls.multiply(price).multiply(ton); + allMoney = allMoney.add(glsMoney); vo.setCost(glsMoney.toString()); vo.setGlsMoney(glsMoney.toString()); - }catch (Exception e){ + } catch (Exception e) { return "公里数不在厂商合同范围内"; } - }else{ + } else { //计划天数 - int day=vo.getPlanDay(); - int isOutSet=vo.getIsOutSet(); - try{ - BigDecimal days=new BigDecimal(day); - BigDecimal dcMoney=new BigDecimal("0"); - BigDecimal month=new BigDecimal("30"); - PriceVo priceVo=getMoney(vo.getContractId(),vo.getModelId(),vo.getSupId(),null); + int day = vo.getPlanDay(); + int isOutSet = vo.getIsOutSet(); + try { + BigDecimal days = new BigDecimal(day); + BigDecimal dcMoney = new BigDecimal("0"); + BigDecimal month = new BigDecimal("30"); + PriceVo priceVo = getMoney(vo.getContractId(), vo.getModelId(), vo.getSupId(), null); sb.append("依据:").append(priceVo.getName()).append("-").append(priceVo.getModel()); vo.setPriceId(priceVo.getId()); vo.setGlsPrice(priceVo.getPrice()); - int dayToMonth= priceVo.getDayToMonth(); - if (day>=dayToMonth){ + int dayToMonth = priceVo.getDayToMonth(); + if (day >= dayToMonth) { sb.append("、作业天数>=").append(dayToMonth); vo.setDcUnit("元/月/台"); vo.setIsDayOrMonth("2"); - BigDecimal monthPrice=new BigDecimal(priceVo.getMonthPrice()); - if(day>30){ + BigDecimal monthPrice = new BigDecimal(priceVo.getMonthPrice()); + if (day > 30) { vo.setDcPrice(monthPrice.divide(month, RoundingMode.CEILING).toString()); - dcMoney=monthPrice.divide(month, RoundingMode.CEILING).multiply(days); + dcMoney = monthPrice.divide(month, RoundingMode.CEILING).multiply(days); vo.setDcMoney(dcMoney.toString()); - allMoney=allMoney.add(dcMoney); - cost=cost.add(dcMoney); + allMoney = allMoney.add(dcMoney); + cost = cost.add(dcMoney); vo.setCost(cost.toString()); - }else{ + } else { vo.setDcPrice(priceVo.getMonthPrice()); vo.setDcMoney(priceVo.getMonthPrice()); - allMoney=allMoney.add(monthPrice); - cost=cost.add(monthPrice); + allMoney = allMoney.add(monthPrice); + cost = cost.add(monthPrice); vo.setCost(cost.toString()); } - }else{ + } else { sb.append("、作业天数<").append(dayToMonth); vo.setIsDayOrMonth("1"); vo.setDcPrice(priceVo.getDayPrice()); vo.setDcUnit("元/天/台"); - BigDecimal dayPrice=new BigDecimal(priceVo.getDayPrice()); - dcMoney=dayPrice.multiply(days); + BigDecimal dayPrice = new BigDecimal(priceVo.getDayPrice()); + dcMoney = dayPrice.multiply(days); vo.setDcMoney(dcMoney.toString()); - allMoney=allMoney.add(dcMoney); - cost=cost.add(dcMoney); + allMoney = allMoney.add(dcMoney); + cost = cost.add(dcMoney); vo.setCost(cost.toString()); } - if(isOutSet==1){ + if (isOutSet == 1) { sb.append("@"); - sb.append(priceVo.getName()).append("-").append(priceVo.getModel()+"收取进出场费用"); + sb.append(priceVo.getName()).append("-").append(priceVo.getModel() + "收取进出场费用"); } vo.setDayPrice(priceVo.getDayPrice()); vo.setMonthPrice(priceVo.getMonthPrice()); - }catch (Exception e){ + } catch (Exception e) { return "公里数不在厂商合同范围内"; } - if(isOutSet==1){ + if (isOutSet == 1) { //进出场公里数 - String jcGls=vo.getJcGls(); - try{ - PriceVo priceVo =getJccMoney(vo.getContractId(),vo.getModelId(),vo.getSupId(),jcGls); + String jcGls = vo.getJcGls(); + try { + PriceVo priceVo = getJccMoney(vo.getContractId(), vo.getModelId(), vo.getSupId(), jcGls); sb.append("依据:").append(priceVo.getGlsStart()).append("-").append(priceVo.getGlsEnd()); sb.append("公里:").append(priceVo.getPrice()).append("元"); vo.setCarOutId(priceVo.getId()); vo.setJcMoney(priceVo.getPrice()); - BigDecimal jcMoney=new BigDecimal(priceVo.getPrice()); - allMoney=allMoney.add(jcMoney); - cost=cost.add(jcMoney); + BigDecimal jcMoney = new BigDecimal(priceVo.getPrice()); + allMoney = allMoney.add(jcMoney); + cost = cost.add(jcMoney); vo.setCost(cost.toString()); - }catch (Exception e){ + } catch (Exception e) { return "公里数不在进出场费用范围内"; } } @@ -531,34 +537,36 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ } } outVo.setMoney(allMoney.toString()); - return null; + return null; } /** * 计算 车辆 公里数价格 + * * @param gls * @return */ - private PriceVo getMoney(String contractId,String modelId,String supId,String gls) throws Exception { - List list=mapper.getContractPriceList(contractId,modelId,supId); - //车辆 - if(StringHelper.isEmpty(modelId)){ - BigDecimal nowGls=new BigDecimal(gls); - for (PriceVo priceVo:list){ - BigDecimal glsEnd=new BigDecimal(priceVo.getGlsEnd()); - BigDecimal glsStart=new BigDecimal(priceVo.getGlsStart()); - if(nowGls.compareTo(glsEnd)<=0 && nowGls.compareTo(glsStart)>= 0){ - return priceVo; - } - } - throw new Exception(); - }else{ - return list.get(0); + private PriceVo getMoney(String contractId, String modelId, String supId, String gls) throws Exception { + List list = mapper.getContractPriceList(contractId, modelId, supId); + //车辆 + if (StringHelper.isEmpty(modelId)) { + BigDecimal nowGls = new BigDecimal(gls); + for (PriceVo priceVo : list) { + BigDecimal glsEnd = new BigDecimal(priceVo.getGlsEnd()); + BigDecimal glsStart = new BigDecimal(priceVo.getGlsStart()); + if (nowGls.compareTo(glsEnd) <= 0 && nowGls.compareTo(glsStart) >= 0) { + return priceVo; + } } + throw new Exception(); + } else { + return list.get(0); + } } /** * 进出场费用 + * * @param contractId * @param modelId * @param supId @@ -566,17 +574,17 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ * @return * @throws Exception */ - private PriceVo getJccMoney(String contractId,String modelId,String supId,String gls) throws Exception { - List list=mapper.getCarOutList(contractId,modelId,supId); - BigDecimal nowGls=new BigDecimal(gls); - for (PriceVo priceVo:list){ - BigDecimal glsEnd=new BigDecimal(priceVo.getGlsEnd()); - BigDecimal glsStart=new BigDecimal(priceVo.getGlsStart()); - if(nowGls.compareTo(glsEnd)<=0 && nowGls.compareTo(glsStart)> 0){ - return priceVo; + private PriceVo getJccMoney(String contractId, String modelId, String supId, String gls) throws Exception { + List list = mapper.getCarOutList(contractId, modelId, supId); + BigDecimal nowGls = new BigDecimal(gls); + for (PriceVo priceVo : list) { + BigDecimal glsEnd = new BigDecimal(priceVo.getGlsEnd()); + BigDecimal glsStart = new BigDecimal(priceVo.getGlsStart()); + if (nowGls.compareTo(glsEnd) <= 0 && nowGls.compareTo(glsStart) > 0) { + return priceVo; } } - throw new Exception(); + throw new Exception(); } @@ -586,7 +594,7 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ try { //先查询数据 List list = mapper.getData(data); - for (CarPlanOutVo outVo:list){ + for (CarPlanOutVo outVo : list) { //删除car_plan_out int res = mapper.delCarPlanOutData(outVo); //删除car_plan_out_record @@ -608,21 +616,16 @@ public class SupDispatchCarServiceImpl implements SupDispatchCarService{ //修改car_plan_apply状态 int res7 = mapper.updateCarPlanApplyStatus(outVo); //删除car_plan_audit_record - outVo.setOutId("out-"+outVo.getOutId()); + outVo.setOutId("out-" + outVo.getOutId()); int res8 = mapper.delAuditRecord(outVo); } - return ServerResponse.createSuccess("删除成功","删除成功"); + return ServerResponse.createSuccess("删除成功", "删除成功"); } catch (Exception e) { - log.error(e.toString(),e); + log.error(e.toString(), e); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return ServerResponse.createErroe("删除失败"); } } - - - - - }