d3d6db175e572418b246419f7037fb39b405c8eb.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package com.kingdee.shr.compensation.web.handler.integrate;
  2. import java.sql.SQLException;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Calendar;
  7. import java.util.Date;
  8. import java.util.HashSet;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.Set;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.apache.log4j.Logger;
  14. import com.kingdee.bos.BOSException;
  15. import com.kingdee.bos.Context;
  16. import com.kingdee.customer.util.handler.ConfigurationHandler;
  17. import com.kingdee.eas.basedata.person.PersonInfo;
  18. import com.kingdee.eas.util.app.ContextUtil;
  19. import com.kingdee.eas.util.app.DbUtil;
  20. import com.kingdee.jdbc.rowset.IRowSet;
  21. import com.kingdee.shr.base.syssetting.context.SHRContext;
  22. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  23. import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillEntryCollection;
  24. import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillEntryInfo;
  25. import com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillInfo;
  26. import com.kingdee.shr.customer.gtiit.util.DateTimeUtils;
  27. public class BatchSubmitSchemeUtils {
  28. private static Logger logger =
  29. Logger.getLogger("com.kingdee.shr.compensation.web.handler.integrate.BatchSubmitSchemeUtils");
  30. /**
  31. * 校验只能提交发生日期和提报日期在一个月内的单据
  32. * @param info
  33. * @throws ShrWebBizException
  34. */
  35. public static void checkSubmitDate(BatchSubmitShemeBillInfo info) throws ShrWebBizException{
  36. Calendar calendar = Calendar.getInstance();
  37. //提报日期
  38. Date applyDate = info.getApplyDate();
  39. calendar.setTime(applyDate);
  40. int thisYear = calendar.get(Calendar.YEAR);
  41. int thisMonth = calendar.get(Calendar.MONTH);
  42. BatchSubmitShemeBillEntryCollection entryColl = info.getEntry();
  43. for(int i=0;i<entryColl.size();i++) {
  44. BatchSubmitShemeBillEntryInfo entryInfo = entryColl.get(i);
  45. Date effectDate = entryInfo.getEffectDate();
  46. calendar.setTime(effectDate);
  47. int effectYear = calendar.get(Calendar.YEAR);
  48. int effectMonth = calendar.get(Calendar.MONTH);
  49. if(thisYear != effectYear || thisMonth != effectMonth) {
  50. throw new ShrWebBizException("The occurrence date of the entry should be consistent with the reporting date");
  51. }
  52. }
  53. }
  54. /**
  55. * 校验调整后的发生日期是否在所选的发薪任职日期范围内
  56. * @param info
  57. * @throws ShrWebBizException
  58. */
  59. public static void checkSubmitAdjust(BatchSubmitShemeBillInfo info) throws ShrWebBizException{
  60. Context ctx = SHRContext.getInstance().getContext();
  61. String sql = "select top 1 * from T_HR_SHRRsvItem0 where fnumber = '1005' and FState = '1'";
  62. logger.error("获取调整月份SQL:"+sql);
  63. //调整月份
  64. int adjustMonth = 0;
  65. try {
  66. IRowSet rs = DbUtil.executeQuery(ctx, sql);
  67. while(rs.next()) {
  68. adjustMonth = rs.getInt("FName_l2");
  69. }
  70. Date applyDate = info.getApplyDate();
  71. Calendar calendar = Calendar.getInstance();
  72. calendar.setTime(applyDate);
  73. calendar.add(Calendar.MONTH, adjustMonth);
  74. calendar.set(Calendar.DAY_OF_MONTH, 1);
  75. String adjustDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  76. BatchSubmitShemeBillEntryCollection entryColl = info.getEntry();
  77. List<String> personIdList = new ArrayList<String>();
  78. List<String> cmpEmpOrgIdList = new ArrayList<String>();
  79. for(int i=0;i<entryColl.size();i++) {
  80. BatchSubmitShemeBillEntryInfo entryInfo = entryColl.get(i);
  81. personIdList.add(entryInfo.getPerson().getId().toString());
  82. cmpEmpOrgIdList.add(entryInfo.getCmpEmpORelation().getId().toString());
  83. }
  84. StringBuffer strBuffer = new StringBuffer();
  85. for (int i = 0; i < cmpEmpOrgIdList.size(); i++) {
  86. strBuffer.append("'"+cmpEmpOrgIdList.get(i)+"'");
  87. if (i != cmpEmpOrgIdList.size() - 1) {
  88. strBuffer.append(", ");
  89. }
  90. }
  91. String empOrgSql = "/*dialect*/SELECT c.fnumber,c.fid FROM T_HR_SCmpEmpORelation a "
  92. + "left join T_HR_EmpOrgRelation b on a.femporgrelationid = b.fid "
  93. + "left join T_BD_Person c on a.FPERSONID = c.fid "
  94. + "where b.feffdt <= '"+adjustDate+"' and b.fleffdt >= '"+adjustDate+"' "
  95. + "and a.fid in ("+strBuffer.toString()+")";
  96. logger.error("获取员工发薪任职日期SQL:"+empOrgSql);
  97. IRowSet empRowSet = DbUtil.executeQuery(ctx, empOrgSql);
  98. List<String> empPerIdList = new ArrayList<String>();
  99. while(empRowSet.next()) {
  100. empPerIdList.add(empRowSet.getString("fid"));
  101. }
  102. StringBuffer personIdBuffer = new StringBuffer();
  103. for(String personId:personIdList) {
  104. if(!empPerIdList.contains(personId)) {
  105. personIdBuffer.append("'"+personId+"',");
  106. }
  107. }
  108. if(personIdBuffer.length()>0) {
  109. personIdBuffer = personIdBuffer.deleteCharAt(personIdBuffer.length()-1);
  110. String personSql = "select fnumber from T_BD_Person where fid in ("+personIdBuffer+")";
  111. IRowSet personRowSet = DbUtil.executeQuery(ctx, personSql);
  112. StringBuffer numberBuffer = new StringBuffer();
  113. while(personRowSet.next()) {
  114. numberBuffer.append("'"+personRowSet.getString("fnumber")+"',");
  115. }
  116. numberBuffer = numberBuffer.deleteCharAt(numberBuffer.length()-1);
  117. throw new ShrWebBizException("The following employees: ("+numberBuffer.toString()+") The adjusted occurrence date is not within the range of salary and employment dates");
  118. }
  119. } catch (BOSException e) {
  120. e.printStackTrace();
  121. } catch (SQLException e) {
  122. e.printStackTrace();
  123. }
  124. }
  125. /**
  126. * 校验员工+方案+发生日期不能重复
  127. * @param info
  128. * @throws ShrWebBizException
  129. */
  130. public static void checkSubmitRepeat(BatchSubmitShemeBillInfo info) throws ShrWebBizException{
  131. Context ctx = SHRContext.getInstance().getContext();
  132. BatchSubmitShemeBillEntryCollection entryColl = info.getEntry();
  133. String submitSchemeId = info.getSubmitScheme().getId().toString();
  134. StringBuffer personBuffer = new StringBuffer();
  135. for(int i=0;i<entryColl.size();i++) {
  136. BatchSubmitShemeBillEntryInfo entryInfo = entryColl.get(i);
  137. personBuffer.append("'"+entryInfo.getPerson().getId().toString()+"',");
  138. }
  139. personBuffer = personBuffer.deleteCharAt(personBuffer.length()-1);
  140. Date applyDate = info.getApplyDate();
  141. Calendar calendar = Calendar.getInstance();
  142. calendar.setTime(applyDate);
  143. int applyYear = calendar.get(Calendar.YEAR);
  144. int applyMonth = calendar.get(Calendar.MONTH)+1;
  145. String sql = "SELECT c.fnumber FROM T_HR_SBatchSubmitShemeBill a left join T_HR_SchemeBillEntry b on a.fid = b.fbillid left join T_BD_Person c on b.FPERSONID = c.fid where a.FSUBMITSCHEMEID = '"+submitSchemeId+"' and year(b.FEFFECTDATE) = "+applyYear+" and month(b.FEFFECTDATE) = "+applyMonth+" and a.FBILLSTATE in ('1','2','3') and a.FDATASOURCE = '2' and b.FPERSONID in ("+personBuffer.toString()+") ";
  146. logger.error("获取员工提报SQL:"+sql);
  147. try {
  148. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  149. StringBuffer numberBuffer = new StringBuffer();
  150. while(rowSet.next()) {
  151. numberBuffer.append("'"+rowSet.getString("fnumber")+"',");
  152. }
  153. if(numberBuffer.length()>0) {
  154. numberBuffer = numberBuffer.deleteCharAt(numberBuffer.length()-1);
  155. throw new ShrWebBizException("The following employees ("+numberBuffer+") have submitted data for this plan with an occurrence date of that month");
  156. }
  157. } catch (BOSException e) {
  158. e.printStackTrace();
  159. } catch (SQLException e) {
  160. e.printStackTrace();
  161. }
  162. }
  163. /**
  164. * 校验员工+提报月+方案只能提交一次
  165. * @throws ShrWebBizException
  166. */
  167. public static void checkSubmitCount(BatchSubmitShemeBillInfo info) throws ShrWebBizException{
  168. Context ctx = SHRContext.getInstance().getContext();
  169. String personId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString();
  170. String proposerId = info.getProposer().getId().toString();
  171. String submitSchemeId = info.getSubmitScheme().getId().toString();
  172. if(!StringUtils.equals(personId, proposerId)) {
  173. throw new ShrWebBizException("Only self created documents can be submitted");
  174. }
  175. //提报日期
  176. Date applyDate = info.getApplyDate();
  177. Calendar calendar = Calendar.getInstance();
  178. calendar.setTime(applyDate);
  179. calendar.set(Calendar.DAY_OF_MONTH, 1);
  180. String startDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  181. calendar.add(Calendar.MONTH, 1);
  182. String endDate = DateTimeUtils.dateFormat(calendar.getTime(), "yyyy-MM-dd");
  183. int count = 0;
  184. String sql = "select count(1) count from T_HR_SBatchSubmitShemeBill where FPROPOSERID = '"+personId+"' and fbillstate in ('1','2','3') "
  185. + "and fdatasource = '2' and fapplydate >= '"+startDate+"' and fapplydate < '"+endDate+"' and FSUBMITSCHEMEID = '"+submitSchemeId+"'";
  186. logger.error("查询员工当月提交次数SQL:"+sql);
  187. try {
  188. IRowSet iRowSet = DbUtil.executeQuery(ctx, sql);
  189. while(iRowSet.next()) {
  190. count = iRowSet.getInt("count");
  191. }
  192. logger.error("员工该方案当月提交次数:"+count);
  193. if(count>0) {
  194. throw new ShrWebBizException("Your proposal has been submitted in the month of submission and cannot be resubmitted");
  195. }
  196. } catch (BOSException e) {
  197. e.printStackTrace();
  198. } catch (SQLException e) {
  199. e.printStackTrace();
  200. }
  201. }
  202. /**
  203. * 校验分录人员是否重复
  204. * @param info
  205. * @throws ShrWebBizException
  206. */
  207. public static void checkPersonRepeat(BatchSubmitShemeBillInfo info) throws ShrWebBizException{
  208. BatchSubmitShemeBillEntryCollection entryColl = info.getEntry();
  209. Set<String> personIdSet = new HashSet<String>();
  210. for(int i=0;i<entryColl.size();i++) {
  211. BatchSubmitShemeBillEntryInfo entryInfo = entryColl.get(i);
  212. PersonInfo person = entryInfo.getPerson();
  213. if(person != null) {
  214. personIdSet.add(person.getId().toString());
  215. }
  216. }
  217. if(personIdSet.size() != entryColl.size()) {
  218. throw new ShrWebBizException("Entries can only have one row of data per person");
  219. }
  220. }
  221. /**
  222. * 参数校验
  223. * @param info
  224. * @throws ShrWebBizException
  225. */
  226. public static void checkExists(BatchSubmitShemeBillInfo info) throws ShrWebBizException{
  227. Context ctx = SHRContext.getInstance().getContext();
  228. int day = 0;
  229. Calendar calendar = Calendar.getInstance();
  230. int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
  231. try {
  232. String paramSql = "SELECT FNUMBER,fname_l2 name FROM T_HR_SHRRSVITEM0 where fstate = '1' and FNUMBER = '1002'";
  233. IRowSet paramRow = DbUtil.executeQuery(ctx, paramSql);
  234. while(paramRow.next()) {
  235. day = paramRow.getObject("name")==null?0:paramRow.getInt("name");
  236. }
  237. //最后提交日期校验
  238. if(day != 0 && thisDay > day) {
  239. throw new ShrWebBizException(" documents have passed the last submission date !");
  240. }
  241. } catch (SQLException e) {
  242. e.printStackTrace();
  243. } catch (BOSException e) {
  244. e.printStackTrace();
  245. }
  246. }
  247. }