OverTimeAgainstApproveUtil.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. package com.kingdee.eas.custom.ot.util;
  2. import com.google.common.collect.Maps;
  3. import com.kingdee.bos.BOSException;
  4. import com.kingdee.bos.Context;
  5. import com.kingdee.bos.dao.ObjectNotFoundException;
  6. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  7. import com.kingdee.bos.metadata.entity.SelectorItemCollection;
  8. import com.kingdee.bos.metadata.entity.SelectorItemInfo;
  9. import com.kingdee.bos.util.BOSUuid;
  10. import com.kingdee.eas.base.permission.UserInfo;
  11. import com.kingdee.eas.common.EASBizException;
  12. import com.kingdee.eas.framework.CoreBaseCollection;
  13. import com.kingdee.eas.hr.ats.*;
  14. import com.kingdee.eas.hr.ats.dataLog.util.DataLogsRecordUtil;
  15. import com.kingdee.eas.hr.ats.takeWorkLimit.impl.GenerateTakeWorkLimit;
  16. import com.kingdee.eas.hr.ats.thread.ExecutorService.TaskPool;
  17. import com.kingdee.eas.hr.ats.thread.executor.Callable;
  18. import com.kingdee.eas.hr.ats.util.AtsDateUtils;
  19. import com.kingdee.eas.hr.ats.util.AtsServerCalUtils;
  20. import com.kingdee.eas.hr.ats.util.SHRBillServerUtil;
  21. import com.kingdee.eas.hr.ats.util.common.MLUtile;
  22. import com.kingdee.eas.util.app.DbUtil;
  23. import com.kingdee.jdbc.rowset.IRowSet;
  24. import com.kingdee.shr.ats.bill.util.AtsBillSourceTypeUtil;
  25. import com.kingdee.shr.ats.service.result.AttendCalculateParent;
  26. import com.kingdee.shr.ats.service.vo.AtsOverTimeVo;
  27. import com.kingdee.shr.base.syssetting.app.osf.OSFAppUtil;
  28. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  29. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  30. import org.apache.commons.lang.StringUtils;
  31. import org.apache.log4j.Logger;
  32. import javax.servlet.http.HttpServletRequest;
  33. import java.math.BigDecimal;
  34. import java.sql.Timestamp;
  35. import java.text.SimpleDateFormat;
  36. import java.util.*;
  37. import java.util.concurrent.ThreadPoolExecutor;
  38. /**
  39. * 加班单
  40. * 反审批
  41. *
  42. * @ lhbj
  43. */
  44. public class OverTimeAgainstApproveUtil {
  45. private static Logger logger = Logger.getLogger(OverTimeAgainstApproveUtil.class);
  46. public String getBillIds(HttpServletRequest request) throws ShrWebBizException {
  47. String billId = (String) request.getAttribute("billId");
  48. if (StringUtils.isEmpty(billId)) {
  49. billId = request.getParameter("billId");
  50. }
  51. if (StringUtils.isEmpty(billId)) {
  52. billId = request.getParameter("billID");
  53. }
  54. if (StringUtils.isEmpty(billId)) {
  55. billId = (String) request.getAttribute("billID");
  56. }
  57. if (StringUtils.isEmpty(billId)) {
  58. throw new ShrWebBizException(new AtsCommonBizException(AtsCommonBizException.NULLBILLID));
  59. } else {
  60. return billId;
  61. }
  62. }
  63. /**
  64. * 取消核通过的单据分录变更
  65. * @param ctx
  66. * @param billId
  67. * @param entryId
  68. * @return
  69. * @throws SHRWebException
  70. */
  71. public Map<String, Object> unChangeOTEntry(Context ctx, String billId, String entryId) throws BOSException {
  72. Map<String, Object> res = Maps.newHashMap();
  73. // IAtsOverTimeBill iBill = AtsOverTimeBillFactory.getLocalInstance(ctx);
  74. // IAtsOverTimeBillEntry iBillEntry = AtsOverTimeBillEntryFactory.getLocalInstance(ctx);
  75. //删除新单据分录
  76. String updEntry2 = "delete from T_HR_ATS_OverTimeBillEntry where fid=?";
  77. DbUtil.execute(ctx, updEntry2, new String[]{entryId.toString()});
  78. //新单据
  79. // String delNewBill = "delete from T_HR_ATS_OverTimeBill where fid=?";
  80. // DbUtil.execute(ctx, delNewBill, new String[]{billId.toString()});
  81. return res;
  82. }
  83. /**
  84. * 变更审批通过的分录
  85. * 第一步:生成一样数据进行
  86. *
  87. * @param ctx
  88. * @param billId
  89. * @param entryId
  90. * @return
  91. */
  92. public Map<String, Object> changeOTEntry(Context ctx, String billId, String entryId) throws BOSException {
  93. System.out.println("changeOTEntry");
  94. Map<String, Object> res = Maps.newHashMap();
  95. IAtsOverTimeBill iBill = AtsOverTimeBillFactory.getLocalInstance(ctx);
  96. IAtsOverTimeBillEntry iBillEntry = AtsOverTimeBillEntryFactory.getLocalInstance(ctx);
  97. //更新id
  98. BOSUuid newId = null;
  99. BOSUuid newEntryId = null;
  100. res.put("code", "err");
  101. res.put("msg", "失败");
  102. try {
  103. System.out.println("changeOTEntry:" + billId + "-" + entryId);
  104. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  105. selectorItemCollection.add(new SelectorItemInfo("*"));
  106. //获取原单分录
  107. AtsOverTimeBillEntryInfo oldEntryInfo = iBillEntry.getAtsOverTimeBillEntryInfo(new ObjectUuidPK(entryId), selectorItemCollection);
  108. //获取原单
  109. AtsOverTimeBillInfo oldBillInfo = iBill.getAtsOverTimeBillInfo(new ObjectUuidPK(billId), selectorItemCollection);
  110. System.out.println("changeOTEntry");
  111. //创建新单
  112. AtsOverTimeBillInfo newBillInfo = (AtsOverTimeBillInfo) oldBillInfo.clone();
  113. newBillInfo.setSourceBillId(newBillInfo.getId().toString());
  114. //更新为单人编辑界面
  115. newBillInfo.setBillSubmitType(BillSubmitTypeEnum.common);
  116. System.out.println("changeOTEntry");
  117. //更新id
  118. newId = BOSUuid.create(oldBillInfo.getBOSType());
  119. newBillInfo.setId(newId);
  120. //创建新单分录集合
  121. AtsOverTimeBillEntryCollection newEntryCollection = new AtsOverTimeBillEntryCollection();
  122. //添加待变更分录
  123. AtsOverTimeBillEntryInfo newEntryInfo = (AtsOverTimeBillEntryInfo) oldEntryInfo.clone();
  124. //变更分录id
  125. newEntryId = BOSUuid.create(oldEntryInfo.getBOSType());
  126. newEntryInfo.setId(newEntryId);
  127. newEntryInfo.setBill(newBillInfo);
  128. newEntryCollection.add(newEntryInfo);
  129. newBillInfo.put("entries", newEntryCollection);
  130. System.out.println("changeOTEntry4" + newBillInfo);
  131. iBill.addnew(new ObjectUuidPK(newId), newBillInfo);
  132. //更新新单为审批通过
  133. String updBill = "update T_HR_ATS_OverTimeBill set FBillState=3 where fid=?";
  134. DbUtil.execute(ctx, updBill, new String[]{newId.toString()});
  135. System.out.println("changeOTEntry5" + newId.toString());
  136. //反审批校验
  137. Map<String, Object> bres = this.beforeAgainstApproveAction(ctx, newId.toString());
  138. System.out.println("changeOTEntry6" + bres.toString());
  139. res.putAll(bres);
  140. String errorMsgList = (String) bres.get("errorMsgList");
  141. if (StringUtils.isNotBlank(errorMsgList)) {
  142. //校验失败
  143. res.put("code", "err");
  144. res.put("msg", errorMsgList);
  145. } else {
  146. //更新新单为未提交状态
  147. String updBill2 = "update T_HR_ATS_OverTimeBill set FBillState=0 where fid=?";
  148. DbUtil.execute(ctx, updBill2, new String[]{newId.toString()});
  149. res.put("msg", "成功");
  150. res.put("billID", newId.toString());
  151. res.put("entryId", newEntryId.toString());
  152. res.put("oldBillID", billId.toString());
  153. res.put("oldEntryId", entryId.toString());
  154. res.put("code", "ses");
  155. }
  156. //反审批失败处理
  157. if ("err".equals(res.get("code"))) {
  158. //删除新单据分录
  159. String updEntry2 = "delete from T_HR_ATS_OverTimeBillEntry where fid=?";
  160. DbUtil.execute(ctx, updEntry2, new String[]{newEntryId.toString()});
  161. //新单据
  162. String delNewBill = "delete from T_HR_ATS_OverTimeBill where fid=?";
  163. DbUtil.execute(ctx, delNewBill, new String[]{newId.toString()});
  164. } else {
  165. //需要等待专员变更后处理
  166. }
  167. } catch (Exception e) {
  168. e.printStackTrace();
  169. res.put("msg", e.getMessage());
  170. //删除新单据分录
  171. String updEntry2 = "delete from T_HR_ATS_OverTimeBillEntry where fid=?";
  172. DbUtil.execute(ctx, updEntry2, new String[]{newEntryId.toString()});
  173. //新单据
  174. String delNewBill = "delete from T_HR_ATS_OverTimeBill where fid=?";
  175. DbUtil.execute(ctx, delNewBill, new String[]{newId.toString()});
  176. logger.error(e);
  177. } finally {
  178. System.out.println("deleteOTEntry.finally:" + res);
  179. }
  180. return res;
  181. }
  182. /**
  183. * 删除审批通过的分录
  184. *
  185. * @param ctx
  186. * @param billId
  187. * @param entryId
  188. * @return
  189. */
  190. public Map<String, Object> deleteOTEntry(Context ctx, String billId, String entryId) throws BOSException, EASBizException {
  191. System.out.println("deleteOTEntry");
  192. Map<String, Object> res = Maps.newHashMap();
  193. IAtsOverTimeBill iBill = AtsOverTimeBillFactory.getLocalInstance(ctx);
  194. IAtsOverTimeBillEntry iBillEntry = AtsOverTimeBillEntryFactory.getLocalInstance(ctx);
  195. //更新id
  196. BOSUuid newId = null;
  197. res.put("code", "err");
  198. res.put("msg", "失败");
  199. try {
  200. System.out.println("deleteOTEntry:" + billId + "-" + entryId);
  201. SelectorItemCollection selectorItemCollection = new SelectorItemCollection();
  202. selectorItemCollection.add(new SelectorItemInfo("*"));
  203. //获取原单分录
  204. AtsOverTimeBillEntryInfo oldEntryInfo = iBillEntry.getAtsOverTimeBillEntryInfo(new ObjectUuidPK(entryId), selectorItemCollection);
  205. //获取原单
  206. AtsOverTimeBillInfo oldBillInfo = iBill.getAtsOverTimeBillInfo(new ObjectUuidPK(billId), selectorItemCollection);
  207. System.out.println("deleteOTEntry1");
  208. //创建新单
  209. AtsOverTimeBillInfo newBillInfo = (AtsOverTimeBillInfo) oldBillInfo.clone();
  210. newBillInfo.setSourceBillId(newBillInfo.getId().toString());
  211. System.out.println("deleteOTEntry2");
  212. //更新id
  213. newId = BOSUuid.create(oldBillInfo.getBOSType());
  214. newBillInfo.setId(newId);
  215. //创建新单分录集合
  216. AtsOverTimeBillEntryCollection newEntryCollection = new AtsOverTimeBillEntryCollection();
  217. //添加待删除分录
  218. newBillInfo.put("entries", newEntryCollection);
  219. System.out.println("deleteOTEntry4" + newBillInfo);
  220. iBill.addnew(new ObjectUuidPK(newId), newBillInfo);
  221. //更新原单分录为新单据分录
  222. String updEntry = "update T_HR_ATS_OverTimeBillEntry set fbillid=? where fid=?";
  223. DbUtil.execute(ctx, updEntry, new String[]{newId.toString(), entryId});
  224. System.out.println("deleteOTEntry3");
  225. //更新新单为审批通过
  226. String updBill = "update T_HR_ATS_OverTimeBill set FBillState=3 where fid=?";
  227. DbUtil.execute(ctx, updBill, new String[]{newId.toString()});
  228. System.out.println("deleteOTEntry5" + newId.toString());
  229. //反审批校验
  230. Map<String, Object> bres = this.beforeAgainstApproveAction(ctx, newId.toString());
  231. System.out.println("deleteOTEntry6" + bres.toString());
  232. res.putAll(bres);
  233. String errorMsgList = (String) bres.get("errorMsgList");
  234. if (StringUtils.isNotBlank(errorMsgList)) {
  235. //校验失败
  236. res.put("code", "err");
  237. res.put("msg", errorMsgList);
  238. } else {
  239. Map<String, Object> ares = this.againstApproveAction(ctx, "删除分录", newId.toString());
  240. res.putAll(ares);
  241. Set<String> successIds = (Set<String>) ares.get("successIds");
  242. if (1 != successIds.size()) {
  243. //反审批失败
  244. res.put("code", "err");
  245. } else {
  246. res.put("code", "ses");
  247. }
  248. }
  249. //反审批失败处理
  250. if ("err".equals(res.get("code"))) {
  251. //更新新单据分录为原单分录
  252. String updEntry2 = "update T_HR_ATS_OverTimeBillEntry set fbillid=? where fid=?";
  253. DbUtil.execute(ctx, updEntry2, new String[]{billId, entryId});
  254. //新单据
  255. String delNewBill = "delete from T_HR_ATS_OverTimeBill where fid=?";
  256. DbUtil.execute(ctx, delNewBill, new String[]{newId.toString()});
  257. } else {
  258. //新单据
  259. String delNewBill = "delete from T_HR_ATS_OverTimeBill where fid=?";
  260. DbUtil.execute(ctx, delNewBill, new String[]{newId.toString()});
  261. //新单据
  262. String delNewEntry = "delete from T_HR_ATS_OverTimeBillEntry where fid=?";
  263. DbUtil.execute(ctx, delNewEntry, new String[]{entryId.toString()});
  264. }
  265. } catch (Exception e) {
  266. e.printStackTrace();
  267. res.put("msg", e.getMessage());
  268. //更新新单据分录为原单分录
  269. String updEntry2 = "update T_HR_ATS_OverTimeBillEntry set fbillid=? where fid=?";
  270. DbUtil.execute(ctx, updEntry2, new String[]{billId, entryId});
  271. logger.error(e);
  272. } finally {
  273. System.out.println("deleteOTEntry.finally:" + res);
  274. String delNewBill = "delete from T_HR_ATS_OverTimeBill where fid=?";
  275. DbUtil.execute(ctx, delNewBill, new String[]{newId.toString()});
  276. }
  277. return res;
  278. }
  279. /**
  280. * 反审批前校验
  281. *
  282. * @param ctx
  283. * @param billIds
  284. * @return {"turned":15,"errorMsgList":"[贺加贝]的选中记录中存在加班单参与了加班转调休计算,反审批后调休额度的剩余额度小于0且假期制度不允许超额请假,请先将请假单反审批再操作!","turnedInfos":"[刘光辉 2025-07-01]、[Mike 2025-07-01]、[王斌 2025-07-01]、[周芳 2025-07-01]、[刘浔 2025-07-01]、[simone 2025-07-01]、[曹浪 2025-07-01]、[唐建强 2025-07-01]、[田文立 2025-07-01]、[张晗 2025-07-01]、[张大利 2025-07-01]、[Vincent 2025-07-01]、[高爽 2025-07-01]、[贺加贝 2025-07-01]、[张三01 2025-07-01]"}
  285. * @throws SHRWebException
  286. * @throws BOSException
  287. * @throws EASBizException
  288. */
  289. public Map<String, Object> beforeAgainstApproveAction(Context ctx, String billIds) throws SHRWebException, BOSException, EASBizException {
  290. Map<String, Object> res = new HashMap();
  291. String flag = "true";
  292. if (StringUtils.isBlank(billIds)) {
  293. throw new ShrWebBizException(new AtsCommonBizException(AtsCommonBizException.ILLEGALID));
  294. } else {
  295. IAtsOverTimeBill iAtsOverTimeInfo = AtsOverTimeBillFactory.getRemoteInstance();
  296. String[] ids = billIds.split(",");
  297. Map<String, BigDecimal> limitDeductMap = new HashMap();
  298. if (ids != null && ids.length > 0) {
  299. for (int i = 0; i < ids.length; ++i) {
  300. String billId = ids[i];
  301. if ("true".equals(flag)) {
  302. StringBuffer checkSB = new StringBuffer("");
  303. checkSB.append("select sum.fid from T_HR_ATS_AttendanceResultSum sum inner join T_HR_ATS_OverTimeBillEntry lbe on lbe.fpersonId = sum.fproposerId and lbe.fadminOrgUnitId = sum.fadminOrgUnitId and sum.FSalaryStatus = 1 ");
  304. checkSB.append("inner join T_HR_ATS_OverTimeBill lb on lb.fid = lbe.FBillID inner join T_HR_ATS_AttendancePeriod ap on ap.fid = sum.FAttendancePeriodID and lbe.FRealEndTime < DATEADD(DAY,1,ap.FEndDate) ");
  305. checkSB.append(" where lb.fid = '" + billId + "' ");
  306. IRowSet row = DbUtil.executeQuery(ctx, checkSB.toString());
  307. if (row.size() > 0) {
  308. throw new ShrWebBizException(new AtsAgainstApprove(AtsAgainstApprove.EXCEPTIONOVER));
  309. }
  310. }
  311. AtsOverTimeBillInfo billInfo = iAtsOverTimeInfo.getAtsOverTimeBillInfo(new ObjectUuidPK(billId));
  312. if (billInfo.getBillState().getValue() != 3) {
  313. throw new ShrWebBizException(new AtsOTBizException(AtsOTBizException.CANCERAUDITNOTMATHAUDIT));
  314. }
  315. this.isTurned(ctx, billInfo, res, limitDeductMap);
  316. }
  317. String turnedInfos = (String) res.get("turnedInfos");
  318. if (turnedInfos != null && turnedInfos.length() > 0) {
  319. turnedInfos = turnedInfos.substring(0, turnedInfos.length() - 1);
  320. res.put("turnedInfos", turnedInfos);
  321. }
  322. }
  323. return res;
  324. }
  325. }
  326. public void isTurned(Context ctx, AtsOverTimeBillInfo billInfo, Map<String, Object> res, Map<String, BigDecimal> limitDeductMap) {
  327. Map<String, OTtoTakeWorkDetailInfo> toTakeWorkDetailMap = new HashMap();
  328. AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
  329. Map<String, Date> otDates = new HashMap();
  330. Set<String> entryPersonIds = new HashSet();
  331. Map<String, BigDecimal> detailInfosMap = new HashMap();
  332. if (entries != null && entries.size() > 0) {
  333. for (int i = 0; i < entries.size(); ++i) {
  334. String personId = entries.get(i).getPerson().getId().toString();
  335. entryPersonIds.add(personId);
  336. otDates.put(personId, entries.get(i).getOtDate());
  337. try {
  338. OTtoTakeWorkDetailCollection detailInfos = OTtoTakeWorkDetailFactory.getLocalInstance(ctx).getOTtoTakeWorkDetailCollection("select id, proposer.id,proposer.name,proposer.number,limit,limitValue where sourceBillID = '" + entries.get(i).getId() + "' and state = 0 ");
  339. if (detailInfos != null && detailInfos.size() > 0) {
  340. toTakeWorkDetailMap.put(personId, detailInfos.get(0));
  341. String limitId = detailInfos.get(0).getLimit();
  342. if (limitDeductMap.get(limitId) == null) {
  343. limitDeductMap.put(limitId, detailInfos.get(0).getLimitValue());
  344. } else {
  345. limitDeductMap.put(limitId, ((BigDecimal) limitDeductMap.get(limitId)).add(detailInfos.get(0).getLimitValue()));
  346. }
  347. } else {
  348. AttendanceResultCollection results = AttendanceResultFactory.getLocalInstance(ctx).getAttendanceResultCollection("select id where attenceDate = '" + entries.get(i).getOtDate() + "' and proposer.id = '" + entries.get(i).getPerson().getId().toString() + "'");
  349. if (results.size() > 0) {
  350. detailInfos = OTtoTakeWorkDetailFactory.getLocalInstance(ctx).getOTtoTakeWorkDetailCollection("select id, proposer.id,proposer.name,proposer.number,limit,limitValue where sourceBillID = '" + results.get(0).getId() + "' and state = 0 ");
  351. if (detailInfos.size() > 0) {
  352. toTakeWorkDetailMap.put(personId, detailInfos.get(0));
  353. if (detailInfosMap.get(detailInfos.get(0).getId().toString()) == null) {
  354. String limitId = detailInfos.get(0).getLimit();
  355. detailInfosMap.put(detailInfos.get(0).getId().toString(), detailInfos.get(0).getLimitValue());
  356. if (limitDeductMap.get(limitId) == null) {
  357. limitDeductMap.put(limitId, detailInfos.get(0).getLimitValue());
  358. } else {
  359. limitDeductMap.put(limitId, ((BigDecimal) limitDeductMap.get(limitId)).add(detailInfos.get(0).getLimitValue()));
  360. }
  361. }
  362. }
  363. }
  364. }
  365. } catch (ObjectNotFoundException e) {
  366. e.printStackTrace();
  367. } catch (BOSException e) {
  368. e.printStackTrace();
  369. }
  370. }
  371. }
  372. int turned = res.get("turned") == null ? 0 : (Integer) res.get("turned");
  373. String turnedInfos = res.get("turnedInfos") == null ? "" : (String) res.get("turnedInfos");
  374. if (!toTakeWorkDetailMap.isEmpty()) {
  375. for (String key : toTakeWorkDetailMap.keySet()) {
  376. ++turned;
  377. turnedInfos = turnedInfos + "[" + ((OTtoTakeWorkDetailInfo) toTakeWorkDetailMap.get(key)).getProposer().getName() + " " + AtsDateUtils.dateShortToString((Date) otDates.get(key)) + "]、";
  378. }
  379. this.checkRemainLimit(ctx, res, limitDeductMap);
  380. }
  381. res.put("turned", turned);
  382. res.put("turnedInfos", turnedInfos);
  383. }
  384. private void checkRemainLimit(Context ctx, Map<String, Object> res, Map<String, BigDecimal> limitDeductMap) {
  385. StringBuffer sb = new StringBuffer();
  386. try {
  387. IRowSet rs = DbUtil.executeQuery(ctx, "SELECT LI.FREMAINLIMIT,LI.FID ,PO.FIsOver, PERSON.FNAME" + MLUtile.getMlFlag(ctx) + " AS personName FROM T_HR_ATS_HOLIDAYLIMIT LI INNER JOIN T_HR_ATS_HolidayPolicy PO ON LI.FHOLIDAYPOLICYID = PO.FID INNER JOIN T_BD_PERSON PERSON ON PERSON.FID = LI.FPROPOSERID WHERE LI.FID IN (" + AtsUtil.convertSetToString(limitDeductMap.keySet()) + ")");
  388. while (rs.next()) {
  389. String limitId = rs.getString("FID");
  390. BigDecimal remainLimit = rs.getBigDecimal("FREMAINLIMIT");
  391. int isOver = rs.getInt("FIsOver");
  392. BigDecimal deductLimit = (BigDecimal) limitDeductMap.get(limitId);
  393. if (deductLimit != null && isOver == 0 && remainLimit.subtract(deductLimit).compareTo(BigDecimal.ZERO) < 0) {
  394. sb.append("[" + rs.getString("personName") + "]");
  395. }
  396. }
  397. } catch (Exception e) {
  398. e.printStackTrace();
  399. }
  400. if (StringUtils.isNotEmpty(sb.toString())) {
  401. res.put("errorMsgList", MLUtile.getRes(AtsOverTimeBillResEnum.existsOTDetailAndRemainLimitLessThanZero, ctx, new Object[]{sb.toString()}));
  402. }
  403. }
  404. public String doAgainApprove(Context ctx, String billId, String aiReason) throws EASBizException, BOSException, SHRWebException {
  405. IAtsOverTimeBill iAtsOverTimeInfo = AtsOverTimeBillFactory.getRemoteInstance();
  406. AtsOverTimeBillInfo billInfo = iAtsOverTimeInfo.getAtsOverTimeBillInfo(new ObjectUuidPK(billId));
  407. CoreBaseCollection detailColl = new CoreBaseCollection();
  408. AtsOverTimeBillEntryCollection entries = billInfo.getEntries();
  409. boolean isCreateTagISAuto = false;
  410. if (entries != null && entries.size() > 0) {
  411. for (int i = 0; i < entries.size(); ++i) {
  412. OverTimeCreateTag createTag = entries.get(i).getCreateTag();
  413. entries.get(i).setCreateTag(OverTimeCreateTag.userCreate);
  414. if (null != createTag && createTag.getValue() == 3) {
  415. isCreateTagISAuto = true;
  416. }
  417. if (null != createTag && createTag.getValue() == 2) {
  418. isCreateTagISAuto = true;
  419. }
  420. OTtoTakeWorkDetailInfo detailInfo = null;
  421. try {
  422. detailInfo = OTtoTakeWorkDetailFactory.getLocalInstance(ctx).getOTtoTakeWorkDetailInfo(" where sourceBillID = '" + entries.get(i).getId().toString() + "' and state = 0 ");
  423. } catch (ObjectNotFoundException e) {
  424. e.printStackTrace();
  425. }
  426. if (detailInfo != null) {
  427. detailInfo.setState(OTtoTakeWorkDetailStatus.invalid);
  428. detailColl.add(detailInfo);
  429. }
  430. }
  431. }
  432. OTtoTakeWorkDetailFactory.getLocalInstance(ctx).save(detailColl);
  433. if (SHRBillServerUtil.overTimeControl(ctx, billInfo.getHrOrgUnit().getId().toString()) && !isCreateTagISAuto) {
  434. try {
  435. String serviceName = "calculatePersonOTLimit";
  436. Map param = new HashMap();
  437. param.put("billId", billId);
  438. param.put("operator", "against");
  439. OSFAppUtil.callService(ctx, serviceName, (HashMap) param);
  440. } catch (Exception e) {
  441. e.printStackTrace();
  442. }
  443. }
  444. String successId = this.callOverTimeBillAgainstApproveJob(ctx, billInfo, aiReason);
  445. AtsBillSourceTypeUtil.uptBillSourceTypeWithBack(ctx, billId);
  446. DataLogsRecordUtil.processListObjectsLog(billInfo, OperActionEnum.againstApprove, ctx);
  447. return successId;
  448. }
  449. private String callOverTimeBillAgainstApproveJob(Context ctx, AtsOverTimeBillInfo billInfo, String aiReason) throws EASBizException, BOSException {
  450. AtsOverTimeBillEntryCollection entrysInfo = billInfo.getEntries();
  451. IAtsOverTimeBillEntry iAtsOverTimeBillEntry = AtsOverTimeBillEntryFactory.getRemoteInstance();
  452. CoreBaseCollection colls = new CoreBaseCollection();
  453. List<String> personIds = new ArrayList();
  454. Date minOtDate = null;
  455. Date maxOtDate = null;
  456. for (int i = 0; i < entrysInfo.size(); ++i) {
  457. AtsOverTimeBillEntryInfo entryInfo = entrysInfo.get(i);
  458. entryInfo.setCalculateState(false);
  459. entryInfo.setHolidayLimit((HolidayLimitInfo) null);
  460. entryInfo.setLastUpdateUser((UserInfo) ctx.get("UserInfo"));
  461. entryInfo.setLastUpdateTime(AtsDateUtils.dateToTimestamp(new Date()));
  462. colls.add(entryInfo);
  463. personIds.add(entryInfo.getPerson().getId().toString());
  464. if (null == minOtDate) {
  465. minOtDate = entryInfo.getOtDate();
  466. maxOtDate = entryInfo.getOtDate();
  467. } else {
  468. if (entryInfo.getOtDate().compareTo(minOtDate) < 0) {
  469. minOtDate = entryInfo.getOtDate();
  470. }
  471. if (entryInfo.getOtDate().compareTo(maxOtDate) > 0) {
  472. maxOtDate = entryInfo.getOtDate();
  473. }
  474. }
  475. }
  476. if (!colls.isEmpty()) {
  477. iAtsOverTimeBillEntry.update(colls);
  478. }
  479. String billId = billInfo.getId().toString();
  480. String sql = " update t_hr_ats_overTimeBill set fbillstate = 0,faireason=? ,fLastUpdateTime=?,fLastUpdateUserId=? where fid = ?";
  481. Object[] params = new Object[]{aiReason, new Timestamp(System.currentTimeMillis()), ctx.getCaller().toString(), billId};
  482. DbUtil.execute(ctx, sql, params);
  483. AtsOverTimeVo atsOverTimeVo = new AtsOverTimeVo();
  484. atsOverTimeVo.setMaxOtDate(maxOtDate);
  485. atsOverTimeVo.setMinOtDate(minOtDate);
  486. atsOverTimeVo.setPersonIds(personIds);
  487. atsOverTimeVo.setEntrysInfo(entrysInfo);
  488. try {
  489. ThreadPoolExecutor pool = TaskPool.getFixedInstance("updateHolidayLimit", 1, 10L);
  490. pool.submit((Callable) (new Callable<Object>() {
  491. public Object call() throws Exception {
  492. AtsOverTimeVo overTimeVo = (AtsOverTimeVo) this.getDependency();
  493. AttendCalculateParent cal = new AttendCalculateParent();
  494. String personIdsStr = AtsServerCalUtils.getPersonIdsNoQuote(overTimeVo.getPersonIds());
  495. cal.calAttendResultByAdminOrgPersonAndDate(this.ctx, overTimeVo.getMinOtDate(), overTimeVo.getMaxOtDate(), 1, (String) null, personIdsStr, 0, "", 1);
  496. AtsOverTimeBillEntryCollection entrysInfo = overTimeVo.getEntrysInfo();
  497. for (int i = 0; i < entrysInfo.size(); ++i) {
  498. Map<String, String> param = new HashMap();
  499. param.put("adminOrgUnitNum", "");
  500. param.put("personNum", entrysInfo.get(i).getPerson().getId().toString());
  501. param.put("cycleDate", AtsDateUtils.dateShortToString(entrysInfo.get(i).getOtDate()));
  502. GenerateTakeWorkLimit service = new GenerateTakeWorkLimit(this.ctx);
  503. service.generateTakeWorkLimitBackGround(this.ctx, param);
  504. }
  505. return null;
  506. }
  507. }).setDependency(atsOverTimeVo).setCtx(ctx));
  508. } catch (Exception e) {
  509. e.printStackTrace();
  510. }
  511. return billId;
  512. }
  513. /**
  514. * 反审批
  515. *
  516. * @param ctx
  517. * @param aiReason
  518. * @param billIds
  519. * @return
  520. * @throws SHRWebException
  521. * @throws BOSException
  522. * @throws EASBizException
  523. */
  524. public Map<String, Object> againstApproveAction(Context ctx, String aiReason, String billIds) throws SHRWebException, BOSException, EASBizException {
  525. List<String> atsInfoIds = new ArrayList();
  526. Map<String, Object> res = new HashMap();
  527. SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  528. aiReason = sf.format(new Date()) + "," + ctx.getUserName() + ":" + aiReason;
  529. Set<String> successIds = new HashSet();
  530. res.put("successIds", successIds);
  531. String[] ids = billIds.split(",");
  532. if (ids != null && ids.length > 0) {
  533. for (int t = 0; t < ids.length; ++t) {
  534. String billId = ids[t].trim();
  535. if (!atsInfoIds.contains(billId)) {
  536. atsInfoIds.add(billId);
  537. successIds.add(this.doAgainApprove(ctx, billId, aiReason));
  538. }
  539. }
  540. }
  541. res.put("msg", MLUtile.getRes(AtsOverTimeBillResEnum.againstApproveSuccess, ctx));
  542. return res;
  543. }
  544. }