|
|
@@ -18,6 +18,7 @@ import org.quartz.JobExecutionContext;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
@@ -38,10 +39,149 @@ public class TenMinutesJob extends AbstractJob{
|
|
|
context.getTrigger().getKey().getName());
|
|
|
logger.warn("jobDataMap=is {}.", JacksonUtil.toJsonString(dataMap.getWrappedMap()));
|
|
|
|
|
|
- // 开启 员工建议调查表 流程
|
|
|
+ //任务1 开启 员工建议调查表 流程
|
|
|
startYgjydcbFlow();
|
|
|
+ //任务2 任务4293 新增一个定时 药敏试验人员比对-增加计划功能 都是十分钟执行一次所以和开启员工建议调查表流程放在一起,两个是不同的业务
|
|
|
+ // 如果以后某一个需要修改推送时间需要移出该定时
|
|
|
+ startYmsyrydbFlow();
|
|
|
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 替换SQL中的占位符 {p0}、{p1} 为实际参数值
|
|
|
+ * @param sql 原始SQL(如 "UPDATE ... WHERE id_= {p0} AND p_id_ = {p1}")
|
|
|
+ * @param params 参数值(按 p0, p1 顺序传入)
|
|
|
+ * @return 替换后的SQL
|
|
|
+ */
|
|
|
+ public static String replaceSqlParams(String sql, Object... params) {
|
|
|
+ // 使用正则匹配所有 {p0}, {p1}, {p2}... 占位符
|
|
|
+ java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("\\{p\\d+\\}");
|
|
|
+ java.util.regex.Matcher matcher = pattern.matcher(sql);
|
|
|
+
|
|
|
+ // 计算占位符数量
|
|
|
+ int expectedParams = 0;
|
|
|
+ while (matcher.find()) {
|
|
|
+ expectedParams++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (params.length != expectedParams) {
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ String.format("参数数量不匹配: 需要 %d 个参数,实际传入 %d", expectedParams, params.length)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 替换占位符
|
|
|
+ for (int i = 0; i < params.length; i++) {
|
|
|
+ sql = sql.replaceAll("\\{p" + i + "\\}", String.valueOf(params[i]));
|
|
|
+ }
|
|
|
+ return sql;
|
|
|
+ }
|
|
|
+ private void startYmsyrydbFlow() throws Exception {
|
|
|
+ //1.0业务处理,只推送比对日期为当日且未推送过的数据
|
|
|
+ String fetchSql = "select * FROM t_ymsyrybdb where type='startRecord' and DATE_FORMAT(bi_dui_ri_qi_,'%Y-%m-%d')=CURRENT_DATE and (flag_ is null or flag_=0)";
|
|
|
+ List<Map<String, Object>> qryList = (List<Map<String, Object>>) commonDao.query(fetchSql);
|
|
|
+ if (BeanUtils.isEmpty(qryList)) return;
|
|
|
+ //HashMap<String, Object> ids = new HashMap<>();
|
|
|
+ for(Map<String, Object> zhubData : qryList){
|
|
|
+ Object bi_dui_ren_ ;
|
|
|
+ ArrayList<String> zbParentIds = new ArrayList<>();//子表对应主表的parent_id_集合
|
|
|
+ if(BeanUtils.isEmpty(bi_dui_ren_= zhubData.get("bi_dui_ren_"))){
|
|
|
+ throw new NullPointerException("bi_dui_ren_不允许为空");
|
|
|
+ }
|
|
|
+ String[] biDuiRenArray = bi_dui_ren_.toString().split(StringPool.COMMA);
|
|
|
+ for(String biDuiRen : biDuiRenArray){
|
|
|
+ insertYmsyrybdb(biDuiRen,zhubData,zbParentIds);
|
|
|
+ }
|
|
|
+ //拆分的数据全部插入数据库之后需要将元数据的flag_值设置为1
|
|
|
+ String execSql = "UPDATE t_ymsyrybdb SET flag_ = '1' where id_= {p0} ";
|
|
|
+ String newExecSql = replaceSqlParams(execSql, zhubData.get("id_"));
|
|
|
+ commonDao.execute(newExecSql);
|
|
|
+ //更新子表t_jcjgxqb和t_bbxqb
|
|
|
+ if(zbParentIds.size()>0){
|
|
|
+ UpJcjgxqbAndBbxqb((String) zhubData.get("id_"),zbParentIds);
|
|
|
+ }
|
|
|
+ //2.0流程推送
|
|
|
+ //for(String id :zbParentIds){
|
|
|
+ startYmWorkflow(zbParentIds,"ymsyrybdb","Process_0av0xhm");
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void startYmWorkflow(ArrayList<String> ids, String formKey, String defKey) {
|
|
|
+ if (BeanUtils.isEmpty(ids) || ids.size()<1) return;
|
|
|
+ String[] arrayIds = ids.stream().toArray(String[]::new);
|
|
|
+ //System.out.println(Arrays.toString(array)); // 输出: [id1, id2, id3]
|
|
|
+ IBpmInstService bpmInstService = AppUtil.getBean(IBpmInstService.class);
|
|
|
+ if (StringUtils.isBlank(ContextUtil.getCurrentAccessToken())) {
|
|
|
+ ITenantTokenService tenantTokenService = AppUtil.getBean(ITenantTokenService.class);
|
|
|
+ String accessToken = tenantTokenService.getAccessToken();
|
|
|
+ ContextUtil.setCurrentAccessToken(accessToken);
|
|
|
+ }
|
|
|
+ APIResult<String> result = bpmInstService.startFlowFromList(arrayIds, formKey, defKey,StringPool.TRUE);
|
|
|
+ result.getState();
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * id_ 主表id 用于去子表查找需要编辑的元数据
|
|
|
+ * zbParentIds 子表需要插入数据,每一个都需要插入用主表id_查出的条数
|
|
|
+ * */
|
|
|
+ private void UpJcjgxqbAndBbxqb(String id_, ArrayList<String> zbParentIds) throws Exception {
|
|
|
+ String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
+ String sqlJcjgxqb = "select * from t_jcjgxqb where parent_id_= {p0}";
|
|
|
+ String sqlBbxqb ="select * from t_bbxqb where parent_id_= {p0}";
|
|
|
+ List<Map<String, Object>> qryJcjgxqb = (List<Map<String, Object>>) commonDao.query(replaceSqlParams(sqlJcjgxqb,id_));
|
|
|
+ List<Map<String, Object>> qryBbxqb = (List<Map<String, Object>>) commonDao.query(replaceSqlParams(sqlBbxqb,id_));
|
|
|
+ if(BeanUtils.isNotEmpty(qryJcjgxqb) && qryJcjgxqb.size()>0){
|
|
|
+ for(String zbParentId :zbParentIds){
|
|
|
+ for(Map<String, Object> jcjgxqbData : qryJcjgxqb){
|
|
|
+ String id = UniqueIdUtil.getId();
|
|
|
+ //需要重新修改的值
|
|
|
+ jcjgxqbData.put("id_", id);
|
|
|
+ jcjgxqbData.put("parent_id_", zbParentId);
|
|
|
+ jcjgxqbData.put("create_time_", currentTime);
|
|
|
+ commonDao.execute(buildInsertSql(jcjgxqbData,"t_jcjgxqb"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(BeanUtils.isNotEmpty(qryBbxqb) && qryBbxqb.size()>0){
|
|
|
+ for(String zbParentId :zbParentIds){
|
|
|
+ for(Map<String, Object> qryBbxqbData : qryBbxqb){
|
|
|
+ String id = UniqueIdUtil.getId();
|
|
|
+ //需要重新修改的值
|
|
|
+ qryBbxqbData.put("id_", id);
|
|
|
+ qryBbxqbData.put("parent_id_", zbParentId);
|
|
|
+ qryBbxqbData.put("create_time_", currentTime);
|
|
|
+ commonDao.execute(buildInsertSql(qryBbxqbData,"t_bbxqb"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> insertYmsyrybdb(String biDuiRen, Map<String, Object> map, ArrayList<String> zbParentIds) throws Exception {
|
|
|
+ //深拷贝值
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ String id = UniqueIdUtil.getId();
|
|
|
+ map.forEach((key, value) -> {
|
|
|
+ data.put(key, value);
|
|
|
+ });
|
|
|
+ //需要重新修改的值
|
|
|
+ data.put("id_", id);
|
|
|
+ //新拆分的数据的的type必须重置为空
|
|
|
+ data.put("type","");
|
|
|
+ data.put("bi_dui_ren_",biDuiRen);
|
|
|
+ String sql = "select * from ibps_party_employee where id_ = {p0}";
|
|
|
+ String newSql = replaceSqlParams(sql, biDuiRen);
|
|
|
+ List<Map<String, Object>> qryList = (List<Map<String, Object>>) commonDao.query(newSql);
|
|
|
+ //data.put("parent_id_",map.get("id_"));
|
|
|
+ //Map<String, Object> m1 = qryList.get(0);
|
|
|
+ //String s = (String) m1.get("NAME_");
|
|
|
+ data.put("bi_dui_ren_ming_c",qryList.get(0).get("NAME_"));
|
|
|
+ //修改编制人为比对人,前端流程审批管理页面候选人取值取得就是编制人
|
|
|
+ data.put("bian_zhi_ren_",data.get("bi_dui_ren_"));
|
|
|
+ String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
+ data.put("create_time_", currentTime);
|
|
|
+ commonDao.execute(buildInsertSql(data,"t_ymsyrybdb"));
|
|
|
+ //执行成功后将生成的主表新数据的id登记下来作为子表的parent_id_
|
|
|
+ zbParentIds.add(id);
|
|
|
+ return zbParentIds;
|
|
|
+ }
|
|
|
|
|
|
private void startYgjydcbFlow() throws Exception {
|
|
|
String fetchSql = "SELECT *from t_ygjydcbz WHERE shi_fou_guo_shen_='未开始' and DATE_FORMAT(diao_cha_shi_jian,'%Y-%m-%d')=CURRENT_DATE";
|