一、需求:对于系统中满55岁女性在职的党员和满60岁男性在职党员通过xxl-job进行定时提醒该人本级和上级管理员进行转出。
二、控制层
- package com.cnpc.dj.party.controller;
-
-
- import com.cnpc.dj.common.JsonResult;
- import com.cnpc.dj.common.exception.BusiException;
- import com.cnpc.dj.party.service.PartyRetiredMemService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.CrossOrigin;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
-
- @RestController
- @CrossOrigin
- @RequestMapping("member")
- @Slf4j
- public class PartyRetiredMemController extends BaseControllerAdapter{
-
- @Autowired
- private PartyRetiredMemService partyRetiredMemService;
-
-
- /**
- * 定时任务离退休党员
- * 【每天8点定时提醒前一天到55岁的女性和到60岁的男性】
- * @return 发送邮件提醒
- * @throws BusiException
- */
- @PostMapping("getRemindTransOutMem")
- public JsonResult> getRemindTransOutMem() throws Exception {
- log.info("getFiftyFiveFemale接口开始定时查询信息");
- String remindTransOutMem = partyRetiredMemService.getRemindTransOutMem();
- return JsonResult.success(remindTransOutMem);
- }
- }
三、逻辑层代码
- package com.cnpc.dj.party.service;
-
- import com.alibaba.druid.util.StringUtils;
- import com.cnpc.dj.party.entity.*;
- import com.cnpc.dj.party.repository.RetiredMemMapper;
- import com.cnpc.dj.party.utils.FeedMailSender;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Isolation;
- import org.springframework.transaction.annotation.Transactional;
-
- import java.time.LocalDate;
- import java.time.Period;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
-
-
- /**
- * @author 解忧杂货铺
- */
- @Service
- @Slf4j
- public class PartyRetiredMemService {
-
- @Autowired
- private RetiredMemMapper retiredMemMapper;
-
- @Value("${isMailOpen}")
- private String open;
-
- @Value("${username}")
- private String mailSendMail;
-
- @Value("${host}")
- private String mailServiceHost;
-
- @Value("${password}")
- private String mailServicePwd;
-
- @Value("${addr}")
- private String mailServiceAddr;
-
- // 党组白名单党员
- @Value("${excludePerson}")
- private String excludePerson;
-
- /**
- * 55岁女性党员60岁男性党员
- * 满55岁60岁第二天早8点提醒党支部管理员和上级管理员
- * @return
- */
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
- public String getRemindTransOutMem() throws Exception {
- //查询已满55岁女/60岁男党员的上级管理员,发送邮件提醒进行党员转出
- // 截取党组白名单成员
- List
sapList = Arrays.asList(excludePerson.split(",")); - List
retiredMemList = retiredMemMapper.getRemindTransOutMem(sapList); - if (retiredMemList != null && retiredMemList.size()>0) {
- for (RetiredMember member : retiredMemList) {
- String gender = member.getGender();
- String idCard = member.getIdentityCard();
- String realName = member.getRealName();//已达退休年龄待转出的党员
- String orgName = member.getOrg().getOrgName();//已达退休年龄待转出的党员所在组织
- // 截取生日部分
- int birthYear = Integer.parseInt(idCard.substring(6, 10)); // 截取出生年份
- int birthMonth = Integer.parseInt(idCard.substring(10, 12)); // 截取出生月份
- int birthDay = Integer.parseInt(idCard.substring(12, 14)); // 截取出生日期
- Period age = null; // 计算年龄
- try {
- LocalDate birthDate = LocalDate.of(birthYear, birthMonth, birthDay); // 创建出生日期对象
- LocalDate currentDate = LocalDate.now(); // 获取当前日期
- age = Period.between(birthDate, currentDate);
-
- } catch (Exception e) {
- e.printStackTrace();
- continue;
- }
- // System.out.println("该人的年龄为:" + age.getYears() + "岁 " + age.getMonths() + "个月 " + age.getDays() + "天");
- //判断年龄是否为整55岁+1天女
- if (gender.equals("xb_002") && age.getYears() >= 55 && age.getDays() == 1) {
- //获取党员的组织code查询本支级和上级管理员邮箱发邮件
- String orgCode = member.getOrg().getOrgCode();
- String parentOrgCode = member.getOrg().getParentOrgCode();
- List
list = new ArrayList<>(); - list.add(orgCode);
- list.add(parentOrgCode);
- RetiredMember retiredMember = new RetiredMember();
- retiredMember.setOrgCodeList(list);
- List
receiverEmail = retiredMemMapper.getReceiverEmail(retiredMember); - if (receiverEmail != null && receiverEmail.size() >0 ) {
- log.info(""+orgName+"下55岁女党员"+realName+"转出提醒  开始发送邮件  start in");
- for (ReceiverEmailInfo receiverEmailInfo : receiverEmail) {
- if (Boolean.valueOf(open)) {
- String email = receiverEmailInfo.getEmail();
- String sendStatus = "0";
- if (!StringUtils.isEmpty(email) && !"".equals(email)) {
- Boolean aBoolean = sendMail(email,orgName,realName);
- if (aBoolean) {
- sendStatus = "1";
- } else {//发送失败再次发送
- //发送邮件
- Boolean bBoolean = sendMail(email,orgName,realName);
- if (bBoolean) {
- sendStatus = "1";
- }
- }
- }
- }
- }
- }
- log.info(""+orgName+"下55岁女党员"+realName+"转出提醒  邮件发送完毕  end out");
- //判断年龄是否为整60岁+1天男
- }else if (gender.equals("xb_001") && age.getYears() >= 60 && age.getDays() == 1) {
- //获取党员的组织code查询本支级和上级管理员邮箱发邮件
- String orgCode = member.getOrg().getOrgCode();
- String parentOrgCode = member.getOrg().getParentOrgCode();
- List
list = new ArrayList<>(); - list.add(orgCode);
- list.add(parentOrgCode);
- RetiredMember retiredMember = new RetiredMember();
- retiredMember.setOrgCodeList(list);
- List
receiverEmail = retiredMemMapper.getReceiverEmail(retiredMember); - if (receiverEmail != null && receiverEmail.size() >0 ) {
- log.info(""+orgName+"下60岁男党员"+realName+"转出提醒  开始发送邮件  start in");
- for (ReceiverEmailInfo receiverEmailInfo : receiverEmail) {
- if (Boolean.valueOf(open)) {
- String email = receiverEmailInfo.getEmail();
- String sendStatus = "0";
- if (!StringUtils.isEmpty(email) && !"".equals(email)) {
- Boolean aBoolean = sendMail(email,orgName,realName);
- if (aBoolean) {
- sendStatus = "1";
- } else {//发送失败再次发送
- //发送邮件
- Boolean bBoolean = sendMail(email,orgName,realName);
- if (bBoolean) {
- sendStatus = "1";
- }
- }
- }
- }
- }
- }
- log.info(""+orgName+"下60岁男党员"+realName+"转出提醒  邮件发送完毕  end out");
- }
- }
- }
- return "ok";
- }
-
-
- @Async
- public Boolean sendMail(String email,String orgName,String realName){
- //发送邮件
- MailSendInfo mailInfo = new MailSendInfo();
- mailInfo.setMailServerHost(mailServiceHost);
- mailInfo.setValidate(true);
- mailInfo.setUserName(mailSendMail);
- mailInfo.setPassword(mailServicePwd);// 您的邮箱密码
- mailInfo.setFromAddress(mailServiceAddr);
- mailInfo.setToAddress(email);
-
- mailInfo.setSubject("【海油党建】党组织关系转接提醒");
- String content1 = "您好:
"; - String content2 = " "+orgName + realName + "同志已达到国家法定退休年龄,请结合实际情况核实该名同志是否需要转出党组织关系,谢谢。
"; - String content3 = " 此邮件为党建信息化平台自动发送,无需回复。如有问题请联系平台运维热线010-84527171。";
- mailInfo.setContent(content1 + content2 + content3);
-
- return FeedMailSender.sendHtmlMail(mailInfo);// 发送html格式
-
- }
- }
四、mapper层
- package com.cnpc.dj.party.repository;
-
- import com.cnpc.dj.party.entity.ReceiverEmailInfo;
- import com.cnpc.dj.party.entity.RetiredMember;
- import org.apache.ibatis.annotations.Mapper;
- import org.apache.ibatis.annotations.Param;
- import org.springframework.stereotype.Repository;
-
- import java.util.List;
-
- @Mapper
- @Repository
- public interface RetiredMemMapper {
-
- //获取在职正常党籍党员的身份证
- List
getRemindTransOutMem(@Param("sapList") List sapList) ; -
- // 获取党员所在组织本级和上级管理员
- List
getReceiverEmail(RetiredMember retiredMember); -
- }
五、xml层
- "1.0" encoding="UTF-8"?>
- mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.cnpc.dj.party.repository.RetiredMemMapper">
- <resultMap id="BaseResultMap" type="com.cnpc.dj.party.entity.RetiredMember">
- <id column="ID" jdbcType="DECIMAL" property="id" />
- <result column="HEAD_IMG" jdbcType="VARCHAR" property="headImg" />
- <result column="REAL_NAME" jdbcType="VARCHAR" property="realName" />
- <result column="IDENTITY_CARD" jdbcType="VARCHAR" property="identityCard" typeHandler="com.cnpc.dj.party.utils.AESTypeHandler"/>
- <result column="SAP_NO" jdbcType="VARCHAR" property="sapNo" />
- <result column="GENDER" jdbcType="VARCHAR" property="gender" />
- <result column="NATION" jdbcType="VARCHAR" property="nation" />
- <result column="EDU_LEVEL" jdbcType="VARCHAR" property="eduLevel" />
- <result column="DEGREE" jdbcType="VARCHAR" property="degree" />
- <result column="NATIVE_PLACE" jdbcType="VARCHAR" property="nativePlace" />
- <result column="MOBILE_PHONE" jdbcType="VARCHAR" property="mobilePhone" />
- <result column="TELEPHONE" jdbcType="VARCHAR" property="telephone" />
- <result column="EMAIL" jdbcType="VARCHAR" property="email" />
- <result column="COMPANY" jdbcType="VARCHAR" property="company" />
- <result column="BIRTH_DATE" jdbcType="VARCHAR" property="birthDate" />
- <result column="ADDRESS" jdbcType="VARCHAR" property="address" />
- <result column="BIRTH_ADDRESS" jdbcType="VARCHAR" property="birthAddress" />
- <result column="HOME_ADDRESS" jdbcType="VARCHAR" property="homeAddress" />
- <result column="NEW_SOCIAL_PERSONNEL" jdbcType="VARCHAR" property="newSocialPersonnel" />
- <result column="DUTY" jdbcType="VARCHAR" property="duty" />
- <result column="BEGIN_WORK_DATE" jdbcType="VARCHAR" property="beginWorkDate" />
- <result column="JOB" jdbcType="VARCHAR" property="job" />
- <result column="JOB_START_DATE" jdbcType="VARCHAR" property="jobStartDate" />
- <result column="PRO_TECHNICAL_DUTY" jdbcType="VARCHAR" property="proTechnicalDuty" />
- <result column="ORG_ID" jdbcType="DECIMAL" property="orgId" />
- <result column="IS_DELETE" jdbcType="VARCHAR" property="isDelete" />
- <result column="CREATE_USERID" jdbcType="DECIMAL" property="createUserid" />
- <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
- <result column="UPDATE_USERID" jdbcType="DECIMAL" property="updateUserid" />
- <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
- <result column="USER_ID" jdbcType="DECIMAL" property="userId" />
- <result column="TRANSFER_STATUS" jdbcType="DECIMAL" property="transferStatus" />
- <result column="IS_HR" jdbcType="DECIMAL" property="isHr" />
- resultMap>
-
- <resultMap id="MemberAndMemberShip" type="com.cnpc.dj.party.entity.RetiredMember" extends="BaseResultMap">
- <association property="memberShip" javaType="com.cnpc.dj.party.entity.MemberShip">
- <id column="memberShipId" jdbcType="DECIMAL" property="id"/>
- <result column="STATUS" jdbcType="VARCHAR" property="status"/>
- <result column="APPLY_PARTY_DATE" jdbcType="VARCHAR" property="applyPartyDate"/>
- <result column="ACTIVIST_BEGIN_DATE" jdbcType="VARCHAR" property="activistBeginDate"/>
- <result column="DEVELOPER_BEGIN_DATE" jdbcType="VARCHAR" property="developerBeginDate"/>
- <result column="JOIN_PARTY_DATE" jdbcType="VARCHAR" property="joinPartyDate"/>
- <result column="BECOME_DATE" jdbcType="VARCHAR" property="becomeDate"/>
- <result column="MEMBER_TYPE" jdbcType="DECIMAL" property="memberType"/>
- <result column="REMOVE_TYPE" jdbcType="DECIMAL" property="removeType"/>
- <result column="PREPARE_START_DATE" jdbcType="VARCHAR" property="prepareStartDate" />
- <result column="PREPARE_END_DATE" jdbcType="VARCHAR" property="prepareEndDate" />
- <result column="LEAVE_BRANCH_TIME" jdbcType="VARCHAR" property="leaveBranchTime" />
- <result column="LEAVE_AGE" jdbcType="DECIMAL" property="leaveAge" />
- <result column="CONNECT_ADDRESS" jdbcType="VARCHAR" property="connectAddress" />
- association>
- resultMap>
-
- <resultMap id="MemberAndMemberShipAndOrg" type="com.cnpc.dj.party.entity.RetiredMember" extends="MemberAndMemberShip">
- <association property="org" javaType="com.cnpc.dj.party.entity.Org">
- <id column="ORG_ID" property="id" jdbcType="DECIMAL"/>
- <result column="PARENT_ID" property="parentId" jdbcType="DECIMAL"/>
- <result column="ORG_CODE" property="orgCode" jdbcType="VARCHAR"/>
- <result column="PARENT_ORG_CODE" property="parentOrgCode" jdbcType="VARCHAR"/>
- <result column="ORG_NAME" property="orgName" jdbcType="VARCHAR"/>
- <result column="ORG_TYPE" property="orgType" jdbcType="VARCHAR"/>
- <result column="ORG_DEPENDENCY" property="orgDependency" jdbcType="VARCHAR"/>
- <result column="UNIT_SITUATION" property="unitSituation" jdbcType="VARCHAR"/>
- <result column="ORG_SECRETARY" property="orgSecretary" jdbcType="VARCHAR"/>
- <result column="ORG_CONTACTOR" property="orgContactor" jdbcType="VARCHAR"/>
- <result column="PHONE" property="phone" jdbcType="VARCHAR"/>
- <result column="ADDRESS" property="address" jdbcType="VARCHAR"/>
- <result column="VALID_FLAG" property="validFlag" jdbcType="VARCHAR"/>
- <result column="IS_RETIRED_ORG" property="isRetiredOrg" jdbcType="VARCHAR"/>
- <result column="IS_DEL_ORG" property="isDelOrg" jdbcType="VARCHAR"/>
- <result column="PARENT_ORG_CODE" property="parentOrgCode" jdbcType="VARCHAR"/>
- <result column="INDEX" property="index" jdbcType="VARCHAR"/>
- <result column="IS_ACCREDIT_IN" property="isAccreditIn" jdbcType="VARCHAR"/>
- <result column="ORG_SHORT_NAME" property="orgShortName" jdbcType="VARCHAR"/>
- <result column="REAL_TYPE" property="orgRealType" jdbcType="VARCHAR"/>
- <result column="IS_ACCREDIT_OUT" property="isAccreditOut" jdbcType="VARCHAR"/>
- <result column="SUB_ORG_COUNT" property="subOrgCount" jdbcType="DECIMAL"/>
- association>
- resultMap>
- <sql id="Base_Column_List">
- M.ID,M.SAP_NO,M.REAL_NAME,M.IDENTITY_CARD,M.GENDER,M.BIRTH_DATE,M.ORG_ID,M.TRANSFER_STATUS,M.IS_DELETE,
- MS.ID,MS.STATUS,MS.MEMBER_TYPE,O.ID,O.PARENT_ID,O.ORG_CODE,O.PARENT_ORG_CODE,O.ORG_NAME,O.ORG_SHORT_NAME,O.ORG_TYPE,O.IS_RETIRED_ORG,O.IS_JN,O.IN_OUT_COUNTRY,O.IS_DEL_ORG,O.IS_DELETE
- sql>
-
- <select id="getRemindTransOutMem" resultMap="MemberAndMemberShipAndOrg" parameterType="java.util.List">
- SELECT
- <include refid="Base_Column_List"/>
- FROM ZHONGHY_BASIC_INFO.DJ_MEMBER M
- LEFT JOIN ZHONGHY_BASIC_INFO.DJ_MEMBERSHIP MS ON M.ID = MS.MEMBER_ID
- LEFT JOIN ZHONGHY_BASIC_INFO.DJ_ORG O on O.ID = M.ORG_ID
- WHERE 1=1
- AND MEMBER_TYPE = '0'
- AND M.TRANSFER_STATUS = '0'
- AND MS.STATUS = 'djzt_001'
- AND M.IS_DELETE = '0'
- AND O.IS_DELETE = '0'
- AND O.IS_DEL_ORG = '0'
- AND !REGEXP_LIKE(O.ORG_CODE, '^(000.001|000.002)')
- AND !REGEXP_LIKE(O.ORG_NAME,'退休')
- <if test="sapList != null">
- AND M.SAP_NO NOT IN
- <foreach item="item" index="index" collection="sapList" open="(" separator="," close=")">
- #{item}
- foreach>
- if>
- select>
-
- <select id="getReceiverEmail" resultType="com.cnpc.dj.party.entity.ReceiverEmailInfo">
- SELECT ID,ORG_ID,ORG_CODE,SAP,USER_NAME,EMAIL
- FROM ZHONGHY_BASIC_INFO.DJ_UM_USERINFO
- WHERE ID IN (
- SELECT USER_ID
- FROM ZHONGHY_BASIC_INFO.DJ_UM_USER_ROLE
- WHERE 1 = 1
- <if test="orgCodeList != null">
- AND ORG_CODE IN
- <foreach item="item" index="index" collection="orgCodeList" open="(" separator="," close=")">
- #{item}
- foreach>
- if>
- AND ROLE_CODE IN ('dzbgly', 'dzzgly', 'dwgly'))
- select>
- mapper>
六、xxl-job定时器
- /**
- * @Description://每天8:00调用一次查询满55岁女和60岁男的党员
- * @date: 2024年05月24日下午15:15:48
- */
- @XxlJob("getRemindTransOutMem") //必须要写的,注解参数需要和在xxl-job-admin里创建的jobhandler得名称是一致的
- public ReturnT
getRemindTransOutMem(String param) { -
- try {
- log.info("getRemindTransOutMem start:" + LocalDateTime.now());
- // Create URL object with the desired endpoint
- // URL url = new URL("http://127.0.0.1:8080/org/insertOrgUnitDetail");
- URL url = new URL("http://fundamental:8080/member/getRemindTransOutMem");
- // URL url = new URL("http://127.0.0.1:9002/autoStatsRPT/generateReport");
- HttpUtil.httpPost(url);
-
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- log.info("getRemindTransOutMem end:" + LocalDateTime.now());
- return ReturnT.SUCCESS;
- }