SaveFluctuationBizBillService.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. package com.kingdee.eas.custom.attendance.service;
  2. import com.aliyun.odps.utils.StringUtils;
  3. import com.kingdee.bos.BOSException;
  4. import com.kingdee.bos.Context;
  5. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  6. import com.kingdee.bos.dao.IObjectPK;
  7. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  8. import com.kingdee.eas.base.permission.UserFactory;
  9. import com.kingdee.eas.base.permission.UserInfo;
  10. import com.kingdee.eas.basedata.org.*;
  11. import com.kingdee.eas.basedata.person.PersonFactory;
  12. import com.kingdee.eas.basedata.person.PersonInfo;
  13. import com.kingdee.eas.common.EASBizException;
  14. import com.kingdee.eas.framework.ObjectBaseInfo;
  15. import com.kingdee.eas.hr.affair.FluctuationBizBillEntryInfo;
  16. import com.kingdee.eas.hr.affair.FluctuationBizBillFactory;
  17. import com.kingdee.eas.hr.affair.FluctuationBizBillInfo;
  18. import com.kingdee.eas.hr.base.*;
  19. import com.kingdee.eas.hr.emp.PersonPositionFactory;
  20. import com.kingdee.eas.hr.emp.PersonPositionInfo;
  21. import com.kingdee.eas.util.app.DbUtil;
  22. import com.kingdee.jdbc.rowset.IRowSet;
  23. import com.kingdee.shr.ats.web.util.SHRBillUtil;
  24. import java.sql.SQLException;
  25. import java.text.SimpleDateFormat;
  26. import java.util.Date;
  27. import java.util.HashMap;
  28. import java.util.Map;
  29. /**
  30. * 调动
  31. */
  32. public class SaveFluctuationBizBillService implements IHRMsfService {
  33. @Override
  34. public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
  35. System.out.println("SaveFluctuationBizBillService" + map);
  36. StringBuffer reason = new StringBuffer();
  37. String personNumbe = (String)map.get("personNumber");
  38. String bizDate = (String)map.get("bizDate");
  39. String position = (String)map.get("positionName");
  40. String remarks = (String)map.get("description");
  41. // String applier = (String)map.get("createPerson");
  42. // String applyDate = (String)map.get("createDate");
  43. String variationReason = (String)map.get("variationReasonInfoNumber");
  44. // 调动后 部门 编码
  45. String orgUnitNumber = (String)map.get("orgUnitNumber");
  46. // 直接上级
  47. String leaderPersonNumber = (String)map.get("leaderPersonNumber");
  48. if (StringUtils.isBlank(personNumbe)){
  49. reason.append("调动人员编码不能为空;");
  50. }
  51. // if (StringUtils.isBlank(applier)){
  52. // reason.append("制单人员编码不能为空;");
  53. // }
  54. if (StringUtils.isBlank(position)){
  55. reason.append("调动职位名称不能为空;");
  56. }
  57. if (StringUtils.isBlank(bizDate)){
  58. reason.append("调动日期不能为空;");
  59. }
  60. Map<Object, Object> resultMap = this.createFluctuationBizBill(context, personNumbe, bizDate, position, remarks, variationReason, orgUnitNumber,leaderPersonNumber);
  61. return resultMap;
  62. }
  63. /**
  64. * @param ctx
  65. * @param personNumbe 员工工号
  66. * @param bizDate 调动日期
  67. * @param position 调动职位 名称
  68. * @param remarks 备注
  69. * @param variationReason 调岗后工作地点
  70. * @param orgUnitNumber 调动部门编码
  71. * @param leaderPersonNumber 直接上级
  72. * @return
  73. */
  74. public Map<Object, Object> createFluctuationBizBill(Context ctx, String personNumbe, String bizDate, String position, String remarks, String variationReason , String orgUnitNumber,String leaderPersonNumber) {
  75. Map<Object, Object> returnMap = new HashMap();
  76. //调动单对象
  77. FluctuationBizBillInfo info = new FluctuationBizBillInfo();
  78. //调动单分录对象
  79. FluctuationBizBillEntryInfo enInfo = new FluctuationBizBillEntryInfo();
  80. //员工个人信息
  81. PersonInfo peInfo = new PersonInfo();
  82. //职位
  83. PositionInfo oldPoInfo = new PositionInfo();
  84. //行政组织单元
  85. AdminOrgUnitInfo oldAdInfo = new AdminOrgUnitInfo();
  86. AdminOrgUnitInfo oldCompanyInfo = new AdminOrgUnitInfo();
  87. //用工关系状态
  88. EmployeeTypeInfo emsInfo = new EmployeeTypeInfo();
  89. //变动原因
  90. VariationReasonInfo varInfo = new VariationReasonInfo();
  91. //职位
  92. PositionInfo poInfo = new PositionInfo();
  93. AdminOrgUnitInfo adInfo = new AdminOrgUnitInfo();
  94. AdminOrgUnitInfo companyInfo = new AdminOrgUnitInfo(); //
  95. PersonInfo ueInfo = new PersonInfo();
  96. Date compDates = null;
  97. boolean isK = false;
  98. String msg = null;
  99. String fid = null;
  100. String fnumber = null;
  101. StringBuffer reason = new StringBuffer();
  102. String msgType = null;
  103. try {
  104. HROrgUnitInfo hrInfo = HROrgUnitFactory.getLocalInstance(ctx).getHROrgUnitInfo(new ObjectUuidPK("00000000-0000-0000-0000-000000000000CCE7AED4"));
  105. //hr组织
  106. info.setHrOrgUnit(hrInfo);
  107. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  108. PersonInfo shrPerson = SHRBillUtil.getCurrPersonInfo();
  109. info.setApplyDate(new Date());
  110. Map pe;
  111. // 取到 制表人 的 员工信息 pe ,用户信息 ue
  112. pe = this.getPerson(ctx, shrPerson.getNumber()); //制单人工号
  113. if (pe.get("pe") != null) {
  114. ueInfo = (PersonInfo)pe.get("pe");
  115. // 申请人
  116. info.setApplier(ueInfo);
  117. } else {
  118. reason.append("制单人编码有误,请认真检查;");
  119. }
  120. pe = this.getPerson(ctx, personNumbe);//调动员工编码
  121. if (pe.get("pe") != null) {
  122. //员工个人信息
  123. peInfo = (PersonInfo)pe.get("pe");
  124. // 分录 enInfo
  125. enInfo.setPerson(peInfo);
  126. // 用工关系
  127. emsInfo = EmployeeTypeFactory.getLocalInstance(ctx).getEmployeeTypeInfo(new ObjectUuidPK(peInfo.getEmployeeType().getId()));
  128. enInfo.setOldEmpType(emsInfo);
  129. enInfo.setEmpType(emsInfo);
  130. } else {
  131. reason.append("调动员工编码未能获取员工信息有误,请认真检查;");
  132. }
  133. Map ap = this.getPersonAP(ctx, personNumbe);
  134. if (peInfo != null) {
  135. // 员工用工关系 , 入职时间
  136. String seSql = "SELECT FEnterDate FROM T_HR_EmpLaborRelation where FPERSONID = '" + peInfo.getId().toString() + "'";
  137. IRowSet seSet = DbUtil.executeQuery(ctx, seSql);
  138. if (seSet.next()) {
  139. //入职时间
  140. compDates = seSet.getDate("FEnterDate");
  141. }
  142. }
  143. //调动者 职位
  144. if (ap.get("po") != null) {
  145. // 职位
  146. oldPoInfo = (PositionInfo)ap.get("po");
  147. //调动单分录对象 , 原职位
  148. enInfo.setOldPosition(oldPoInfo);
  149. } else {
  150. reason.append("调动员工职位信息有误,请检查相关员工信息;");
  151. }
  152. //调动者 行政组织
  153. if (ap.get("ad") != null) {
  154. oldAdInfo = (AdminOrgUnitInfo)ap.get("ad");
  155. //调动单分录对象 , 原行政组织
  156. enInfo.setOldAdminOrg(oldAdInfo);
  157. oldCompanyInfo = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitInfo(new ObjectUuidPK(oldAdInfo.getCompany().getId()));
  158. //调动单分录对象 , 原行政组织
  159. enInfo.setOldCompany(oldCompanyInfo);
  160. } else {
  161. reason.append("调动员工组织信息有误,请检查相关员工信息;");
  162. }
  163. // 调动 部门 编码
  164. boolean isFull = false;
  165. // 职位编码
  166. String positionNumber = null;
  167. if (StringUtils.isNotBlank(orgUnitNumber)){
  168. AdminOrgUnitCollection adminOrgUnitCollection = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitCollection("where number = '" + orgUnitNumber + "'");
  169. if (adminOrgUnitCollection.size() > 0){
  170. AdminOrgUnitInfo adminOrgUnitInfo = adminOrgUnitCollection.get(0);
  171. positionNumber = adminOrgUnitInfo.getNumber();
  172. isFull = true;
  173. }else {
  174. reason.append("调动后部门为空,请认真检查;");
  175. }
  176. if (isFull){
  177. PositionCollection poCOl = PositionFactory.getLocalInstance(ctx).getPositionCollection(" where number = '" + positionNumber + "'");
  178. if (poCOl.size() > 0) {
  179. //职位
  180. poInfo = poCOl.get(0);
  181. //调动单分录对象 , 职员
  182. enInfo.setPosition(poInfo);
  183. //行政组织
  184. adInfo = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitInfo(new ObjectUuidPK(poInfo.getAdminOrgUnit().getId()));
  185. //调动单分录对象 , 目标组织
  186. enInfo.setAdminOrg(adInfo);
  187. companyInfo = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitInfo(new ObjectUuidPK(adInfo.getCompany().getId()));
  188. //调动单分录对象 , 公司
  189. enInfo.setCompany(companyInfo);
  190. }else{
  191. reason.append("系统中不存在 职位编码为:" + position + " 的职位;");
  192. }
  193. }else {
  194. reason.append("调动后职位与部门编码不匹配;");
  195. }
  196. }else {
  197. PositionCollection poCOl = PositionFactory.getLocalInstance(ctx).getPositionCollection("where number = '" + position + "'");
  198. if (poCOl.size() > 0) {
  199. //职位
  200. poInfo = poCOl.get(0);
  201. //调动单分录对象 , 职员
  202. enInfo.setPosition(poInfo);
  203. //行政组织
  204. adInfo = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitInfo(new ObjectUuidPK(poInfo.getAdminOrgUnit().getId()));
  205. //调动单分录对象 , 目标组织
  206. enInfo.setAdminOrg(adInfo);
  207. companyInfo = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitInfo(new ObjectUuidPK(adInfo.getCompany().getId()));
  208. //调动单分录对象 , 公司
  209. enInfo.setCompany(companyInfo);
  210. }else{
  211. reason.append("系统中不存在 职位编码为:" + position + " 的职位;");
  212. }
  213. }
  214. enInfo.setBizDate(format.parse(bizDate));//调动日期(必填)
  215. //调动单分录对象 , 备注
  216. enInfo.setDescription(remarks);// 备注
  217. //单据业务配置 DawAAAApVj/maL7Z (公司内调动)
  218. HRBizDefineInfo hrdInfo = HRBizDefineFactory.getLocalInstance(ctx).getHRBizDefineInfo(new ObjectUuidPK("DawAAAApVj/maL7Z"));
  219. //调动单分录对象 , 变动操作
  220. enInfo.setHrBizDefine(hrdInfo);
  221. //变动类型 7ta1EwaZTZmts8L4z/J0LJYRae4= (调动调出)
  222. AffairActionReasonInfo affInfo = AffairActionReasonFactory.getLocalInstance(ctx).getAffairActionReasonInfo(new ObjectUuidPK("7ta1EwaZTZmts8L4z/J0LJYRae4="));
  223. //调动单分录对象 , 变动类型
  224. enInfo.setAffairActionReason(affInfo);
  225. //变动原因编码 ,
  226. if (StringUtils.isNotBlank(variationReason)) {
  227. VariationReasonCollection varCol = VariationReasonFactory.getLocalInstance(ctx).getVariationReasonCollection(" where number='" + variationReason + "'");
  228. if (varCol.size() > 0) {
  229. varInfo = varCol.get(0);
  230. enInfo.setVariationReason(varInfo);
  231. } else {
  232. reason.append("变动原因有误,请认真检查;");
  233. }
  234. } else {// 默认
  235. VariationReasonCollection varCol = VariationReasonFactory.getLocalInstance(ctx).getVariationReasonCollection(" where number='00101'");
  236. if (varCol.size() > 0) {
  237. varInfo = varCol.get(0);
  238. enInfo.setVariationReason(varInfo);
  239. }
  240. }
  241. info.getEntrys().add(enInfo);
  242. FluctuationBizBillFactory.getLocalInstance(ctx).submitEffect(info);
  243. } catch (Exception e) {
  244. e.getMessage();
  245. reason.append(e.getMessage());
  246. }
  247. if (reason.length() > 0) {
  248. returnMap.put("msgType", "0");
  249. returnMap.put("msg", reason.toString());
  250. } else {
  251. returnMap.put("msgType", "1");
  252. returnMap.put("msg", "success");
  253. returnMap.put("fnumber", info.getNumber());
  254. }
  255. return returnMap;
  256. }
  257. // 员工跟用户之间
  258. public Map<String, ObjectBaseInfo> getPerson(Context ctx, String number) {
  259. Map<String, ObjectBaseInfo> map = new HashMap();
  260. PersonInfo peInfo = null;
  261. UserInfo ueInfo = null;
  262. String sql = "SELECT pe.FID PEID , UE.FID UEID FROM T_BD_PERSON PE LEFT OUTER JOIN T_PM_USER UE ON UE.FPersonId = PE.FID WHERE PE.FNUMBER = '" + number + "'";
  263. try {
  264. IRowSet asSet = DbUtil.executeQuery(ctx, sql.toString());
  265. if (asSet.next()) {
  266. if (asSet.getString("PEID") != null) {
  267. peInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(asSet.getString("PEID")));
  268. }
  269. if (asSet.getString("UEID") != null) {
  270. ueInfo = UserFactory.getLocalInstance(ctx).getUserInfo(new ObjectUuidPK(asSet.getString("UEID")));
  271. }
  272. }
  273. } catch (BOSException var8) {
  274. var8.printStackTrace();
  275. } catch (SQLException var9) {
  276. var9.printStackTrace();
  277. } catch (EASBizException var10) {
  278. var10.printStackTrace();
  279. }
  280. map.put("pe", peInfo);
  281. map.put("ue", ueInfo);
  282. return map;
  283. }
  284. /**
  285. * 根据调动者number,查询员工职位id,职位id,行政组织id
  286. * @param ctx
  287. * @param number
  288. * @return
  289. */
  290. public Map<String, ObjectBaseInfo> getPersonAP(Context ctx, String number) {
  291. Map<String, ObjectBaseInfo> map = new HashMap();
  292. //员工职位信息
  293. PersonPositionInfo psoInfo = null;
  294. //行政组织单元
  295. AdminOrgUnitInfo adInfo = null;
  296. //职位
  297. PositionInfo poInfo = null;
  298. //根据调动者number,查询员工职位id,职位id,行政组织id
  299. String sql = "SELECT PSO.FID PSOID,PO.FID POID,AD.FID ADID FROM T_BD_PERSON PE INNER JOIN T_HR_PERSONPOSITION PSO ON PE.FID = PSO.FPERSONID LEFT OUTER JOIN T_ORG_POSITION PO ON PO.FID = PSO.FPRIMARYPOSITIONID LEFT OUTER JOIN T_ORG_ADMIN AD ON AD.FID = PO.FADMINORGUNITID WHERE PE.FNUMBER = '" + number + "'";
  300. try {
  301. IRowSet asSet = DbUtil.executeQuery(ctx, sql.toString());
  302. if (asSet.next()) {
  303. //员工职位id
  304. if (asSet.getString("PSOID") != null) {
  305. //调动者,员工职位信息
  306. psoInfo = PersonPositionFactory.getLocalInstance(ctx).getPersonPositionInfo(new ObjectUuidPK(asSet.getString("PSOID")));
  307. }
  308. //职位id
  309. if (asSet.getString("POID") != null) {
  310. //调动者,职位
  311. poInfo = PositionFactory.getLocalInstance(ctx).getPositionInfo(new ObjectUuidPK(asSet.getString("POID")));
  312. //行政组织id
  313. if (asSet.getString("ADID") != null) {
  314. //调动者,行政组织
  315. adInfo = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitInfo(new ObjectUuidPK(asSet.getString("ADID")));
  316. }
  317. } else {
  318. //查询调动员工历史任职记录,组织,岗位
  319. String exSql = "select FAdminOrgID,FPositionID from T_HR_EmpPostExperienceHis where FPersonID = (SELECT FID FROM T_BD_PERSON WHERE FNUMBER = '" + number + "') " + "order by FEndDateTime desc";
  320. IRowSet exSet = DbUtil.executeQuery(ctx, exSql.toString());
  321. if (exSet.next() && exSet.getString("FPositionID") != null) {
  322. //职位
  323. poInfo = PositionFactory.getLocalInstance(ctx).getPositionInfo(new ObjectUuidPK(exSet.getString("FPositionID")));
  324. if (exSet.getString("FAdminOrgID") != null) {
  325. //行政组织
  326. adInfo = AdminOrgUnitFactory.getLocalInstance(ctx).getAdminOrgUnitInfo(new ObjectUuidPK(exSet.getString("FAdminOrgID")));
  327. }
  328. }
  329. }
  330. }
  331. } catch (BOSException var11) {
  332. var11.printStackTrace();
  333. } catch (SQLException var12) {
  334. var12.printStackTrace();
  335. } catch (EASBizException var13) {
  336. var13.printStackTrace();
  337. }
  338. //调动者number,员工职位id
  339. map.put("pso", psoInfo);
  340. //调动者,职位
  341. map.put("po", poInfo);
  342. //调动者,行政组织
  343. map.put("ad", adInfo);
  344. System.out.println("getPersonAP:" + map);
  345. return map;
  346. }
  347. }