获取员工合同信息列表 定时任务

/**
     * 获取员工合同信息列表 定时任务
     * @param
     * @return
     */
    @Override
    public boolean getTimerTaskEmployeeContractList() {
        //获取合同设置信息
        EmployeeContractSet contractSet=new EmployeeContractSet();
        contractSet.setTenantId(AuthUtil.getTenantId());
        List<EmployeeContractSet>setList=list(Condition.getQueryWrapper(contractSet).orderByDesc("times"));
        EmployeeBasicInformation bean =new EmployeeBasicInformation();
        bean.setTenantId(AuthUtil.getTenantId());
        bean.setIsDeleted(0);
        bean.setIsInform("0");
        List<EmployeeBasicInformation>list=employeeBasicInformationServiceImpl.list(Condition.getQueryWrapper(bean));
        log.info("获取员工信息list========"+list);
        if(Func.isNotEmpty(setList)&&Func.isNotEmpty(list)){
            EmployeeContractSet setInfo=setList.get(0);
            //合同结束时间
            String nowDate=new SimpleDateFormat("yyyy-MM-dd").format(new Date());
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String endTime = df.format(new Date().getTime()+Long.valueOf(setInfo.getContractExpire())*24*60*60*1000);
            //筛选出合同快到期的人
            String realNames="合同"+setInfo.getContractExpire()+"之天内"+endTime+"日之前到期员工姓名:";
            Boolean isInform=false;
            for(EmployeeBasicInformation basicInfo:list){
                if(basicInfo.getContractEndDate().compareTo(nowDate)>=0 && basicInfo.getContractEndDate().compareTo(endTime)<=0){
                    realNames+=deptUserEmployeeUtil.getUserById(basicInfo.getId()).getRealName()+"  ";//合同快到期的用户名
                    //将员工状态改为已经通知
                    EmployeeBasicInformation information=new EmployeeBasicInformation();
                    information.setId(basicInfo.getId());
                    information.setIsInform("1");
                    employeeBasicInformationServiceImpl.updateById(information);
                    isInform=true;
                }
            }
            realNames.trim();//去掉结尾空格
            //开启通知
            if(isInform && "0".equals(setInfo.getIsOpen())){//0开启
                List<User>weChatIds=new ArrayList<User>();
                //获取人事部主管
                String deptId=deptUserEmployeeUtil.getDeptId(AuthUtil.getTenantId(),"人力资源部");
                String roleId=deptUserEmployeeUtil.getRoleId(AuthUtil.getTenantId(),"人事");
                String mangerRoleId=deptUserEmployeeUtil.getRoleId(AuthUtil.getTenantId(),"主管");
                if(setInfo.getNotificationPerson().contains("2")){//人事
                    List<User>personnelUsers=deptUserEmployeeUtil.getUserListByRoleIdAndDeptId(roleId,deptId);//人事角色用户
                    if(Func.isNotEmpty(personnelUsers)){
                        for(User usr:personnelUsers){
                            weChatIds.add(usr);
                        }
                    }
                }
                if(setInfo.getNotificationPerson().contains("3")){//人事主管
                    //根据角色名称获取用户
                    List<User>userList=deptUserEmployeeUtil.getUserListByRoleIdAndDeptId(mangerRoleId,deptId);//主管
                    if(Func.isNotEmpty(userList)){
                        for(User usr:userList){
                            weChatIds.add(usr);
                        }
                    }
                }
                //获取指定接收人id
                String[]assignNotificationPersonIds=setInfo.getAssignNotificationPersonCode().split(",");
                if(Func.isNotEmpty(assignNotificationPersonIds)){
                    for(String id:assignNotificationPersonIds){
                        if(Func.isNotEmpty(id)){
                            User user=deptUserEmployeeUtil.getUserById(Long.valueOf(id));
                            if(Func.isNotEmpty(user)){
                                weChatIds.add(user);
                            }
                        }
                    }
                }
                if(Func.isNotEmpty(weChatIds)){
                    log.info("进入通知》》》weChatIds==="+weChatIds);
                    for(User uer:weChatIds){
                        //获取用户的微信id
                        //默认text
                        WeChatSendMsgTextParam text = new WeChatSendMsgTextParam();
                        text.setTouser(uer.getWeChatId());
                        text.setContent(realNames);
                        weChatClient.sendTextMsgFlow(String.valueOf(uer.getId()),uer.getRealName(),"",text);
                    }
                }
                for(EmployeeBasicInformation basicInfo:list){
                    if(basicInfo.getContractEndDate().compareTo(nowDate)>=0 && basicInfo.getContractEndDate().compareTo(endTime)<=0){
                        //将员工状态改为已经通知
                        EmployeeBasicInformation information=new EmployeeBasicInformation();
                        information.setId(basicInfo.getId());
                        information.setIsInform("1");
                        employeeBasicInformationServiceImpl.updateById(information);
                    }
                }
            }
        }
        return true;
    }

    /**
     * 获取修改记录信息,保存修改记录信息
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveRecordMsg(EmployeeContractSet original,EmployeeContractSet newInfo){
        Map<String,Object>isNull=JSONObject.parseObject(JSONObject.toJSONString(original),Map.class);
        if(!Func.isEmpty(isNull)){
            if("0".equals(original.getIsOpen())){
                original.setIsOpen("开启");
            }
            if("1".equals(original.getIsOpen())){
                original.setIsOpen("关闭");
            }
            log.info("保存修改记录信息original==="+original);
            String personName="";
            if(Func.isNotEmpty(original.getNotificationPerson())){
                String[]personList=original.getNotificationPerson().split(",");
                for (String person:personList){
                    if("2".equals(person)){
                        personName+="人事 ";
                    }
                    if("3".equals(person)){
                        personName+="主管";
                    }
                }
                original.setNotificationPerson(personName);
            }

        }
        Map<String,Object>isNullNew=JSONObject.parseObject(JSONObject.toJSONString(newInfo),Map.class);
        if(!Func.isEmpty(isNullNew)){
            if("0".equals(newInfo.getIsOpen())){
                newInfo.setIsOpen("开启");
            }
            if("1".equals(newInfo.getIsOpen())){
                newInfo.setIsOpen("关闭");
            }
            String personName="";
            if(Func.isNotEmpty(original.getNotificationPerson())){
                String[]personList=original.getNotificationPerson().split(",");
                for (String person:personList){
                    if("2".equals(person)){
                        personName+="人事 ";
                    }
                    if("3".equals(person)){
                        personName+="主管";
                    }
                }
                original.setNotificationPerson(personName);
            }
        }
        String updateTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:SSS").format(new Date());
        //将原数据和新数据转换成map
        Map<String,Object>originalMap= JSONObject.parseObject(JSONObject.toJSONString(original),Map.class);
        Map<String,Object>newInfoMap=JSONObject.parseObject(JSONObject.toJSONString(newInfo),Map.class);
        String[] nameList= EmployeeConstant.CONTRACT_SET.split(",");
        for(String name:nameList){
            EmployeeBasicInformationUpdateRecord record=new EmployeeBasicInformationUpdateRecord();
            //修改之前的数据
            if(Func.isNotEmpty(original)&& Func.isNotEmpty(newInfoMap)){
                if(Func.isNotEmpty(newInfoMap.get(name.split(":")[0]))){
                    record.setPersonName("合同设置");
                    record.setUpdateItem((name.split(":")[1]));//变更项目
                    record.setUpdateTime(updateTime);//修改时间
                    record.setOriginalContent(String.valueOf(originalMap.get(name.split(":")[0])));//原内容
                    record.setUpdateContent(String.valueOf(newInfoMap.get(name.split(":")[0])));//修改内容
                    record.setAfterUpdateContent(String.valueOf(newInfoMap.get(name.split(":")[0])));//修改后的内容
                    record.setUpdatePeople(newInfo.getOperationPerson());//修改人名称
                    record.setTenantId(AuthUtil.getTenantId());//租户id
                    //将信息插入记录表
                    updateRecordServiceImpl.save(record);
                }
            }
        }
    }
public interface EmployeeConstant {
	String EMPLOYEE_INFO="idCardNumber:身份证号码,entryDate:入职日期,entryMonths:入职月数,becomeFullMemberDate:转正日期,department:入职部门名称,groups:组别," +
		"groupCode:组编号,position:职位,function:职能(角色),positionRank:职级名称,positionRankCode:职级编号,isMarry:婚否,contractStartDate:合同开始日期," +
		"contractEndDate:合同结束日期,profession:专业,educationBackground:学历,politicsStatus:政治面貌,schoolOfGraduation:毕业院校,censusRegisterAddress:户籍地址," +
		"registeredResidenceType:户口类型,temporaryAddress:暂住地址,emergencyContact:紧急联系人,emergencyContactPhone:紧急联系人电话,workingState:在职状态0在职1离职," +
		"realName:员工姓名,phone:手机,birthday:生日,termContract:合同年限,contractType:合同类型,remark:备注";

	 String default_password="123456";
	 String CONTRACT_SET="isOpen:是否开启,notificationPerson:接收人,assignNotificationPerson:指定接收人,contractExpire:合同到期前天数";
}

  

posted @ 2020-09-25 14:51  红尘沙漏  阅读(255)  评论(0编辑  收藏  举报