ModifyServiceImpl.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. package cn.com.lzt.leave.service.impl;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  9. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  10. import org.jeecgframework.core.constant.Globals;
  11. import org.jeecgframework.core.util.StringUtil;
  12. import org.jeecgframework.web.system.pojo.base.TSBaseUser;
  13. import org.jeecgframework.web.system.pojo.base.TSDepart;
  14. import org.jeecgframework.web.system.pojo.base.TSUser;
  15. import org.jeecgframework.web.system.pojo.base.TSUserOrg;
  16. import org.jeecgframework.web.system.service.SystemService;
  17. import org.jeecgframework.web.system.service.UserService;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import com.dingtalk.open.client.api.model.corp.CorpUserDetail;
  22. import cn.com.lzt.correction.dao.CorrectionMinidaoDao;
  23. import cn.com.lzt.correction.entity.CorrectionDaoEntity;
  24. import cn.com.lzt.demotetransfer.dao.DemotetransferMinidaoDao;
  25. import cn.com.lzt.dingding.service.DingdingService;
  26. import cn.com.lzt.leave.dao.LeaveMinidaoDao;
  27. import cn.com.lzt.leave.dto.LeaveDto;
  28. import cn.com.lzt.leave.service.ModifyServiceI;
  29. import cn.com.lzt.personnelbasearchivesmanage.entity.PersonnelBaseArchivesManageEntity;
  30. import cn.com.lzt.promotiontransfer.dao.PromotiontransferMinidaoDao;
  31. import cn.com.lzt.sameleveltransfer.dao.SameleveltransferMinidaoDao;
  32. import cn.com.lzt.sameleveltransfer.entity.SamelevelTransferDaoEntity;
  33. import cn.com.lzt.socialsecuritystrategy.entity.SocialSecurityStrategyEntity;
  34. import cn.com.lzt.userchangeslog.entity.UserChangesLogEntity;
  35. import cn.com.lzt.userwagestrategy.entity.UserWagestrategyEntity;
  36. @Service("modifyService")
  37. @Transactional
  38. public class ModifyServiceImpl extends CommonServiceImpl implements ModifyServiceI {
  39. @Autowired
  40. private LeaveMinidaoDao leaveMinidaoDao;
  41. @Autowired
  42. private CorrectionMinidaoDao correctionMinidaoDao;
  43. @Autowired
  44. private SameleveltransferMinidaoDao sameleveltransferMinidaoDao;
  45. @Autowired
  46. private PromotiontransferMinidaoDao promotiontransferMinidaoDao;
  47. @Autowired
  48. private DemotetransferMinidaoDao demotetransferMinidaoDao;
  49. @Autowired
  50. private SystemService systemService;
  51. @Autowired
  52. private DingdingService dingdingService;
  53. @Autowired
  54. private UserService userService;
  55. /**
  56. * 人事申请修改在职状态和所属部门 离职
  57. * @throws ParseException
  58. */
  59. @Override
  60. public void modifyUpdateLeave() throws ParseException{
  61. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  62. Date da = new Date();
  63. //离职申请
  64. List<LeaveDto> leList = leaveMinidaoDao.getByDate(format.parse(format.format(da)));
  65. if(!leList.isEmpty() && leList.size() > 0){
  66. for (LeaveDto leaveDto : leList) {
  67. PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", leaveDto.getUserid());
  68. if(per != null){
  69. if("citui".equals(leaveDto.getLeaveType())){
  70. per.setPositionStatus(Globals.JOBSTATUS_4);
  71. }else{
  72. per.setPositionStatus(Globals.JOBSTATUS_3);
  73. }
  74. per.setLeaveDate(format.parse(format.format(new Date())));
  75. this.saveOrUpdate(per);
  76. this.modifyUpdate(Globals.LEAVE_TYPE, leaveDto.getUserid(), leaveDto.getBelongUnitid(), leaveDto.getCreateName(), "");
  77. }
  78. }
  79. }
  80. }
  81. /**
  82. * 人事申请修改在职状态和所属部门 转正
  83. * @throws ParseException
  84. */
  85. @Override
  86. public void modifyUpdateCorr() throws ParseException{
  87. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  88. Date da = new Date();
  89. //转正申请
  90. List<CorrectionDaoEntity> coList = correctionMinidaoDao.getByDate(format.parse(format.format(da)));
  91. if(!coList.isEmpty() && coList.size() > 0){
  92. for (CorrectionDaoEntity correctionDao : coList) {
  93. PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", correctionDao.getUserid());
  94. if(per != null){
  95. per.setCorrectionDate(format.parse(format.format(new Date())));
  96. per.setPositionStatus(Globals.JOBSTATUS_2);
  97. this.saveOrUpdate(per);
  98. //添加人事变动记录
  99. this.modifyUpdate(Globals.CORRECTION_TYPE, correctionDao.getUserid(), correctionDao.getBelongUnitid(), correctionDao.getCreateName(), "");
  100. }
  101. }
  102. }
  103. }
  104. /**
  105. * 平调
  106. */
  107. @Override
  108. public void modifySameleveltransfer() throws ParseException {
  109. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
  110. Date da = new Date();
  111. String dastr = format.format(da)+"-"+"01";
  112. //平调
  113. List<SamelevelTransferDaoEntity> saList = sameleveltransferMinidaoDao.getByDate(format.parse(dastr));
  114. if(!saList.isEmpty() && saList.size() > 0){
  115. for (SamelevelTransferDaoEntity samelevelTransferDao : saList) {
  116. TSDepart tsDepart = get(TSDepart.class, samelevelTransferDao.getInUnitid());
  117. CriteriaQuery cq = new CriteriaQuery(TSUserOrg.class);
  118. cq.eq("tsUser.id", samelevelTransferDao.getUserid());
  119. cq.add();
  120. cq.eq("ifpluralism", "0");
  121. cq.add();
  122. cq.eq("status", "0");
  123. cq.add();
  124. List<TSUserOrg> tsList = getListByCriteriaQuery(cq, false);
  125. // List<TSUserOrg> tsList = this.getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+samelevelTransferDao.getUserid()+"' and ifpluralism = 0 and status = 0").addEntity(TSUserOrg.class).list();
  126. //List<TSUserOrg> tsList = findListbySql("select * from t_s_user_org where user_id = '"+samelevelTransferDao.getUserid()+"' and ifpluralism = 0 and status = 0");
  127. if(!tsList.isEmpty() && tsList.size() > 0 ){
  128. TSUserOrg tsuo = tsList.get(0);
  129. String sql="delete from t_s_user_org where id='"+tsuo.getId()+"'";
  130. this.executeSql(sql);
  131. // String sqlDel_arrang = "delete from t_bus_user_wagestrategy where userid='" + samelevelTransferDao.getUserid()+"'";
  132. // this.executeSql(sqlDel_arrang);
  133. // System.out.println("delete userwageStr: " + tsuo.getTsUser().getRealName() +":"+tsuo.getTsUser().getId());
  134. StringBuffer hql = new StringBuffer("from UserWagestrategyEntity where userid = :str");
  135. List<UserWagestrategyEntity> wageStrategys = systemService.getSession().createQuery(hql.toString()).setParameter("str", samelevelTransferDao.getUserid()).list();
  136. if(wageStrategys != null && wageStrategys.size()>0) {
  137. UserWagestrategyEntity ws = wageStrategys.get(0);
  138. ws.setBelongUnitid(samelevelTransferDao.getInUnitid());
  139. this.saveOrUpdate(ws);
  140. System.out.println(tsuo.getTsUser().getRealName()+ "的工资策略BelongUnitid改为:"+samelevelTransferDao.getInUnitid());
  141. }
  142. TSUserOrg tSUserOrg1=new TSUserOrg();
  143. TSDepart tSDepart1=new TSDepart();
  144. TSUser tSUser1=tsuo.getTsUser();
  145. tSDepart1.setId(tsDepart.getId());
  146. tSUserOrg1.setTsUser(tSUser1);
  147. tSUserOrg1.setTsDepart(tSDepart1);
  148. tSUserOrg1.setIfpluralism(Globals.PLURALISM_NO.toString());
  149. tSUserOrg1.setIntime(new Date());
  150. tSUserOrg1.setStatus(Globals.Enabled_Status.toString());
  151. this.save(tSUserOrg1);
  152. String message = "数据保存成功,钉钉数据同步成功!";
  153. try {
  154. if(StringUtil.isNotEmpty(tsDepart.getDingdepartid())) {
  155. List<Long> departIdList = new ArrayList<Long>();
  156. departIdList.add(Long.valueOf(tsDepart.getDingdepartid()));
  157. CorpUserDetail corpUserDetail = dingdingService.getUser(tSUser1.getId());
  158. boolean dingFlg = false;
  159. if(StringUtil.isNotEmpty(corpUserDetail.getUserid())) {
  160. dingFlg = dingdingService.updateUser(tSUser1.getId(), tSUser1.getRealName(), departIdList,tSUser1.getMobilePhone(), tSUser1.getUserName());
  161. } else {
  162. dingFlg = dingdingService.createUser(tSUser1.getId(), tSUser1.getRealName(), departIdList,tSUser1.getMobilePhone(), tSUser1.getUserName());
  163. }
  164. if(dingFlg) {
  165. tSUser1.setDingIsSynchronization(Globals.DingIsSynchronization_YES.toString());
  166. }else{
  167. message = "数据保存成功,钉钉数据同步失败!";
  168. tSUser1.setDingIsSynchronization(Globals.DingIsSynchronization_NO.toString());
  169. }
  170. } else {
  171. message = "数据保存成功,所属部门没有同步到钉钉,同步失败!";
  172. }
  173. message = message + "[user:" +tSUser1.getRealName()+"]";
  174. }catch(Exception e) {
  175. System.out.println(message);
  176. }
  177. //添加人事变动记录
  178. this.modifyUpdate(Globals.SAMELEVEL_TRANSFER_TYPE, samelevelTransferDao.getUserid(), samelevelTransferDao.getBelongUnitid(), samelevelTransferDao.getCreateName(),samelevelTransferDao.getInUnitid());
  179. }
  180. }
  181. }
  182. }
  183. /**
  184. * 升职
  185. */
  186. @Override
  187. public void modifyPromotiontransfer() throws ParseException {
  188. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  189. Date da = new Date();
  190. //升职 inPostid
  191. List<SamelevelTransferDaoEntity> smList = promotiontransferMinidaoDao.getByDate(format.parse(format.format(da)));
  192. if(!smList.isEmpty() && smList.size() > 0){
  193. for (SamelevelTransferDaoEntity samelevelTransferDao : smList) {
  194. PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", samelevelTransferDao.getUserid());
  195. if(per != null){
  196. per.setBelongDutiesid(samelevelTransferDao.getInDutiesid());
  197. per.setInPostid(samelevelTransferDao.getInPostid());
  198. saveOrUpdate(per);
  199. //添加人事变动记录
  200. this.modifyUpdate(Globals.PROMOTION_TRANSFER_TYPE, samelevelTransferDao.getUserid(), samelevelTransferDao.getBelongUnitid(), samelevelTransferDao.getCreateName(),samelevelTransferDao.getInUnitid());
  201. }
  202. TSDepart tsDepart = get(TSDepart.class, samelevelTransferDao.getInUnitid());
  203. //List<TSUserOrg> tsList = findListbySql("select * from t_s_user_org where user_id = '"+samelevelTransferDao.getUserid()+"' and ifpluralism = 0 and status = 0");
  204. List<TSUserOrg> tsList = this.getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+samelevelTransferDao.getUserid()+"' and ifpluralism = 0 and status = 0").addEntity(TSUserOrg.class).list();
  205. if(!tsList.isEmpty() && tsList.size() > 0 ){
  206. tsList.get(0).setTsDepart(tsDepart);
  207. this.saveOrUpdate(tsList.get(0));
  208. }
  209. }
  210. }
  211. }
  212. /**
  213. * 降职
  214. */
  215. @Override
  216. public void modifyDemotetransfer() throws ParseException {
  217. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  218. Date da = new Date();
  219. //降职
  220. List<SamelevelTransferDaoEntity> sList = demotetransferMinidaoDao.getByDate(format.parse(format.format(da)));
  221. if(!sList.isEmpty() && sList.size() > 0){
  222. for (SamelevelTransferDaoEntity samelevelTransferDao : sList) {
  223. PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", samelevelTransferDao.getUserid());
  224. if(per != null){
  225. per.setBelongDutiesid(samelevelTransferDao.getInDutiesid());
  226. per.setInPostid(samelevelTransferDao.getInPostid());
  227. this.saveOrUpdate(per);
  228. //添加人事变动记录
  229. this.modifyUpdate(Globals.DEMOTE_TRANSFER_TYPE, samelevelTransferDao.getUserid(), samelevelTransferDao.getBelongUnitid(), samelevelTransferDao.getCreateName(),samelevelTransferDao.getInUnitid());
  230. }
  231. TSDepart tsDepart = get(TSDepart.class, samelevelTransferDao.getInUnitid());
  232. List<TSUserOrg> tsList = this.getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+samelevelTransferDao.getUserid()+"' and ifpluralism = 0 and status = 0").addEntity(TSUserOrg.class).list();
  233. if(!tsList.isEmpty() && tsList.size() > 0 ){
  234. tsList.get(0).setTsDepart(tsDepart);
  235. this.saveOrUpdate(tsList.get(0));
  236. }
  237. }
  238. }
  239. }
  240. /**
  241. * 添加人事表动记录信息
  242. * @param bustable 变动类型
  243. * @param userid 变动人员
  244. * @param belongUnitid 变动人员原单位
  245. * @param createName 申请人姓名
  246. * @param inUnitid 调入单位
  247. */
  248. private void modifyUpdate(String bustable,String userid,String belongUnitid,String createName,String inUnitid){
  249. if (StringUtils.isNotEmpty(userid)) {
  250. UserChangesLogEntity uc = new UserChangesLogEntity();
  251. uc.setChangeTime(new Date());
  252. TSDepart t = this.get(TSDepart.class,belongUnitid);
  253. TSBaseUser tsBaseUser = this.get(TSBaseUser.class, userid);
  254. UserWagestrategyEntity ussfEntity = this.findUniqueByProperty(UserWagestrategyEntity.class, "userid", userid);
  255. if(ussfEntity != null && StringUtils.isNotEmpty(ussfEntity.getSocialSecurityStrategyid())){
  256. SocialSecurityStrategyEntity soc = get(SocialSecurityStrategyEntity.class,ussfEntity.getSocialSecurityStrategyid());
  257. if(soc != null){
  258. uc.setPayUnit(soc.getSocialSecurityUnit());
  259. }
  260. }
  261. //修改用户组织机构关联表
  262. /*StringBuffer hql = new StringBuffer("from TSUserOrg where tsUser.id = :userid and ifpluralism = 0 and status = 0");
  263. List<TSUserOrg> or = this.getSession().createQuery(hql.toString()).setParameter("userid", tsBaseUser.getId()).list();*/
  264. //List<TSUserOrg> or = this.getSession().createSQLQuery("select * from t_s_user_org where user_id = '"+tsBaseUser.getId()+"' and ifpluralism = 0 and status = 0").addEntity(TSUserOrg.class).list();
  265. uc.setUserCode(tsBaseUser.getUserName());
  266. uc.setUserName(tsBaseUser.getRealName());
  267. uc.setBelongUnitid(t.getId());
  268. if(Globals.LEAVE_TYPE.equals(bustable)){ //离职
  269. uc.setChangeType(Globals.CHANGE_TYPE_LIZHI);
  270. uc.setPayRemindStatus("1");
  271. /*PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", userid);
  272. if(per != null && "1".equals(per.getIfpayment())){
  273. }*/
  274. }else if(Globals.CORRECTION_TYPE.equals(bustable)){ //转正
  275. uc.setChangeType(Globals.CHANGE_TYPE_ZHUANZHENG);
  276. }else{
  277. uc.setInUnitid(inUnitid);
  278. if(Globals.SAMELEVEL_TRANSFER_TYPE.equals(bustable)){ //平调
  279. /*if(!or.isEmpty() && or.size() > 0){
  280. or.get(0).setTsDepart(t);
  281. }*/
  282. if(ussfEntity != null){
  283. ussfEntity.setPjtId(getBybelongId(t.getId()));
  284. }
  285. uc.setChangeType(Globals.CHANGE_TYPE_PINGDIAO);
  286. }else if(Globals.PROMOTION_TRANSFER_TYPE.equals(bustable)){ //升职
  287. /*if(!or.isEmpty() && or.size() > 0){
  288. or.get(0).setTsDepart(t);
  289. }*/
  290. if(ussfEntity != null){
  291. ussfEntity.setPjtId(getBybelongId(t.getId()));
  292. }
  293. uc.setChangeType(Globals.CHANGE_TYPE_SHENGZHI);
  294. }else if(Globals.DEMOTE_TRANSFER_TYPE.equals(bustable)){//降职
  295. /*if(!or.isEmpty() && or.size() > 0){
  296. or.get(0).setTsDepart(t);
  297. }*/
  298. if(ussfEntity != null){
  299. ussfEntity.setPjtId(getBybelongId(t.getId()));
  300. }
  301. uc.setChangeType(Globals.CHANGE_TYPE_JIANGZHI);
  302. }else if(Globals.SNAP_SINGLEBORROW_TYPE.equals(bustable)){//单次
  303. uc.setChangeType(Globals.CHANGE_TYPE_DANCI);
  304. }else if(Globals.SNAP_REGULARBORROW_TYPE.equals(bustable)){//定期
  305. uc.setChangeType(Globals.CHANGE_TYPE_DINGQI);
  306. }
  307. }
  308. uc.setApplicant(createName);
  309. //this.saveOrUpdate(or.get(0));
  310. if(ussfEntity != null){
  311. this.saveOrUpdate(ussfEntity);
  312. }
  313. this.save(uc);
  314. //this.addLog(temp, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  315. }
  316. }
  317. /**
  318. * 通过人查询所属项目
  319. * @param userid
  320. * @return
  321. */
  322. @Override
  323. public String getBybelongId(String orgid){
  324. String temp = "";
  325. StringBuffer hql = new StringBuffer("from TSDepart where id = :userid");
  326. List<TSDepart> tsList = systemService.getSession().createQuery(hql.toString()).setParameter("userid", orgid).list();
  327. if(!tsList.isEmpty()){
  328. TSDepart tsDepart = tsList.get(0);
  329. if("1".equals(tsDepart.getOrgType()) || "3".equals(tsDepart.getOrgType()) || "4".equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){
  330. temp = tsDepart.getId();
  331. }else if("2".equals(tsDepart.getOrgType()) && "1".equals(tsDepart.getTSPDepart().getOrgType())){
  332. temp = tsDepart.getId();
  333. }else{
  334. temp = selectById(tsDepart.getId());
  335. }
  336. //temp = systemService.get(TSDepart.class, temp).getDepartname();
  337. }
  338. return temp;
  339. }
  340. private String selectById(String id){
  341. String temp = "";
  342. TSDepart tsDepart =systemService.getEntity(TSDepart.class,id);
  343. if("3".equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){
  344. temp = tsDepart.getId();
  345. }else{
  346. if(tsDepart.getTSPDepart() != null){
  347. selectById(tsDepart.getTSPDepart().getId());
  348. temp = tsDepart.getTSPDepart().getId();
  349. }
  350. }
  351. return temp;
  352. }
  353. /**
  354. * 通过所属部门查询所属项目
  355. * @param userid
  356. * @return
  357. */
  358. @Override
  359. public String getByorgId(String orgid){
  360. String temp = "";
  361. StringBuffer hql = new StringBuffer("from TSDepart where id = :userid");
  362. List<TSDepart> tsList = systemService.getSession().createQuery(hql.toString()).setParameter("userid", orgid).list();
  363. if(!tsList.isEmpty()){
  364. TSDepart tsDepart = tsList.get(0);
  365. if("1".equals(tsDepart.getOrgType()) || "3".equals(tsDepart.getOrgType()) || "4".equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){
  366. temp = tsDepart.getId();
  367. }else if("2".equals(tsDepart.getOrgType()) && "1".equals(tsDepart.getTSPDepart().getOrgType())){
  368. temp = tsDepart.getId();
  369. }else{
  370. temp = selectById(tsDepart.getId());
  371. }
  372. if(temp.equals(orgid)){
  373. temp = systemService.get(TSDepart.class, temp).getDepartname();
  374. }else{
  375. temp = systemService.get(TSDepart.class, temp).getDepartname()+"-"+tsDepart.getDepartname();
  376. }
  377. }
  378. return temp;
  379. }
  380. }