TimepieceSchemeBillEditHandlerEx.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. package com.kingdee.shr.compensation.web.handler.timepiece.bill;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.metadata.entity.EntityViewInfo;
  5. import com.kingdee.bos.metadata.entity.FilterInfo;
  6. import com.kingdee.bos.metadata.entity.FilterItemInfo;
  7. import com.kingdee.bos.metadata.entity.SelectorItemCollection;
  8. import com.kingdee.bos.metadata.entity.SelectorItemInfo;
  9. import com.kingdee.bos.metadata.query.util.CompareType;
  10. import com.kingdee.eas.framework.CoreBaseInfo;
  11. import com.kingdee.eas.util.ToolUtils;
  12. import com.kingdee.shr.base.syssetting.context.SHRContext;
  13. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  14. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  15. import com.kingdee.shr.compensation.app.integrate.*;
  16. import com.kingdee.shr.compensation.app.utils.DateRange;
  17. import com.kingdee.shr.compensation.app.utils.SubmitShemeUtils;
  18. import com.kingdee.shr.compensation.exception.ExceptionHandle;
  19. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  20. import java.text.SimpleDateFormat;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.HashSet;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.Set;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30. import org.apache.commons.lang3.ObjectUtils;
  31. import org.apache.commons.lang3.StringUtils;
  32. import org.slf4j.Logger;
  33. import org.slf4j.LoggerFactory;
  34. import org.springframework.ui.ModelMap;
  35. /**
  36. * 提报单拓展
  37. * @author coyle
  38. * 20250520
  39. */
  40. public class TimepieceSchemeBillEditHandlerEx extends TimepieceSchemeBillEditHandler {
  41. private static Logger logger = LoggerFactory.getLogger(TimepieceSchemeBillEditHandlerEx.class);
  42. private static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");
  43. //完成率
  44. // private static String COMRATE = "MQ005";
  45. // //岗位类型
  46. // private static String JOBTYPE = "MQ004";
  47. // //技能等级 SKILLLEVEL
  48. // private static String SKILLLEVEL = "MQ003";
  49. // //是否现场作业 On site
  50. // private static String ONSITE = "MQ007";
  51. // //班组任职 Team app
  52. // private static String TEAMAPP = "MQ007";
  53. // //工资序列 Salary seq
  54. // private static String SALARYSEQ = "MQ007";
  55. //
  56. // private static String[] ITEMNUMS = {COMRATE,JOBTYPE,SKILLLEVEL,ONSITE,TEAMAPP,SALARYSEQ};
  57. //
  58. // private static Map<String,String> FEILDS = new HashMap();
  59. // public TimepieceSchemeBillEditHandlerEx() throws BOSException {
  60. // Context ctx = SHRContext.getInstance().getContext();
  61. // CalSubmitItemCollection subColl = CalSubmitItemFactory.getLocalInstance(ctx)
  62. // .getCalSubmitItemCollection("SELECT ID,FieldSn,number where number in (" + ToolUtils.aryToStr(ITEMNUMS) + ")");
  63. // if (subColl != null && subColl.size() > 0) {
  64. // for (int i =0 ;i<subColl.size();i++) {
  65. // CalSubmitItemInfo itemInfo = subColl.get(i);
  66. // if (itemInfo != null) {
  67. // String columnName = "S" + itemInfo.getFieldSn();
  68. // FEILDS.put(itemInfo.getNumber() , columnName);
  69. // }
  70. // }
  71. // }
  72. // }
  73. protected void beforeSubmit(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model) throws SHRWebException {
  74. super.beforeSubmit(request, response, model);
  75. Context ctx = SHRContext.getInstance().getContext();
  76. String operateStatus = (String)request.getAttribute("operateState");
  77. if (StringUtils.isEmpty(operateStatus)) {
  78. operateStatus = request.getParameter("operateState");
  79. }
  80. if ("VIEW".equalsIgnoreCase(operateStatus)) {
  81. model = (CoreBaseInfo)request.getAttribute("dynamic_model");
  82. }
  83. try {
  84. BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo)model;
  85. BatchSubmitShemeBillEntryCollection collection = info.getEntry();
  86. for(int i = 0; i < collection.size(); i++){
  87. BatchSubmitShemeBillEntryInfo entry =collection.get(i);
  88. //点检率是否为空
  89. if(CheckIwclUtil.checkDataIsNull(ctx,entry)){
  90. throw new IllegalArgumentException("分录中" + entry.getPerson().getName() + ",有点检率为空的数据,请检查");
  91. }
  92. }
  93. } catch (IllegalArgumentException var10) {
  94. throw new ShrWebBizException(var10.getMessage(), var10);
  95. } catch (BOSException e) {
  96. e.printStackTrace();
  97. }
  98. }
  99. protected void beforeSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  100. throws SHRWebException {
  101. super.beforeSave(request, response, model);
  102. Context ctx = SHRContext.getInstance().getContext();
  103. BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model;
  104. BatchSubmitShemeBillEntryCollection entry = info.getEntry();
  105. String billId = "";
  106. if(ObjectUtils.allNotNull(info.getId())) {
  107. billId = info.getId().toString();
  108. }
  109. //拉取mes点检率数据
  110. try {
  111. exeDataOnDay( request,billId,entry);
  112. } catch (BOSException e) {
  113. e.printStackTrace();
  114. }
  115. //先重置点检率标识
  116. SubmitShemeUtils.reductionInspectionRate( ctx, info);
  117. //更新点检率数据
  118. Set<String> checkbillIds = (Set<String> ) request.getAttribute("checkbillIds");
  119. SubmitShemeUtils.updateInspectionRate(ctx, info,checkbillIds);
  120. }
  121. /**
  122. * 数据处理
  123. * 校验对应的某一天已存在数据/mes数据获取等
  124. * @param billId
  125. * @param entrys
  126. * @throws SHRWebException
  127. * @throws BOSException
  128. */
  129. public void exeDataOnDay(HttpServletRequest request,String billId,BatchSubmitShemeBillEntryCollection entrys) throws SHRWebException, BOSException {
  130. Context ctx = SHRContext.getInstance().getContext();
  131. Map<String, Set<String>> personDateMap = new HashMap<>();
  132. //
  133. HashSet<String> selectPerson = new HashSet();
  134. HashSet<String> selectDate = new HashSet();
  135. for (int i = 0; i < entrys.size(); i++) {
  136. BatchSubmitShemeBillEntryInfo entry = entrys.get(i);
  137. String personId = entry.getPerson().getId().toString();
  138. selectPerson.add(personId);
  139. Date effectDate = entry.getEffectDate();
  140. // 增加对 effectDate 为 null 的检查
  141. if (effectDate == null) {
  142. throw new IllegalArgumentException("分录中发生日期不能为空,请检查");
  143. }
  144. String formattedEffectDate = SDF.format(effectDate);
  145. selectDate.add(formattedEffectDate);
  146. // 使用 computeIfAbsent 减少冗余代码,并增加重复检查
  147. personDateMap.computeIfAbsent(personId, k -> new HashSet<>());
  148. if (!personDateMap.get(personId).add(formattedEffectDate)) {
  149. // 如果 add 方法返回 false,说明该日期已经存在,抛出异常
  150. throw new IllegalArgumentException("分录中" + entry.getPerson().getName() + ",有当日重复提报的数据,请检查");
  151. }
  152. }
  153. if (personDateMap.isEmpty()) {
  154. return;
  155. }
  156. // 找出最大日期与最小日期
  157. DateRange dateRange = SubmitShemeUtils.findMinMaxDate(selectDate);
  158. //校验重复
  159. verifiOneData(ctx, billId, selectPerson, dateRange, personDateMap);
  160. //校验完后进行mes数据填充;
  161. //获取mes数据
  162. HashMap<String, HashMap> mesData = SubmitShemeUtils.getMesData( ctx, selectPerson, dateRange);
  163. SubmitShemeUtils.setMesData(ctx, request, entrys, mesData);
  164. }
  165. /**
  166. * 校验当天是否有重复数据
  167. * @param ctx
  168. * @param billId
  169. * @param selectPerson
  170. * @param dateRange
  171. * @param personDateMap
  172. * @throws SHRWebException
  173. */
  174. public void verifiOneData(Context ctx ,String billId,HashSet<String> selectPerson,DateRange dateRange,Map<String, Set<String>> personDateMap) throws SHRWebException {
  175. HashMap<String,String> dataMap = new HashMap();
  176. try {
  177. IBatchSubmitShemeBillEntry entryIns = BatchSubmitShemeBillEntryFactory.getLocalInstance(ctx);
  178. FilterInfo filter = new FilterInfo();
  179. filter.getFilterItems().add(new FilterItemInfo("person", selectPerson, CompareType.INCLUDE));
  180. filter.getFilterItems().add(new FilterItemInfo("bill.id", billId , CompareType.NOTEQUALS ));
  181. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMaxDate() , CompareType.LESS_EQUALS));
  182. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMinDate() , CompareType.GREATER_EQUALS ));
  183. EntityViewInfo viewInfo = new EntityViewInfo();
  184. SelectorItemCollection selector = viewInfo.getSelector();
  185. selector.add(new SelectorItemInfo("person.id"));
  186. selector.add(new SelectorItemInfo("person.name"));
  187. selector.add(new SelectorItemInfo("bill.number"));
  188. selector.add(new SelectorItemInfo("effectDate"));
  189. viewInfo.setFilter(filter);
  190. BatchSubmitShemeBillEntryCollection entryCol = entryIns.getBatchSubmitShemeBillEntryCollection(viewInfo);
  191. for(int i = 0;i<entryCol.size();i++) {
  192. BatchSubmitShemeBillEntryInfo entryInfo = entryCol.get(i);
  193. Date effectDate = entryInfo.getEffectDate();
  194. String personId = entryInfo.getPerson().getId().toString();
  195. Set<String> pAndDate = personDateMap.get(personId);
  196. if(pAndDate.contains(SDF.format(effectDate))) {
  197. String personName = entryInfo.getPerson().getName().toString();
  198. BatchSubmitShemeBillInfo billInfo = entryInfo.getBill();
  199. String billNo = billInfo.getNumber();
  200. dataMap.put(personName, billNo);
  201. }
  202. }
  203. } catch (BOSException e) {
  204. e.printStackTrace();
  205. }
  206. //如果dataMap不为空则循环dataMap的数据组成字符串并抛出异常,"存在哪些人,单据编码为:****"
  207. if(!dataMap.isEmpty()) {
  208. String errorMsg = "存在以下当日重复提报人员,姓名与单据编码为:";
  209. for(String personName : dataMap.keySet()) {
  210. String billNo = dataMap.get(personName);
  211. errorMsg += personName + ":" + billNo + " ";
  212. }
  213. throw new SHRWebException(errorMsg);
  214. }
  215. }
  216. /**
  217. * handler校验,先不启用
  218. * @param request
  219. * @param response
  220. * @param modelMap
  221. * @throws SHRWebException
  222. */
  223. public void hasDataOnDayAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  224. throws SHRWebException {
  225. Context ctx = SHRContext.getInstance().getContext();
  226. // 获取人员 //格式为[pseron1:2025-04-03,person2:2025-04-03],需要转为map
  227. String proposers = request.getParameter("proposers");
  228. if (proposers == null || proposers.isEmpty()) {
  229. return;
  230. }
  231. String[] personArr = proposers.split(",");
  232. HashSet<String> selectPerson = new HashSet();
  233. HashSet<String> selectData = new HashSet();
  234. Map<String, Set<String>> personDateMap = new HashMap<>();
  235. for (int i = 0; i< personArr.length;i++) {
  236. String personIds = personArr[i];
  237. String[] parts = personIds.split(":");
  238. if (parts.length == 2) {
  239. String personId = parts[0].trim();
  240. String date = parts[1].trim();
  241. selectPerson.add(personId);
  242. selectData.add(date);
  243. personDateMap.computeIfAbsent(personId, k -> new HashSet<>()).add(date);
  244. }
  245. }
  246. if (personDateMap.isEmpty()) {
  247. return;
  248. }
  249. HashMap<String,String> dataMap = new HashMap();
  250. // 找出最大日期与最小日期
  251. DateRange dateRange = SubmitShemeUtils.findMinMaxDate(selectData);
  252. IBatchSubmitShemeBillEntry entryIns;
  253. try {
  254. entryIns = BatchSubmitShemeBillEntryFactory.getLocalInstance(ctx);
  255. FilterInfo filter = new FilterInfo();
  256. filter.getFilterItems().add(new FilterItemInfo("proposer", selectPerson, CompareType.INCLUDE));
  257. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMaxDate() , CompareType.LESS_EQUALS));
  258. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMinDate() , CompareType.GREATER_EQUALS ));
  259. EntityViewInfo viewInfo = new EntityViewInfo();
  260. viewInfo.setFilter(filter);
  261. BatchSubmitShemeBillEntryCollection entryCol = entryIns.getBatchSubmitShemeBillEntryCollection(viewInfo);
  262. for(int i = 0;i<entryCol.size();i++) {
  263. BatchSubmitShemeBillEntryInfo entryInfo = entryCol.get(i);
  264. Date effectDate = entryInfo.getEffectDate();
  265. String personId = entryInfo.getPerson().getId().toString();
  266. Set<String> pAndDate = personDateMap.get(personId);
  267. if(pAndDate.contains(SDF.format(effectDate))) {
  268. String personName = entryInfo.getPerson().getName().toString();
  269. BatchSubmitShemeBillInfo billInfo = entryInfo.getBill();
  270. String billNo = billInfo.getNumber();
  271. dataMap.put(personName, billNo);
  272. }
  273. }
  274. } catch (BOSException e) {
  275. e.printStackTrace();
  276. }
  277. Map resultMap = new HashMap();
  278. JSONUtils.SUCCESS( resultMap );
  279. }
  280. protected void afterSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  281. throws SHRWebException {
  282. super.afterSave(request, response, model);
  283. Context ctx = SHRContext.getInstance().getContext();
  284. BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model;
  285. BatchSubmitShemeBillEntryCollection entry = info.getEntry();
  286. }
  287. public String saveAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  288. throws SHRWebException {
  289. try {
  290. BatchSubmitShemeBillInfo model = (BatchSubmitShemeBillInfo) request.getAttribute("dynamic_model");
  291. this.doFieldPermFilterSave(request, model);
  292. this.doSave(request, response, model);
  293. this.afterSave(request, response, model);
  294. this.saveAttachment(request, response, model);
  295. Object responseData = this.generateResponseDataAfterSave(request, response, model);
  296. Map resultMap = new HashMap();
  297. resultMap.put("responseData", responseData);
  298. resultMap.put("assignedRowsCount", request.getAttribute("assignedRowsCount"));
  299. this.writeSuccessData(resultMap);
  300. } catch (Exception var6) {
  301. ExceptionHandle.handleException(var6);
  302. }
  303. return null;
  304. }
  305. /**
  306. * 获取点检率与标识字段的字段名称
  307. * @param request
  308. * @param response
  309. * @param modelMap
  310. */
  311. public String getFieldRemarkAction(HttpServletRequest request,
  312. HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  313. String fieldStr = request.getParameter("fieldArr");
  314. Context ctx = SHRContext.getInstance().getContext();
  315. if(fieldStr!= null &&!fieldStr.isEmpty()){
  316. String[] split = fieldStr.split(",");
  317. try {
  318. CalSubmitItemCollection subColl = CalSubmitItemFactory.getLocalInstance(ctx)
  319. .getCalSubmitItemCollection("SELECT ID,FieldSn,number where number in ("+ToolUtils.aryToStr(split)+")");
  320. for(int i = 0;i<subColl.size();i++){
  321. CalSubmitItemInfo calSubmitItemInfo = subColl.get(i);
  322. int fieldSn = calSubmitItemInfo.getFieldSn();
  323. String number = calSubmitItemInfo.getNumber();
  324. String field = "S"+fieldSn ;
  325. modelMap.put(number, field);
  326. }
  327. } catch (BOSException e) {
  328. throw new RuntimeException(e);
  329. }
  330. }
  331. JSONUtils.writeJson(response, modelMap);
  332. return null;
  333. }
  334. }