BatchSubmitShemeBillMySubmissionEditHandlerEx.java 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. package com.kingdee.shr.customer.gtiit.handler;
  2. import java.math.BigDecimal;
  3. import java.sql.SQLException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Calendar;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import com.kingdee.bos.dao.IObjectCollection;
  14. import com.kingdee.bos.dao.IObjectValue;
  15. import com.kingdee.bos.framework.DynamicObjectFactory;
  16. import com.kingdee.bos.framework.IDynamicObject;
  17. import com.kingdee.bos.metadata.data.SortType;
  18. import com.kingdee.bos.metadata.entity.*;
  19. import com.kingdee.bos.util.BOSObjectType;
  20. import com.kingdee.eas.basedata.person.IPerson;
  21. import com.kingdee.eas.basedata.person.PersonFactory;
  22. import com.kingdee.eas.basedata.person.PersonInfo;
  23. import com.kingdee.eas.framework.DataBaseInfo;
  24. import com.kingdee.eas.hr.affair.*;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.apache.log4j.Logger;
  27. import org.springframework.ui.ModelMap;
  28. import com.google.common.collect.Maps;
  29. import com.kingdee.bos.BOSException;
  30. import com.kingdee.bos.Context;
  31. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  32. import com.kingdee.eas.common.EASBizException;
  33. import com.kingdee.eas.framework.CoreBaseInfo;
  34. import com.kingdee.eas.util.app.ContextUtil;
  35. import com.kingdee.eas.util.app.DbUtil;
  36. import com.kingdee.jdbc.rowset.IRowSet;
  37. import com.kingdee.shr.base.syssetting.context.SHRContext;
  38. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  39. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  40. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  41. import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillEntryCollection;
  42. import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillEntryInfo;
  43. import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillFactory;
  44. import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillInfo;
  45. import com.kingdee.shr.compensation.app.integrate.CalSubmitSchemeFactory;
  46. import com.kingdee.shr.compensation.app.integrate.CalSubmitSchemeInfo;
  47. import com.kingdee.shr.compensation.util.columnModel.CmpColumnModels;
  48. import com.kingdee.shr.compensation.web.handler.integrate.BatchSubmitShemeBillMySubmissionEditHandler;
  49. import com.kingdee.shr.customer.gtiit.util.DateTimeUtils;
  50. /**
  51. * 扩展员工自助-我要提报表单handler
  52. *
  53. * @author xiaoxin
  54. */
  55. public class BatchSubmitShemeBillMySubmissionEditHandlerEx extends BatchSubmitShemeBillMySubmissionEditHandler {
  56. private static Logger logger = Logger.getLogger("com.kingdee.shr.customer.gtiit.handler.BatchSubmitShemeBillMySubmissionEditHandlerEx");
  57. private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  58. /**
  59. * 获取开始结束时间
  60. * 罗俊新增方法
  61. * 2025-07-10
  62. *
  63. * @param request
  64. * @param response
  65. * @param modelMap
  66. * @throws BOSException
  67. * @throws SHRWebException
  68. */
  69. public void getDateTimeAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, SHRWebException {
  70. String personId = request.getParameter("personId");
  71. String type = request.getParameter("type");
  72. String id = request.getParameter("id");
  73. String effectDate = request.getParameter("effectDate");
  74. String leffectDate = request.getParameter("leffectDate");
  75. String ptlmanagerName = request.getParameter("ptlmanagerName");
  76. String positionId = request.getParameter("positionId");
  77. String hourlywage = request.getParameter("hourlywage");
  78. Context ctx = SHRContext.getInstance().getContext();
  79. if (StringUtils.isEmpty(personId) || StringUtils.isEmpty(type)) {
  80. throw new ShrWebBizException("员工编码或任职类型不能为空!!");
  81. }
  82. //返回信息
  83. Map map = new HashMap();
  84. //员工信息
  85. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  86. IDynamicObject iDynamicObject = DynamicObjectFactory.getLocalInstance(ctx);
  87. try {
  88. PersonInfo personInfo = iPerson.getPersonInfo(new ObjectUuidPK(personId));
  89. //主要任职
  90. if (type.equals("Full")) {
  91. //EE23D375=全职或兼职
  92. DataBaseInfo ftorptInfo = (DataBaseInfo) personInfo.get("ftorpt");
  93. if (ftorptInfo == null) {
  94. throw new ShrWebBizException("请在员工信息维护全职或兼职字段!!");
  95. }
  96. IObjectValue ftorpt = iDynamicObject.getValue(BOSObjectType.create("EE23D375"), new ObjectUuidPK(ftorptInfo.getId()));
  97. //入职日期
  98. Date hireDate = personInfo.getHireDate();
  99. map.put("startDate", sdf.format(hireDate));
  100. if (ftorpt.get("number").equals("FULL")) {
  101. //全职 获取入职日期以及合同信息最新的结束日期 D8595360=合同信息
  102. //查询条件
  103. FilterInfo filterInfo = new FilterInfo();
  104. FilterItemCollection filterItems = filterInfo.getFilterItems();
  105. filterItems.add(new FilterItemInfo("person", personId));
  106. //排序
  107. SorterItemCollection sc = new SorterItemCollection();
  108. SorterItemInfo sorterItem = new SorterItemInfo("ExpiredDate");
  109. sorterItem.setSortType(SortType.DESCEND);
  110. sc.add(sorterItem);
  111. //排序获取第一条最新的数据
  112. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, sc);
  113. IObjectCollection collection = iDynamicObject.getCollection(BOSObjectType.create("D8595360"), entityViewInfo);
  114. //结束时间
  115. Date expiredDate = null;
  116. if (collection.size() > 0) {
  117. IObjectValue pcontractinfo = collection.getObject(0);
  118. expiredDate = (Date) pcontractinfo.get("ExpiredDate");
  119. }
  120. map.put("endDate", expiredDate == null ? "" : sdf.format(expiredDate));
  121. } else if (ftorpt.get("number").equals("PART")) {
  122. //兼职 获取入职日期以及员工信息兼职类人员任职结束时间
  123. Date jobEndTime = (Date) personInfo.get("jobEndTime");
  124. map.put("endDate", jobEndTime == null ? "" : sdf.format(jobEndTime));
  125. }
  126. } else if (type.equals("Part")) {//兼职任职
  127. if (StringUtils.isEmpty(id)) {
  128. throw new ShrWebBizException("人员任职信息Id不能为空!!");
  129. }
  130. //兼职单
  131. IPluralityAddBizBillEntry iPluralityAddBizBillEntry = PluralityAddBizBillEntryFactory.getLocalInstance(ctx);
  132. FilterInfo filterInfo = new FilterInfo();
  133. FilterItemCollection filterItems = filterInfo.getFilterItems();
  134. filterItems.add(new FilterItemInfo("person.id", personId));
  135. filterItems.add(new FilterItemInfo("bizDate", DateTimeUtils.parseDate(effectDate)));
  136. filterItems.add(new FilterItemInfo("ptlmanager.name", ptlmanagerName));
  137. filterItems.add(new FilterItemInfo("position.id", positionId));
  138. filterItems.add(new FilterItemInfo("pthwage", hourlywage));
  139. filterItems.add(new FilterItemInfo("bill.billState", 3));
  140. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
  141. System.out.println("查询兼职单信息SQL:" + entityViewInfo.getFilter().toSql());
  142. logger.error("查询兼职单信息SQL:" + entityViewInfo.getFilter().toSql());
  143. PluralityAddBizBillEntryCollection pluralityAddBizBillEntryCollection = iPluralityAddBizBillEntry.getPluralityAddBizBillEntryCollection(entityViewInfo);
  144. System.out.println("pluralityAddBizBillEntryCollection:" + pluralityAddBizBillEntryCollection.size());
  145. map.put("startDate", effectDate);
  146. if (pluralityAddBizBillEntryCollection.size() > 0) {
  147. PluralityAddBizBillEntryInfo pluralityAddBizBillEntryInfo = pluralityAddBizBillEntryCollection.get(0);
  148. Date bizDate = null;
  149. //查询单据是否存在兼职终止单
  150. IPluralityDelBizBillEntry iPluralityDelBizBillEntry = PluralityDelBizBillEntryFactory.getLocalInstance(ctx);
  151. FilterInfo filterInfo2 = new FilterInfo();
  152. FilterItemCollection filterItems2 = filterInfo.getFilterItems();
  153. filterItems2.add(new FilterItemInfo("person.id", personId));
  154. filterItems2.add(new FilterItemInfo("beginDate", DateTimeUtils.parseDate(effectDate)));
  155. filterItems2.add(new FilterItemInfo("ptlmanager.name", ptlmanagerName));
  156. filterItems2.add(new FilterItemInfo("position.id", positionId));
  157. filterItems2.add(new FilterItemInfo("pthwage", hourlywage));
  158. filterItems2.add(new FilterItemInfo("bill.billState", 3));
  159. EntityViewInfo entityViewInfo2 = EntityViewInfo.getInstance(filterInfo, null, null);
  160. PluralityDelBizBillEntryCollection pluralityDelBizBillEntryCollection = iPluralityDelBizBillEntry.getPluralityDelBizBillEntryCollection(entityViewInfo2);
  161. //判断是否存在兼职终止单 存在获取兼职终止单结束日期 不存在获取兼职单结束日期
  162. if (pluralityDelBizBillEntryCollection.size() > 0) {
  163. PluralityDelBizBillEntryInfo pluralityDelBizBillEntryInfo = pluralityDelBizBillEntryCollection.get(0);
  164. bizDate = pluralityDelBizBillEntryInfo.getBizDate();
  165. } else {
  166. bizDate = pluralityAddBizBillEntryInfo.getEndDate();
  167. }
  168. map.put("endDate", sdf.format(bizDate));
  169. } else {
  170. throw new ShrWebBizException("未查询到兼职单信息!!");
  171. //map.put("endDate", leffectDate);
  172. }
  173. }
  174. } catch (Exception e) {
  175. e.printStackTrace();
  176. throw new ShrWebBizException(e);
  177. }
  178. JSONUtils.writeJson(response, map);
  179. }
  180. @Override
  181. public String getEditGridColModelAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  182. String submitSchemeId = request.getParameter("submitSchemeId");
  183. if (StringUtils.isEmpty(submitSchemeId)) {
  184. JSONUtils.writeJson(response, modelMap);
  185. return null;
  186. } else {
  187. boolean dynamicColmunRequired = this.isDynamicColmunRequired(request);
  188. Map<String, Object> params = Maps.newHashMap();
  189. params.put("datasource", Integer.valueOf(request.getParameter("datasource")));
  190. params.put("costTypeId", request.getParameter("costTypeId"));
  191. params.put("dynamicColmunRequired", dynamicColmunRequired);
  192. params.put("hrOrgUnitId", request.getParameter("hrOrgUnitId"));
  193. Context ctx = SHRContext.getInstance().getContext();
  194. CmpColumnModels cmpColumnModels = new BaseSubmitBillEntryGenerator().getEntryColumnModels(ctx, submitSchemeId, params);
  195. modelMap.put("colNames", cmpColumnModels.getColNames());
  196. modelMap.put("colModel", cmpColumnModels.getColModel());
  197. modelMap.put("defaultSortname", (Object) null);
  198. CalSubmitSchemeInfo schemeInfo;
  199. try {
  200. schemeInfo = CalSubmitSchemeFactory.getLocalInstance(ctx).getCalSubmitSchemeInfo(new ObjectUuidPK(submitSchemeId));
  201. } catch (EASBizException var11) {
  202. throw new ShrWebBizException(var11.getMessage(), var11);
  203. } catch (BOSException var12) {
  204. throw new SHRWebException(var12.getMessage(), var12);
  205. }
  206. modelMap.put("description", schemeInfo.getDescription());
  207. JSONUtils.writeJson(response, modelMap);
  208. return null;
  209. }
  210. }
  211. @Override
  212. protected void beforeSubmit(HttpServletRequest request, HttpServletResponse response, CoreBaseInfo model) throws SHRWebException {
  213. super.beforeSubmit(request, response, model);
  214. Context ctx = SHRContext.getInstance().getContext();
  215. BatchSubmitShemeBillInfo info = (BatchSubmitShemeBillInfo) model;
  216. if (StringUtils.isNotBlank(info.getString("id"))) {
  217. try {
  218. info = BatchSubmitShemeBillFactory.getLocalInstance(ctx).getBatchSubmitShemeBillInfo(new ObjectUuidPK(info.getString("id")));
  219. } catch (EASBizException e) {
  220. e.printStackTrace();
  221. } catch (BOSException e) {
  222. e.printStackTrace();
  223. }
  224. }
  225. String sql = "select cfistakecheck,CFIsCurrentDepart from T_HR_SCalSubmitScheme where fid = '" + info.getSubmitScheme().getId().toString() + "'";
  226. //是否参与校验
  227. boolean isPlanCheck = false;
  228. try {
  229. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  230. while (iRowSet.next()) {
  231. if (StringUtils.equals("1", iRowSet.getString("cfistakecheck"))) {
  232. isPlanCheck = true;
  233. }
  234. }
  235. } catch (BOSException e) {
  236. e.printStackTrace();
  237. } catch (SQLException e) {
  238. e.printStackTrace();
  239. }
  240. checkPosition(info);
  241. checkDateOverlap(info);
  242. if (isPlanCheck) {
  243. checkPositionCount(info);
  244. checkHours(info);
  245. }
  246. }
  247. /**
  248. * 校验职位不允许提交法定节假日那天
  249. *
  250. * @param info
  251. * @throws ShrWebBizException
  252. */
  253. public void checkPosition(BatchSubmitShemeBillInfo info) throws ShrWebBizException {
  254. Context ctx = SHRContext.getInstance().getContext();
  255. String billId = info.getId().toString();
  256. String sql = "select b.FNAME_L1 from T_HR_SchemeBillEntry a left join T_ORG_Position b on a.FPOSITIONID = b.FID " + "where a.FBILLID = '" + billId + "' " + "and b.FNAME_L1 = (SELECT fname_l2 FROM T_HR_SHRRSVITEM0 where fstate = '1' and FNUMBER = '1007') " + "and EXISTS (SELECT d.CFWORKMULTIPLE FROM T_HR_ATS_LegalHoliday c " + "left join T_HR_ATS_LegalHolidayItem d on c.fid = d.FGROUPID where c.FSTATE = '1' " + "and d.CFWORKMULTIPLE = '3' and d.FSTARTDATE <= a.feffectdate and d.FENDDATE >= a.feffectdate)";
  257. logger.error("查询职位对应日期是否在法定节假日SQL:" + sql);
  258. try {
  259. boolean flag = false;
  260. String positionName = "";
  261. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  262. while (rowSet.next()) {
  263. flag = true;
  264. positionName = rowSet.getString("FNAME_L1");
  265. }
  266. if (flag) {
  267. throw new ShrWebBizException("This position (" + positionName + ") does not allow submission of documents that occur on statutory holidays");
  268. }
  269. } catch (SQLException e) {
  270. e.printStackTrace();
  271. } catch (BOSException e) {
  272. e.printStackTrace();
  273. }
  274. }
  275. /**
  276. * 校验该员工本月的开始时间和结束时间有没有重叠
  277. *
  278. * @param info
  279. * @throws ShrWebBizException
  280. */
  281. public void checkDateOverlap(BatchSubmitShemeBillInfo info) throws ShrWebBizException {
  282. Context ctx = SHRContext.getInstance().getContext();
  283. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  284. BatchSubmitShemeBillEntryCollection entryColl = info.getEntry();
  285. String billId = info.getId().toString();
  286. logger.error("单据ID:" + billId);
  287. Date effectDate = entryColl.get(0).getEffectDate();
  288. Calendar calendar = Calendar.getInstance();
  289. calendar.setTime(effectDate);
  290. calendar.set(Calendar.DAY_OF_MONTH, 1);
  291. Date startDate = calendar.getTime();
  292. calendar.add(Calendar.MONTH, 1);
  293. Date endDate = calendar.getTime();
  294. String startDateStr = DateTimeUtils.dateFormat(startDate, "yyyy-MM-dd");
  295. String endDateStr = DateTimeUtils.dateFormat(endDate, "yyyy-MM-dd");
  296. boolean flag = false;
  297. String sql = "SELECT a.*,b.billNumber FROM T_HR_SchemeBillEntry a , " + "(SELECT a.fnumber billNumber,b.* FROM T_HR_SBatchSubmitShemeBill a " + "left join T_HR_SchemeBillEntry b on a.fid = b.fbillid " + "where a.FBILLSTATE in ('1','2','3') and b.FPERSONID = '" + personId + "' " + "and b.FEFFECTDATE >= '" + startDateStr + "' and b.FEFFECTDATE < '" + endDateStr + "' and a.FDATASOURCE = '1') b " + "where a.FBILLID = '" + billId + "' and a.cfstarttime < b.CFENDTIME " + "and a.cfendtime > b.CFSTARTTIME";
  298. logger.error("查询是否有时间段重叠数据SQL:" + sql);
  299. try {
  300. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  301. String billNumber = "";
  302. while (rowSet.next()) {
  303. billNumber = rowSet.getString("billNumber");
  304. flag = true;
  305. }
  306. if (flag) {
  307. throw new ShrWebBizException("The start and end times overlap with another document (" + billNumber + ")");
  308. }
  309. } catch (BOSException e1) {
  310. e1.printStackTrace();
  311. } catch (SQLException e) {
  312. e.printStackTrace();
  313. }
  314. }
  315. /**
  316. * 校验员工每月提交工时不能超过最大工时数
  317. *
  318. * @param info
  319. * @throws ShrWebBizException
  320. */
  321. public void checkHours(BatchSubmitShemeBillInfo info) throws ShrWebBizException {
  322. Context ctx = SHRContext.getInstance().getContext();
  323. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  324. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  325. BatchSubmitShemeBillEntryCollection entryColl = info.getEntry();
  326. //上月工时数
  327. BigDecimal lastHours = BigDecimal.ZERO;
  328. //当月工时数
  329. BigDecimal currentHour = BigDecimal.ZERO;
  330. Calendar calendar = Calendar.getInstance();
  331. int currentYear = calendar.get(Calendar.YEAR);
  332. int currentMonth = calendar.get(Calendar.MONTH);
  333. for (int i = 0; i < entryColl.size(); i++) {
  334. BatchSubmitShemeBillEntryInfo entryInfo = entryColl.get(i);
  335. Date effectDate = entryInfo.getEffectDate();
  336. calendar.setTime(effectDate);
  337. if (currentYear == calendar.get(Calendar.YEAR) && currentMonth == calendar.get(Calendar.MONTH)) {
  338. currentHour = currentHour.add(entryInfo.getBigDecimal("totalWorkHours"));
  339. } else {
  340. lastHours = lastHours.add(entryInfo.getBigDecimal("totalWorkHours"));
  341. }
  342. }
  343. try {
  344. BigDecimal maxHour = BigDecimal.ZERO;
  345. String paramSql = "SELECT FNUMBER,fname_l2 name FROM T_HR_SHRRSVITEM0 where fstate = '1' and FNUMBER = '1003'";
  346. IRowSet paramRow = DbUtil.executeQuery(ctx, paramSql);
  347. while (paramRow.next()) {
  348. //最大工时数
  349. if (paramRow.getString("FNUMBER").equals("1003")) {
  350. maxHour = paramRow.getObject("name") == null ? BigDecimal.ZERO : paramRow.getBigDecimal("name");
  351. }
  352. }
  353. if (lastHours.compareTo(BigDecimal.ZERO) != 0) {
  354. calendar = Calendar.getInstance();
  355. calendar.set(Calendar.DAY_OF_MONTH, 1);
  356. Date endDate = calendar.getTime();
  357. calendar.add(Calendar.MONTH, -1);
  358. Date startDate = calendar.getTime();
  359. BigDecimal totalHour = BigDecimal.ZERO;
  360. String hourSql = "SELECT sum(b.cftotalworkhours) as totalHour FROM T_HR_SBatchSubmitShemeBill a left join T_HR_SchemeBillEntry b on a.fid=b.fbillid where b.fpersonid='" + personId + "' and b.feffectdate>='" + sdf.format(startDate) + "' and b.feffectdate<'" + sdf.format(endDate) + "' and a.FBILLSTATE in ('1','2','3')";
  361. IRowSet iRowSet = DbUtil.executeQuery(ctx, hourSql);
  362. while (iRowSet.next()) {
  363. totalHour = iRowSet.getObject("totalHour") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("totalHour");
  364. }
  365. totalHour = totalHour.add(lastHours);
  366. BigDecimal adjustHour = BigDecimal.ZERO;
  367. //获取调整工时数
  368. String adjustSql = "/*dialect*/SELECT cfadjustinghours FROM CT_MP_Ptworkinghours where fpersonid='" + personId + "' and DATE_TRUNC('month', cfeffectivedate)<='" + sdf.format(startDate) + "' and cfenddate>='" + sdf.format(startDate) + "' order by FLastUpdateTime desc limit 1";
  369. logger.error("获取调整工时SQL:" + adjustSql);
  370. IRowSet adjustRow = DbUtil.executeQuery(ctx, adjustSql);
  371. while (adjustRow.next()) {
  372. adjustHour = adjustRow.getObject("cfadjustinghours") == null ? BigDecimal.ZERO : adjustRow.getBigDecimal("cfadjustinghours");
  373. }
  374. if (totalHour.compareTo(maxHour.add(adjustHour)) > 0) {
  375. throw new ShrWebBizException("The total reported working hours for the previous month cannot exceed the maximum number of working hours");
  376. }
  377. }
  378. if (currentHour.compareTo(BigDecimal.ZERO) != 0) {
  379. calendar = Calendar.getInstance();
  380. calendar.set(Calendar.DAY_OF_MONTH, 1);
  381. Date startDate = calendar.getTime();
  382. calendar.add(Calendar.MONTH, 1);
  383. Date endDate = calendar.getTime();
  384. BigDecimal totalHour = BigDecimal.ZERO;
  385. String hourSql = "SELECT sum(b.cftotalworkhours) as totalHour FROM T_HR_SBatchSubmitShemeBill a left join T_HR_SchemeBillEntry b on a.fid=b.fbillid where b.fpersonid='" + personId + "' and b.feffectdate>='" + sdf.format(startDate) + "' and b.feffectdate<'" + sdf.format(endDate) + "' and a.FBILLSTATE in ('1','2','3')";
  386. IRowSet iRowSet = DbUtil.executeQuery(ctx, hourSql);
  387. while (iRowSet.next()) {
  388. totalHour = iRowSet.getObject("totalHour") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("totalHour");
  389. }
  390. totalHour = totalHour.add(lastHours);
  391. BigDecimal adjustHour = BigDecimal.ZERO;
  392. //获取调整工时数
  393. String adjustSql = "/*dialect*/SELECT cfadjustinghours FROM CT_MP_Ptworkinghours where fpersonid='" + personId + "' and DATE_TRUNC('month', cfeffectivedate)<='" + sdf.format(startDate) + "' and cfenddate>='" + sdf.format(startDate) + "' order by FLastUpdateTime desc limit 1";
  394. logger.error("获取调整工时SQL:" + adjustSql);
  395. IRowSet adjustRow = DbUtil.executeQuery(ctx, adjustSql);
  396. while (adjustRow.next()) {
  397. adjustHour = adjustRow.getObject("cfadjustinghours") == null ? BigDecimal.ZERO : adjustRow.getBigDecimal("cfadjustinghours");
  398. }
  399. if (totalHour.compareTo(maxHour.add(adjustHour)) > 0) {
  400. throw new ShrWebBizException("The total reported working hours for the current month cannot exceed the maximum number of working hours");
  401. }
  402. }
  403. } catch (BOSException e) {
  404. e.printStackTrace();
  405. } catch (SQLException e) {
  406. e.printStackTrace();
  407. }
  408. }
  409. /**
  410. * 校验员工该职位每个月只能提交一次
  411. *
  412. * @param info
  413. * @throws ShrWebBizException
  414. */
  415. public void checkPositionCount(BatchSubmitShemeBillInfo info) throws ShrWebBizException {
  416. Context ctx = SHRContext.getInstance().getContext();
  417. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  418. BatchSubmitShemeBillEntryCollection entryColl = info.getEntry();
  419. //是否有上月发生日期
  420. boolean isLastMonth = false;
  421. //是否有当月发生日期
  422. boolean isCurrentMonth = false;
  423. String positionId = "";
  424. String superiorId = "";
  425. Calendar calendar = Calendar.getInstance();
  426. int currentYear = calendar.get(Calendar.YEAR);
  427. int currentMonth = calendar.get(Calendar.MONTH);
  428. for (int i = 0; i < entryColl.size(); i++) {
  429. BatchSubmitShemeBillEntryInfo entryInfo = entryColl.get(i);
  430. Date effectDate = entryInfo.getEffectDate();
  431. calendar.setTime(effectDate);
  432. if (currentYear == calendar.get(Calendar.YEAR) && currentMonth == calendar.get(Calendar.MONTH)) {
  433. isCurrentMonth = true;
  434. } else {
  435. isLastMonth = true;
  436. }
  437. positionId = entryInfo.getPosition().getId().toString();
  438. superiorId = entryInfo.getString("superiorId");
  439. }
  440. logger.error("职位ID:" + positionId + ", 直接上级ID:" + superiorId);
  441. try {
  442. if (isLastMonth) {
  443. calendar = Calendar.getInstance();
  444. calendar.set(Calendar.DAY_OF_MONTH, 1);
  445. String endDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  446. calendar.add(Calendar.MONTH, -1);
  447. String startDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  448. int count = 0;
  449. String sql = "select count(1) count from T_HR_SBatchSubmitShemeBill a left join T_HR_SchemeBillEntry b on a.fid=b.fbillid where b.FPERSONID = '" + personId + "' and b.FPOSITIONID = '" + positionId + "' and b.CFSuperiorID = '" + superiorId + "' and a.fbillstate in ('1','2','3') and a.fdatasource = '1' and b.FEFFECTDATE >= '" + startDate + "' and b.FEFFECTDATE < '" + endDate + "'";
  450. logger.error("查询员工该职位当月提交次数SQL:" + sql);
  451. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  452. while (iRowSet.next()) {
  453. count = iRowSet.getInt("count");
  454. }
  455. logger.error("员工该职位当月提交次数:" + count);
  456. if (count > 0) {
  457. throw new ShrWebBizException("The employee submits the position once within a month");
  458. }
  459. }
  460. if (isCurrentMonth) {
  461. calendar = Calendar.getInstance();
  462. calendar.set(Calendar.DAY_OF_MONTH, 1);
  463. String startDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  464. calendar.add(Calendar.MONTH, 1);
  465. String endDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  466. int count = 0;
  467. String sql = "select count(1) count from T_HR_SBatchSubmitShemeBill a left join T_HR_SchemeBillEntry b on a.fid=b.fbillid where b.FPERSONID = '" + personId + "' and b.FPOSITIONID = '" + positionId + "' and b.CFSuperiorID = '" + superiorId + "' and a.fbillstate in ('1','2','3') and a.fdatasource = '1' and b.FEFFECTDATE >= '" + startDate + "' and b.FEFFECTDATE < '" + endDate + "'";
  468. logger.error("查询员工该职位当月提交次数SQL:" + sql);
  469. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  470. while (iRowSet.next()) {
  471. count = iRowSet.getInt("count");
  472. }
  473. logger.error("员工该职位当月提交次数:" + count);
  474. if (count > 0) {
  475. throw new ShrWebBizException("The employee submits the position once within a month");
  476. }
  477. }
  478. } catch (BOSException e) {
  479. e.printStackTrace();
  480. } catch (SQLException e) {
  481. e.printStackTrace();
  482. }
  483. }
  484. /**
  485. * 校验XX号之后不允许提交
  486. *
  487. * @param request
  488. * @param response
  489. * @param modelMap
  490. * @throws SHRWebException
  491. */
  492. public void checkSumbitDateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  493. Context ctx = SHRContext.getInstance().getContext();
  494. int day = 0;
  495. Calendar calendar = Calendar.getInstance();
  496. int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
  497. String resultMessage = "";
  498. try {
  499. String paramSql = "SELECT FNUMBER,fname_l2 name FROM T_HR_SHRRSVITEM0 where fstate = '1' and FNUMBER = '1004'";
  500. IRowSet paramRow = DbUtil.executeQuery(ctx, paramSql);
  501. while (paramRow.next()) {
  502. if (paramRow.getString("FNUMBER").equals("1004")) {
  503. day = paramRow.getObject("name") == null ? 0 : paramRow.getInt("name");
  504. }
  505. }
  506. if (day != 0 && thisDay > day) {
  507. resultMessage = "It is not allowed to submit the previous month's work hours after the " + day + "th of each month";
  508. }
  509. } catch (BOSException e) {
  510. e.printStackTrace();
  511. } catch (SQLException e) {
  512. e.printStackTrace();
  513. }
  514. modelMap.put("resultMessage", resultMessage);
  515. JSONUtils.writeJson(response, modelMap);
  516. }
  517. /**
  518. * 根据人员id获取它的直属上级id和时薪
  519. *
  520. * @param request
  521. * @param response
  522. * @param modelMap
  523. * @return
  524. * @throws SHRWebException
  525. */
  526. public String getPersonCareerDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  527. Context ctx = SHRContext.getInstance().getContext();
  528. String personId = request.getParameter("personId");
  529. String parentId = "";
  530. String workHour = "";
  531. String sql = "select re.FPERSONID,rl.cflinemanagernameI linemanagername,rl.cfhourlywage from (SELECT FPERSONID,max(FEFFDT) as maxDate FROM T_HR_EmpOrgRelation where fassignType = '1' group by FPERSONID) as re left join T_HR_EmpOrgRelation rl on re.fpersonid = rl.fpersonid and re.maxDate = rl.feffdt and rl.fassignType = '1' where re.fpersonid='" + personId + "'";
  532. try {
  533. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  534. while (iRowSet.next()) {
  535. parentId = iRowSet.getString("linemanagername");
  536. workHour = iRowSet.getString("cfhourlywage");
  537. }
  538. } catch (BOSException e) {
  539. e.printStackTrace();
  540. } catch (SQLException e) {
  541. e.printStackTrace();
  542. }
  543. modelMap.put("parentId", parentId);
  544. modelMap.put("workHour", workHour);
  545. JSONUtils.writeJson(response, modelMap);
  546. return null;
  547. }
  548. /**
  549. * 获取当前员工的最新入职日期
  550. *
  551. * @param request
  552. * @param response
  553. * @param modelMap
  554. * @return
  555. * @throws SHRWebException
  556. */
  557. public String getInductionDateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  558. Context ctx = SHRContext.getInstance().getContext();
  559. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  560. String sql = "select b.fenterdate from (SELECT FPERSONID,max(FEFFDT) as maxDate FROM T_HR_EmpLaborRelationHis group by fpersonid) a left join T_HR_EmpLaborRelationHis b on a.fpersonid=b.fpersonid and a.maxdate=b.FEFFDT where a.fpersonid='" + personId + "'";
  561. String enterDate = "";
  562. try {
  563. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  564. while (iRowSet.next()) {
  565. enterDate = iRowSet.getString("fenterdate");
  566. }
  567. } catch (BOSException e) {
  568. e.printStackTrace();
  569. } catch (SQLException e) {
  570. e.printStackTrace();
  571. }
  572. modelMap.put("enterDate", enterDate);
  573. JSONUtils.writeJson(response, modelMap);
  574. return null;
  575. }
  576. /**
  577. * 查询人员对应职位的最新的合同开始和结束日期
  578. *
  579. * @param request
  580. * @param response
  581. * @param modelMap
  582. * @throws SHRWebException
  583. */
  584. public void getContractDateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  585. //职位id
  586. String positionId = request.getParameter("positionId");
  587. Context ctx = SHRContext.getInstance().getContext();
  588. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  589. // String sql = "SELECT b.cfcommencingdate,b.cfexpireddate FROM (SELECT max(cfcommencingdate) maxdate,fpersonid,cfpositionid FROM CT_MP_Pcontractinfo group by fpersonid,cfpositionid) a left join CT_MP_Pcontractinfo b on a.maxdate=b.cfcommencingdate and a.fpersonid=b.fpersonid and a.cfpositionid=b.cfpositionid where a.fpersonid='"+personId+"' and a.cfpositionid='"+positionId+"' and b.cftype!='1'";
  590. String sql = "SELECT cfcommencingdate,cfexpireddate,cftype FROM CT_MP_Pcontractinfo where fpersonid='" + personId + "' and cfpositionid='" + positionId + "' order by cfcommencingdate asc";
  591. logger.error("查询合同信息SQL:" + sql);
  592. Date beginContractDate = null;
  593. Date endContractDate = null;
  594. String contractType = "";
  595. try {
  596. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  597. /*while(iRowSet.next()) {
  598. //合同开始日期
  599. beginContractDate = iRowSet.getDate("cfcommencingdate");
  600. //合同结束日期
  601. endContractDate = iRowSet.getDate("cfexpireddate");
  602. }*/
  603. List<Map<String, Object>> list = new ArrayList<>();
  604. while (iRowSet.next()) {
  605. //合同开始日期
  606. Date beginDate = iRowSet.getDate("cfcommencingdate");
  607. //合同结束日期
  608. Date endDate = iRowSet.getDate("cfexpireddate");
  609. //合同类型
  610. String type = iRowSet.getString("cftype");
  611. Map<String, Object> map = new HashMap<String, Object>();
  612. map.put("beginDate", beginDate);
  613. map.put("endDate", endDate);
  614. map.put("type", type);
  615. list.add(map);
  616. }
  617. for (int i = 0; i < list.size(); i++) {
  618. Map<String, Object> map = list.get(i);
  619. Date beginDate = (Date) map.get("beginDate");
  620. Date endDate = (Date) map.get("endDate");
  621. String type = (String) map.get("type");
  622. //获取连续时间段的开始日期和结束日期,如果中间合同类型发生变动或者日期中断,则重新计算
  623. if (StringUtils.equals(contractType, type)) {
  624. Calendar beginCalendar = Calendar.getInstance();
  625. Calendar endCalendar = Calendar.getInstance();
  626. beginCalendar.setTime(beginDate);
  627. beginCalendar.add(Calendar.DAY_OF_MONTH, -1);
  628. endCalendar.setTime(endContractDate);
  629. boolean isYear = beginCalendar.get(Calendar.YEAR) == endCalendar.get(Calendar.YEAR);
  630. boolean isMonth = beginCalendar.get(Calendar.MONTH) == endCalendar.get(Calendar.MONTH);
  631. boolean isDay = beginCalendar.get(Calendar.DAY_OF_MONTH) == endCalendar.get(Calendar.DAY_OF_MONTH);
  632. boolean flag = isYear && isMonth && isDay;
  633. if (flag) {
  634. endContractDate = endDate;
  635. } else {
  636. beginContractDate = beginDate;
  637. endContractDate = endDate;
  638. }
  639. } else {
  640. beginContractDate = beginDate;
  641. endContractDate = endDate;
  642. contractType = type;
  643. }
  644. }
  645. } catch (SQLException e) {
  646. e.printStackTrace();
  647. } catch (BOSException e) {
  648. e.printStackTrace();
  649. }
  650. modelMap.put("beginContractDate", beginContractDate);
  651. modelMap.put("endContractDate", endContractDate);
  652. JSONUtils.writeJson(response, modelMap);
  653. }
  654. /**
  655. * 校验月提交总工时不能大于最大工时(废弃)
  656. *
  657. * @param request
  658. * @param response
  659. * @param modelMap
  660. * @return
  661. * @throws SHRWebException
  662. */
  663. public String checkEscalationDateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  664. Context ctx = SHRContext.getInstance().getContext();
  665. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  666. BigDecimal hours = new BigDecimal(request.getParameter("hours"));
  667. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  668. Calendar calendar = Calendar.getInstance();
  669. int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
  670. calendar.set(Calendar.DAY_OF_MONTH, 1);
  671. Date endDate = calendar.getTime();
  672. calendar.add(Calendar.MONTH, -1);
  673. Date stratDate = calendar.getTime();
  674. try {
  675. BigDecimal maxHour = BigDecimal.ZERO;
  676. int day = 0;
  677. String paramSql = "SELECT FNUMBER,fname_l2 name FROM T_HR_SHRRSVITEM0 where fstate = '1' and (FNUMBER = '1003' or FNUMBER = '1004')";
  678. IRowSet paramRow = DbUtil.executeQuery(ctx, paramSql);
  679. while (paramRow.next()) {
  680. //最大工时数
  681. if (paramRow.getString("FNUMBER").equals("1003")) {
  682. maxHour = paramRow.getObject("name") == null ? BigDecimal.ZERO : paramRow.getBigDecimal("name");
  683. }
  684. if (paramRow.getString("FNUMBER").equals("1004")) {
  685. day = paramRow.getObject("name") == null ? 0 : paramRow.getInt("name");
  686. }
  687. }
  688. //校验XX号之后不允许提交
  689. if (thisDay > day) {
  690. modelMap.put("resultMessage", "It is not allowed to submit the previous month's work hours after the " + day + "th of each month");
  691. JSONUtils.writeJson(response, modelMap);
  692. return null;
  693. }
  694. BigDecimal totalHour = BigDecimal.ZERO;
  695. String hourSql = "SELECT sum(b.cftotalworkhours) as totalHour FROM T_HR_SBatchSubmitShemeBill a left join T_HR_SchemeBillEntry b on a.fid=b.fbillid where b.fpersonid='" + personId + "' and b.feffectdate>='" + sdf.format(stratDate) + "' and b.feffectdate<'" + sdf.format(endDate) + "' and a.FBILLSTATE in ('1','2','3')";
  696. IRowSet iRowSet = DbUtil.executeQuery(ctx, hourSql);
  697. while (iRowSet.next()) {
  698. totalHour = iRowSet.getObject("totalHour") == null ? BigDecimal.ZERO : iRowSet.getBigDecimal("totalHour");
  699. }
  700. totalHour = totalHour.add(hours);
  701. BigDecimal adjustHour = BigDecimal.ZERO;
  702. //获取调整工时数
  703. String adjustSql = "SELECT cfadjustinghours FROM CT_MP_Ptworkinghours where fpersonid='" + personId + "' and cfeffectivedate>='" + sdf.format(stratDate) + "' and cfeffectivedate<'" + sdf.format(endDate) + "'";
  704. IRowSet adjustRow = DbUtil.executeQuery(ctx, adjustSql);
  705. while (adjustRow.next()) {
  706. adjustHour = adjustRow.getObject("cfadjustinghours") == null ? BigDecimal.ZERO : adjustRow.getBigDecimal("cfadjustinghours");
  707. }
  708. if (totalHour.compareTo(maxHour.add(adjustHour)) > 0) {
  709. modelMap.put("resultMessage", "The total working hours in a month cannot exceed the maximum number of hours");
  710. JSONUtils.writeJson(response, modelMap);
  711. }
  712. } catch (BOSException e) {
  713. e.printStackTrace();
  714. } catch (SQLException e) {
  715. e.printStackTrace();
  716. }
  717. return null;
  718. }
  719. /**
  720. * 汇总分录的工时和金额到单头
  721. *
  722. * @param request
  723. * @param response
  724. * @param modelMap
  725. * @throws SHRWebException
  726. */
  727. public void countHourAmountAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  728. String billId = request.getParameter("billId");
  729. if (StringUtils.isEmpty(billId)) {
  730. return;
  731. }
  732. Context ctx = SHRContext.getInstance().getContext();
  733. try {
  734. BatchSubmitShemeBillInfo batchSubmitShemeBillInfo = BatchSubmitShemeBillFactory.getLocalInstance(ctx).getBatchSubmitShemeBillInfo(new ObjectUuidPK(billId));
  735. BatchSubmitShemeBillEntryCollection entryColl = batchSubmitShemeBillInfo.getEntry();
  736. BigDecimal sumHours = BigDecimal.ZERO;
  737. BigDecimal sumAmount = BigDecimal.ZERO;
  738. for (int i = 0; i < entryColl.size(); i++) {
  739. BatchSubmitShemeBillEntryInfo entryInfo = entryColl.get(i);
  740. BigDecimal hour = entryInfo.getBigDecimal("totalWorkHours") == null ? BigDecimal.ZERO : entryInfo.getBigDecimal("totalWorkHours");
  741. BigDecimal amount = entryInfo.getBigDecimal("totalAmount") == null ? BigDecimal.ZERO : entryInfo.getBigDecimal("totalAmount");
  742. sumHours = sumHours.add(hour);
  743. sumAmount = sumAmount.add(amount);
  744. }
  745. batchSubmitShemeBillInfo.put("totalWorkHours", sumHours);
  746. batchSubmitShemeBillInfo.put("totalAmount", sumAmount);
  747. BatchSubmitShemeBillFactory.getLocalInstance(ctx).save(batchSubmitShemeBillInfo);
  748. } catch (EASBizException e) {
  749. e.printStackTrace();
  750. } catch (BOSException e) {
  751. e.printStackTrace();
  752. }
  753. }
  754. /**
  755. * 根据提报日期判断法定节假日和休息日
  756. *
  757. * @param request
  758. * @param response
  759. * @param modelMap
  760. * @throws SHRWebException
  761. */
  762. public void workMultipleAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  763. Context ctx = SHRContext.getInstance().getContext();
  764. String otDate = request.getParameter("otDate");
  765. logger.error("提报日期:" + otDate);
  766. Date parseDate = DateTimeUtils.parseDate(otDate, "yyyy-MM-dd");
  767. otDate = DateTimeUtils.dateFormat(parseDate, "yyyy-MM-dd");
  768. String sql = "SELECT b.CFWORKMULTIPLE FROM T_HR_ATS_LegalHoliday a left join T_HR_ATS_LegalHolidayItem b on a.fid = b.FGROUPID where a.FSTATE = '1' and b.FSTARTDATE <= '" + otDate + "' and b.FENDDATE >= '" + otDate + "'";
  769. logger.error("查询加班类型SQL:" + sql);
  770. Map<String, String> returnMap = new HashMap<String, String>();
  771. try {
  772. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  773. boolean flag = false;
  774. while (iRowSet.next()) {
  775. if (StringUtils.equals(iRowSet.getString("CFWORKMULTIPLE"), "3")) {
  776. //法定节假日加班
  777. flag = true;
  778. }
  779. }
  780. if (flag) {
  781. returnMap.put("returnType", "0");
  782. } else {
  783. Calendar calendar = Calendar.getInstance();
  784. calendar.setTime(parseDate);
  785. int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
  786. if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
  787. //休息日加班
  788. returnMap.put("returnType", "1");
  789. }
  790. }
  791. } catch (BOSException e) {
  792. e.printStackTrace();
  793. } catch (SQLException throwables) {
  794. throwables.printStackTrace();
  795. }
  796. JSONUtils.writeJson(response, returnMap);
  797. }
  798. /**
  799. * 根据人员档案获取当月是否离职或兼职失效
  800. *
  801. * @param request
  802. * @param response
  803. * @param modelMap
  804. * @throws SHRWebException
  805. */
  806. public void checkDepartDateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  807. Context ctx = SHRContext.getInstance().getContext();
  808. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  809. String cmpOrgRelationId = request.getParameter("cmpOrgRelationId");
  810. Calendar calendar = Calendar.getInstance();
  811. int currentYear = calendar.get(Calendar.YEAR);
  812. int currentMonth = calendar.get(Calendar.MONTH) + 1;
  813. boolean flag = false;
  814. String cmpSql = "select b.fassigntype,b.fpositionid from T_HR_SCmpEmpORelation a left join T_HR_EmpOrgRelation b on a.FEMPORGRELATIONID = b.fid where a.fid ='" + cmpOrgRelationId + "'";
  815. logger.error("查询员工档案信息SQL:" + cmpSql);
  816. try {
  817. IRowSet iRowSet = DbUtil.executeQuery(ctx, cmpSql);
  818. //任职类型
  819. String assignType = "";
  820. //职位id
  821. String positionId = "";
  822. while (iRowSet.next()) {
  823. assignType = iRowSet.getString("fassigntype");
  824. positionId = iRowSet.getString("fpositionid");
  825. }
  826. //主要任职时
  827. if (StringUtils.equals(assignType, "1")) {
  828. String resignSql = "select year(b.FBIZDATE) year,month(b.FBIZDATE) month from T_HR_ResignBizBill a left join T_HR_ResignBizBillentry b on a.fid=b.fbillid where b.FPERSONID ='" + personId + "' and a.FBILLSTATE = '3' order by b.FBIZDATE desc";
  829. logger.error("查询员工离职单SQL:" + resignSql);
  830. IRowSet resignRow = DbUtil.executeQuery(ctx, resignSql);
  831. int resignYear = 0;
  832. int resignMonth = 0;
  833. if (resignRow.next()) {
  834. resignYear = resignRow.getInt("year");
  835. resignMonth = resignRow.getInt("month");
  836. }
  837. if (currentYear == resignYear && currentMonth == resignMonth) {
  838. flag = true;
  839. }
  840. } else {
  841. String empSql = "select top 1 year(fleffdt) year,month(fleffdt) month from T_HR_EmpOrgRelation where fpositionid = '" + positionId + "' and fpersonid='" + personId + "' order by feffdt desc";
  842. logger.error("查询员工兼职SQL:" + empSql);
  843. int leffdtYear = 0;
  844. int leffdtMonth = 0;
  845. IRowSet empRow = DbUtil.executeQuery(ctx, empSql);
  846. if (empRow.next()) {
  847. leffdtYear = empRow.getInt("year");
  848. leffdtMonth = empRow.getInt("month");
  849. }
  850. if (currentYear == leffdtYear && currentMonth == leffdtMonth) {
  851. flag = true;
  852. }
  853. }
  854. } catch (BOSException e) {
  855. e.printStackTrace();
  856. } catch (SQLException e) {
  857. e.printStackTrace();
  858. }
  859. modelMap.put("flag", flag);
  860. JSONUtils.writeJson(response, modelMap);
  861. }
  862. /**
  863. * 员工同一职位一个月内只能提交一次
  864. *
  865. * @param request
  866. * @param response
  867. * @param modelMap
  868. * @throws SHRWebException
  869. */
  870. public void checkSubmitCountAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  871. Context ctx = SHRContext.getInstance().getContext();
  872. String positionId = request.getParameter("positionId");
  873. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  874. Calendar calendar = Calendar.getInstance();
  875. calendar.set(Calendar.DAY_OF_MONTH, 1);
  876. String startDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  877. calendar.add(Calendar.MONTH, 1);
  878. String endDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  879. int count = 0;
  880. String sql = "SELECT count(1) count FROM T_HR_SBatchSubmitShemeBill where fid in (select distinct a.fid from T_HR_SBatchSubmitShemeBill a left join T_HR_SchemeBillEntry b on a.fid=b.fbillid where a.FPROPOSERID = '" + personId + "' and b.FPOSITIONID = '" + positionId + "' and a.fbillstate in ('1','2','3') and a.fdatasource = '1' and a.FSUBMITTIME >= '" + startDate + "' and a.FSUBMITTIME < '" + endDate + "')";
  881. logger.error("查询员工该职位当月提交次数SQL:" + sql);
  882. try {
  883. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  884. while (iRowSet.next()) {
  885. count = iRowSet.getInt("count");
  886. }
  887. logger.error("员工该职位当月提交次数:" + count);
  888. } catch (BOSException e) {
  889. e.printStackTrace();
  890. } catch (SQLException e) {
  891. e.printStackTrace();
  892. }
  893. modelMap.put("count", count);
  894. JSONUtils.writeJson(response, modelMap);
  895. }
  896. /**
  897. * 判断是否参与校验
  898. *
  899. * @param request
  900. * @param response
  901. * @param modelMap
  902. * @throws SHRWebException
  903. */
  904. public void isTakeCheckAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
  905. Context ctx = SHRContext.getInstance().getContext();
  906. //提报方案ID
  907. String calSchemeId = request.getParameter("calSchemeId");
  908. logger.error("提报方案ID:" + calSchemeId);
  909. //是否参与校验
  910. boolean isPlanCheck = false;
  911. //当月离职处理
  912. boolean isCurrentDepart = false;
  913. String sql = "select cfistakecheck,CFIsCurrentDepart from T_HR_SCalSubmitScheme where fid = '" + calSchemeId + "'";
  914. logger.error("查询提报方案SQL:" + sql);
  915. try {
  916. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  917. while (iRowSet.next()) {
  918. if (StringUtils.equals("1", iRowSet.getString("cfistakecheck"))) {
  919. isPlanCheck = true;
  920. }
  921. if (StringUtils.equals("1", iRowSet.getString("CFIsCurrentDepart"))) {
  922. isCurrentDepart = true;
  923. }
  924. }
  925. } catch (BOSException e) {
  926. e.printStackTrace();
  927. } catch (SQLException e) {
  928. e.printStackTrace();
  929. }
  930. modelMap.put("isPlanCheck", isPlanCheck);
  931. modelMap.put("isCurrentDepart", isCurrentDepart);
  932. JSONUtils.writeJson(response, modelMap);
  933. }
  934. }