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