From c310e85a79c69e711076c7a246205d8cfe45ac75 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 27 Dec 2022 09:23:04 +0800
Subject: [PATCH] 添加车辆变更审核流程

---
 src/main/java/org/springblade/flow/business/controller/WorkController.java                                   |   26 ++
 src/main/java/org/springblade/modules/application/entity/CarEntity.java                                      |   11 
 src/main/java/org/springblade/common/constant/AuditStatusConstant.java                                       |   33 +++
 src/main/java/org/springblade/modules/applicationCarChange/service/IApplicationCarChangeService.java         |   22 ++
 src/main/java/org/springblade/modules/application/mapper/BasicInfoMapper.xml                                 |    3 
 src/main/java/org/springblade/modules/applicationCarChange/controller/ApplicationCarChangeController.java    |   39 ++++
 src/main/java/org/springblade/modules/applicationCarChange/entity/ApplicationCarChangeEntity.java            |   15 
 src/main/java/org/springblade/modules/applicationDelay/service/impl/ApplicationDelayServiceImpl.java         |   80 ++++++++
 src/main/java/org/springblade/modules/applicationCarChange/mapper/ApplicationCarChangeMapper.xml             |    9 
 src/main/java/org/springblade/modules/application/mapper/ApplicationMapper.xml                               |   13 +
 src/main/java/org/springblade/modules/applicationCarChange/service/impl/ApplicationCarChangeServiceImpl.java |  159 +++++++++++++++++
 src/main/java/org/springblade/modules/applicationCarChange/vo/ApplicationCarChangeVO.java                    |   36 ++++
 src/main/java/org/springblade/modules/application/entity/BasicInfoEntity.java                                |    4 
 src/main/java/org/springblade/modules/applicationDelay/entity/ApplicationDelayEntity.java                    |   31 +++
 src/main/java/org/springblade/modules/application/vo/ApplicationVO.java                                      |    5 
 src/main/java/org/springblade/modules/application/entity/SchemeEntity.java                                   |    2 
 src/main/java/org/springblade/modules/application/service/impl/ApplicationServiceImpl.java                   |   38 +++-
 17 files changed, 489 insertions(+), 37 deletions(-)

diff --git a/src/main/java/org/springblade/common/constant/AuditStatusConstant.java b/src/main/java/org/springblade/common/constant/AuditStatusConstant.java
new file mode 100644
index 0000000..d0920e1
--- /dev/null
+++ b/src/main/java/org/springblade/common/constant/AuditStatusConstant.java
@@ -0,0 +1,33 @@
+package org.springblade.common.constant;
+
+public interface AuditStatusConstant {
+	/**
+	 * 已提交
+	 */
+	Integer COMMIT = 1;
+
+	/**
+	 * 处理中
+	 */
+	Integer PROCESSING = 2;
+
+	/**
+	 * 自行撤销
+	 */
+	Integer SELF_CANCEL = 3;
+
+	/**
+	 * 已完成
+	 */
+	Integer FINISH = 4;
+
+	/**
+	 * 许可证已发放
+	 */
+	Integer PASS_DISTRIBUTE = 10;
+
+	/**
+	 * 拒绝受理
+	 */
+	Integer REJECT_AUDIT = 99;
+}
diff --git a/src/main/java/org/springblade/flow/business/controller/WorkController.java b/src/main/java/org/springblade/flow/business/controller/WorkController.java
index 21addaf..5020192 100644
--- a/src/main/java/org/springblade/flow/business/controller/WorkController.java
+++ b/src/main/java/org/springblade/flow/business/controller/WorkController.java
@@ -26,13 +26,17 @@
 import org.springblade.core.launch.constant.AppConstant;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
+import org.springblade.core.redis.cache.BladeRedis;
 import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
 import org.springblade.flow.business.service.FlowBusinessService;
 import org.springblade.flow.core.entity.BladeFlow;
 import org.springblade.flow.core.utils.TaskUtil;
 import org.springblade.flow.engine.entity.FlowProcess;
 import org.springblade.flow.engine.service.FlowEngineService;
 import org.springframework.web.bind.annotation.*;
+
+import java.time.Duration;
 
 /**
  * 流程事务通用接口
@@ -48,6 +52,8 @@
 	private final TaskService taskService;
 	private final FlowEngineService flowEngineService;
 	private final FlowBusinessService flowBusinessService;
+
+	private final BladeRedis bladeRedis;
 
 	/**
 	 * 发起事务列表页
@@ -143,4 +149,24 @@
 		return R.success("删除任务成功");
 	}
 
+	/**
+	 * 撤销任务
+	 *
+	 */
+	@PostMapping("withdraw-task")
+	@ApiOperationSupport(order = 9)
+	@ApiOperation(value = "撤销任务", notes = "传入流程信息")
+	public R withdraw(String userId){
+		int times = Func.toInt(bladeRedis.get("AUDIT-CANCEL" + userId), 1);
+		if (times>3){
+			return R.success("撤销任务失败");
+		}
+
+		bladeRedis.setEx("AUDIT-CANCEL"+userId,times+1, Duration.ofDays(1));
+		//撤销任务操作
+
+
+		return R.success("撤销任务成功");
+	}
+
 }
diff --git a/src/main/java/org/springblade/modules/application/entity/BasicInfoEntity.java b/src/main/java/org/springblade/modules/application/entity/BasicInfoEntity.java
index 4692eeb..a774df5 100644
--- a/src/main/java/org/springblade/modules/application/entity/BasicInfoEntity.java
+++ b/src/main/java/org/springblade/modules/application/entity/BasicInfoEntity.java
@@ -72,14 +72,14 @@
 	@DateTimeFormat(pattern = "yyyy-MM-dd")
 	@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
 	@ApiModelProperty(value = "通行开始时间")
-	private Date startTime;
+	private Date startPassTime;
 	/**
 	 * 通行结束时间
 	 */
 	@DateTimeFormat(pattern = "yyyy-MM-dd")
 	@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
 	@ApiModelProperty(value = "通行结束时间")
-	private Date endTime;
+	private Date endPassTime;
 	/**
 	 * 起运机构
 	 */
diff --git a/src/main/java/org/springblade/modules/application/entity/CarEntity.java b/src/main/java/org/springblade/modules/application/entity/CarEntity.java
index b510ac1..903b512 100644
--- a/src/main/java/org/springblade/modules/application/entity/CarEntity.java
+++ b/src/main/java/org/springblade/modules/application/entity/CarEntity.java
@@ -46,8 +46,13 @@
 	/**
 	 * 申请表主键
 	 */
-	@ApiModelProperty(value = "经办人姓名")
+	@ApiModelProperty(value = "申请表主键")
 	private String applicationId;
+	/**
+	 * 变更车辆表主键
+	 */
+	@ApiModelProperty(value = "变更车辆表主键")
+	private String carChangeId;
 	/**
 	 * 车牌号
 	 */
@@ -89,9 +94,9 @@
 	@ApiModelProperty(value = "轴距")
 	private String wheelbase;
 	/**
-	 * 状态1启用 2废弃
+	 * 状态1启用 2废弃 3审核中
 	 */
-	@ApiModelProperty(value = "状态1启用 2废弃")
+	@ApiModelProperty(value = "状态1启用 2废弃 3审核中")
 	private String status;
 
 	public CarEntity (String applicationId){
diff --git a/src/main/java/org/springblade/modules/application/entity/SchemeEntity.java b/src/main/java/org/springblade/modules/application/entity/SchemeEntity.java
index f5bcfe6..787add1 100644
--- a/src/main/java/org/springblade/modules/application/entity/SchemeEntity.java
+++ b/src/main/java/org/springblade/modules/application/entity/SchemeEntity.java
@@ -55,7 +55,7 @@
 	 * 省份
 	 */
 	@ApiModelProperty(value = "省份")
-	private String transportDept;
+	private String transportDepart;
 	/**
 	 * 文件名称
 	 */
diff --git a/src/main/java/org/springblade/modules/application/mapper/ApplicationMapper.xml b/src/main/java/org/springblade/modules/application/mapper/ApplicationMapper.xml
index 0d5a4e9..f0cfe6a 100644
--- a/src/main/java/org/springblade/modules/application/mapper/ApplicationMapper.xml
+++ b/src/main/java/org/springblade/modules/application/mapper/ApplicationMapper.xml
@@ -34,13 +34,14 @@
         enterprise.enterprise_name,
         enterprise.legal_person
         from sys_application app
-        LEFT JOIN sys_application_car car ON car.application_id = app.id
+        LEFT JOIN sys_application_car car ON car.application_id = app.id AND car.status = 1
         LEFT JOIN sys_application_goods goods ON goods.application_id = app.id
         LEFT JOIN sys_enterprise enterprise ON enterprise.user_id = app.user_id AND enterprise.is_deleted = 0
         where app.is_deleted = 0
         <if test="application.userId != null and application.userId !='' ">
            AND app.user_id = #{application.userId}
         </if>
+        ORDER BY app.no DESC
     </select>
     <select id="getMaxNoEntity" resultType="org.springblade.modules.application.entity.ApplicationEntity">
         SELECT * from sys_application where is_deleted = 0 ORDER BY create_time DESC LIMIT 1
@@ -49,8 +50,16 @@
         SELECT * FROM sys_application WHERE is_deleted = 0 AND no = #{no}
     </select>
     <select id="getAll" resultType="org.springblade.modules.application.vo.ApplicationVO">
-        SELECT app.*,basic.end_time FROM sys_application app
+        SELECT app.*,basic.end_pass_time,
+        (
+            CASE
+                WHEN car.trailer_license IS NOT NULL
+            THEN CONCAT( car.car_license, car.trailer_license )
+                ELSE car.car_license
+            END) licensePlate
+        FROM sys_application app
         LEFT JOIN sys_application_basic_info basic ON basic.application_id = app.id
+        LEFT JOIN sys_application_car car ON car.application_id = app.id AND car.status = 1
         WHERE app.is_deleted = 0
         <if test="application.userId !=null and application.userId !=''">
             AND app.user_id = #{application.userId}
diff --git a/src/main/java/org/springblade/modules/application/mapper/BasicInfoMapper.xml b/src/main/java/org/springblade/modules/application/mapper/BasicInfoMapper.xml
index b0183ce..36b8df1 100644
--- a/src/main/java/org/springblade/modules/application/mapper/BasicInfoMapper.xml
+++ b/src/main/java/org/springblade/modules/application/mapper/BasicInfoMapper.xml
@@ -8,14 +8,11 @@
         <result column="name" property="name"/>
         <result column="id_card" property="idCard"/>
         <result column="phone" property="phone"/>
-        <result column="start_time" property="startTime"/>
-        <result column="end_time" property="endTime"/>
         <result column="transport_dept" property="transportDept"/>
         <result column="pass_province" property="passProvince"/>
         <result column="departure" property="departure"/>
         <result column="destination" property="destination"/>
         <result column="pathway" property="pathway"/>
-        <result column="pass_birdge" property="passBirdge"/>
     </resultMap>
 
 
diff --git a/src/main/java/org/springblade/modules/application/service/impl/ApplicationServiceImpl.java b/src/main/java/org/springblade/modules/application/service/impl/ApplicationServiceImpl.java
index 3d50638..e4b52a2 100644
--- a/src/main/java/org/springblade/modules/application/service/impl/ApplicationServiceImpl.java
+++ b/src/main/java/org/springblade/modules/application/service/impl/ApplicationServiceImpl.java
@@ -25,6 +25,8 @@
 import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
 import org.flowable.engine.runtime.ProcessInstance;
 import org.flowable.task.api.Task;
+import org.springblade.common.constant.AuditStatusConstant;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.common.utils.CommonUtil;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.secure.utils.AuthUtil;
@@ -124,7 +126,12 @@
 		applicationVO.setBasicInfoEntity(basicInfoService.getOne(Condition.getQueryWrapper(new BasicInfoEntity(applicationId))));
 		applicationVO.setSchemeEntity(schemeService.getOne(Condition.getQueryWrapper(new SchemeEntity(applicationId))));
 		applicationVO.setPlanEntity(planService.getOne(Condition.getQueryWrapper(new PlanEntity(applicationId))));
-		applicationVO.setCarEntity(carService.getOne(Condition.getQueryWrapper(new CarEntity(applicationId))));
+
+		CarEntity carEntity = new CarEntity();
+		carEntity.setApplicationId(applicationId);
+		carEntity.setStatus("1");
+		applicationVO.setCarEntity(carService.getOne(Condition.getQueryWrapper(carEntity)));
+
 		applicationVO.setBasicInfoEntity(basicInfoService.getOne(Condition.getQueryWrapper(new BasicInfoEntity(applicationId))));
 
 		GoodsEntity goods = goodsService.getOne(Condition.getQueryWrapper(new GoodsEntity(applicationId)));
@@ -194,7 +201,7 @@
 			BladeFlow flow = flowService.startProcessInstanceById(application.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(application.getId())), variables);
 			if (Func.isNotEmpty(flow)) {
 				log.error("流程已启动,流程ID:" + flow.getProcessInstanceId());
-				// 返回流程id写入leave
+				// 返回流程id
 				application.setProcessInstanceId(flow.getProcessInstanceId());
 				updateById(application);
 			} else {
@@ -225,8 +232,8 @@
 		if (!StringUtil.isBlank(applicationEntity.getSuggestion())){
 			entity.setSuggestion(applicationEntity.getSuggestion());
 		}
-		if (entity.getStatus() == 1){
-			entity.setStatus(2);
+		if (entity.getStatus() == AuditStatusConstant.COMMIT){
+			entity.setStatus(AuditStatusConstant.PROCESSING);
 		}
 
 		String processInstanceId = flow.getProcessInstanceId();
@@ -249,9 +256,9 @@
 		//判读是否有末尾节点
 		if (getEndNode(task,entity.getProcessDefinitionId())){
 			//判断是否pass
-			if ((Boolean)variables.get(ProcessConstant.PASS_KEY)){
+			if (flow.isPass()){
 				//改变业务状态
-				entity.setStatus(10);
+				entity.setStatus(AuditStatusConstant.PASS_DISTRIBUTE);
 				//生成通行证
 				PassEntity passEntity = new PassEntity();
 				passEntity.setNo(entity.getNo());
@@ -260,6 +267,17 @@
 				EvaluationEntity evaluationEntity = new EvaluationEntity();
 				evaluationEntity.setNo(entity.getNo());
 				evaluationService.save(evaluationEntity);
+//				//修改车辆信息状态
+//				CarEntity carEntity = new CarEntity();
+//				carEntity.setApplicationId(entity.getId().toString());
+//				carEntity.setStatus("3");
+//				CarEntity one = carService.getOne(Condition.getQueryWrapper(carEntity));
+//				one.setStatus("1");
+//				carService.updateById(one);
+			}else if (!applicationEntity.getIsSuggestion()&&!flow.isPass()){
+				//判断是否拒绝受理
+				entity.setStatus(AuditStatusConstant.REJECT_AUDIT);
+
 			}
 		}
 		boolean update = updateById(entity);
@@ -318,21 +336,21 @@
 	 */
 	public boolean getEndNode(Task task,String definitionId){
 		boolean isEnd=false;
-		boolean isAuditTask2 = false;
+		boolean finalTask = false;
 		BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionId);
 		FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
 		List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows();
 		for (SequenceFlow outgoingFlow : outgoingFlows) {
 			FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
 			FlowElement sourceFlowElement = outgoingFlow.getSourceFlowElement();
-			if (sourceFlowElement.getId().equals("auditTask_2")){
-				isAuditTask2 = true;
+			if (sourceFlowElement.getId().equals("finalTask")){
+				finalTask = true;
 			}
 			if (targetFlowElement instanceof EndEvent){
 				isEnd = true;
 				break;
 			}
 		}
-		return isEnd&&isAuditTask2;
+		return isEnd&&finalTask;
 	}
 }
diff --git a/src/main/java/org/springblade/modules/application/vo/ApplicationVO.java b/src/main/java/org/springblade/modules/application/vo/ApplicationVO.java
index 8432737..4ee5185 100644
--- a/src/main/java/org/springblade/modules/application/vo/ApplicationVO.java
+++ b/src/main/java/org/springblade/modules/application/vo/ApplicationVO.java
@@ -74,5 +74,8 @@
 	 */
 	private String legalPerson;
 
-	private String endTime;
+	/**
+	 * 通行结束时间
+	 */
+	private String endPassTime;
 }
diff --git a/src/main/java/org/springblade/modules/applicationCarChange/controller/ApplicationCarChangeController.java b/src/main/java/org/springblade/modules/applicationCarChange/controller/ApplicationCarChangeController.java
index ce8b4ab..e620f91 100644
--- a/src/main/java/org/springblade/modules/applicationCarChange/controller/ApplicationCarChangeController.java
+++ b/src/main/java/org/springblade/modules/applicationCarChange/controller/ApplicationCarChangeController.java
@@ -23,11 +23,16 @@
 import lombok.AllArgsConstructor;
 import javax.validation.Valid;
 
+import org.springblade.common.cache.UserCache;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.flow.core.entity.BladeFlow;
+import org.springblade.modules.application.entity.CarEntity;
+import org.springblade.modules.applicationDelay.entity.ApplicationDelayEntity;
+import org.springblade.modules.applicationDelay.vo.ApplicationDelayVO;
 import org.springframework.web.bind.annotation.*;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.modules.applicationCarChange.entity.ApplicationCarChangeEntity;
@@ -121,6 +126,40 @@
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status(applicationCarChangeService.deleteLogic(Func.toLongList(ids)));
 	}
+	//=======================工作流===================================
+	/**
+	 * 开始任务
+	 *
+	 * @param entity 车辆变更信息
+	 */
+	@PostMapping("start-process")
+	public R startProcess(@RequestBody ApplicationCarChangeEntity entity, @RequestBody CarEntity carEntity) {
+		return R.status(applicationCarChangeService.startProcess(entity,carEntity));
+	}
 
+	/**
+	 * 完成任务
+	 *
+	 * @param flow 延期信息
+	 */
+	@PostMapping("complete-task")
+	@ApiOperationSupport(order = 7)
+	@ApiOperation(value = "完成任务", notes = "传入流程信息")
+	public R completeTask(@ApiParam("任务信息") @RequestBody BladeFlow flow) {
+		return R.status(applicationCarChangeService.completeTask(flow));
+	}
+
+	/**
+	 * 详情
+	 *
+	 * @param businessId 主键
+	 */
+	@GetMapping("/process-detail")
+	public R<ApplicationCarChangeVO> detail(Long businessId) {
+		ApplicationCarChangeEntity detail = applicationCarChangeService.getById(businessId);
+		ApplicationCarChangeVO applicationCarChangeVO = applicationCarChangeService.getVo(detail);
+		applicationCarChangeVO.getFlow().setAssigneeName(UserCache.getUser(detail.getCreateUser()).getName());
+		return R.data(applicationCarChangeVO);
+	}
 
 }
diff --git a/src/main/java/org/springblade/modules/applicationCarChange/entity/ApplicationCarChangeEntity.java b/src/main/java/org/springblade/modules/applicationCarChange/entity/ApplicationCarChangeEntity.java
index 5c5fc22..e39b46c 100644
--- a/src/main/java/org/springblade/modules/applicationCarChange/entity/ApplicationCarChangeEntity.java
+++ b/src/main/java/org/springblade/modules/applicationCarChange/entity/ApplicationCarChangeEntity.java
@@ -44,15 +44,16 @@
 	private String no;
 
 	/**
-	 * 车辆id主键
-	 */
-	@ApiModelProperty(value = "申请编号")
-	private String carId;
-
-	/**
 	 * 变更车辆原因
 	 */
 	@ApiModelProperty(value = "变更车辆原因")
 	private String reason;
-
+	/**
+	 * 流程定义id
+	 */
+	private String processDefinitionId;
+	/**
+	 * 流程实例id
+	 */
+	private String processInstanceId;
 }
diff --git a/src/main/java/org/springblade/modules/applicationCarChange/mapper/ApplicationCarChangeMapper.xml b/src/main/java/org/springblade/modules/applicationCarChange/mapper/ApplicationCarChangeMapper.xml
index 9e59ccf..05f08ef 100644
--- a/src/main/java/org/springblade/modules/applicationCarChange/mapper/ApplicationCarChangeMapper.xml
+++ b/src/main/java/org/springblade/modules/applicationCarChange/mapper/ApplicationCarChangeMapper.xml
@@ -5,9 +5,6 @@
     <!-- 通用查询映射结果 -->
     <resultMap id="applicationCarChangeResultMap" type="org.springblade.modules.applicationCarChange.entity.ApplicationCarChangeEntity">
         <result column="id" property="id"/>
-        <result column="application_id" property="applicationId"/>
-        <result column="license_url" property="licenseUrl"/>
-        <result column="tenant_id" property="tenantId"/>
         <result column="create_user" property="createUser"/>
         <result column="create_dept" property="createDept"/>
         <result column="create_time" property="createTime"/>
@@ -18,8 +15,10 @@
     </resultMap>
 
 
-    <select id="selectApplicationCarChangePage" resultMap="applicationCarChangeResultMap">
-        select * from sys_application_car_change where is_deleted = 0
+    <select id="selectApplicationCarChangePage" resultType="org.springblade.modules.applicationCarChange.vo.ApplicationCarChangeVO">
+        select * from sys_application_car_change carChange
+        LEFT JOIN sys_application_car car ON car.car_change_id = carChange.id
+        where carChange.is_deleted = 0
     </select>
 
 
diff --git a/src/main/java/org/springblade/modules/applicationCarChange/service/IApplicationCarChangeService.java b/src/main/java/org/springblade/modules/applicationCarChange/service/IApplicationCarChangeService.java
index 5dfe072..960577d 100644
--- a/src/main/java/org/springblade/modules/applicationCarChange/service/IApplicationCarChangeService.java
+++ b/src/main/java/org/springblade/modules/applicationCarChange/service/IApplicationCarChangeService.java
@@ -16,10 +16,13 @@
  */
 package org.springblade.modules.applicationCarChange.service;
 
+import org.springblade.flow.core.entity.BladeFlow;
+import org.springblade.modules.application.entity.CarEntity;
 import org.springblade.modules.applicationCarChange.entity.ApplicationCarChangeEntity;
 import org.springblade.modules.applicationCarChange.vo.ApplicationCarChangeVO;
 import org.springblade.core.mp.base.BaseService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.modules.applicationDelay.vo.ApplicationDelayVO;
 
 /**
  * 车辆变更申请表 服务类
@@ -38,5 +41,24 @@
 	 */
 	IPage<ApplicationCarChangeVO> selectApplicationCarChangePage(IPage<ApplicationCarChangeVO> page, ApplicationCarChangeVO applicationCarChange);
 
+	/**
+	 * 开始任务
+	 * @param entity
+	 * @return
+	 */
+    Boolean startProcess(ApplicationCarChangeEntity entity, CarEntity carEntity);
 
+	/**
+	 * 完成任务
+	 * @param flow
+	 * @return
+	 */
+	Boolean completeTask(BladeFlow flow);
+
+	/**
+	 * 获取详情
+	 * @param detail
+	 * @return
+	 */
+	ApplicationCarChangeVO getVo(ApplicationCarChangeEntity detail);
 }
diff --git a/src/main/java/org/springblade/modules/applicationCarChange/service/impl/ApplicationCarChangeServiceImpl.java b/src/main/java/org/springblade/modules/applicationCarChange/service/impl/ApplicationCarChangeServiceImpl.java
index f3a88ba..75f3e44 100644
--- a/src/main/java/org/springblade/modules/applicationCarChange/service/impl/ApplicationCarChangeServiceImpl.java
+++ b/src/main/java/org/springblade/modules/applicationCarChange/service/impl/ApplicationCarChangeServiceImpl.java
@@ -16,13 +16,44 @@
  */
 package org.springblade.modules.applicationCarChange.service.impl;
 
+import lombok.AllArgsConstructor;
+import org.flowable.bpmn.model.*;
+import org.flowable.engine.RepositoryService;
+import org.flowable.engine.RuntimeService;
+import org.flowable.engine.TaskService;
+import org.flowable.engine.runtime.ProcessInstance;
+import org.flowable.task.api.Task;
+import org.springblade.common.constant.AuditStatusConstant;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.support.Kv;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.flow.business.service.IFlowService;
+import org.springblade.flow.core.constant.ProcessConstant;
+import org.springblade.flow.core.entity.BladeFlow;
+import org.springblade.flow.core.utils.FlowUtil;
+import org.springblade.modules.application.entity.ApplicationEntity;
+import org.springblade.modules.application.entity.BasicInfoEntity;
+import org.springblade.modules.application.entity.CarEntity;
+import org.springblade.modules.application.service.IApplicationService;
+import org.springblade.modules.application.service.ICarService;
+import org.springblade.modules.application.vo.ApplicationVO;
+import org.springblade.modules.application.wrapper.ApplicationWrapper;
 import org.springblade.modules.applicationCarChange.entity.ApplicationCarChangeEntity;
 import org.springblade.modules.applicationCarChange.vo.ApplicationCarChangeVO;
 import org.springblade.modules.applicationCarChange.mapper.ApplicationCarChangeMapper;
 import org.springblade.modules.applicationCarChange.service.IApplicationCarChangeService;
 import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.modules.applicationCarChange.wrapper.ApplicationCarChangeWrapper;
+import org.springblade.modules.applicationDelay.entity.ApplicationDelayEntity;
+import org.springblade.modules.applicationDelay.vo.ApplicationDelayVO;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * 车辆变更申请表 服务实现类
@@ -31,12 +62,140 @@
  * @since 2022-12-13
  */
 @Service
+@AllArgsConstructor
 public class ApplicationCarChangeServiceImpl extends BaseServiceImpl<ApplicationCarChangeMapper, ApplicationCarChangeEntity> implements IApplicationCarChangeService {
+	private final ICarService carService;
+	private final IApplicationService applicationService;
+
+	private final IFlowService flowService;
+	private final TaskService taskService;
+	private final RuntimeService runtimeService;
+	private final RepositoryService repositoryService;
 
 	@Override
 	public IPage<ApplicationCarChangeVO> selectApplicationCarChangePage(IPage<ApplicationCarChangeVO> page, ApplicationCarChangeVO applicationCarChange) {
 		return page.setRecords(baseMapper.selectApplicationCarChangePage(page, applicationCarChange));
 	}
 
+	@Override
+	public Boolean startProcess(ApplicationCarChangeEntity entity, CarEntity carEntity) {
+		String businessTable = FlowUtil.getBusinessTable(ProcessConstant.CAR_CHANGE_AUDIT);
+		if (Func.isEmpty(entity.getId())) {
+			// 保存变更信息
+			save(entity);
+			//保存车辆信息
+			ApplicationEntity applicationEntity = applicationService.getByNo(entity.getNo());
+			carEntity.setCarChangeId(entity.getId().toString());
+			carEntity.setApplicationId(applicationEntity.getId().toString());
+			carService.save(carEntity);
+			// 启动流程
+			Kv variables = Kv.create()
+				.set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName());
+			BladeFlow flow = flowService.startProcessInstanceById(entity.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(entity.getId())), variables);
+			if (Func.isNotEmpty(flow)) {
+				log.debug("流程已启动,流程ID:" + flow.getProcessInstanceId());
+				// 返回流程id写入leave
+				entity.setProcessInstanceId(flow.getProcessInstanceId());
+				updateById(entity);
+			} else {
+				throw new ServiceException("开启流程失败");
+			}
+		} else {
 
+			updateById(entity);
+		}
+		return true;
+	}
+
+	@Override
+	public Boolean completeTask(BladeFlow flow) {
+		String taskId = flow.getTaskId();
+		String processInstanceId = flow.getProcessInstanceId();
+		String comment = Func.toStr(flow.getComment(), ProcessConstant.PASS_COMMENT);
+		// 增加评论
+		if (StringUtil.isNoneBlank(processInstanceId, comment)) {
+			taskService.addComment(taskId, processInstanceId, comment);
+		}
+
+		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+		ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
+		// 通过流程实例获取“业务键”
+		String businessKey = pi.getBusinessKey().split(":")[1];
+
+		//获取实例对象
+		ApplicationCarChangeEntity entity = getById(businessKey);
+		ApplicationEntity applicationEntity = applicationService.getByNo(entity.getNo());
+
+		//驳回时
+		if (!flow.isPass()){
+			entity.setStatus(AuditStatusConstant.REJECT_AUDIT);
+		}
+
+		//通过且下一个节点结束流程时
+		if (flow.isPass() && getEndNode(task, entity.getProcessDefinitionId())) {
+			//替换车辆信息
+			CarEntity searchCar = new CarEntity();
+			searchCar.setApplicationId(applicationEntity.getId().toString());
+
+			List<CarEntity> listCar = carService.list(Condition.getQueryWrapper(searchCar));
+			listCar.forEach(car->{
+				if (car.getStatus().equals("1")){
+					car.setStatus("2");
+				}else if (car.getStatus().equals("3") && car.getCarChangeId().equals(entity.getId().toString())){
+					car.setStatus("1");
+				}
+			});
+			carService.updateBatchById(listCar);
+			//修改流程状态
+			entity.setStatus(AuditStatusConstant.FINISH);
+		}
+
+		updateById(entity);
+
+		// 创建变量
+		Map<String, Object> variables = flow.getVariables();
+		if (variables == null) {
+			variables = Kv.create();
+		}
+		variables.put(ProcessConstant.PASS_KEY, flow.isPass());
+		// 完成任务
+		taskService.complete(taskId, variables);
+		return true;
+	}
+
+	@Override
+	public ApplicationCarChangeVO getVo(ApplicationCarChangeEntity detail) {
+		ApplicationCarChangeVO vo = ApplicationCarChangeWrapper.build().entityVO(detail);
+		CarEntity carEntity = new CarEntity();
+		carEntity.setCarChangeId(detail.getId().toString());
+		carEntity.setStatus("3");
+		vo.setCarEntity(carService.getOne(Condition.getQueryWrapper(carEntity)));
+		return vo;
+	}
+
+	/**
+	 * 判断是否包含最终节点且为倒数第二个节点
+	 * @param task
+	 * @param definitionId
+	 * @return
+	 */
+	public boolean getEndNode(Task task, String definitionId){
+		boolean isEnd=false;
+		boolean finalTask = false;
+		BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionId);
+		FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
+		List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows();
+		for (SequenceFlow outgoingFlow : outgoingFlows) {
+			FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
+			FlowElement sourceFlowElement = outgoingFlow.getSourceFlowElement();
+			if (sourceFlowElement.getId().equals("finalTask")){
+				finalTask = true;
+			}
+			if (targetFlowElement instanceof EndEvent){
+				isEnd = true;
+				break;
+			}
+		}
+		return isEnd&&finalTask;
+	}
 }
diff --git a/src/main/java/org/springblade/modules/applicationCarChange/vo/ApplicationCarChangeVO.java b/src/main/java/org/springblade/modules/applicationCarChange/vo/ApplicationCarChangeVO.java
index 3103771..673fb96 100644
--- a/src/main/java/org/springblade/modules/applicationCarChange/vo/ApplicationCarChangeVO.java
+++ b/src/main/java/org/springblade/modules/applicationCarChange/vo/ApplicationCarChangeVO.java
@@ -16,6 +16,8 @@
  */
 package org.springblade.modules.applicationCarChange.vo;
 
+import io.swagger.annotations.ApiModelProperty;
+import org.springblade.modules.application.entity.CarEntity;
 import org.springblade.modules.applicationCarChange.entity.ApplicationCarChangeEntity;
 import org.springblade.core.tool.node.INode;
 import lombok.Data;
@@ -32,4 +34,38 @@
 public class ApplicationCarChangeVO extends ApplicationCarChangeEntity {
 	private static final long serialVersionUID = 1L;
 
+	private CarEntity carEntity;
+
+	/**
+	 * 车牌号
+	 */
+	private String carLicense;
+	/**
+	 * 厂牌型号
+	 */
+	private String carModel;
+	/**
+	 * 挂车牌号
+	 */
+	private String trailerLicense;
+	/**
+	 * 挂车厂牌型号
+	 */
+	private String trailerModel;
+	/**
+	 * 装备质量
+	 */
+	private Double equipmentWeight;
+	/**
+	 * 轴数
+	 */
+	private Integer shaftNumber;
+	/**
+	 * 轮胎数
+	 */
+	private Integer tireNumber;
+	/**
+	 * 轴距
+	 */
+	private String wheelbase;
 }
diff --git a/src/main/java/org/springblade/modules/applicationDelay/entity/ApplicationDelayEntity.java b/src/main/java/org/springblade/modules/applicationDelay/entity/ApplicationDelayEntity.java
index 46f4e39..f9ae0a3 100644
--- a/src/main/java/org/springblade/modules/applicationDelay/entity/ApplicationDelayEntity.java
+++ b/src/main/java/org/springblade/modules/applicationDelay/entity/ApplicationDelayEntity.java
@@ -59,10 +59,35 @@
 	@ApiModelProperty(value = "延期后的结束时间")
 	private Date delayEndTime;
 	/**
-	 * 延期行驶的路线
+	 * 起运机构
 	 */
-	@ApiModelProperty(value = "延期行驶的路线")
-	private String pathWay;
+	@ApiModelProperty(value = "起运机构")
+	private String transportDept;
+	/**
+	 * 途径省份
+	 */
+	@ApiModelProperty(value = "途径省份")
+	private String passProvince;
+	/**
+	 * 出发地
+	 */
+	@ApiModelProperty(value = "出发地")
+	private String departure;
+	/**
+	 * 目的地
+	 */
+	@ApiModelProperty(value = "目的地")
+	private String destination;
+	/**
+	 * 通行路线
+	 */
+	@ApiModelProperty(value = "通行路线")
+	private String pathway;
+	/**
+	 * 通行桥涵
+	 */
+	@ApiModelProperty(value = "通行桥涵")
+	private String passBridge;
 	/**
 	 * 延期原因
 	 */
diff --git a/src/main/java/org/springblade/modules/applicationDelay/service/impl/ApplicationDelayServiceImpl.java b/src/main/java/org/springblade/modules/applicationDelay/service/impl/ApplicationDelayServiceImpl.java
index 30671eb..307a952 100644
--- a/src/main/java/org/springblade/modules/applicationDelay/service/impl/ApplicationDelayServiceImpl.java
+++ b/src/main/java/org/springblade/modules/applicationDelay/service/impl/ApplicationDelayServiceImpl.java
@@ -17,8 +17,15 @@
 package org.springblade.modules.applicationDelay.service.impl;
 
 import lombok.AllArgsConstructor;
+import org.flowable.bpmn.model.*;
+import org.flowable.engine.RepositoryService;
+import org.flowable.engine.RuntimeService;
 import org.flowable.engine.TaskService;
+import org.flowable.engine.runtime.ProcessInstance;
+import org.flowable.task.api.Task;
+import org.springblade.common.constant.AuditStatusConstant;
 import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.mp.support.Condition;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.support.Kv;
 import org.springblade.core.tool.utils.DateUtil;
@@ -30,6 +37,10 @@
 import org.springblade.flow.core.utils.FlowUtil;
 import org.springblade.flow.core.utils.TaskUtil;
 import org.springblade.flow.demo.leave.entity.ProcessLeave;
+import org.springblade.modules.application.entity.ApplicationEntity;
+import org.springblade.modules.application.entity.BasicInfoEntity;
+import org.springblade.modules.application.service.IApplicationService;
+import org.springblade.modules.application.service.IBasicInfoService;
 import org.springblade.modules.applicationDelay.entity.ApplicationDelayEntity;
 import org.springblade.modules.applicationDelay.vo.ApplicationDelayVO;
 import org.springblade.modules.applicationDelay.mapper.ApplicationDelayMapper;
@@ -39,6 +50,7 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -50,8 +62,13 @@
 @Service
 @AllArgsConstructor
 public class ApplicationDelayServiceImpl extends BaseServiceImpl<ApplicationDelayMapper, ApplicationDelayEntity> implements IApplicationDelayService {
+	private final IApplicationService applicationService;
+	private final IBasicInfoService basicInfoService;
+
 	private final IFlowService flowService;
 	private final TaskService taskService;
+	private final RuntimeService runtimeService;
+	private final RepositoryService repositoryService;
 
 	@Override
 	public IPage<ApplicationDelayVO> selectApplicationDelayPage(IPage<ApplicationDelayVO> page, ApplicationDelayVO applicationDelay) {
@@ -98,10 +115,73 @@
 		if (variables == null) {
 			variables = Kv.create();
 		}
+
+
+		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+		ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
+		// 通过流程实例获取“业务键”
+		String businessKey = pi.getBusinessKey().split(":")[1];
+
+		//获取实例对象
+		ApplicationDelayEntity entity = getById(businessKey);
+
+		//未通过审核
+		if (!flow.isPass()){
+			entity.setStatus(AuditStatusConstant.REJECT_AUDIT);
+		}
+
+		//通过审核且下一步就结束
+		if (flow.isPass() && getEndNode(task, entity.getProcessDefinitionId())) {
+			Long applicationId = applicationService.getByNo(entity.getNo()).getId();
+			BasicInfoEntity basicInfo = basicInfoService.getOne(Condition.getQueryWrapper(new BasicInfoEntity(applicationId.toString())));
+			//更新基础信息
+			basicInfo.setStartPassTime(entity.getDelayStartTime());
+			basicInfo.setEndPassTime(entity.getDelayEndTime());
+			basicInfo.setPathway(entity.getPathway());
+			basicInfo.setDeparture(entity.getDeparture());
+			basicInfo.setDestination(entity.getDestination());
+			basicInfo.setPassProvince(entity.getPassProvince());
+			basicInfo.setPassBridge(entity.getPassBridge());
+			basicInfo.setTransportDept(entity.getTransportDept());
+			basicInfoService.updateById(basicInfo);
+
+			//修改审核状态
+			entity.setStatus(AuditStatusConstant.FINISH);
+		}
+
+		updateById(entity);
+
 		variables.put(ProcessConstant.PASS_KEY, flow.isPass());
 		// 完成任务
 		taskService.complete(taskId, variables);
 		return true;
 	}
 
+	/**
+	 * 判断是否包含最终节点且为倒数第二个节点
+	 *
+	 * @param task
+	 * @param definitionId
+	 * @return
+	 */
+	public boolean getEndNode(Task task, String definitionId) {
+		boolean isEnd = false;
+		boolean finalTask = false;
+		BpmnModel bpmnModel = repositoryService.getBpmnModel(definitionId);
+		FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
+		List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows();
+		for (SequenceFlow outgoingFlow : outgoingFlows) {
+			FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
+			FlowElement sourceFlowElement = outgoingFlow.getSourceFlowElement();
+			if (sourceFlowElement.getId().equals("finalTask")) {
+				finalTask = true;
+			}
+			if (targetFlowElement instanceof EndEvent) {
+				isEnd = true;
+				break;
+			}
+		}
+		return isEnd && finalTask;
+	}
+
 }

--
Gitblit v1.9.3