PluralitySubFacadeControllerBean.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package com.kingdee.eas.custom.facade.plurality;
  2. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  3. import com.kingdee.eas.framework.CoreBaseCollection;
  4. import com.kingdee.eas.framework.CoreBaseInfo;
  5. import com.kingdee.eas.hr.affair.*;
  6. import com.kingdee.eas.hr.base.AffairActionReasonFactory;
  7. import com.kingdee.eas.hr.base.AffairActionReasonInfo;
  8. import com.kingdee.eas.hr.base.ApproveTypeEnum;
  9. import com.kingdee.eas.hr.base.HRBillStateEnum;
  10. import com.kingdee.eas.hr.base.HRBizDefineFactory;
  11. import com.kingdee.eas.hr.base.HRBizDefineInfo;
  12. import com.kingdee.eas.util.app.ContextUtil;
  13. import com.kingdee.eas.util.app.DbUtil;
  14. import com.kingdee.jdbc.rowset.IRowSet;
  15. import com.kingdee.util.DateTimeUtils;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.apache.log4j.Logger;
  18. import java.sql.SQLException;
  19. import java.text.ParseException;
  20. import java.util.Date;
  21. import java.util.HashMap;
  22. import com.kingdee.bos.*;
  23. import com.kingdee.eas.common.EASBizException;
  24. import com.kingdee.eas.custom.hr.utils.DateUtil;
  25. import java.lang.String;
  26. public class PluralitySubFacadeControllerBean extends AbstractPluralitySubFacadeControllerBean
  27. {
  28. private static Logger logger =
  29. Logger.getLogger("com.kingdee.eas.custom.facade.plurality.PluralitySubFacadeControllerBean");
  30. @Override
  31. protected void _autoPluralitEnd(Context ctx, String personId, String curdate, int offset) throws BOSException, EASBizException {
  32. super._autoPluralitEnd(ctx, personId,curdate, offset);
  33. //变动类型
  34. AffairActionReasonInfo reasonInfo = AffairActionReasonFactory.getLocalInstance(ctx).getAffairActionReasonInfo(" where number = '0211' ");
  35. HRBizDefineInfo defineInfo = HRBizDefineFactory.getLocalInstance(ctx).getHRBizDefineInfo( " where number = 'SHR19' " );
  36. HashMap<String, Object> params = new HashMap ();
  37. params.put("reasonInfo", reasonInfo);
  38. params.put("defineInfo", defineInfo);
  39. Date bizDate = new Date();
  40. //查询所有当天日期的离职单
  41. if (StringUtils.isNotBlank(curdate)) {
  42. bizDate = DateUtil.stringToDate(curdate, "yyyy-MM-dd");
  43. }
  44. Date startDate = DateUtil.getDateStartTime(bizDate);
  45. Date endDate = DateUtil.getDateEndTime(bizDate);
  46. if( offset > 0 ){
  47. endDate = DateUtil.add(endDate, offset) ;
  48. }else if( offset < 0 ) {
  49. startDate = DateUtil.add(startDate, offset) ;
  50. }
  51. //查询兼职单
  52. StringBuilder sbu = new StringBuilder();
  53. sbu.append(" select bill.fid billId from T_HR_PluralityAddBizBill bill ");
  54. sbu.append(" left join T_HR_PluralityAddBizBillEntry entry on bill.FEntryId = entry.fbillid ");
  55. sbu.append(" where bill.fbillstate = '3' " );
  56. sbu.append(" and entry.fenddate >= '" + startDate+"' " );
  57. sbu.append(" and entry.fenddate <= '" + endDate+"' " );
  58. if( StringUtils.isNotBlank(personId)){
  59. sbu.append(" and entry.fpersonid = " + personId );
  60. }
  61. IRowSet rowSet = DbUtil.executeQuery(ctx, sbu.toString());
  62. try {
  63. while(rowSet.next()) {
  64. String billId = rowSet.getString("billId");
  65. newDelBill( ctx, billId , params);
  66. }
  67. } catch (SQLException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71. private void newDelBill(Context ctx, String billId,HashMap<String, Object> params) throws BOSException, EASBizException {
  72. IPluralityAddBizBill addIns = PluralityAddBizBillFactory.getLocalInstance(ctx);
  73. PluralityAddBizBillInfo addInfo = addIns.getPluralityAddBizBillInfo(new ObjectUuidPK(billId));
  74. //创建新集合
  75. CoreBaseCollection delCol = new CoreBaseCollection();
  76. PluralityDelBizBillInfo delInfo = new PluralityDelBizBillInfo();
  77. // delInfo.setAdminOrg(addInfo.getAdminOrg());
  78. delInfo.setHrOrgUnit(addInfo.getHrOrgUnit());
  79. delInfo.setBizDate(new Date());
  80. delInfo.setCU(addInfo.getCU());
  81. delInfo.setApplier(addInfo.getApplier());
  82. //分录数据
  83. PluralityAddBizBillEntryCollection addEntrys = addInfo.getEntrys();
  84. //分录赋值
  85. PluralityDelBizBillEntryCollection addEntryData = addEntryData(addEntrys, params);
  86. delInfo.put("entrys", addEntryData);
  87. delInfo.setApplyDate(new Date());
  88. delInfo.setBizDate(new Date());
  89. delInfo.setCreator(ContextUtil.getCurrentUserInfo(ctx));
  90. delInfo.setHrOrgUnit(addInfo.getHrOrgUnit());
  91. delInfo.setIsMulti(addInfo.isIsMulti() );
  92. delInfo.setUseDefault(addInfo.isUseDefault());
  93. delInfo.setIsMultiEntry(addInfo.isIsMultiEntry());
  94. delInfo.setBillState(HRBillStateEnum.SAVED);
  95. delInfo.setApproveType(ApproveTypeEnum.DIRECT);
  96. // delCol.add(delInfo);
  97. //保存数据库
  98. IPluralityDelBizBill delIns = PluralityDelBizBillFactory.getLocalInstance(ctx);
  99. delIns.addnew(delInfo);
  100. delInfo.setBillState(HRBillStateEnum.AUDITED);
  101. delIns.submitEffect((CoreBaseInfo)delInfo);
  102. logger.error("兼职单审核完");
  103. }
  104. /**
  105. * 分录赋值
  106. * @param addEntrys
  107. * @return
  108. */
  109. private PluralityDelBizBillEntryCollection addEntryData(PluralityAddBizBillEntryCollection addEntrys,HashMap<String, Object> params){
  110. PluralityDelBizBillEntryCollection delEntryCol = new PluralityDelBizBillEntryCollection();
  111. for(int i =0 ;i< addEntrys.size();i++){
  112. PluralityAddBizBillEntryInfo addEntryInfo = addEntrys.get(i);
  113. PluralityDelBizBillEntryInfo delEntryInfo = new PluralityDelBizBillEntryInfo();
  114. delEntryInfo.setPerson(addEntryInfo.getPerson());
  115. delEntryInfo.setDescription("自动终止");
  116. delEntryInfo.setAffairActionReason((AffairActionReasonInfo)params.get("reasonInfo"));
  117. delEntryInfo.setHrBizDefine((HRBizDefineInfo)params.get("defineInfo"));
  118. delEntryInfo.setDefaultLocale(addEntryInfo.getDefaultLocale());
  119. delEntryInfo.setHrOrgUnit(addEntryInfo.getHrOrgUnit());
  120. //兼职组织-
  121. delEntryInfo.setOldEmpType(addEntryInfo.getEmpType());
  122. delEntryInfo.setOldAdminOrg(addEntryInfo.getAdminOrg());
  123. delEntryInfo.setOldPosition(addEntryInfo.getPosition());
  124. delEntryInfo.setOldCompany(addEntryInfo.getCompany());
  125. //任职职位-现任职位
  126. delEntryInfo.setEmpType(addEntryInfo.getOldEmpType());
  127. delEntryInfo.setMainPosition(addEntryInfo.getOldPosition());
  128. delEntryInfo.setMainAdminOrg(addEntryInfo.getOldAdminOrg());
  129. //任职部门-现任部门
  130. delEntryInfo.setMainDepartment(addEntryInfo.getOldAdminOrg());
  131. delEntryInfo.setMainCompany(addEntryInfo.getOldCompany());
  132. //不需要
  133. // delEntryInfo.setPosition(addEntryInfo.getOldPosition());
  134. // delEntryInfo.setAdminOrg(addEntryInfo.getOldAdminOrg());
  135. delEntryInfo.setBeginDate(addEntryInfo.getBizDate());
  136. delEntryInfo.setEmployerUnit(addEntryInfo.getEmployerUnit());
  137. delEntryInfo.put("pthwage", addEntryInfo.get("pthwage"));
  138. delEntryInfo.put("ptlmanager", addEntryInfo.get("ptlmanager"));
  139. // if(params.containsKey("isResign") && Boolean.getBoolean(params.get("isResign").toString()) ) {
  140. //
  141. // }
  142. //结束日期
  143. if(params.containsKey("endDate") ) {
  144. try {
  145. Date endDate = DateTimeUtils.parseDate( params.get("endDate").toString(), "yyyy-MM-dd");
  146. delEntryInfo.setBizDate(endDate);
  147. } catch (ParseException e) {
  148. e.printStackTrace();
  149. }
  150. }else {
  151. delEntryInfo.setBizDate(addEntryInfo.getEndDate());
  152. }
  153. delEntryCol.add(delEntryInfo);
  154. }
  155. return delEntryCol;
  156. }
  157. @Override
  158. protected void _resignCreateEnd(Context ctx, String personId, String endDate) throws BOSException, EASBizException {
  159. super._resignCreateEnd(ctx, personId, endDate);
  160. if(StringUtils.isBlank(endDate)) {
  161. endDate = DateUtil.dateToString(new Date(), "yyyy-MM-dd");
  162. }
  163. //变动类型
  164. AffairActionReasonInfo reasonInfo = AffairActionReasonFactory.getLocalInstance(ctx).getAffairActionReasonInfo(" where number = '0211' ");
  165. HRBizDefineInfo defineInfo = HRBizDefineFactory.getLocalInstance(ctx).getHRBizDefineInfo( " where number = 'SHR19' " );
  166. HashMap<String, Object> params = new HashMap<String,Object> ();
  167. params.put("reasonInfo", reasonInfo);
  168. params.put("defineInfo", defineInfo);
  169. params.put("isResign", true);
  170. params.put("endDate", endDate);
  171. //查询兼职单
  172. StringBuilder sbu = new StringBuilder();
  173. sbu.append(" select bill.fid billId , delen.fid delId from T_HR_PluralityAddBizBill bill ");
  174. sbu.append(" left join T_HR_PluralityAddBizBillEntry entry on bill.FId = entry.fbillid ");
  175. sbu.append(" left join T_HR_PluralityDelBizBillEntry delen ");
  176. sbu.append(" on entry.fpersonid = delen.fpersonid ");
  177. sbu.append(" and entry.foldpositionid = delen.FMainPositionID ");
  178. sbu.append(" and ( ");
  179. sbu.append(" entry.cfpthwage = delen.cfpthwage ");
  180. sbu.append(" OR ( entry.cfpthwage IS NULL AND delen.cfpthwage IS NULL ) ");
  181. sbu.append(" ) ");
  182. sbu.append(" where bill.fbillstate = '3' ");
  183. sbu.append(" and entry.fpersonid = '" + personId+"'" );
  184. sbu.append(" and ( entry.fenddate >= {" + endDate+"} or entry.fenddate is null ) ");
  185. IRowSet rowSet = DbUtil.executeQuery(ctx, sbu.toString());
  186. try {
  187. while(rowSet.next()) {
  188. String billId = rowSet.getString("billId");
  189. String delId = rowSet.getString("delId");
  190. if(StringUtils.isBlank(delId)) {
  191. newDelBill( ctx, billId ,params);
  192. }
  193. }
  194. } catch (SQLException e) {
  195. e.printStackTrace();
  196. }
  197. }
  198. }