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