BatchSubmitShemeBillMySubmissionEditHandlerEx.java 48 KB

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