6bc66d9b36da258b248db4c6f7d0942771e117d0.svn-base 36 KB

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