package cn.com.lzt.leave.service.impl; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery; import org.jeecgframework.core.common.service.impl.CommonServiceImpl; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.StringUtil; import org.jeecgframework.web.system.pojo.base.TSBaseUser; import org.jeecgframework.web.system.pojo.base.TSDepart; import org.jeecgframework.web.system.pojo.base.TSUser; import org.jeecgframework.web.system.pojo.base.TSUserOrg; import org.jeecgframework.web.system.service.SystemService; import org.jeecgframework.web.system.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.dingtalk.open.client.api.model.corp.CorpUserDetail; import cn.com.lzt.correction.dao.CorrectionMinidaoDao; import cn.com.lzt.correction.entity.CorrectionDaoEntity; import cn.com.lzt.demotetransfer.dao.DemotetransferMinidaoDao; import cn.com.lzt.dingding.service.DingdingService; import cn.com.lzt.leave.dao.LeaveMinidaoDao; import cn.com.lzt.leave.dto.LeaveDto; import cn.com.lzt.leave.service.ModifyServiceI; import cn.com.lzt.personnelbasearchivesmanage.entity.PersonnelBaseArchivesManageEntity; import cn.com.lzt.promotiontransfer.dao.PromotiontransferMinidaoDao; import cn.com.lzt.sameleveltransfer.dao.SameleveltransferMinidaoDao; import cn.com.lzt.sameleveltransfer.entity.SamelevelTransferDaoEntity; import cn.com.lzt.socialsecuritystrategy.entity.SocialSecurityStrategyEntity; import cn.com.lzt.userchangeslog.entity.UserChangesLogEntity; import cn.com.lzt.userwagestrategy.entity.UserWagestrategyEntity; @Service("modifyService") @Transactional public class ModifyServiceImpl extends CommonServiceImpl implements ModifyServiceI { @Autowired private LeaveMinidaoDao leaveMinidaoDao; @Autowired private CorrectionMinidaoDao correctionMinidaoDao; @Autowired private SameleveltransferMinidaoDao sameleveltransferMinidaoDao; @Autowired private PromotiontransferMinidaoDao promotiontransferMinidaoDao; @Autowired private DemotetransferMinidaoDao demotetransferMinidaoDao; @Autowired private SystemService systemService; @Autowired private DingdingService dingdingService; @Autowired private UserService userService; /** * 人事申请修改在职状态和所属部门 离职 * @throws ParseException */ @Override public void modifyUpdateLeave() throws ParseException{ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date da = new Date(); //离职申请 List leList = leaveMinidaoDao.getByDate(format.parse(format.format(da))); if(!leList.isEmpty() && leList.size() > 0){ for (LeaveDto leaveDto : leList) { PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", leaveDto.getUserid()); if(per != null){ if("citui".equals(leaveDto.getLeaveType())){ per.setPositionStatus(Globals.JOBSTATUS_4); }else{ per.setPositionStatus(Globals.JOBSTATUS_3); } per.setLeaveDate(format.parse(format.format(new Date()))); this.saveOrUpdate(per); this.modifyUpdate(Globals.LEAVE_TYPE, leaveDto.getUserid(), leaveDto.getBelongUnitid(), leaveDto.getCreateName(), ""); } } } } /** * 人事申请修改在职状态和所属部门 转正 * @throws ParseException */ @Override public void modifyUpdateCorr() throws ParseException{ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date da = new Date(); //转正申请 List coList = correctionMinidaoDao.getByDate(format.parse(format.format(da))); if(!coList.isEmpty() && coList.size() > 0){ for (CorrectionDaoEntity correctionDao : coList) { PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", correctionDao.getUserid()); if(per != null){ per.setCorrectionDate(format.parse(format.format(new Date()))); per.setPositionStatus(Globals.JOBSTATUS_2); this.saveOrUpdate(per); //添加人事变动记录 this.modifyUpdate(Globals.CORRECTION_TYPE, correctionDao.getUserid(), correctionDao.getBelongUnitid(), correctionDao.getCreateName(), ""); } } } } /** * 平调 */ @Override public void modifySameleveltransfer() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); Date da = new Date(); String dastr = format.format(da)+"-"+"01"; //平调 List saList = sameleveltransferMinidaoDao.getByDate(format.parse(dastr)); if(!saList.isEmpty() && saList.size() > 0){ for (SamelevelTransferDaoEntity samelevelTransferDao : saList) { TSDepart tsDepart = get(TSDepart.class, samelevelTransferDao.getInUnitid()); CriteriaQuery cq = new CriteriaQuery(TSUserOrg.class); cq.eq("tsUser.id", samelevelTransferDao.getUserid()); cq.add(); cq.eq("ifpluralism", "0"); cq.add(); cq.eq("status", "0"); cq.add(); List tsList = getListByCriteriaQuery(cq, false); // List 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(); //List tsList = findListbySql("select * from t_s_user_org where user_id = '"+samelevelTransferDao.getUserid()+"' and ifpluralism = 0 and status = 0"); if(!tsList.isEmpty() && tsList.size() > 0 ){ TSUserOrg tsuo = tsList.get(0); String sql="delete from t_s_user_org where id='"+tsuo.getId()+"'"; this.executeSql(sql); // String sqlDel_arrang = "delete from t_bus_user_wagestrategy where userid='" + samelevelTransferDao.getUserid()+"'"; // this.executeSql(sqlDel_arrang); // System.out.println("delete userwageStr: " + tsuo.getTsUser().getRealName() +":"+tsuo.getTsUser().getId()); StringBuffer hql = new StringBuffer("from UserWagestrategyEntity where userid = :str"); List wageStrategys = systemService.getSession().createQuery(hql.toString()).setParameter("str", samelevelTransferDao.getUserid()).list(); if(wageStrategys != null && wageStrategys.size()>0) { UserWagestrategyEntity ws = wageStrategys.get(0); ws.setBelongUnitid(samelevelTransferDao.getInUnitid()); this.saveOrUpdate(ws); System.out.println(tsuo.getTsUser().getRealName()+ "的工资策略BelongUnitid改为:"+samelevelTransferDao.getInUnitid()); } TSUserOrg tSUserOrg1=new TSUserOrg(); TSDepart tSDepart1=new TSDepart(); TSUser tSUser1=tsuo.getTsUser(); tSDepart1.setId(tsDepart.getId()); tSUserOrg1.setTsUser(tSUser1); tSUserOrg1.setTsDepart(tSDepart1); tSUserOrg1.setIfpluralism(Globals.PLURALISM_NO.toString()); tSUserOrg1.setIntime(new Date()); tSUserOrg1.setStatus(Globals.Enabled_Status.toString()); this.save(tSUserOrg1); String message = "数据保存成功,钉钉数据同步成功!"; try { if(StringUtil.isNotEmpty(tsDepart.getDingdepartid())) { List departIdList = new ArrayList(); departIdList.add(Long.valueOf(tsDepart.getDingdepartid())); CorpUserDetail corpUserDetail = dingdingService.getUser(tSUser1.getId()); boolean dingFlg = false; if(StringUtil.isNotEmpty(corpUserDetail.getUserid())) { dingFlg = dingdingService.updateUser(tSUser1.getId(), tSUser1.getRealName(), departIdList,tSUser1.getMobilePhone(), tSUser1.getUserName()); } else { dingFlg = dingdingService.createUser(tSUser1.getId(), tSUser1.getRealName(), departIdList,tSUser1.getMobilePhone(), tSUser1.getUserName()); } if(dingFlg) { tSUser1.setDingIsSynchronization(Globals.DingIsSynchronization_YES.toString()); }else{ message = "数据保存成功,钉钉数据同步失败!"; tSUser1.setDingIsSynchronization(Globals.DingIsSynchronization_NO.toString()); } } else { message = "数据保存成功,所属部门没有同步到钉钉,同步失败!"; } message = message + "[user:" +tSUser1.getRealName()+"]"; }catch(Exception e) { System.out.println(message); } //添加人事变动记录 this.modifyUpdate(Globals.SAMELEVEL_TRANSFER_TYPE, samelevelTransferDao.getUserid(), samelevelTransferDao.getBelongUnitid(), samelevelTransferDao.getCreateName(),samelevelTransferDao.getInUnitid()); } } } } /** * 升职 */ @Override public void modifyPromotiontransfer() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date da = new Date(); //升职 inPostid List smList = promotiontransferMinidaoDao.getByDate(format.parse(format.format(da))); if(!smList.isEmpty() && smList.size() > 0){ for (SamelevelTransferDaoEntity samelevelTransferDao : smList) { PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", samelevelTransferDao.getUserid()); if(per != null){ per.setBelongDutiesid(samelevelTransferDao.getInDutiesid()); per.setInPostid(samelevelTransferDao.getInPostid()); saveOrUpdate(per); //添加人事变动记录 this.modifyUpdate(Globals.PROMOTION_TRANSFER_TYPE, samelevelTransferDao.getUserid(), samelevelTransferDao.getBelongUnitid(), samelevelTransferDao.getCreateName(),samelevelTransferDao.getInUnitid()); } TSDepart tsDepart = get(TSDepart.class, samelevelTransferDao.getInUnitid()); //List tsList = findListbySql("select * from t_s_user_org where user_id = '"+samelevelTransferDao.getUserid()+"' and ifpluralism = 0 and status = 0"); List 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(); if(!tsList.isEmpty() && tsList.size() > 0 ){ tsList.get(0).setTsDepart(tsDepart); this.saveOrUpdate(tsList.get(0)); } } } } /** * 降职 */ @Override public void modifyDemotetransfer() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date da = new Date(); //降职 List sList = demotetransferMinidaoDao.getByDate(format.parse(format.format(da))); if(!sList.isEmpty() && sList.size() > 0){ for (SamelevelTransferDaoEntity samelevelTransferDao : sList) { PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", samelevelTransferDao.getUserid()); if(per != null){ per.setBelongDutiesid(samelevelTransferDao.getInDutiesid()); per.setInPostid(samelevelTransferDao.getInPostid()); this.saveOrUpdate(per); //添加人事变动记录 this.modifyUpdate(Globals.DEMOTE_TRANSFER_TYPE, samelevelTransferDao.getUserid(), samelevelTransferDao.getBelongUnitid(), samelevelTransferDao.getCreateName(),samelevelTransferDao.getInUnitid()); } TSDepart tsDepart = get(TSDepart.class, samelevelTransferDao.getInUnitid()); List 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(); if(!tsList.isEmpty() && tsList.size() > 0 ){ tsList.get(0).setTsDepart(tsDepart); this.saveOrUpdate(tsList.get(0)); } } } } /** * 添加人事表动记录信息 * @param bustable 变动类型 * @param userid 变动人员 * @param belongUnitid 变动人员原单位 * @param createName 申请人姓名 * @param inUnitid 调入单位 */ private void modifyUpdate(String bustable,String userid,String belongUnitid,String createName,String inUnitid){ if (StringUtils.isNotEmpty(userid)) { UserChangesLogEntity uc = new UserChangesLogEntity(); uc.setChangeTime(new Date()); TSDepart t = this.get(TSDepart.class,belongUnitid); TSBaseUser tsBaseUser = this.get(TSBaseUser.class, userid); UserWagestrategyEntity ussfEntity = this.findUniqueByProperty(UserWagestrategyEntity.class, "userid", userid); if(ussfEntity != null && StringUtils.isNotEmpty(ussfEntity.getSocialSecurityStrategyid())){ SocialSecurityStrategyEntity soc = get(SocialSecurityStrategyEntity.class,ussfEntity.getSocialSecurityStrategyid()); if(soc != null){ uc.setPayUnit(soc.getSocialSecurityUnit()); } } //修改用户组织机构关联表 /*StringBuffer hql = new StringBuffer("from TSUserOrg where tsUser.id = :userid and ifpluralism = 0 and status = 0"); List or = this.getSession().createQuery(hql.toString()).setParameter("userid", tsBaseUser.getId()).list();*/ //List 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(); uc.setUserCode(tsBaseUser.getUserName()); uc.setUserName(tsBaseUser.getRealName()); uc.setBelongUnitid(t.getId()); if(Globals.LEAVE_TYPE.equals(bustable)){ //离职 uc.setChangeType(Globals.CHANGE_TYPE_LIZHI); uc.setPayRemindStatus("1"); /*PersonnelBaseArchivesManageEntity per = findUniqueByProperty(PersonnelBaseArchivesManageEntity.class, "userid", userid); if(per != null && "1".equals(per.getIfpayment())){ }*/ }else if(Globals.CORRECTION_TYPE.equals(bustable)){ //转正 uc.setChangeType(Globals.CHANGE_TYPE_ZHUANZHENG); }else{ uc.setInUnitid(inUnitid); if(Globals.SAMELEVEL_TRANSFER_TYPE.equals(bustable)){ //平调 /*if(!or.isEmpty() && or.size() > 0){ or.get(0).setTsDepart(t); }*/ if(ussfEntity != null){ ussfEntity.setPjtId(getBybelongId(t.getId())); } uc.setChangeType(Globals.CHANGE_TYPE_PINGDIAO); }else if(Globals.PROMOTION_TRANSFER_TYPE.equals(bustable)){ //升职 /*if(!or.isEmpty() && or.size() > 0){ or.get(0).setTsDepart(t); }*/ if(ussfEntity != null){ ussfEntity.setPjtId(getBybelongId(t.getId())); } uc.setChangeType(Globals.CHANGE_TYPE_SHENGZHI); }else if(Globals.DEMOTE_TRANSFER_TYPE.equals(bustable)){//降职 /*if(!or.isEmpty() && or.size() > 0){ or.get(0).setTsDepart(t); }*/ if(ussfEntity != null){ ussfEntity.setPjtId(getBybelongId(t.getId())); } uc.setChangeType(Globals.CHANGE_TYPE_JIANGZHI); }else if(Globals.SNAP_SINGLEBORROW_TYPE.equals(bustable)){//单次 uc.setChangeType(Globals.CHANGE_TYPE_DANCI); }else if(Globals.SNAP_REGULARBORROW_TYPE.equals(bustable)){//定期 uc.setChangeType(Globals.CHANGE_TYPE_DINGQI); } } uc.setApplicant(createName); //this.saveOrUpdate(or.get(0)); if(ussfEntity != null){ this.saveOrUpdate(ussfEntity); } this.save(uc); //this.addLog(temp, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); } } /** * 通过人查询所属项目 * @param userid * @return */ @Override public String getBybelongId(String orgid){ String temp = ""; StringBuffer hql = new StringBuffer("from TSDepart where id = :userid"); List tsList = systemService.getSession().createQuery(hql.toString()).setParameter("userid", orgid).list(); if(!tsList.isEmpty()){ TSDepart tsDepart = tsList.get(0); if("1".equals(tsDepart.getOrgType()) || "3".equals(tsDepart.getOrgType()) || "4".equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){ temp = tsDepart.getId(); }else if("2".equals(tsDepart.getOrgType()) && "1".equals(tsDepart.getTSPDepart().getOrgType())){ temp = tsDepart.getId(); }else{ temp = selectById(tsDepart.getId()); } //temp = systemService.get(TSDepart.class, temp).getDepartname(); } return temp; } private String selectById(String id){ String temp = ""; TSDepart tsDepart =systemService.getEntity(TSDepart.class,id); if("3".equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){ temp = tsDepart.getId(); }else{ if(tsDepart.getTSPDepart() != null){ selectById(tsDepart.getTSPDepart().getId()); temp = tsDepart.getTSPDepart().getId(); } } return temp; } /** * 通过所属部门查询所属项目 * @param userid * @return */ @Override public String getByorgId(String orgid){ String temp = ""; StringBuffer hql = new StringBuffer("from TSDepart where id = :userid"); List tsList = systemService.getSession().createQuery(hql.toString()).setParameter("userid", orgid).list(); if(!tsList.isEmpty()){ TSDepart tsDepart = tsList.get(0); if("1".equals(tsDepart.getOrgType()) || "3".equals(tsDepart.getOrgType()) || "4".equals(tsDepart.getOrgType()) || "5".equals(tsDepart.getOrgType())){ temp = tsDepart.getId(); }else if("2".equals(tsDepart.getOrgType()) && "1".equals(tsDepart.getTSPDepart().getOrgType())){ temp = tsDepart.getId(); }else{ temp = selectById(tsDepart.getId()); } if(temp.equals(orgid)){ temp = systemService.get(TSDepart.class, temp).getDepartname(); }else{ temp = systemService.get(TSDepart.class, temp).getDepartname()+"-"+tsDepart.getDepartname(); } } return temp; } }