Преглед на файлове

小程序非发起环节重复表可编辑

ouyj преди 1 седмица
родител
ревизия
800a87574c

+ 44 - 2
src/main/bpm/com/yw/bpm/client/action/BpmClientFlowForm2Action.java

@@ -223,6 +223,37 @@ public class BpmClientFlowForm2Action extends RequestAbs {
 						element.put("beCareful", fe.getBeCareful());
 						elementList.add(element);
 					}
+
+					// 重复表组查询
+					conditions.put("formId", formId);
+					conditions.put("isGroup", "0");
+					conditions.put("!type", "0");
+					conditions.put("tmodelId", tmodelId);
+					formElementList = bpmFormDao.getListOfFormElementByConditionsAddBDDZ(conditions);
+					int groupCanEdit = 0;
+					for (int i = 0; i < formElementList.size(); i++) {
+						FormElement fe = formElementList.get(i);
+						String l_element_id = fe.getElementId();
+						conditions.put("elementId", l_element_id);
+						String n_can_edit = "1";
+						if (!StringUtil.isEmptyStr(tmodelId)) {
+							conditions.put("tmodelId", tmodelId);
+							FlowFormElement flowFormElement = bpmFlowModelDao
+									.getFlowFormElementByConditions(conditions);
+							int count = bpmFormDao.getCountOfCanEditForElement(conditions);
+							if (count == 0) {
+								n_can_edit = "0";
+							} else {
+								n_can_edit = flowFormElement.getCanEdit().getValue();
+							}
+						} else {
+							n_can_edit = "0";
+						}
+						if("1".equals(n_can_edit)){
+							groupCanEdit = 1;
+						}
+					}
+
 					// 重复表查询
 					conditions.clear();
 					conditions.put("formId", formId);
@@ -230,6 +261,7 @@ public class BpmClientFlowForm2Action extends RequestAbs {
 					conditions.put("!type", "-1");
 					conditions.put("tmodelId", tmodelId);
 					formElementList = bpmFormDao.getListOfFormElementByConditionsAddBDDZ(conditions);// 根据条件获取表单元素列表(添加表单动作)
+
 					HashMap<String, Object> repeatingForm = new HashMap<>();
 					repeatingForm.put("elementItem", formElementList);
 					List<Map<String, String>> repeatingFormElementList = new ArrayList<>();
@@ -283,6 +315,7 @@ public class BpmClientFlowForm2Action extends RequestAbs {
 								} else {
 									n_can_edit = "0";
 								}
+
 								element.put("defaultValue", defaultValue);
 								element.put("canEdit", n_can_edit);
 								element.put("formId", fe.getFormId().getFormId());
@@ -334,7 +367,7 @@ public class BpmClientFlowForm2Action extends RequestAbs {
 						elementList.get(i).put("defaultValue", defaultValue);
 					}
 					String formElements = JSONArray.fromObject(elementList).toString();
-					return ("{formInfo:" + formInfo + ",formElements:" + formElements + ",\"repeatingForm\":" + repeatingFormStr + "}").replaceAll(":null",
+					return ("{formInfo:" + formInfo + ",formElements:" + formElements + ",\"repeatingForm\":" + repeatingFormStr +",\"groupCanEdit\":" + groupCanEdit + "}").replaceAll(":null",
 							":\"\"");
 				}
 				return "0";
@@ -453,6 +486,15 @@ public class BpmClientFlowForm2Action extends RequestAbs {
 						element.put("beCareful", fe.getBeCareful());
 						elementList.add(element);
 					}
+
+					// 重复表组查询
+					/*conditions.clear();
+					conditions.put("formId", formId);
+					conditions.put("isGroup", "0");
+					conditions.put("!type", "0");
+					formElementList = bpmFormDao.getListOfFormElementByConditions(conditions);*/
+					int groupCanEdit = 0;
+
 					// 重复表查询
 					conditions.clear();
 					conditions.put("formId", formId);
@@ -545,7 +587,7 @@ public class BpmClientFlowForm2Action extends RequestAbs {
 					String repeatingFormStr = JSONObject.fromObject(repeatingForm).toString();
 
 					String formElements = JSONArray.fromObject(elementList).toString();
-					return ("{formInfo:" + formInfo + ",formElements:" + formElements + ",\"repeatingForm\":" + repeatingFormStr + ",control:\"-1\"}")
+					return ("{formInfo:" + formInfo + ",formElements:" + formElements + ",\"repeatingForm\":" + repeatingFormStr+",\"groupCanEdit\":" + groupCanEdit + ",control:\"-1\"}")
 							.replaceAll(":null", ":\"\"");
 				}
 				return "0";

+ 46 - 3
src/main/bpm/com/yw/bpm/client/action/BpmClientFlowFormAction.java

@@ -316,6 +316,37 @@ public class BpmClientFlowFormAction extends RequestAbs {
 						elementList.add(element);
 					}
 
+					// 重复表组查询
+					conditions.clear();
+					conditions.put("formId", formId);
+					conditions.put("isGroup", "0");
+					conditions.put("!type", "0");
+					conditions.put("tmodelId", l_tmodel_id);
+					formElementList = bpmFormDao.getListOfFormElementByConditionsAddBDDZ(conditions);
+					int groupCanEdit = 0;
+					for (int i = 0; i < formElementList.size(); i++) {
+						FormElement fe = formElementList.get(i);
+						String l_element_id = fe.getElementId();
+						conditions.put("elementId", l_element_id);
+						String n_can_edit = "1";
+						if (!StringUtil.isEmptyStr(l_tmodel_id)) {
+							conditions.put("tmodelId", l_tmodel_id);
+							FlowFormElement flowFormElement = bpmFlowModelDao
+									.getFlowFormElementByConditions(conditions);
+							int count = bpmFormDao.getCountOfCanEditForElement(conditions);
+							if (count == 0) {
+								n_can_edit = "0";
+							} else {
+								n_can_edit = flowFormElement.getCanEdit().getValue();
+							}
+						} else {
+							n_can_edit = "0";
+						}
+						if("1".equals(n_can_edit)){
+							groupCanEdit = 1;
+						}
+					}
+
 					// 重复表查询
 					conditions.clear();
 					conditions.put("formId", formId);
@@ -379,6 +410,7 @@ public class BpmClientFlowFormAction extends RequestAbs {
 								} else {
 									n_can_edit = "0";
 								}
+
 								element.put("inputPrompt", inputPrompt);
 								element.put("beCareful", beCareful);
 								element.put("defaultValue", defaultValue);
@@ -453,7 +485,7 @@ public class BpmClientFlowFormAction extends RequestAbs {
 					if(allowCancel>0&&fiDate==null&&caDate==null){
 						allowCancelS=1;
 					}
-					return ("{\"formInfo\":" + formInfo + ",\"formElements\":" + formElements + ",\"repeatingForm\":" + repeatingFormStr +",\"isCancel\":" + isCancel +",\"allowCancel\":" + allowCancelS +",\"fileList\":"+ fileList + "}").replaceAll(":null",":\"\"");
+					return ("{\"formInfo\":" + formInfo + ",\"formElements\":" + formElements + ",\"repeatingForm\":" + repeatingFormStr +",\"groupCanEdit\":" + groupCanEdit +",\"isCancel\":" + isCancel +",\"allowCancel\":" + allowCancelS +",\"fileList\":"+ fileList + "}").replaceAll(":null",":\"\"");
 				}
 				return "0";
 			} else {
@@ -585,6 +617,16 @@ public class BpmClientFlowFormAction extends RequestAbs {
 						element.put("noNull", n_no_null);
 						elementList.add(element);
 					}
+
+					// 重复表组查询
+					/*conditions.clear();
+					conditions.put("formId", formId);
+					conditions.put("isGroup", "0");
+					conditions.put("!type", "0");
+					conditions.put("lmodelId", l_model_id);
+					formElementList = bpmFormDao.getListOfFormElementByConditions(conditions);*/
+					int groupCanEdit = 0;
+
 					// 重复表查询
 					conditions.clear();
 					conditions.put("formId", formId);
@@ -643,6 +685,7 @@ public class BpmClientFlowFormAction extends RequestAbs {
 								} else {
 									n_can_edit = flowFormElement.getCanEdit().getValue();
 								}
+
 								inputPrompt = flowFormElement.getInputPrompt();
 								beCareful = flowFormElement.getBeCareful();
 								element.put("n_can_view", flowFormElement.getCanView().getValue());
@@ -742,8 +785,8 @@ public class BpmClientFlowFormAction extends RequestAbs {
 					}
 					String formElements = JSONArray.fromObject(elementList).toString();
 					String fileList = JsonUtil.getJson(fileMap, true);
-					return ("{\"formInfo\":" + formInfo + ",\"formElements\":" + formElements + ",\"isCancel\":" + ",\"repeatingForm\":" + repeatingFormStr
-							+ isCancel + ",\"allowCancel\":" + allowCancelS +",\"fileList\":"+ fileList+ "}").replaceAll(":null", ":\"\"");
+					return ("{\"formInfo\":" + formInfo + ",\"formElements\":" + formElements + ",\"repeatingForm\":" + repeatingFormStr +",\"groupCanEdit\":" + groupCanEdit
+							+ ",\"isCancel\":" + isCancel + ",\"allowCancel\":" + allowCancelS +",\"fileList\":"+ fileList+ "}").replaceAll(":null", ":\"\"");
 				}
 			}
 			return "0";

+ 159 - 22
src/main/bpm/com/yw/bpm/client/service/BpmClientFlowSubProcessServiceImpl.java

@@ -10,6 +10,7 @@ import java.util.Set;
 
 import com.yw.bpm.seal.service.SealService;
 import org.springframework.context.ApplicationContext;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.transaction.annotation.Transactional; 
 
 import com.yw.bpm.flow.dao.FlowModelDao;
@@ -41,9 +42,10 @@ public class BpmClientFlowSubProcessServiceImpl implements BpmClientFlowSubProce
 		FormDao bpmFormDao = (FormDao) cxt.getBean("bpmFormDao");
 		FlowModelDao flowModelDao = (FlowModelDao) cxt.getBean("bpmFlowModelDao");
 		FormSealInfoDao bpmFormSealDao = (FormSealInfoDao) cxt.getBean("bpmFormSealDao");
+		JdbcTemplate jdbcTemplate = (JdbcTemplate) cxt.getBean("jdbcTemplate");
 //		SealService sealService = (SealService) cxt.getBean("bpmSealService");
 		//FormDao bpmFormDao = (FormDao) cxt.getBean("iformDao"); 
-		int result = 0;
+		int result = 0; // 默认值为 0,后续根据实际执行情况更新
 		String l_form_id = String.valueOf(formIns.get("formId")); 
 		String l_form_ins_id = String.valueOf(formIns.get("formInsId"));
 		List<Map<String, Object>> formElementsList = (List<Map<String, Object>>)formIns.get("formElementsList");
@@ -128,28 +130,163 @@ public class BpmClientFlowSubProcessServiceImpl implements BpmClientFlowSubProce
 				result = bpmFormDao.updateSqlForGen(sql.toString(), values);
 			}
 			if(formElementsListForGroup.size() > 0){
-				// 拼成sql语句
-				//待修改
+			 	result = 1; // 标记已进入重复表处理逻辑,避免 result 保持为 0
+				// 获取所有重复表字段配置
+				Map<String, String> conditions = new HashMap<String, String>();
+				conditions.put("formId", l_form_id);
+				conditions.put("isGroup", "1");
+				conditions.put("!type", "-1");
+				List<FormElement> elementInfos = bpmFormDao.getListOfFormElementByConditions(conditions);
+				
+				// 建立映射:elementId -> FormElement
+				Map<String, FormElement> elementConfigMap = new HashMap<String, FormElement>();
+				for (FormElement fe : elementInfos) {
+					elementConfigMap.put(fe.getElementId(), fe);
+				}
+				
+				// 按 groupid 分组(兼容大小写)
+				Map<String, List<Map<String, Object>>> groupMap = new HashMap<String, List<Map<String, Object>>>();
 				for (Map<String, Object> element : formElementsListForGroup) {
-					StringBuffer sql = new StringBuffer("UPDATE oa_form_group_"+element.get("groupid"));
-					//String tableName = String.valueOf(formInfo.getTable());
-					//sql.append(tableName);
-					sql.append(" SET "); 
-					StringBuffer elementSbuffer = new StringBuffer("");
-					List<Object> values = new ArrayList<Object>();  
-			 		String elementName = String.valueOf(element
-			 				.get("tableField"));
-					elementSbuffer.append(elementName + "=?,");
-					if ("".equals(element.get("value"))) {
-						values.add(null);
-					} else {
-						values.add(element.get("value"));
-					} 
-					sql.append(elementSbuffer.substring(0, elementSbuffer.length() - 1));
-					sql.append(" WHERE l_form_ins_id=? AND l_form_group_id=? ");
-					values.add(l_form_ins_id);
-					values.add(element.get("groupuid"));
-					result = bpmFormDao.updateSqlForGen(sql.toString(), values);
+					String gid = String.valueOf(element.get("groupid"));
+					if (StringUtil.stringIsNull(gid) || "null".equals(gid)) {
+						gid = String.valueOf(element.get("groupId"));
+					}
+					if (StringUtil.stringIsNull(gid) || "null".equals(gid)) {
+						continue;
+					}
+					if (!groupMap.containsKey(gid)) {
+						groupMap.put(gid, new ArrayList<Map<String, Object>>());
+					}
+					groupMap.get(gid).add(element);
+				}
+
+				// 遍历每个组进行处理
+				for (Map.Entry<String, List<Map<String, Object>>> entry : groupMap.entrySet()) {
+					String groupId = entry.getKey();
+					List<Map<String, Object>> groupItems = entry.getValue();
+
+					// 提取前端传来的所有 groupuid
+					List<String> submittedUids = new ArrayList<String>();
+					for (Map<String, Object> item : groupItems) {
+						String uid = String.valueOf(item.get("groupuid"));
+						if (!StringUtil.stringIsNull(uid) && !submittedUids.contains(uid)) {
+							submittedUids.add(uid);
+						}
+					}
+					
+					// 同步删除:查出数据库里所有旧行,如果前端没传就删掉
+					String oldIdsSql = "SELECT l_form_group_id FROM oa_form_group_" + groupId + " WHERE l_form_ins_id=?";
+					List<Map<String, Object>> oldRows = jdbcTemplate.queryForList(oldIdsSql, l_form_ins_id);
+					for (Map<String, Object> oldRow : oldRows) {
+						String oldUid = String.valueOf(oldRow.get("l_form_group_id"));
+						if (!submittedUids.contains(oldUid)) {
+							String deleteSql = "DELETE FROM oa_form_group_" + groupId + " WHERE l_form_ins_id=? AND l_form_group_id=?";
+							bpmFormDao.updateSqlForGen(deleteSql, java.util.Arrays.asList(l_form_ins_id, oldUid));
+						}
+					}
+					
+					// 按 groupuid 分组
+					Map<String, List<Map<String, Object>>> rowMap = new HashMap<String, List<Map<String, Object>>>();
+					List<String> newRowOrder = new ArrayList<String>();
+					String currentNewRowUid = null; // 当前新行的 UID
+					int fieldCount = elementInfos.size(); // 每行有多少个字段
+					int fieldIndex = 0;
+					
+					for (Map<String, Object> item : groupItems) {
+						String uid = String.valueOf(item.get("groupuid"));
+						if (StringUtil.stringIsNull(uid) || "null".equals(uid)) {
+							// 新行:每 fieldCount 个字段换一次 UID
+							if (fieldIndex % fieldCount == 0) {
+								currentNewRowUid = SystemUtil.getSeq();
+							}
+							uid = currentNewRowUid;
+							item.put("groupuid", uid);
+							fieldIndex++;
+						}
+						if (!rowMap.containsKey(uid)) {
+							rowMap.put(uid, new ArrayList<Map<String, Object>>());
+							newRowOrder.add(uid);
+						}
+						rowMap.get(uid).add(item);
+					}
+					
+					// 遍历每一行进行保存
+					int currentCount = 1;
+					for (String rowUid : newRowOrder) {
+						List<Map<String, Object>> rowData = rowMap.get(rowUid);
+						
+						// 检查数据库中是否存在该 l_form_group_id
+						int count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM oa_form_group_" + groupId + " WHERE l_form_ins_id=? AND l_form_group_id=?", Integer.class, l_form_ins_id, rowUid);
+						boolean isExistingRow = count > 0;
+
+						// 收集字段值
+						List<Object> values = new ArrayList<Object>();
+						StringBuilder updateBuffer = new StringBuilder(); // 用于 UPDATE: field=?, 
+						StringBuilder insertFields = new StringBuilder(); // 用于 INSERT: field, 
+						boolean hasField = false;
+						
+						for (Map<String, Object> item : rowData) {
+							String elementId = String.valueOf(item.get("elementId"));
+							FormElement config = elementConfigMap.get(elementId);
+							String elementName = config != null ? config.getTableField() : String.valueOf(item.get("tableField"));
+							
+							if (StringUtil.stringIsNull(elementName) || "null".equals(elementName)) continue;
+							
+							Object value = "".equals(item.get("value")) ? null : item.get("value");
+							
+							// UPDATE 时跳过 null 值,避免覆盖数据库原有数据
+							if (isExistingRow && value == null) {
+								continue;
+							}
+							
+							hasField = true;
+							updateBuffer.append(elementName).append("=?, ");
+							insertFields.append(elementName).append(", ");
+							values.add(value);
+						}
+						
+						if (!hasField) continue;
+						
+						if (isExistingRow) {
+							// 执行 UPDATE
+							String updateSql = "UPDATE oa_form_group_" + groupId + " SET " 
+									+ updateBuffer.substring(0, updateBuffer.length() - 2) 
+									+ " WHERE l_form_ins_id=? AND l_form_group_id=?";
+							values.add(l_form_ins_id);
+							values.add(rowUid);
+							int updateResult = bpmFormDao.updateSqlForGen(updateSql, values);
+							if (updateResult > 0) {
+								result = updateResult; // 记录成功的结果
+							}
+												
+							// 更新序号
+							String updateCountSql = "UPDATE oa_form_group_" + groupId + " SET l_form_group_count=? WHERE l_form_ins_id=? AND l_form_group_id=?";
+							bpmFormDao.updateSqlForGen(updateCountSql, java.util.Arrays.asList(currentCount, l_form_ins_id, rowUid));
+						} else {
+							// 执行 INSERT
+							String insertSql = "INSERT INTO oa_form_group_" + groupId 
+									+ "(l_form_ins_id, l_form_group_id, l_form_group_count, " 
+									+ insertFields.substring(0, insertFields.length() - 2) + ") "
+									+ "VALUES (?, ?, ?, " 
+									+ String.join(", ", java.util.Collections.nCopies(values.size(), "?")) + ")";
+												
+							List<Object> allValues = new ArrayList<Object>();
+							allValues.add(l_form_ins_id);
+							allValues.add(rowUid);
+							allValues.add(currentCount);
+							allValues.addAll(values);
+							try {
+								int insertResult = bpmFormDao.updateSqlForGen(insertSql, allValues);
+								if (insertResult > 0) {
+									result = insertResult; // 记录成功的结果
+								}
+							} catch (Exception e) {
+								e.printStackTrace();
+								throw e;
+							}
+						}
+						currentCount++;
+					}
 				}
 			}
 		}else{

+ 1 - 1
src/main/hr/com/yw/hr/timer_task.xml

@@ -2,7 +2,7 @@
 	<jobs>
 		<job name="hrQualificationValidTimerTask" init="false" class="com.yw.hr.job.config.action.HrQualificationValidTimerTask"></job>
 		<job name="hrQualificationYearTimerTask" init="false" class="com.yw.hr.job.config.action.HrQualificationYearTimerTask"></job>
-		<job name="hrSegementTipTimerTask" init="true" class="com.yw.hr.staff.action.HrSegementTipTimerTask"></job>
+		<!--<job name="hrSegementTipTimerTask" init="true" class="com.yw.hr.staff.action.HrSegementTipTimerTask"></job>-->
 		<!-- 漏打卡定时器 -->
 		<job name="hrClockInLeakageTimerTask" init="true" class="com.yw.hr.job.config.action.HrClockInLeakageTimerTask"></job>
 		<!-- 海康考勤记录同步定时器 -->