• java通过解密身份证计算年龄(精确到日)


    一、需求:对于系统中满55岁女性在职的党员和满60岁男性在职党员通过xxl-job进行定时提醒该人本级和上级管理员进行转出。

    二、控制层 

    1. package com.cnpc.dj.party.controller;
    2. import com.cnpc.dj.common.JsonResult;
    3. import com.cnpc.dj.common.exception.BusiException;
    4. import com.cnpc.dj.party.service.PartyRetiredMemService;
    5. import lombok.extern.slf4j.Slf4j;
    6. import org.springframework.beans.factory.annotation.Autowired;
    7. import org.springframework.web.bind.annotation.CrossOrigin;
    8. import org.springframework.web.bind.annotation.PostMapping;
    9. import org.springframework.web.bind.annotation.RequestMapping;
    10. import org.springframework.web.bind.annotation.RestController;
    11. @RestController
    12. @CrossOrigin
    13. @RequestMapping("member")
    14. @Slf4j
    15. public class PartyRetiredMemController extends BaseControllerAdapter{
    16. @Autowired
    17. private PartyRetiredMemService partyRetiredMemService;
    18. /**
    19. * 定时任务离退休党员
    20. * 【每天8点定时提醒前一天到55岁的女性和到60岁的男性】
    21. * @return 发送邮件提醒
    22. * @throws BusiException
    23. */
    24. @PostMapping("getRemindTransOutMem")
    25. public JsonResult getRemindTransOutMem() throws Exception {
    26. log.info("getFiftyFiveFemale接口开始定时查询信息");
    27. String remindTransOutMem = partyRetiredMemService.getRemindTransOutMem();
    28. return JsonResult.success(remindTransOutMem);
    29. }
    30. }

    三、逻辑层代码

    1. package com.cnpc.dj.party.service;
    2. import com.alibaba.druid.util.StringUtils;
    3. import com.cnpc.dj.party.entity.*;
    4. import com.cnpc.dj.party.repository.RetiredMemMapper;
    5. import com.cnpc.dj.party.utils.FeedMailSender;
    6. import lombok.extern.slf4j.Slf4j;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.beans.factory.annotation.Value;
    9. import org.springframework.scheduling.annotation.Async;
    10. import org.springframework.stereotype.Service;
    11. import org.springframework.transaction.annotation.Isolation;
    12. import org.springframework.transaction.annotation.Transactional;
    13. import java.time.LocalDate;
    14. import java.time.Period;
    15. import java.util.ArrayList;
    16. import java.util.Arrays;
    17. import java.util.List;
    18. /**
    19. * @author 解忧杂货铺
    20. */
    21. @Service
    22. @Slf4j
    23. public class PartyRetiredMemService {
    24. @Autowired
    25. private RetiredMemMapper retiredMemMapper;
    26. @Value("${isMailOpen}")
    27. private String open;
    28. @Value("${username}")
    29. private String mailSendMail;
    30. @Value("${host}")
    31. private String mailServiceHost;
    32. @Value("${password}")
    33. private String mailServicePwd;
    34. @Value("${addr}")
    35. private String mailServiceAddr;
    36. // 党组白名单党员
    37. @Value("${excludePerson}")
    38. private String excludePerson;
    39. /**
    40. * 55岁女性党员60岁男性党员
    41. * 满55岁60岁第二天早8点提醒党支部管理员和上级管理员
    42. * @return
    43. */
    44. @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
    45. public String getRemindTransOutMem() throws Exception {
    46. //查询已满55岁女/60岁男党员的上级管理员,发送邮件提醒进行党员转出
    47. // 截取党组白名单成员
    48. List sapList = Arrays.asList(excludePerson.split(","));
    49. List retiredMemList = retiredMemMapper.getRemindTransOutMem(sapList);
    50. if (retiredMemList != null && retiredMemList.size()>0) {
    51. for (RetiredMember member : retiredMemList) {
    52. String gender = member.getGender();
    53. String idCard = member.getIdentityCard();
    54. String realName = member.getRealName();//已达退休年龄待转出的党员
    55. String orgName = member.getOrg().getOrgName();//已达退休年龄待转出的党员所在组织
    56. // 截取生日部分
    57. int birthYear = Integer.parseInt(idCard.substring(6, 10)); // 截取出生年份
    58. int birthMonth = Integer.parseInt(idCard.substring(10, 12)); // 截取出生月份
    59. int birthDay = Integer.parseInt(idCard.substring(12, 14)); // 截取出生日期
    60. Period age = null; // 计算年龄
    61. try {
    62. LocalDate birthDate = LocalDate.of(birthYear, birthMonth, birthDay); // 创建出生日期对象
    63. LocalDate currentDate = LocalDate.now(); // 获取当前日期
    64. age = Period.between(birthDate, currentDate);
    65. } catch (Exception e) {
    66. e.printStackTrace();
    67. continue;
    68. }
    69. // System.out.println("该人的年龄为:" + age.getYears() + "岁 " + age.getMonths() + "个月 " + age.getDays() + "天");
    70. //判断年龄是否为整55岁+1天女
    71. if (gender.equals("xb_002") && age.getYears() >= 55 && age.getDays() == 1) {
    72. //获取党员的组织code查询本支级和上级管理员邮箱发邮件
    73. String orgCode = member.getOrg().getOrgCode();
    74. String parentOrgCode = member.getOrg().getParentOrgCode();
    75. List list = new ArrayList<>();
    76. list.add(orgCode);
    77. list.add(parentOrgCode);
    78. RetiredMember retiredMember = new RetiredMember();
    79. retiredMember.setOrgCodeList(list);
    80. List receiverEmail = retiredMemMapper.getReceiverEmail(retiredMember);
    81. if (receiverEmail != null && receiverEmail.size() >0 ) {
    82. log.info(""+orgName+"下55岁女党员"+realName+"转出提醒  开始发送邮件  start in");
    83. for (ReceiverEmailInfo receiverEmailInfo : receiverEmail) {
    84. if (Boolean.valueOf(open)) {
    85. String email = receiverEmailInfo.getEmail();
    86. String sendStatus = "0";
    87. if (!StringUtils.isEmpty(email) && !"".equals(email)) {
    88. Boolean aBoolean = sendMail(email,orgName,realName);
    89. if (aBoolean) {
    90. sendStatus = "1";
    91. } else {//发送失败再次发送
    92. //发送邮件
    93. Boolean bBoolean = sendMail(email,orgName,realName);
    94. if (bBoolean) {
    95. sendStatus = "1";
    96. }
    97. }
    98. }
    99. }
    100. }
    101. }
    102. log.info(""+orgName+"下55岁女党员"+realName+"转出提醒  邮件发送完毕  end out");
    103. //判断年龄是否为整60岁+1天男
    104. }else if (gender.equals("xb_001") && age.getYears() >= 60 && age.getDays() == 1) {
    105. //获取党员的组织code查询本支级和上级管理员邮箱发邮件
    106. String orgCode = member.getOrg().getOrgCode();
    107. String parentOrgCode = member.getOrg().getParentOrgCode();
    108. List list = new ArrayList<>();
    109. list.add(orgCode);
    110. list.add(parentOrgCode);
    111. RetiredMember retiredMember = new RetiredMember();
    112. retiredMember.setOrgCodeList(list);
    113. List receiverEmail = retiredMemMapper.getReceiverEmail(retiredMember);
    114. if (receiverEmail != null && receiverEmail.size() >0 ) {
    115. log.info(""+orgName+"下60岁男党员"+realName+"转出提醒  开始发送邮件  start in");
    116. for (ReceiverEmailInfo receiverEmailInfo : receiverEmail) {
    117. if (Boolean.valueOf(open)) {
    118. String email = receiverEmailInfo.getEmail();
    119. String sendStatus = "0";
    120. if (!StringUtils.isEmpty(email) && !"".equals(email)) {
    121. Boolean aBoolean = sendMail(email,orgName,realName);
    122. if (aBoolean) {
    123. sendStatus = "1";
    124. } else {//发送失败再次发送
    125. //发送邮件
    126. Boolean bBoolean = sendMail(email,orgName,realName);
    127. if (bBoolean) {
    128. sendStatus = "1";
    129. }
    130. }
    131. }
    132. }
    133. }
    134. }
    135. log.info(""+orgName+"下60岁男党员"+realName+"转出提醒  邮件发送完毕  end out");
    136. }
    137. }
    138. }
    139. return "ok";
    140. }
    141. @Async
    142. public Boolean sendMail(String email,String orgName,String realName){
    143. //发送邮件
    144. MailSendInfo mailInfo = new MailSendInfo();
    145. mailInfo.setMailServerHost(mailServiceHost);
    146. mailInfo.setValidate(true);
    147. mailInfo.setUserName(mailSendMail);
    148. mailInfo.setPassword(mailServicePwd);// 您的邮箱密码
    149. mailInfo.setFromAddress(mailServiceAddr);
    150. mailInfo.setToAddress(email);
    151. mailInfo.setSubject("【海油党建】党组织关系转接提醒");
    152. String content1 = "您好:
      "
      ;
    153. String content2 = "          "+orgName + realName + "同志已达到国家法定退休年龄,请结合实际情况核实该名同志是否需要转出党组织关系,谢谢。

      "
      ;
    154. String content3 = "          此邮件为党建信息化平台自动发送,无需回复。如有问题请联系平台运维热线010-84527171。";
    155. mailInfo.setContent(content1 + content2 + content3);
    156. return FeedMailSender.sendHtmlMail(mailInfo);// 发送html格式
    157. }
    158. }

    四、mapper

    1. package com.cnpc.dj.party.repository;
    2. import com.cnpc.dj.party.entity.ReceiverEmailInfo;
    3. import com.cnpc.dj.party.entity.RetiredMember;
    4. import org.apache.ibatis.annotations.Mapper;
    5. import org.apache.ibatis.annotations.Param;
    6. import org.springframework.stereotype.Repository;
    7. import java.util.List;
    8. @Mapper
    9. @Repository
    10. public interface RetiredMemMapper {
    11. //获取在职正常党籍党员的身份证
    12. List getRemindTransOutMem(@Param("sapList") List sapList);
    13. // 获取党员所在组织本级和上级管理员
    14. List getReceiverEmail(RetiredMember retiredMember);
    15. }

    五、xml

    1. "1.0" encoding="UTF-8"?>
    2. mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    3. <mapper namespace="com.cnpc.dj.party.repository.RetiredMemMapper">
    4. <resultMap id="BaseResultMap" type="com.cnpc.dj.party.entity.RetiredMember">
    5. <id column="ID" jdbcType="DECIMAL" property="id" />
    6. <result column="HEAD_IMG" jdbcType="VARCHAR" property="headImg" />
    7. <result column="REAL_NAME" jdbcType="VARCHAR" property="realName" />
    8. <result column="IDENTITY_CARD" jdbcType="VARCHAR" property="identityCard" typeHandler="com.cnpc.dj.party.utils.AESTypeHandler"/>
    9. <result column="SAP_NO" jdbcType="VARCHAR" property="sapNo" />
    10. <result column="GENDER" jdbcType="VARCHAR" property="gender" />
    11. <result column="NATION" jdbcType="VARCHAR" property="nation" />
    12. <result column="EDU_LEVEL" jdbcType="VARCHAR" property="eduLevel" />
    13. <result column="DEGREE" jdbcType="VARCHAR" property="degree" />
    14. <result column="NATIVE_PLACE" jdbcType="VARCHAR" property="nativePlace" />
    15. <result column="MOBILE_PHONE" jdbcType="VARCHAR" property="mobilePhone" />
    16. <result column="TELEPHONE" jdbcType="VARCHAR" property="telephone" />
    17. <result column="EMAIL" jdbcType="VARCHAR" property="email" />
    18. <result column="COMPANY" jdbcType="VARCHAR" property="company" />
    19. <result column="BIRTH_DATE" jdbcType="VARCHAR" property="birthDate" />
    20. <result column="ADDRESS" jdbcType="VARCHAR" property="address" />
    21. <result column="BIRTH_ADDRESS" jdbcType="VARCHAR" property="birthAddress" />
    22. <result column="HOME_ADDRESS" jdbcType="VARCHAR" property="homeAddress" />
    23. <result column="NEW_SOCIAL_PERSONNEL" jdbcType="VARCHAR" property="newSocialPersonnel" />
    24. <result column="DUTY" jdbcType="VARCHAR" property="duty" />
    25. <result column="BEGIN_WORK_DATE" jdbcType="VARCHAR" property="beginWorkDate" />
    26. <result column="JOB" jdbcType="VARCHAR" property="job" />
    27. <result column="JOB_START_DATE" jdbcType="VARCHAR" property="jobStartDate" />
    28. <result column="PRO_TECHNICAL_DUTY" jdbcType="VARCHAR" property="proTechnicalDuty" />
    29. <result column="ORG_ID" jdbcType="DECIMAL" property="orgId" />
    30. <result column="IS_DELETE" jdbcType="VARCHAR" property="isDelete" />
    31. <result column="CREATE_USERID" jdbcType="DECIMAL" property="createUserid" />
    32. <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    33. <result column="UPDATE_USERID" jdbcType="DECIMAL" property="updateUserid" />
    34. <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
    35. <result column="USER_ID" jdbcType="DECIMAL" property="userId" />
    36. <result column="TRANSFER_STATUS" jdbcType="DECIMAL" property="transferStatus" />
    37. <result column="IS_HR" jdbcType="DECIMAL" property="isHr" />
    38. resultMap>
    39. <resultMap id="MemberAndMemberShip" type="com.cnpc.dj.party.entity.RetiredMember" extends="BaseResultMap">
    40. <association property="memberShip" javaType="com.cnpc.dj.party.entity.MemberShip">
    41. <id column="memberShipId" jdbcType="DECIMAL" property="id"/>
    42. <result column="STATUS" jdbcType="VARCHAR" property="status"/>
    43. <result column="APPLY_PARTY_DATE" jdbcType="VARCHAR" property="applyPartyDate"/>
    44. <result column="ACTIVIST_BEGIN_DATE" jdbcType="VARCHAR" property="activistBeginDate"/>
    45. <result column="DEVELOPER_BEGIN_DATE" jdbcType="VARCHAR" property="developerBeginDate"/>
    46. <result column="JOIN_PARTY_DATE" jdbcType="VARCHAR" property="joinPartyDate"/>
    47. <result column="BECOME_DATE" jdbcType="VARCHAR" property="becomeDate"/>
    48. <result column="MEMBER_TYPE" jdbcType="DECIMAL" property="memberType"/>
    49. <result column="REMOVE_TYPE" jdbcType="DECIMAL" property="removeType"/>
    50. <result column="PREPARE_START_DATE" jdbcType="VARCHAR" property="prepareStartDate" />
    51. <result column="PREPARE_END_DATE" jdbcType="VARCHAR" property="prepareEndDate" />
    52. <result column="LEAVE_BRANCH_TIME" jdbcType="VARCHAR" property="leaveBranchTime" />
    53. <result column="LEAVE_AGE" jdbcType="DECIMAL" property="leaveAge" />
    54. <result column="CONNECT_ADDRESS" jdbcType="VARCHAR" property="connectAddress" />
    55. association>
    56. resultMap>
    57. <resultMap id="MemberAndMemberShipAndOrg" type="com.cnpc.dj.party.entity.RetiredMember" extends="MemberAndMemberShip">
    58. <association property="org" javaType="com.cnpc.dj.party.entity.Org">
    59. <id column="ORG_ID" property="id" jdbcType="DECIMAL"/>
    60. <result column="PARENT_ID" property="parentId" jdbcType="DECIMAL"/>
    61. <result column="ORG_CODE" property="orgCode" jdbcType="VARCHAR"/>
    62. <result column="PARENT_ORG_CODE" property="parentOrgCode" jdbcType="VARCHAR"/>
    63. <result column="ORG_NAME" property="orgName" jdbcType="VARCHAR"/>
    64. <result column="ORG_TYPE" property="orgType" jdbcType="VARCHAR"/>
    65. <result column="ORG_DEPENDENCY" property="orgDependency" jdbcType="VARCHAR"/>
    66. <result column="UNIT_SITUATION" property="unitSituation" jdbcType="VARCHAR"/>
    67. <result column="ORG_SECRETARY" property="orgSecretary" jdbcType="VARCHAR"/>
    68. <result column="ORG_CONTACTOR" property="orgContactor" jdbcType="VARCHAR"/>
    69. <result column="PHONE" property="phone" jdbcType="VARCHAR"/>
    70. <result column="ADDRESS" property="address" jdbcType="VARCHAR"/>
    71. <result column="VALID_FLAG" property="validFlag" jdbcType="VARCHAR"/>
    72. <result column="IS_RETIRED_ORG" property="isRetiredOrg" jdbcType="VARCHAR"/>
    73. <result column="IS_DEL_ORG" property="isDelOrg" jdbcType="VARCHAR"/>
    74. <result column="PARENT_ORG_CODE" property="parentOrgCode" jdbcType="VARCHAR"/>
    75. <result column="INDEX" property="index" jdbcType="VARCHAR"/>
    76. <result column="IS_ACCREDIT_IN" property="isAccreditIn" jdbcType="VARCHAR"/>
    77. <result column="ORG_SHORT_NAME" property="orgShortName" jdbcType="VARCHAR"/>
    78. <result column="REAL_TYPE" property="orgRealType" jdbcType="VARCHAR"/>
    79. <result column="IS_ACCREDIT_OUT" property="isAccreditOut" jdbcType="VARCHAR"/>
    80. <result column="SUB_ORG_COUNT" property="subOrgCount" jdbcType="DECIMAL"/>
    81. association>
    82. resultMap>
    83. <sql id="Base_Column_List">
    84. 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,
    85. 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
    86. sql>
    87. <select id="getRemindTransOutMem" resultMap="MemberAndMemberShipAndOrg" parameterType="java.util.List">
    88. SELECT
    89. <include refid="Base_Column_List"/>
    90. FROM ZHONGHY_BASIC_INFO.DJ_MEMBER M
    91. LEFT JOIN ZHONGHY_BASIC_INFO.DJ_MEMBERSHIP MS ON M.ID = MS.MEMBER_ID
    92. LEFT JOIN ZHONGHY_BASIC_INFO.DJ_ORG O on O.ID = M.ORG_ID
    93. WHERE 1=1
    94. AND MEMBER_TYPE = '0'
    95. AND M.TRANSFER_STATUS = '0'
    96. AND MS.STATUS = 'djzt_001'
    97. AND M.IS_DELETE = '0'
    98. AND O.IS_DELETE = '0'
    99. AND O.IS_DEL_ORG = '0'
    100. AND !REGEXP_LIKE(O.ORG_CODE, '^(000.001|000.002)')
    101. AND !REGEXP_LIKE(O.ORG_NAME,'退休')
    102. <if test="sapList != null">
    103. AND M.SAP_NO NOT IN
    104. <foreach item="item" index="index" collection="sapList" open="(" separator="," close=")">
    105. #{item}
    106. foreach>
    107. if>
    108. select>
    109. <select id="getReceiverEmail" resultType="com.cnpc.dj.party.entity.ReceiverEmailInfo">
    110. SELECT ID,ORG_ID,ORG_CODE,SAP,USER_NAME,EMAIL
    111. FROM ZHONGHY_BASIC_INFO.DJ_UM_USERINFO
    112. WHERE ID IN (
    113. SELECT USER_ID
    114. FROM ZHONGHY_BASIC_INFO.DJ_UM_USER_ROLE
    115. WHERE 1 = 1
    116. <if test="orgCodeList != null">
    117. AND ORG_CODE IN
    118. <foreach item="item" index="index" collection="orgCodeList" open="(" separator="," close=")">
    119. #{item}
    120. foreach>
    121. if>
    122. AND ROLE_CODE IN ('dzbgly', 'dzzgly', 'dwgly'))
    123. select>
    124. mapper>

    六、xxl-job定时器

    1. /**
    2. * @Description://每天8:00调用一次查询满55岁女和60岁男的党员
    3. * @date: 2024年05月24日下午15:15:48
    4. */
    5. @XxlJob("getRemindTransOutMem") //必须要写的,注解参数需要和在xxl-job-admin里创建的jobhandler得名称是一致的
    6. public ReturnT getRemindTransOutMem(String param) {
    7. try {
    8. log.info("getRemindTransOutMem start:" + LocalDateTime.now());
    9. // Create URL object with the desired endpoint
    10. // URL url = new URL("http://127.0.0.1:8080/org/insertOrgUnitDetail");
    11. URL url = new URL("http://fundamental:8080/member/getRemindTransOutMem");
    12. // URL url = new URL("http://127.0.0.1:9002/autoStatsRPT/generateReport");
    13. HttpUtil.httpPost(url);
    14. }
    15. catch (IOException e) {
    16. throw new RuntimeException(e);
    17. }
    18. log.info("getRemindTransOutMem end:" + LocalDateTime.now());
    19. return ReturnT.SUCCESS;
    20. }

     

     

  • 相关阅读:
    字符串 | 字符串匹配 | KMP算法 | leecode刷题笔记
    关于地方美食的HTML网页设计——地方美食介绍网站 HTML顺德美食介绍 html网页制作代码大全
    PDF格式分析(七十五)——线型注释(Line)
    使用C#创建服务端Web API
    想知道海外技术面试都考些什么吗?
    Netty进阶——粘包与半包(滑动窗口)
    数据结构 | 顺序栈与链式队【栈与队列的交际舞】
    微波雷达人体感应器,即时存在感知方案,智能家居人体感应交互
    ros2知识:在单个进程中布置多个节点
    众佰诚:现在的抖音小店赚钱是真的吗
  • 原文地址:https://blog.csdn.net/UTF8_8/article/details/139283108