CustomerFunctionSalaryService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package com.kingdee.shr.compensation.service;
  2. import java.math.BigDecimal;
  3. import java.sql.SQLException;
  4. import java.text.ParseException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Calendar;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.apache.log4j.Logger;
  12. import com.kingdee.bos.BOSException;
  13. import com.kingdee.bos.Context;
  14. import com.kingdee.eas.util.app.DbUtil;
  15. import com.kingdee.jdbc.rowset.IRowSet;
  16. import com.kingdee.shr.compensation.CalSchemeInfo;
  17. import com.kingdee.shr.compensation.app.formula.data.Tools;
  18. import com.kingdee.shr.customer.gtiit.util.DateTimeUtils;
  19. /**
  20. * 薪酬函数
  21. * @author issuser
  22. *
  23. */
  24. public class CustomerFunctionSalaryService {
  25. private static Logger logger =
  26. Logger.getLogger("com.kingdee.shr.compensation.service.CustomerFunctionSalaryService");
  27. /**
  28. * 获取员工工资包当月金额
  29. * @param personId
  30. * @param cmpItemId
  31. * @param months
  32. * @return
  33. * @throws BOSException
  34. * @throws SQLException
  35. */
  36. public double getSalayBag(Map<String, Object> paramMap, HashMap<String, Object> tempMap, CalSchemeInfo calSchemeInfo ,String cmpItemId,String months, String mainTableRowFilter) throws BOSException, SQLException {
  37. Context ctx = Tools.getInstance().getCtx();
  38. String personId = (String)paramMap.get("T_HR_SCMPCALTABLE_FPERSONID");
  39. String sql = "SELECT top 1 b.* FROM CT_SAL_SalaryBag a " +
  40. " left join CT_SAL_SalaryBagEntry b on a.fid = b.fbillId " +
  41. " where a.FBillState = 3 and CFPersonID = '" + personId + "' " +
  42. " and a.CFCmpItemID = (select fid from T_HR_SCmpItem where FNumber = '" + cmpItemId + "') and b.CFMonths = '" + months + "'";
  43. System.out.println("工资包查询sql:" + sql);
  44. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  45. if(rowSet.next()) {
  46. if(rowSet.getObject("CFAmountPayable")==null || rowSet.getDouble("CFAmountPayable")==0) {
  47. return rowSet.getDouble("CFMoneys");
  48. }else {
  49. return rowSet.getDouble("CFAmountPayable");
  50. }
  51. }
  52. return 0.0D;
  53. }
  54. /**
  55. * 获取工资追溯信息
  56. * @param personId
  57. * @param cmpItemId
  58. * @param months
  59. * @return
  60. * @throws BOSException
  61. * @throws SQLException
  62. */
  63. public double getSalayTraceability(Map<String, Object> paramMap, HashMap<String, Object> tempMap, CalSchemeInfo calSchemeInfo ,String projectNumber,String date, String mainTableRowFilter) throws BOSException, SQLException {
  64. Context ctx = Tools.getInstance().getCtx();
  65. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  66. int year = 0;
  67. int month = 0;
  68. try {
  69. Date parse = format.parse(date);
  70. Calendar calendar = Calendar.getInstance();
  71. calendar.setTime(parse);
  72. year = calendar.get(Calendar.YEAR);
  73. month = calendar.get(Calendar.MONTH)+1;
  74. } catch (ParseException e) {
  75. e.printStackTrace();
  76. }
  77. String personId = (String)paramMap.get("T_HR_SCMPCALTABLE_FPERSONID");
  78. String sql = "SELECT sum(cfreissuemonthpay) reissuemonthpay,sum(cfreissueoverpay) reissueoverpay,sum(cfreissuerestoverpay) reissuerestoverpay,"
  79. + "sum(cfreissueholidaysoverpay) reissueholidaysoverpay,sum(cfreissueunleavededuction) reissueunleavededuction "
  80. + "FROM CT_CUS_PersonPayForm where year(cfformmonth)="+year+" and month(cfformmonth)="+month+" and cfpersonid='"+personId+"'";
  81. System.out.println("工资追溯查询sql:" + sql);
  82. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  83. if(rowSet.next()) {
  84. if(projectNumber.equals("0")) {
  85. return rowSet.getDouble("reissuemonthpay");
  86. }else if(projectNumber.equals("1")) {
  87. return rowSet.getDouble("reissueoverpay");
  88. }else if(projectNumber.equals("2")) {
  89. return rowSet.getDouble("reissuerestoverpay");
  90. }else if(projectNumber.equals("3")) {
  91. return rowSet.getDouble("reissueholidaysoverpay");
  92. }else if(projectNumber.equals("4")) {
  93. return rowSet.getDouble("reissueunleavededuction");
  94. }
  95. }
  96. return 0.0D;
  97. }
  98. /**
  99. * 获取工资提报信息
  100. * @param personId
  101. * @param cmpItemId
  102. * @param months
  103. * @return
  104. * @throws BOSException
  105. * @throws SQLException
  106. * 取工资提报,对于AssignType来说, 0表示兼职,1表示主要任职,3表示 无
  107. * 参数takeType 0表示主职,1表示兼职
  108. */
  109. public double getPutForward(Map<String, Object> paramMap, HashMap<String, Object> tempMap, CalSchemeInfo calSchemeInfo ,String projectNumber,String date, String takeType, String isHour, String mainTableRowFilter) throws BOSException, SQLException {
  110. Context ctx = Tools.getInstance().getCtx();
  111. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  112. String personId = (String)paramMap.get("T_HR_SCMPCALTABLE_FPERSONID");
  113. int year = 0;
  114. int month = 0;
  115. try {
  116. Date parse = format.parse(date);
  117. Calendar calendar = Calendar.getInstance();
  118. calendar.setTime(parse);
  119. year = calendar.get(Calendar.YEAR);
  120. month = calendar.get(Calendar.MONTH)+1;
  121. } catch (ParseException e) {
  122. e.printStackTrace();
  123. }
  124. String assignType = "";
  125. if(takeType.equals("0")) {
  126. assignType = "1";
  127. }else {
  128. assignType = "0";
  129. }
  130. //查询全职、兼职总工时数
  131. if(StringUtils.isNotBlank(isHour)) {
  132. String hourSql = "SELECT sum(b.CFTOTALWORKHOURS) sumHour FROM T_HR_SBatchSubmitShemeBill a "
  133. + "left join T_HR_SchemeBillEntry b on a.fid=b.fbillid "
  134. + "left join T_HR_SCmpEmpORelation c on b.FCMPEMPORELATIONID=c.fid "
  135. + "left join T_HR_EmpPostExperienceHis d on d.fid=c.femppostexphisid "
  136. + "where year(b.FEFFECTDATE)="+year+" and month(b.FEFFECTDATE)="+month+" "
  137. + "and d.FASSIGNTYPE='"+assignType+"' and a.FBILLSTATE = '3' and b.fpersonid='"+personId+"'";
  138. logger.error("查询员工全职总工时SQL:"+hourSql);
  139. IRowSet schemeRow = DbUtil.executeQuery(ctx, hourSql);
  140. while(schemeRow.next()) {
  141. return schemeRow.getDouble("sumHour");
  142. }
  143. }
  144. //全职
  145. if(takeType.equals("0")) {
  146. if(StringUtils.isBlank(projectNumber)) {
  147. String amountSql = "SELECT sum(b.CFTOTALAMOUNT) sumAmount FROM T_HR_SBatchSubmitShemeBill a "
  148. + "left join T_HR_SchemeBillEntry b on a.fid=b.fbillid "
  149. + "left join T_HR_SCmpEmpORelation c on b.FCMPEMPORELATIONID=c.fid "
  150. + "left join T_HR_EmpPostExperienceHis d on d.fid=c.femppostexphisid "
  151. + "where year(b.FEFFECTDATE)="+year+" and month(b.FEFFECTDATE)="+month+" "
  152. + "and d.FASSIGNTYPE='1' and a.FBILLSTATE = '3' and b.fpersonid='"+personId+"'";
  153. logger.error("查询员工全职总金额SQL:"+amountSql);
  154. IRowSet schemeRow = DbUtil.executeQuery(ctx, amountSql);
  155. while(schemeRow.next()) {
  156. return schemeRow.getDouble("sumAmount");
  157. }
  158. }
  159. /*String projectFieldSql = "SELECT fieldsn FROM T_HR_SCalSubmitItem where FNUMBER = '"+projectNumber+"'";
  160. IRowSet fieldRow = DbUtil.executeQuery(ctx, projectFieldSql);
  161. String fieldNo = "";
  162. while(fieldRow.next()) {
  163. fieldNo = "S"+fieldRow.getString("fieldsn");
  164. }
  165. if(StringUtils.isEmpty(fieldNo)) {
  166. logger.error("根据提报项目编码未查到提报项目");
  167. return 0.0D;
  168. }
  169. String tableSql = "SELECT c.FBILLENTRYTABLENAME FROM T_HR_SCalSubmitItem a "
  170. + "left join T_HR_SCalSubmitSchemeItem b on a.fid=b.fcalsubmititemid "
  171. + "left join T_HR_SCalShemeTableRelation c on b.FCALSUBMITSCHEMEID = c.fsubmitschemeid "
  172. + "where a.FNUMBER = '"+projectNumber+"'";
  173. logger.error("查询提报项目对应表名SQL:"+tableSql);
  174. IRowSet tableRow = DbUtil.executeQuery(ctx, tableSql);
  175. String tableName = "";
  176. while(tableRow.next()) {
  177. tableName = tableRow.getString("FBILLENTRYTABLENAME");
  178. }
  179. String schemeSql = "SELECT sum(k."+fieldNo+") sumHours FROM T_HR_SBatchSubmitShemeBill a "
  180. + "left join T_HR_SchemeBillEntry b on a.fid=b.fbillid "
  181. + "left join T_HR_SCmpEmpORelation c on b.FCMPEMPORELATIONID=c.fid "
  182. + "left join T_HR_EmpPostExperienceHis d on d.fid=c.femppostexphisid "
  183. + "left join T_HR_SCalSubmitScheme e on e.fid=a.fsubmitschemeid "
  184. + "left join T_HR_SCalShemeTableRelation g on g.fsubmitschemeid=e.fid "
  185. + "left join T_HR_SCalSubmitSchemeItem s on s.FCALSUBMITSCHEMEID = e.fid "
  186. + "left join T_HR_SCalSubmitItem h on h.fid=s.fcalsubmititemid "
  187. + "left join "+tableName+" k on k.fid = b.fid "
  188. + "where year(b.FEFFECTDATE)="+year+" and month(b.FEFFECTDATE)="+month+" and d.FASSIGNTYPE='1' "
  189. + "and h.fnumber='"+projectNumber+"' and a.FBILLSTATE = '3' and b.fpersonid='"+personId+"'";
  190. logger.error("查询项目对应工时SQL:"+schemeSql);
  191. IRowSet schemeRow = DbUtil.executeQuery(ctx, schemeSql);
  192. while(schemeRow.next()) {
  193. return schemeRow.getDouble("sumHours");
  194. }*/
  195. }else {
  196. String amountSql = "SELECT sum(b.CFTOTALAMOUNT) sumAmount FROM T_HR_SBatchSubmitShemeBill a "
  197. + "left join T_HR_SchemeBillEntry b on a.fid=b.fbillid "
  198. + "left join T_HR_SCmpEmpORelation c on b.FCMPEMPORELATIONID=c.fid "
  199. + "left join T_HR_EmpPostExperienceHis d on d.fid=c.femppostexphisid "
  200. + "where year(b.FEFFECTDATE)="+year+" and month(b.FEFFECTDATE)="+month+" "
  201. + "and d.FASSIGNTYPE='0' and a.FBILLSTATE = '3' and b.fpersonid='"+personId+"'";
  202. logger.error("查询员工兼职总金额SQL:"+amountSql);
  203. IRowSet schemeRow = DbUtil.executeQuery(ctx, amountSql);
  204. while(schemeRow.next()) {
  205. return schemeRow.getDouble("sumAmount");
  206. }
  207. }
  208. return 0.0D;
  209. }
  210. // 0 兼职 1 全职
  211. /**
  212. * 获取月份最新的离职补偿金
  213. * @param months
  214. * @return
  215. * @throws BOSException
  216. * @throws SQLException
  217. */
  218. public double getSeparationAllowance(String months ) throws BOSException, SQLException {
  219. Context ctx = Tools.getInstance().getCtx();
  220. String sql = "select top 1 * from CT_COM_Compensationthreshold where CFEffectivedate <= '" + months + "' order by CFEffectivedate desc";
  221. System.out.println("获取月份最新的离职补偿金sql:" + sql);
  222. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  223. if(rowSet.next()) {
  224. return rowSet.getDouble("FName_l2");
  225. }
  226. return 0.0;
  227. }
  228. public double getMianPosHour(Map<String, Object> paramMap, HashMap<String, Object> tempMap, CalSchemeInfo calSchemeInfo ,String date, String mainTableRowFilter) throws BOSException, SQLException {
  229. logger.error("获取主要任职时薪日期参数:"+date);
  230. Context ctx = Tools.getInstance().getCtx();
  231. String personId = (String)paramMap.get("T_HR_SCMPCALTABLE_FPERSONID");
  232. String sql = "SELECT cfhourlywage FROM T_HR_EmpOrgRelation where fpersonid = '"+personId+"' and fassignType = '1' and fislatestinaday = '1' and feffdt <= '"+date+"' and fleffdt >= '"+date+"'";
  233. logger.error("获取主要任职时薪SQL:"+sql);
  234. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  235. int count = 0;
  236. Double hour = 0.0D;
  237. if(rowSet.next()) {
  238. hour = rowSet.getDouble("cfhourlywage");
  239. count++;
  240. }
  241. logger.error("时薪:"+hour+", 次数:"+count);
  242. if(count>1) {
  243. return 0.0D;
  244. }
  245. return hour;
  246. }
  247. /**
  248. * 根据日期段获取人员离职日期
  249. * @param paramMap
  250. * @param tempMap
  251. * @param calSchemeInfo
  252. * @param date
  253. * @param mainTableRowFilter
  254. * @return
  255. * @throws BOSException
  256. * @throws SQLException
  257. */
  258. public String getDepartDate(Map<String, Object> paramMap, HashMap<String, Object> tempMap, CalSchemeInfo calSchemeInfo ,String beginDate, String endDate, String mainTableRowFilter) throws BOSException, SQLException {
  259. logger.error("获取离职日期参数:开始日期:"+beginDate+",结束日期:"+endDate);
  260. Context ctx = Tools.getInstance().getCtx();
  261. String personId = (String)paramMap.get("T_HR_SCMPCALTABLE_FPERSONID");
  262. String departDate = "";
  263. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  264. String sql = "SELECT top 1 b.FBIZDATE FROM T_HR_ResignBizBill a left join T_HR_ResignBizBillEntry b on a.FID = b.FBILLID where b.FBIZDATE >= '"+beginDate+"' and b.FBIZDATE <= '"+endDate+"' and a.FBILLSTATE = '3' and b.FPERSONID = '"+personId+"'";
  265. logger.error("获取离职日期SQL:"+sql);
  266. IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
  267. if(rowSet.next()) {
  268. Date date = rowSet.getDate("FBIZDATE");
  269. departDate = sdf.format(date);
  270. }
  271. if(StringUtils.isNotBlank(departDate)) {
  272. logger.error("人员ID:"+personId+",离职日期:"+departDate);
  273. }
  274. return departDate;
  275. }
  276. }