TimepieceSchemeBillEditHandlerEx.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. String operateStatus = (String)request.getAttribute("operateState");
  76. if (StringUtils.isEmpty(operateStatus)) {
  77. operateStatus = request.getParameter("operateState");
  78. }
  79. if ("VIEW".equalsIgnoreCase(operateStatus)) {
  80. model = (CoreBaseInfo)request.getAttribute("dynamic_model");
  81. }
  82. try {
  83. BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo)model;
  84. BatchSubmitShemeBillEntryCollection collection = info.getEntry();
  85. for(int i = 0; i < collection.size(); i++){
  86. BatchSubmitShemeBillEntryInfo entry =collection.get(i);
  87. //点检率是否为空
  88. if(CheckIwclUtil.isBlank(entry)){
  89. throw new IllegalArgumentException("分录中" + entry.getPerson().getName() + ",有点检率为空的数据,请检查");
  90. }
  91. }
  92. } catch (IllegalArgumentException var10) {
  93. throw new ShrWebBizException(var10.getMessage(), var10);
  94. }
  95. }
  96. protected void beforeSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  97. throws SHRWebException {
  98. super.beforeSave(request, response, model);
  99. Context ctx = SHRContext.getInstance().getContext();
  100. BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model;
  101. BatchSubmitShemeBillEntryCollection entry = info.getEntry();
  102. String billId = "";
  103. if(ObjectUtils.allNotNull(info.getId())) {
  104. billId = info.getId().toString();
  105. }
  106. //拉取mes点检率数据
  107. try {
  108. exeDataOnDay( request,billId,entry);
  109. } catch (BOSException e) {
  110. e.printStackTrace();
  111. }
  112. //先重置点检率标识
  113. SubmitShemeUtils.reductionInspectionRate( ctx, info);
  114. //更新点检率数据
  115. Set<String> checkbillIds = (Set<String> ) request.getAttribute("checkbillIds");
  116. SubmitShemeUtils.updateInspectionRate(ctx, info,checkbillIds);
  117. }
  118. /**
  119. * 数据处理
  120. * 校验对应的某一天已存在数据/mes数据获取等
  121. * @param billId
  122. * @param entrys
  123. * @throws SHRWebException
  124. * @throws BOSException
  125. */
  126. public void exeDataOnDay(HttpServletRequest request,String billId,BatchSubmitShemeBillEntryCollection entrys) throws SHRWebException, BOSException {
  127. Context ctx = SHRContext.getInstance().getContext();
  128. Map<String, Set<String>> personDateMap = new HashMap<>();
  129. //
  130. HashSet<String> selectPerson = new HashSet();
  131. HashSet<String> selectDate = new HashSet();
  132. for (int i = 0; i < entrys.size(); i++) {
  133. BatchSubmitShemeBillEntryInfo entry = entrys.get(i);
  134. String personId = entry.getPerson().getId().toString();
  135. selectPerson.add(personId);
  136. Date effectDate = entry.getEffectDate();
  137. // 增加对 effectDate 为 null 的检查
  138. if (effectDate == null) {
  139. throw new IllegalArgumentException("分录中发生日期不能为空,请检查");
  140. }
  141. String formattedEffectDate = SDF.format(effectDate);
  142. selectDate.add(formattedEffectDate);
  143. // 使用 computeIfAbsent 减少冗余代码,并增加重复检查
  144. personDateMap.computeIfAbsent(personId, k -> new HashSet<>());
  145. if (!personDateMap.get(personId).add(formattedEffectDate)) {
  146. // 如果 add 方法返回 false,说明该日期已经存在,抛出异常
  147. throw new IllegalArgumentException("分录中" + entry.getPerson().getName() + ",有当日重复提报的数据,请检查");
  148. }
  149. }
  150. if (personDateMap.isEmpty()) {
  151. return;
  152. }
  153. // 找出最大日期与最小日期
  154. DateRange dateRange = SubmitShemeUtils.findMinMaxDate(selectDate);
  155. //校验重复
  156. verifiOneData(ctx, billId, selectPerson, dateRange, personDateMap);
  157. //校验完后进行mes数据填充;
  158. //获取mes数据
  159. HashMap<String, HashMap> mesData = SubmitShemeUtils.getMesData( ctx, selectPerson, dateRange);
  160. SubmitShemeUtils.setMesData(ctx, request, entrys, mesData);
  161. }
  162. /**
  163. * 校验当天是否有重复数据
  164. * @param ctx
  165. * @param billId
  166. * @param selectPerson
  167. * @param dateRange
  168. * @param personDateMap
  169. * @throws SHRWebException
  170. */
  171. public void verifiOneData(Context ctx ,String billId,HashSet<String> selectPerson,DateRange dateRange,Map<String, Set<String>> personDateMap) throws SHRWebException {
  172. HashMap<String,String> dataMap = new HashMap();
  173. try {
  174. IBatchSubmitShemeBillEntry entryIns = BatchSubmitShemeBillEntryFactory.getLocalInstance(ctx);
  175. FilterInfo filter = new FilterInfo();
  176. filter.getFilterItems().add(new FilterItemInfo("person", selectPerson, CompareType.INCLUDE));
  177. filter.getFilterItems().add(new FilterItemInfo("bill.id", billId , CompareType.NOTEQUALS ));
  178. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMaxDate() , CompareType.LESS_EQUALS));
  179. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMinDate() , CompareType.GREATER_EQUALS ));
  180. EntityViewInfo viewInfo = new EntityViewInfo();
  181. SelectorItemCollection selector = viewInfo.getSelector();
  182. selector.add(new SelectorItemInfo("person.id"));
  183. selector.add(new SelectorItemInfo("person.name"));
  184. selector.add(new SelectorItemInfo("bill.number"));
  185. selector.add(new SelectorItemInfo("effectDate"));
  186. viewInfo.setFilter(filter);
  187. BatchSubmitShemeBillEntryCollection entryCol = entryIns.getBatchSubmitShemeBillEntryCollection(viewInfo);
  188. for(int i = 0;i<entryCol.size();i++) {
  189. BatchSubmitShemeBillEntryInfo entryInfo = entryCol.get(i);
  190. Date effectDate = entryInfo.getEffectDate();
  191. String personId = entryInfo.getPerson().getId().toString();
  192. Set<String> pAndDate = personDateMap.get(personId);
  193. if(pAndDate.contains(SDF.format(effectDate))) {
  194. String personName = entryInfo.getPerson().getName().toString();
  195. BatchSubmitShemeBillInfo billInfo = entryInfo.getBill();
  196. String billNo = billInfo.getNumber();
  197. dataMap.put(personName, billNo);
  198. }
  199. }
  200. } catch (BOSException e) {
  201. e.printStackTrace();
  202. }
  203. //如果dataMap不为空则循环dataMap的数据组成字符串并抛出异常,"存在哪些人,单据编码为:****"
  204. if(!dataMap.isEmpty()) {
  205. String errorMsg = "存在以下当日重复提报人员,姓名与单据编码为:";
  206. for(String personName : dataMap.keySet()) {
  207. String billNo = dataMap.get(personName);
  208. errorMsg += personName + ":" + billNo + " ";
  209. }
  210. throw new SHRWebException(errorMsg);
  211. }
  212. }
  213. /**
  214. * handler校验,先不启用
  215. * @param request
  216. * @param response
  217. * @param modelMap
  218. * @throws SHRWebException
  219. */
  220. public void hasDataOnDayAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  221. throws SHRWebException {
  222. Context ctx = SHRContext.getInstance().getContext();
  223. // 获取人员 //格式为[pseron1:2025-04-03,person2:2025-04-03],需要转为map
  224. String proposers = request.getParameter("proposers");
  225. if (proposers == null || proposers.isEmpty()) {
  226. return;
  227. }
  228. String[] personArr = proposers.split(",");
  229. HashSet<String> selectPerson = new HashSet();
  230. HashSet<String> selectData = new HashSet();
  231. Map<String, Set<String>> personDateMap = new HashMap<>();
  232. for (int i = 0; i< personArr.length;i++) {
  233. String personIds = personArr[i];
  234. String[] parts = personIds.split(":");
  235. if (parts.length == 2) {
  236. String personId = parts[0].trim();
  237. String date = parts[1].trim();
  238. selectPerson.add(personId);
  239. selectData.add(date);
  240. personDateMap.computeIfAbsent(personId, k -> new HashSet<>()).add(date);
  241. }
  242. }
  243. if (personDateMap.isEmpty()) {
  244. return;
  245. }
  246. HashMap<String,String> dataMap = new HashMap();
  247. // 找出最大日期与最小日期
  248. DateRange dateRange = SubmitShemeUtils.findMinMaxDate(selectData);
  249. IBatchSubmitShemeBillEntry entryIns;
  250. try {
  251. entryIns = BatchSubmitShemeBillEntryFactory.getLocalInstance(ctx);
  252. FilterInfo filter = new FilterInfo();
  253. filter.getFilterItems().add(new FilterItemInfo("proposer", selectPerson, CompareType.INCLUDE));
  254. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMaxDate() , CompareType.LESS_EQUALS));
  255. filter.getFilterItems().add(new FilterItemInfo("effectDate", dateRange.getMinDate() , CompareType.GREATER_EQUALS ));
  256. EntityViewInfo viewInfo = new EntityViewInfo();
  257. viewInfo.setFilter(filter);
  258. BatchSubmitShemeBillEntryCollection entryCol = entryIns.getBatchSubmitShemeBillEntryCollection(viewInfo);
  259. for(int i = 0;i<entryCol.size();i++) {
  260. BatchSubmitShemeBillEntryInfo entryInfo = entryCol.get(i);
  261. Date effectDate = entryInfo.getEffectDate();
  262. String personId = entryInfo.getPerson().getId().toString();
  263. Set<String> pAndDate = personDateMap.get(personId);
  264. if(pAndDate.contains(SDF.format(effectDate))) {
  265. String personName = entryInfo.getPerson().getName().toString();
  266. BatchSubmitShemeBillInfo billInfo = entryInfo.getBill();
  267. String billNo = billInfo.getNumber();
  268. dataMap.put(personName, billNo);
  269. }
  270. }
  271. } catch (BOSException e) {
  272. e.printStackTrace();
  273. }
  274. Map resultMap = new HashMap();
  275. JSONUtils.SUCCESS( resultMap );
  276. }
  277. protected void afterSave(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model)
  278. throws SHRWebException {
  279. super.afterSave(request, response, model);
  280. Context ctx = SHRContext.getInstance().getContext();
  281. BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model;
  282. BatchSubmitShemeBillEntryCollection entry = info.getEntry();
  283. }
  284. public String saveAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  285. throws SHRWebException {
  286. try {
  287. BatchSubmitShemeBillInfo model = (BatchSubmitShemeBillInfo) request.getAttribute("dynamic_model");
  288. this.doFieldPermFilterSave(request, model);
  289. this.doSave(request, response, model);
  290. this.afterSave(request, response, model);
  291. this.saveAttachment(request, response, model);
  292. Object responseData = this.generateResponseDataAfterSave(request, response, model);
  293. Map resultMap = new HashMap();
  294. resultMap.put("responseData", responseData);
  295. resultMap.put("assignedRowsCount", request.getAttribute("assignedRowsCount"));
  296. this.writeSuccessData(resultMap);
  297. } catch (Exception var6) {
  298. ExceptionHandle.handleException(var6);
  299. }
  300. return null;
  301. }
  302. /**
  303. * 获取点检率与标识字段的字段名称
  304. * @param request
  305. * @param response
  306. * @param modelMap
  307. */
  308. public String getFieldRemarkAction(HttpServletRequest request,
  309. HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  310. String fieldStr = request.getParameter("fieldArr");
  311. Context ctx = SHRContext.getInstance().getContext();
  312. if(fieldStr!= null &&!fieldStr.isEmpty()){
  313. String[] split = fieldStr.split(",");
  314. try {
  315. CalSubmitItemCollection subColl = CalSubmitItemFactory.getLocalInstance(ctx)
  316. .getCalSubmitItemCollection("SELECT ID,FieldSn,number where number in ("+ToolUtils.aryToStr(split)+")");
  317. for(int i = 0;i<subColl.size();i++){
  318. CalSubmitItemInfo calSubmitItemInfo = subColl.get(i);
  319. int fieldSn = calSubmitItemInfo.getFieldSn();
  320. String number = calSubmitItemInfo.getNumber();
  321. String field = "S"+fieldSn ;
  322. modelMap.put(number, field);
  323. }
  324. } catch (BOSException e) {
  325. throw new RuntimeException(e);
  326. }
  327. }
  328. JSONUtils.writeJson(response, modelMap);
  329. return null;
  330. }
  331. }