|
@@ -0,0 +1,174 @@
|
|
|
|
+package com.zkqy.execution.produce.dispersed.service.impl.runbpm.jiaoyu.common;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
|
+import com.fasterxml.jackson.core.JsonGenerator;
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
+import com.fasterxml.jackson.databind.JsonSerializer;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
|
+import com.fasterxml.jackson.databind.SerializerProvider;
|
|
|
|
+import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
|
+import com.fasterxml.jackson.databind.ser.std.DateSerializer;
|
|
|
|
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
|
+import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
|
|
|
+import com.google.gson.JsonObject;
|
|
|
|
+import com.zkqy.common.utils.StringUtils;
|
|
|
|
+import com.zkqy.execution.produce.dispersed.entity.BpmExecuteNode;
|
|
|
|
+import com.zkqy.execution.produce.dispersed.entity.CommonEntity;
|
|
|
|
+import com.zkqy.execution.produce.dispersed.entity.runbpm.IntoProduction;
|
|
|
|
+import com.zkqy.execution.produce.dispersed.service.IBpmExecuteNodeService;
|
|
|
|
+import com.zkqy.execution.produce.dispersed.service.IScriptService;
|
|
|
|
+import com.zkqy.execution.produce.dispersed.service.impl.CommonServiceImpl;
|
|
|
|
+import com.zkqy.execution.produce.utils.Sending;
|
|
|
|
+import org.apache.xmlbeans.soap.SOAPArrayType;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.context.annotation.Scope;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.annotation.PreDestroy;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.time.temporal.TemporalAccessor;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 教育行业投产脚本呢
|
|
|
|
+ */
|
|
|
|
+@Service("b89c0a3e-2c2b-4959-ac4f-a504966b5db6")
|
|
|
|
+@Scope("prototype")
|
|
|
|
+public class EducationCommonProductionSchedulingServiceImpl implements IScriptService {
|
|
|
|
+
|
|
|
|
+ @Autowired // 执行节点记录表
|
|
|
|
+ private IBpmExecuteNodeService iBpmExecuteNodeService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private Sending sending;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CommonServiceImpl commonService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object preExecutionScript(Object parameter) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object executionScript(Object parameter) {
|
|
|
|
+ // 得到当前脚本执行所需数据
|
|
|
|
+ IntoProduction intoProduction = (IntoProduction) parameter;
|
|
|
|
+ // 根据流程别名 把开始节点执行
|
|
|
|
+ BpmExecuteNode bpmExecuteNode = new BpmExecuteNode();
|
|
|
|
+ bpmExecuteNode.setTaskNodeState("1"); // 0未执行、1已执行
|
|
|
|
+ bpmExecuteNode.setTaskNodeType("startEvent"); // 每个流程里只会存在一个开始节点
|
|
|
|
+ bpmExecuteNode.setTaskProcessKey(intoProduction.getTaskProcessKey()); // 当前任务流程的任务编码
|
|
|
|
+ iBpmExecuteNodeService.updateNodeState(bpmExecuteNode); // 执行修改节点状态
|
|
|
|
+
|
|
|
|
+ // 修改用户业务表中的状态
|
|
|
|
+ CommonEntity commonEntity = new CommonEntity();
|
|
|
|
+ Map<String, Object> conMap = new HashMap<>(); // sql条件map
|
|
|
|
+ Map<String, Object> basicMap = new HashMap<>(); // 默认参数map
|
|
|
|
+
|
|
|
|
+ String con[] = intoProduction.getGuid().split("=");
|
|
|
|
+ conMap.put(con[0], con[1]);
|
|
|
|
+ commonEntity.setConditionMap(conMap); // 得到修改表的条件
|
|
|
|
+ basicMap.put("tableName", intoProduction.getTableName());
|
|
|
|
+ commonEntity.setBasicMap(basicMap); // 得到修改的表名
|
|
|
|
+ commonEntity.setCommMap(intoProduction.getStateMap()); // 需要修改的列
|
|
|
|
+ // 根据其他的条件更新投产表状态
|
|
|
|
+ int i = sending.sendCommonUpdate(commonEntity);
|
|
|
|
+ //开启产线
|
|
|
|
+ //1、查询开启产线需要的相关信息
|
|
|
|
+ CommonEntity common =new CommonEntity();
|
|
|
|
+ //2、查询那张表的的数据
|
|
|
|
+ HashMap basicMapInfo=new HashMap();
|
|
|
|
+ basicMapInfo.put("tableName",intoProduction.getTableName());//查询的是计划表
|
|
|
|
+ common.setBasicMap(basicMapInfo);
|
|
|
|
+ //3、查询表数据的条件信息
|
|
|
|
+ HashMap conditionMapInfo=new HashMap();
|
|
|
|
+ conditionMapInfo.put(con[0],con[1]);
|
|
|
|
+ common.setConditionMap(conditionMapInfo);
|
|
|
|
+ CommonEntity planInfo = commonService.getInfoById(common);
|
|
|
|
+ //4、得到这个计划的基本信息
|
|
|
|
+ Map<String, Object> resultMap = planInfo.getResultMap();
|
|
|
|
+ resultMap.remove("remark");
|
|
|
|
+ resultMap.remove("task_name");
|
|
|
|
+ resultMap.remove("create_by_id");
|
|
|
|
+ resultMap.remove("create_by");
|
|
|
|
+ resultMap.remove("update_time");
|
|
|
|
+ resultMap.remove("process_key");
|
|
|
|
+ resultMap.remove("id");
|
|
|
|
+ resultMap.remove("update_by");
|
|
|
|
+ resultMap.remove("del_flag");
|
|
|
|
+ resultMap.remove("task_node_key");
|
|
|
|
+ resultMap.remove("create_time");
|
|
|
|
+ resultMap.remove("data_approval_status");
|
|
|
|
+ resultMap.remove("task_process_key");
|
|
|
|
+ resultMap.remove("update_by_id");
|
|
|
|
+ resultMap.remove("status");
|
|
|
|
+ Map<String, Object> resultMap2=new HashMap<>();
|
|
|
|
+ //转驼峰
|
|
|
|
+ resultMap.forEach((key,value)->{
|
|
|
|
+ resultMap2.put(StringUtils.toCamelCase(key),value);
|
|
|
|
+ });
|
|
|
|
+ //5、结果转Json对象(是不是启动产线所需要的数据)
|
|
|
|
+ if(resultMap2!=null){
|
|
|
|
+ try {
|
|
|
|
+ //5.1、转换Json SerializerFeature.WriteMapNullValue
|
|
|
|
+ // 创建 ObjectMapper 实例并设置其配置
|
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
|
+ // 开启日期/时间格式化输出
|
|
|
|
+ mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
|
|
+ mapper.registerModule(new JavaTimeModule());
|
|
|
|
+ SimpleModule module = new SimpleModule();
|
|
|
|
+ // 自定义日期格式
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ // 自定义日期格式
|
|
|
|
+ SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ // 处理dataTime类型的
|
|
|
|
+ module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
|
|
|
|
+ // 处理data类型的
|
|
|
|
+ module.addSerializer(Date.class,new JsonSerializer<Date>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers)
|
|
|
|
+ throws IOException {
|
|
|
|
+ String formattedDate = formatter2.format(value);
|
|
|
|
+ gen.writeString(formattedDate);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ mapper.registerModule(module);
|
|
|
|
+ //空的也让他序列化
|
|
|
|
+ mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS); // 或者 Include.NON_NULL 如果你想反向操作,排除所有null值
|
|
|
|
+ String JsonString = mapper.writeValueAsString(resultMap2);
|
|
|
|
+ //String res =sending.sendPostRequest("http://mes.063520.com/api/v1/mes/public/task/start", JsonString, String.class).toString();
|
|
|
|
+ // System.err.println(res);
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object afterExecutionScript(Object parameter) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean isVerificationMethod() {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @PreDestroy
|
|
|
|
+ public boolean preDestroy() {
|
|
|
|
+ System.out.println("清理成功!");
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+}
|