EvaresultAuditBillEntryListHandlerEx.java 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. package com.kingdee.eas.hr.perf.handler;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.google.common.collect.Maps;
  7. import com.google.common.collect.Sets;
  8. import com.kingdee.bos.BOSException;
  9. import com.kingdee.bos.Context;
  10. import com.kingdee.bos.rabbitmq.guava.Lists;
  11. import com.kingdee.eas.hr.perf.PerformProTeamCollection;
  12. import com.kingdee.eas.hr.perf.PerformProTeamFactory;
  13. import com.kingdee.eas.hr.perf.PersonPerformProCollection;
  14. import com.kingdee.eas.hr.perf.PersonPerformProFactory;
  15. import com.kingdee.eas.util.app.DbUtil;
  16. import com.kingdee.jdbc.rowset.IRowSet;
  17. import com.kingdee.shr.base.syssetting.api.bean.BatchMessageTipsBody;
  18. import com.kingdee.shr.base.syssetting.api.bean.BatchMessageTipsHeader;
  19. import com.kingdee.shr.base.syssetting.context.SHRContext;
  20. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  21. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  22. import com.kingdee.shr.perfweb.app.exception.SHRPerfWebBizException;
  23. import com.kingdee.shr.perfweb.planexecute.handler.EvaresultAuditBillEntryListHandler;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.springframework.ui.ModelMap;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.math.BigDecimal;
  29. import java.sql.SQLException;
  30. import java.util.*;
  31. /**
  32. * description: EvaresultAuditBillEntryListHandler <br>
  33. * date: 2025/6/24 12:48 <br>
  34. * author: lhbj <br>
  35. * version: 1.0 <br>
  36. */
  37. public class EvaresultAuditBillEntryListHandlerEx extends EvaresultAuditBillEntryListHandler {
  38. /**
  39. [{"evaResult.pnumber":"0000381","evaResult.pname":"谭梓傲","evaResult.positionName":"物资岗","evaResult.evaObj.perfFile.adminOrgUnit.company.name":"湖南红太阳光电科技有限公司","evaResult.evaObj.perfFile.adminOrgUnit.department.name":"综合管理","evaResult.sumScore":"<span></span>","evaResult.gradeLevel":"","evaResult.auditSumScore":"<span value=\\"86\\">86.00</span>","evaResult.auditGradeLevel":"C","evaResult.auditReason":"<div class=\\"cell-height scrollbarthin\\">正态分布更新结果</div>","evaResult.reviseSumScore":"<span value=\\"86\\">86.00</span>","evaResult.reviseGradeLevel":"C","evaResult.reviseReason":"正态分布更新结果","id":"KQukJy27Skiy1rPPghjkJBdK16Q=","evaResult.id":"Ka7FkRQuTAaPlTaLvJSD3IESG3Q=","bill.id":"m85zTeeDSmaAU2QLbYWMUoZLdW4=","evaResult.evaObj.id":"gjX3giS2RKurkJVjPhnwa4GI54s=","reviseGradeLevelSelect":"[{\\"value\\":\\"S\\",\\"alias\\":\\"S\\"},{\\"value\\":\\"A\\",\\"alias\\":\\"A\\"},{\\"value\\":\\"B\\",\\"alias\\":\\"B\\"},{\\"value\\":\\"C\\",\\"alias\\":\\"C\\"},{\\"value\\":\\"D\\",\\"alias\\":\\"D\\"}]","levelScoreKVInfo":"{\\n \\"90.00~100.00\\": \\"S\\",\\n \\"80.00~90.00\\": \\"A\\",\\n \\"70.00~80.00\\": \\"B\\",\\n \\"60.00~70.00\\": \\"C\\",\\n \\"0.00~60.00\\": \\"D\\"\\n}","scoreLowLimit":"0","scoreUpLimit":"100","evaResult.period.id":"q6myAjHaQLK+wnczfdLCJEUaiOU=","evaResult.reviseFlag":"是","evaResult.auditFlag":"否"}]
  40. * @param request
  41. * @param response
  42. * @param modelMap
  43. * @throws SHRWebException
  44. */
  45. public void verifyBeforeSubmitAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  46. String entryData = request.getParameter("entryData");
  47. BatchMessageTipsHeader header = new BatchMessageTipsHeader();
  48. boolean isExists = true;
  49. if (!com.kingdee.util.StringUtils.isEmpty(entryData)) {
  50. int success = 0;
  51. int fail = 0;
  52. StringBuilder ids = new StringBuilder();
  53. List<String> allIdList = new ArrayList<>();
  54. try {
  55. Context ctx = SHRContext.getInstance().getContext();
  56. //明细数据
  57. JSONArray entryList = JSON.parseArray(entryData);
  58. for(int i=0;i<entryList.size();i++) {
  59. JSONObject object = entryList.getJSONObject(i);
  60. BatchMessageTipsBody body = new BatchMessageTipsBody();
  61. String id =object.getString("id");
  62. boolean isSuccess=false;
  63. String msg="";
  64. String pnumber = object.getString("evaResult.pnumber");
  65. String pname = object.getString("evaResult.pname");
  66. String positionName = object.getString("evaResult.positionName");
  67. String evaResult = object.getString("evaResult.id");
  68. //修改后等级
  69. String auditGradeLevel = object.getString("evaResult.auditGradeLevel");
  70. body.setId(id);
  71. ids.append(id).append(",");
  72. allIdList.add(id);
  73. //获取跨部门协作绩效等级
  74. String sql = "select CFDEPGRADELEVEL from T_EVA_EvaResultSummary where fid = ?";
  75. IRowSet rs = DbUtil.executeQuery(ctx, sql, new String[]{evaResult});
  76. //当跨部门协作绩效等级为C、D等级的,当期员工绩效不得为高绩效(S、A等级)
  77. if (rs.next()){
  78. //跨部门协作绩效等级
  79. String depgradelevel = rs.getString("CFDEPGRADELEVEL");
  80. if(StringUtils.isNotBlank(depgradelevel)) {
  81. switch (depgradelevel) {
  82. case "S":
  83. ;
  84. case "A":
  85. ;
  86. case "B":
  87. isSuccess = true;
  88. msg = "校验通过";
  89. success += 1;
  90. break;
  91. case "C":
  92. case "D":
  93. if ("S".equals(auditGradeLevel) || "A".equals(auditGradeLevel)) {
  94. isSuccess = false;
  95. msg = "当跨部门协作绩效等级为C、D等级的,当期员工绩效不得为高绩效(S、A等级)";
  96. fail += 1;
  97. } else {
  98. isSuccess = true;
  99. msg = "校验通过";
  100. success += 1;
  101. }
  102. break;
  103. }
  104. }else {
  105. msg="没有当跨部门协作绩效等级,请先检查跨部门协作绩效等级";
  106. isSuccess=true;
  107. success+=1;
  108. }
  109. }else {
  110. msg="操作失败,数据异常";
  111. isSuccess=false;
  112. fail+=1;
  113. }
  114. body.setMuitTipsState(isSuccess);
  115. body.setMuitTipsMessage(msg);
  116. List<Object> messageListExt = new ArrayList<>();
  117. messageListExt.add(pnumber);
  118. messageListExt.add(pname);
  119. messageListExt.add(positionName);
  120. body.addMessageListExt(messageListExt);
  121. header.addResult(body);
  122. }
  123. } catch (BOSException | SQLException var7) {
  124. var7.printStackTrace();
  125. }
  126. ids.delete(ids.length()-1,ids.length());
  127. header.setBillId(ids.toString());
  128. header.setFailureCount(fail);
  129. header.setSuccessCount(success);
  130. }
  131. this.writeSuccessData(header);
  132. }
  133. protected static void addBatchMessageTip(String unvalidEvaObj, String message, BatchMessageTipsHeader batchMessageTipsHeader) {
  134. BatchMessageTipsBody body = new BatchMessageTipsBody();
  135. body.setId(unvalidEvaObj);
  136. body.setMuitTipsState(Boolean.FALSE);
  137. body.setMuitTipsMessage(message);
  138. batchMessageTipsHeader.addResult(body);
  139. batchMessageTipsHeader.setFailureCount(batchMessageTipsHeader.getFailureCount() + 1);
  140. }
  141. /**
  142. * 获取人员项目正态分布规则
  143. *
  144. * @param ctx
  145. * @param idList 非必填
  146. * @param batchMessage 非必填
  147. * @return
  148. * @throws BOSException
  149. * @throws SQLException
  150. */
  151. public Map<String, Map<String, BigDecimal>> getProjectPerformPro(Context ctx, List<String> idList, Map<String, String> batchMessage) throws BOSException, SQLException {
  152. //获取正态分布规则
  153. Map<String, Map<String, BigDecimal>> orgLevelMap = Maps.newHashMap();
  154. PerformProTeamCollection proCollection = PerformProTeamFactory.getLocalInstance(ctx).getPerformProTeamCollection(" where status=1 ");
  155. if (proCollection.size() == 1) {
  156. StringBuilder orgPerSql = new StringBuilder();
  157. orgPerSql.append(" select fp.fid,fpe.CFS,fpe.CFA,fpe.CFB,fpe.CFC,fpe.CFD,fpe.CFORGPERFORMTYPE ");
  158. orgPerSql.append(" from CT_PF_PerformProTeam fp ");
  159. orgPerSql.append(" left join CT_PF_PerformProTeamEntry fpe on fp.fid=fpe.FPARENTID ");
  160. orgPerSql.append(" where fp.CFSTATUS = 1 ");
  161. orgPerSql.append(" order by fp.FCREATETIME ");
  162. IRowSet rs = DbUtil.executeQuery(ctx, orgPerSql.toString());
  163. while (rs.next()) {
  164. Map<String, BigDecimal> objectMap = Maps.newHashMap();
  165. String type = rs.getString("CFORGPERFORMTYPE");
  166. objectMap.put("S", rs.getBigDecimal("CFS"));
  167. objectMap.put("A", rs.getBigDecimal("CFA"));
  168. objectMap.put("B", rs.getBigDecimal("CFB"));
  169. objectMap.put("C", rs.getBigDecimal("CFC"));
  170. objectMap.put("D", rs.getBigDecimal("CFD"));
  171. orgLevelMap.put(type, objectMap);
  172. }
  173. } else if (proCollection.size() > 1) {
  174. if (null != batchMessage && null != idList) {
  175. for (String key : idList) {
  176. batchMessage.put(key, "存在多个正态分布规则,请检查!");
  177. }
  178. }
  179. } else {
  180. if (null != batchMessage && null != idList) {
  181. for (String key : idList) {
  182. batchMessage.put(key, "不存在正态分布规则,请检查!");
  183. }
  184. }
  185. }
  186. return orgLevelMap;
  187. }
  188. /**
  189. * 获取人员组织正态分布规则
  190. *
  191. * @param ctx
  192. * @param idList 非必填
  193. * @param batchMessage 非必填
  194. * @return
  195. * @throws BOSException
  196. * @throws SQLException
  197. */
  198. public Map<String, Map<String, BigDecimal>> getPersonPerformPro(Context ctx, List<String> idList, Map<String, String> batchMessage) throws BOSException, SQLException {
  199. //获取正态分布规则
  200. Map<String, Map<String, BigDecimal>> orgLevelMap = Maps.newHashMap();
  201. PersonPerformProCollection proCollection = PersonPerformProFactory.getLocalInstance(ctx).getPersonPerformProCollection(" where state=1 ");
  202. if (proCollection.size() == 1) {
  203. StringBuilder orgPerSql = new StringBuilder();
  204. orgPerSql.append(" select fp.fid,fpe.CFS,fpe.CFA,fpe.CFB,fpe.CFC,fpe.CFD,fpe.CFORGPERFORMTYPE ");
  205. orgPerSql.append(" from CT_PF_PersonPerformPro fp ");
  206. orgPerSql.append(" left join CT_PF_PersonPerformProEntry fpe on fp.fid=fpe.FPARENTID ");
  207. orgPerSql.append(" where fp.CFSTATE = 1 ");
  208. orgPerSql.append(" order by fp.FCREATETIME ");
  209. IRowSet rs = DbUtil.executeQuery(ctx, orgPerSql.toString());
  210. while (rs.next()) {
  211. Map<String, BigDecimal> objectMap = Maps.newHashMap();
  212. String type = rs.getString("CFORGPERFORMTYPE");
  213. objectMap.put("S", rs.getBigDecimal("CFS"));
  214. objectMap.put("A", rs.getBigDecimal("CFA"));
  215. objectMap.put("B", rs.getBigDecimal("CFB"));
  216. objectMap.put("C", rs.getBigDecimal("CFC"));
  217. objectMap.put("D", rs.getBigDecimal("CFD"));
  218. orgLevelMap.put(type, objectMap);
  219. }
  220. } else if (proCollection.size() > 1) {
  221. if (null != batchMessage && null != idList) {
  222. for (String key : idList) {
  223. batchMessage.put(key, "存在多个正态分布规则,请检查!");
  224. }
  225. }
  226. } else {
  227. if (null != batchMessage && null != idList) {
  228. for (String key : idList) {
  229. batchMessage.put(key, "不存在正态分布规则,请检查!");
  230. }
  231. }
  232. }
  233. return orgLevelMap;
  234. }
  235. /**
  236. * 获取人员的等级组织分组
  237. *
  238. * @param ctx
  239. * @param entryList
  240. * @return
  241. * @throws BOSException
  242. * @throws SQLException
  243. */
  244. public Map<String, Map<String, Object>> getPersonLevelLensMap(Context ctx, JSONArray entryList) throws BOSException, SQLException {
  245. Map<String, Map<String, Object>> personLevelMap = Maps.newHashMap();
  246. Map<String, BigDecimal> revLevelMap = Maps.newHashMap();
  247. for(int i=0;i<entryList.size();i++) {
  248. JSONObject object = entryList.getJSONObject(i);
  249. String id =object.getString("id");
  250. String evaResult = object.getString("evaResult.id");
  251. //修改后等级
  252. String auditGradeLevel = object.getString("evaResult.auditGradeLevel");
  253. BigDecimal l = revLevelMap.get(auditGradeLevel);
  254. if(Objects.isNull(l)){
  255. l=BigDecimal.ZERO;
  256. }
  257. l=l.add(BigDecimal.ONE);
  258. revLevelMap.put(auditGradeLevel, l);
  259. }
  260. for(int i=0;i<entryList.size();i++) {
  261. JSONObject object = entryList.getJSONObject(i);
  262. String id =object.getString("id");
  263. String evaResult = object.getString("evaResult.id");
  264. //修改后等级
  265. String auditGradeLevel = object.getString("evaResult.auditGradeLevel");
  266. Map<String, Object> map = Maps.newHashMap();
  267. String key = auditGradeLevel;
  268. map.put("lens", revLevelMap.get(auditGradeLevel));
  269. map.put("id",id);
  270. map.put("evaResult",evaResult);
  271. map.put("revLevel",auditGradeLevel);
  272. personLevelMap.put(key, map);
  273. }
  274. return personLevelMap;
  275. }
  276. /**
  277. * 根据上季度的组织等级,校验当前周期,当前考核计划,所选员工的所属组织的员工绩效等级分布校验
  278. *
  279. * @param request
  280. * @param response
  281. * @param modelMap
  282. * @param batchMessageTipsHeader
  283. * @throws SHRWebException
  284. */
  285. public void beforeAuditEvaResutAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, BatchMessageTipsHeader batchMessageTipsHeader) throws SHRWebException {
  286. Context ctx = SHRContext.getInstance().getContext();
  287. String ids = (String) request.getParameter("ids");
  288. String period = (String) request.getParameter("period");
  289. String planId = (String) request.getParameter("planId");
  290. String entryData = request.getParameter("entryData");
  291. if (ids == null) {
  292. throw new ShrWebBizException(new SHRPerfWebBizException(SHRPerfWebBizException.SYSTEMERR));
  293. }
  294. try {
  295. List<String> idList = Lists.newArrayList();
  296. Set<String> idSet = Sets.newHashSet(idList);
  297. for (String id : ids.split(",")) {
  298. idList.add(id);
  299. }
  300. //明细数据
  301. JSONArray entryList = JSON.parseArray(entryData);
  302. StringBuilder planSql = new StringBuilder();
  303. planSql.append("select fid,CFPerobjectIdId from T_EVA_PerfPlan where fid=? and CFPerobjectIdId is not null ");
  304. IRowSet rs = DbUtil.executeQuery(ctx, planSql.toString(), new Object[]{planId});
  305. if (rs.next()) {
  306. String CFPerobjectIdId = rs.getString("CFPerobjectIdId");
  307. Map<String, String> batchMessage = this.beforeAuditProjectEvaResut(ctx, period, planId, idList,entryList);
  308. if (null != batchMessage && batchMessage.size() > 0) {
  309. for (Map.Entry<String, String> entry : batchMessage.entrySet()) {
  310. addBatchMessageTip(entry.getKey(), entry.getValue(), batchMessageTipsHeader);
  311. idSet.remove(entry.getKey());
  312. }
  313. }
  314. } else {
  315. Map<String, String> batchMessage = this.beforeAuditEvaResut(ctx, period, planId, idList,entryList);
  316. if (null != batchMessage && batchMessage.size() > 0) {
  317. for (Map.Entry<String, String> entry : batchMessage.entrySet()) {
  318. addBatchMessageTip(entry.getKey(), entry.getValue(), batchMessageTipsHeader);
  319. idSet.remove(entry.getKey());
  320. }
  321. }
  322. //addBatchMessageSuccessTips(idSet,"验证成功",batchMessageTipsHeader);
  323. }
  324. this.setSuccessMessage("验证成功");
  325. } catch (Exception e) {
  326. e.printStackTrace();
  327. throw new ShrWebBizException(e);
  328. }
  329. }
  330. public Map<String, String> beforeAuditProjectEvaResut(Context ctx, String period, String planId, List<String> idList,JSONArray entryList ) throws BOSException, SQLException {
  331. Map<String, String> batchMessage = Maps.newHashMap();
  332. StringBuilder selParamId = new StringBuilder("''");
  333. for (int i = 0; i < idList.size(); i++) {
  334. selParamId.append(",?");
  335. }
  336. //获取正态分布规则
  337. Map<String, Map<String, BigDecimal>> personPerformMap = this.getProjectPerformPro(ctx, idList, batchMessage);
  338. if (null != personPerformMap && personPerformMap.size() > 0) {
  339. //获取组织分组人数
  340. //Map<String, Map<String, String>> orgLevelMap = this.getProjectLevelCountMap(ctx, period, planId,selParamId, idList);
  341. //获取人员等级分组
  342. Map<String, Map<String, Object>> personLevelMap = this.getPersonLevelLensMap(ctx,entryList);
  343. BigDecimal big100 = new BigDecimal(100);
  344. for(int i=0;i<entryList.size();i++) {
  345. JSONObject object = entryList.getJSONObject(i);
  346. String fid =object.getString("id");
  347. String evaResult = object.getString("evaResult.id");
  348. //修改后等级
  349. String auditGradeLevel = object.getString("evaResult.auditGradeLevel");
  350. String revLevel = auditGradeLevel;
  351. if (StrUtil.isBlank(auditGradeLevel)) {
  352. batchMessage.put(fid, "绩效等级为空,请维护");
  353. continue;
  354. }
  355. StringBuilder sel = new StringBuilder();
  356. sel.append(" select s1.fid,ppm.CFPROJECTNAME, pp.CFPerobjectIdId, s1.FPERIODID, s1.FEVAPLANID,");
  357. sel.append(" isnull(s1.FREVISEGRADELEVEL,s1.FGRADELEVEL) revLevel,s1.CFProjectLevel ");
  358. sel.append(" from T_EVA_EvaResultSummary s1 ");
  359. sel.append(" left join T_EVA_PerfPlan pp on pp.fid = s1.FEVAPLANID ");
  360. sel.append(" left join CT_PRO_ProjectManagement ppm on ppm.fid = pp.CFPerobjectIdId ");
  361. sel.append(" where s1.fid in ('");
  362. sel.append(evaResult);
  363. sel.append("') ");
  364. IRowSet rs = DbUtil.executeQuery(ctx, sel.toString(), idList.toArray());
  365. if (!rs.next()){
  366. batchMessage.put(fid, "绩效等级为空,请维护");
  367. continue;
  368. }
  369. String CFPROJECTNAME = rs.getString("CFPROJECTNAME");
  370. if (StrUtil.isBlank(revLevel)) {
  371. //String msg = String.format("%s绩效等级为空", CFPROJECTNAME);
  372. batchMessage.put(fid, "绩效等级为空,请维护");
  373. continue;
  374. }
  375. //项目绩效等级
  376. String projectLevel = rs.getString("CFProjectLevel");
  377. if (StrUtil.isBlank(projectLevel)) {
  378. String msg = String.format("%s项目绩效等级为空", CFPROJECTNAME);
  379. batchMessage.put(fid, msg);
  380. continue;
  381. }
  382. //该组织的组织绩效等级的正态分布
  383. Map<String, BigDecimal> personPerform = personPerformMap.get(projectLevel);
  384. if (null == personPerform) {
  385. String msg = String.format("没有找到%s项目绩效等级%s的正态分布规则", CFPROJECTNAME, projectLevel);
  386. batchMessage.put(fid, msg);
  387. continue;
  388. }
  389. //获取该组织下的人员总数
  390. //Map<String, String> orgMap = orgLevelMap.get(key);
  391. //获取该组织下的人员各个绩效等级分组汇总
  392. // String keyRevLevel = FADMINORGUNITID + FPERIODID + FEVAPLANID + revLevel;
  393. // Map<String, String> personMap = personLevelMap.get(keyRevLevel);
  394. Map<String, BigDecimal> leveList = Maps.newHashMap();
  395. //获取该组织下的人员总数
  396. //Map<String, String> orgMap = orgLevelMap.get(key);
  397. //获取等级D人数
  398. String keyRevLevelD = "D";
  399. Map<String, Object> personMapD = personLevelMap.get(keyRevLevelD);
  400. BigDecimal dLens = BigDecimal.ZERO;
  401. if (null != personMapD) {
  402. dLens = (BigDecimal) personMapD.get("lens");
  403. leveList.put("D", dLens);
  404. }
  405. //获取等级C人数
  406. String keyRevLevelC = "C";
  407. Map<String, Object> personMapC = personLevelMap.get(keyRevLevelC);
  408. BigDecimal cLens = BigDecimal.ZERO;
  409. if (null != personMapC) {
  410. cLens = (BigDecimal) personMapC.get("lens");
  411. leveList.put("C", cLens);
  412. }
  413. //获取等级B人数
  414. String keyRevLevelB = "B";
  415. Map<String, Object> personMapB = personLevelMap.get(keyRevLevelB);
  416. BigDecimal bLens = BigDecimal.ZERO;
  417. if (null != personMapB) {
  418. bLens = (BigDecimal) personMapB.get("lens");
  419. leveList.put("B", bLens);
  420. }
  421. //获取等级A人数
  422. String keyRevLevelA = "A";
  423. Map<String, Object> personMapA = personLevelMap.get(keyRevLevelA);
  424. BigDecimal aLens = BigDecimal.ZERO;
  425. if (null != personMapA) {
  426. aLens = (BigDecimal) personMapA.get("lens");
  427. leveList.put("A", aLens);
  428. }
  429. //获取等级S人数
  430. String keyRevLevelS = "S";
  431. Map<String, Object> personMapS = personLevelMap.get(keyRevLevelS);
  432. BigDecimal sLens = BigDecimal.ZERO;
  433. if (null != personMapS) {
  434. sLens = (BigDecimal) personMapS.get("lens");
  435. leveList.put("S", sLens);
  436. }
  437. //总人数
  438. BigDecimal alls = new BigDecimal(idList.size());
  439. //当前等级正态分布比例
  440. BigDecimal scale = personPerform.get(revLevel);
  441. //创建每个等级的人数列表
  442. Map<String, BigDecimal> bigsList = Maps.newHashMap();
  443. BigDecimal bigS = ((personPerform.get("S").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  444. bigsList.put("S", bigS);
  445. BigDecimal bigA = ((personPerform.get("A").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  446. bigsList.put("A", bigA);
  447. BigDecimal bigB = ((personPerform.get("B").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  448. bigsList.put("B", bigB);
  449. BigDecimal bigC = ((personPerform.get("C").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  450. bigsList.put("C", bigC);
  451. BigDecimal bigD = ((personPerform.get("D").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  452. bigsList.put("D", bigD);
  453. //已占用数
  454. BigDecimal lens = BigDecimal.ZERO;
  455. //进行额度加减
  456. BigDecimal personSize = BigDecimal.ZERO;
  457. BigDecimal personMaxSize = BigDecimal.ZERO;
  458. BigDecimal personMinSize = BigDecimal.ZERO;
  459. List<String> ldrs = Lists.newArrayList();
  460. Map<String,String> ldrcd = Maps.newHashMap();
  461. switch (revLevel) {
  462. case "A":
  463. personSize = personSize.add(bigA).subtract(aLens);
  464. lens = lens.add(aLens);
  465. if ("A".equals(revLevel)) {
  466. personMaxSize = personMaxSize.add((bigA));
  467. } else {
  468. personMaxSize = personMaxSize.add((bigA).subtract(aLens));
  469. }
  470. ldrs.add("A最多%A人,");
  471. //bigsList.remove("A");
  472. case "S":
  473. personSize = personSize.add(bigS).subtract(sLens);
  474. lens = lens.add(sLens);
  475. if ("S".equals(revLevel)) {
  476. personMaxSize = personMaxSize.add((bigS));
  477. } else {
  478. personMaxSize = personMaxSize.add((bigS).subtract(sLens));
  479. }
  480. ldrs.add("S最多%S人,");
  481. //bigsList.remove("S");
  482. case "B":
  483. case "C":
  484. if ("C".equals(revLevel)) {
  485. personMinSize = personMinSize.add((bigC));
  486. } else {
  487. personMinSize = personMinSize.add((bigC).subtract(cLens));
  488. }
  489. ldrcd.put("C","C最少"+(personMinSize.compareTo(BigDecimal.ZERO) > 0?personMinSize.toPlainString():'0')+"人,");
  490. //bigsList.remove("C");
  491. case "D":
  492. if ("D".equals(revLevel)) {
  493. personMinSize = personMinSize.add((bigD));
  494. } else {
  495. personMinSize = personMinSize.add((bigD).subtract(dLens));
  496. }
  497. ldrcd.put("D","D最少"+(personMinSize.compareTo(BigDecimal.ZERO) > 0?personMinSize.toPlainString():'0')+"人,");
  498. }
  499. String ld = "当前周期绩效等级为%l的人数为%maxs人,";
  500. if (personMinSize.compareTo(BigDecimal.ZERO) > 0 || personSize.compareTo(BigDecimal.ZERO) < 0) {
  501. if(ldrs.size()>0) {
  502. String ldrstr = ldrs.get(0);
  503. ld += ldrstr;
  504. ld = ld.replace("%" + revLevel, (personMaxSize.compareTo(BigDecimal.ZERO) > 0 ? (personMaxSize) : BigDecimal.ZERO).toPlainString());
  505. }
  506. ld = ld.replace("%l", revLevel);
  507. ld = ld.replace("%maxs", (leveList.get(revLevel) == null ? BigDecimal.ZERO : leveList.get(revLevel)).toPlainString());
  508. for (Map.Entry<String,String> entry : ldrcd.entrySet()) {
  509. String eKey = entry.getKey();
  510. String ldr= entry.getValue();
  511. ld += ldr;
  512. }
  513. ld += "请修正后重新审核.";
  514. batchMessage.put(fid, ld);
  515. }
  516. }
  517. }
  518. return batchMessage;
  519. }
  520. /**
  521. * 结果直接审核、结果工作流审核,绩效等级分布比例校验人数由整个绩效考核计划的人数改为按选择的人数进行分布比例校验。
  522. *
  523. * @param ctx
  524. * @param period
  525. * @param planId
  526. * @param idList
  527. * @return
  528. * @throws BOSException
  529. * @throws SQLException
  530. */
  531. public Map<String, String> beforeAuditEvaResut(Context ctx, String period, String planId, List<String> idList,JSONArray entryList) throws BOSException, SQLException {
  532. Map<String, String> batchMessage = Maps.newHashMap();
  533. StringBuilder selParamId = new StringBuilder("''");
  534. for (int i = 0; i < idList.size(); i++) {
  535. selParamId.append(",?");
  536. }
  537. //获取正态分布规则
  538. Map<String, Map<String, BigDecimal>> personPerformMap = this.getPersonPerformPro(ctx, idList, batchMessage);
  539. if (null != personPerformMap && personPerformMap.size() > 0) {
  540. //获取组织分组人数
  541. //Map<String, Map<String, String>> orgLevelMap = this.getOrgLevelCountMap(ctx, period, planId);
  542. //获取人员等级分组
  543. Map<String, Map<String, Object>> personLevelMap = this.getPersonLevelLensMap(ctx, entryList);
  544. BigDecimal big100 = new BigDecimal(100);
  545. for(int i=0;i<entryList.size();i++) {
  546. JSONObject object = entryList.getJSONObject(i);
  547. String fid = object.getString("id");
  548. String evaResult = object.getString("evaResult.id");
  549. //修改后等级
  550. String auditGradeLevel = object.getString("evaResult.auditGradeLevel");
  551. if (StrUtil.isBlank(auditGradeLevel)) {
  552. batchMessage.put(fid, "绩效等级为空,请维护");
  553. continue;
  554. }
  555. StringBuilder sel = new StringBuilder();
  556. sel.append(" select ers.fid,ers.FADMINORGNAME, ");
  557. sel.append(" ers.FPERIODID, ers.FEVAPLANID,isnull(ers.FREVISEGRADELEVEL, ers.FGRADELEVEL) revLevel,ers.CFOrgLevel ");
  558. sel.append(" from T_EVA_EvaResultSummary ers where ers.fid = '");
  559. sel.append(evaResult);
  560. sel.append("' ");
  561. IRowSet rs = DbUtil.executeQuery(ctx, sel.toString());
  562. String orgLevel="";
  563. String FADMINORGNAME ="";
  564. //上季度组织绩效等级
  565. if (rs.next()){
  566. orgLevel = rs.getString("CFOrgLevel");
  567. FADMINORGNAME = rs.getString("FADMINORGNAME");
  568. if (StringUtils.isBlank(orgLevel)) {
  569. String msg = String.format("%s上季度组织绩效等级为空", FADMINORGNAME);
  570. batchMessage.put(fid, msg);
  571. continue;
  572. }
  573. }
  574. //该组织的组织绩效等级的正态分布
  575. Map<String, BigDecimal> personPerform = personPerformMap.get(orgLevel);
  576. if (null == personPerform) {
  577. String msg = String.format("没有找到%s上季度组织绩效等级%s的正态分布规则", FADMINORGNAME, orgLevel);
  578. batchMessage.put(fid, msg);
  579. continue;
  580. }
  581. //获取该组织下的人员总数
  582. //Map<String, String> orgMap = orgLevelMap.get(key);
  583. Map<String, BigDecimal> leveList = Maps.newHashMap();
  584. //获取等级D人数
  585. String keyRevLevelD = "D";
  586. Map<String, Object> personMapD = personLevelMap.get(keyRevLevelD);
  587. BigDecimal dLens = BigDecimal.ZERO;
  588. if (null != personMapD) {
  589. dLens = (BigDecimal) personMapD.get("lens");
  590. leveList.put("D", dLens);
  591. }
  592. //获取等级C人数
  593. String keyRevLevelC = "C";
  594. Map<String, Object> personMapC = personLevelMap.get(keyRevLevelC);
  595. BigDecimal cLens = BigDecimal.ZERO;
  596. if (null != personMapC) {
  597. cLens = (BigDecimal) personMapC.get("lens");
  598. leveList.put("C", cLens);
  599. }
  600. //获取等级B人数
  601. String keyRevLevelB = "B";
  602. Map<String, Object> personMapB = personLevelMap.get(keyRevLevelB);
  603. BigDecimal bLens = BigDecimal.ZERO;
  604. if (null != personMapB) {
  605. bLens = (BigDecimal) personMapB.get("lens");
  606. leveList.put("B", bLens);
  607. }
  608. //获取等级A人数
  609. String keyRevLevelA = "A";
  610. Map<String, Object> personMapA = personLevelMap.get(keyRevLevelA);
  611. BigDecimal aLens = BigDecimal.ZERO;
  612. if (null != personMapA) {
  613. aLens = (BigDecimal) personMapA.get("lens");
  614. leveList.put("A", aLens);
  615. }
  616. //获取等级S人数
  617. String keyRevLevelS = "S";
  618. Map<String, Object> personMapS = personLevelMap.get(keyRevLevelS);
  619. BigDecimal sLens = BigDecimal.ZERO;
  620. if (null != personMapS) {
  621. sLens = (BigDecimal) personMapS.get("lens");
  622. leveList.put("S", sLens);
  623. }
  624. System.out.println("leveList:"+leveList);
  625. //总人数
  626. BigDecimal alls = new BigDecimal(idList.size());
  627. //当前等级正态分布比例
  628. BigDecimal scale = personPerform.get(auditGradeLevel);
  629. //创建每个等级的人数列表
  630. Map<String, BigDecimal> bigsList = Maps.newHashMap();
  631. BigDecimal bigS = ((personPerform.get("S").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  632. bigsList.put("S", bigS);
  633. BigDecimal bigA = ((personPerform.get("A").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  634. bigsList.put("A", bigA);
  635. BigDecimal bigB = ((personPerform.get("B").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  636. bigsList.put("B", bigB);
  637. BigDecimal bigC = ((personPerform.get("C").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  638. bigsList.put("C", bigC);
  639. BigDecimal bigD = ((personPerform.get("D").divide(big100, BigDecimal.ROUND_HALF_UP, BigDecimal.ROUND_HALF_UP)).multiply(alls).setScale(0, BigDecimal.ROUND_HALF_UP));
  640. bigsList.put("D", bigD);
  641. System.out.println("bigsList:"+bigsList);
  642. //已占用数
  643. BigDecimal lens = BigDecimal.ZERO;
  644. //进行额度加减
  645. //if ("S".equals(revLevel) || "A".equals(revLevel)||"B".equals(revLevel) || "C".equals(revLevel) || "D".equals(revLevel)) {
  646. BigDecimal personSize = BigDecimal.ZERO;
  647. BigDecimal personMaxSize = BigDecimal.ZERO;
  648. BigDecimal personMinSize = BigDecimal.ZERO;
  649. List<String> ldrs = Lists.newArrayList();
  650. Map<String,String> ldrcd = Maps.newHashMap();
  651. switch (auditGradeLevel) {
  652. case "A":
  653. personSize = personSize.add(bigA).subtract(aLens);
  654. lens = lens.add(aLens);
  655. if ("A".equals(auditGradeLevel)) {
  656. personMaxSize = personMaxSize.add((bigA));
  657. } else {
  658. personMaxSize = personMaxSize.add((bigA).subtract(aLens));
  659. }
  660. ldrs.add("A最多%A人,");
  661. //bigsList.remove("A");
  662. case "S":
  663. personSize = personSize.add(bigS).subtract(sLens);
  664. lens = lens.add(sLens);
  665. if ("S".equals(auditGradeLevel)) {
  666. personMaxSize = personMaxSize.add((bigS));
  667. } else {
  668. personMaxSize = personMaxSize.add((bigS).subtract(sLens));
  669. }
  670. ldrs.add("S最多%S人,");
  671. //bigsList.remove("S");
  672. case "B":
  673. case "C":
  674. if ("C".equals(auditGradeLevel)) {
  675. personMinSize = personMinSize.add((bigC));
  676. } else {
  677. personMinSize = personMinSize.add((bigC).subtract(cLens));
  678. }
  679. ldrcd.put("C","C最少"+(personMinSize.compareTo(BigDecimal.ZERO) > 0?personMinSize.toPlainString():'0')+"人,");
  680. //bigsList.remove("C");
  681. case "D":
  682. // if (bigD.compareTo(dLens) > 0) {
  683. // ldrcd.add("D最少" + bigD.toPlainString() + "人,");
  684. // }
  685. if ("D".equals(auditGradeLevel)) {
  686. personMinSize = personMinSize.add((bigD));
  687. } else {
  688. personMinSize = personMinSize.add((bigD).subtract(dLens));
  689. }
  690. ldrcd.put("D","D最少"+(personMinSize.compareTo(BigDecimal.ZERO) > 0?personMinSize.toPlainString():'0')+"人,");
  691. }
  692. String ld = "当前周期绩效等级为%l的人数为%maxs人,";
  693. if (personMinSize.compareTo(BigDecimal.ZERO) > 0 || personSize.compareTo(BigDecimal.ZERO) < 0) {
  694. if(ldrs.size()>0){
  695. String ldrstr = ldrs.get(0);
  696. ld += ldrstr;
  697. ld = ld.replace("%" + auditGradeLevel, (personMaxSize.compareTo(BigDecimal.ZERO) > 0 ? (personMaxSize) : BigDecimal.ZERO).toPlainString());
  698. }
  699. ld = ld.replace("%l", auditGradeLevel);
  700. ld = ld.replace("%maxs", (leveList.get(auditGradeLevel) == null ? BigDecimal.ZERO : leveList.get(auditGradeLevel)).toPlainString());
  701. for (Map.Entry<String,String> entry : ldrcd.entrySet()) {
  702. String eKey = entry.getKey();
  703. String ldr= entry.getValue();
  704. ld += ldr;
  705. }
  706. ld += "请修正后重新审核.";
  707. batchMessage.put(fid, ld);
  708. }
  709. }
  710. }
  711. return batchMessage;
  712. }
  713. }