Browse Source

fix 列表查询,提取年龄

Administrator 3 năm trước cách đây
mục cha
commit
2f7096f649

+ 3 - 1
boman-web-core/src/main/java/com/boman/web/core/controller/VaccineInfoController.java

@@ -113,11 +113,13 @@ public class VaccineInfoController extends BaseController {
     }
 
     /**
-     * 查询疫苗信息列表
+     * 根据身份证号查询用户信息
      */
     @PostMapping("/findHjInfo")
     public AjaxResult findHjInfo(@RequestBody VaccineInfoOperation vaccineInfo) {
         VaccineInfoOperation hjInfo = vaccineInfoService.findHjInfo(vaccineInfo);
         return AjaxResult.success(hjInfo);
     }
+
+
 }

+ 15 - 0
boman-web-core/src/main/java/com/boman/web/core/domain/VaccineInfoOperation.java

@@ -81,6 +81,13 @@ public class VaccineInfoOperation extends BaseEntity {
     @Excel(name = "性别")
     private String gender;
 
+
+    /**
+     * 年龄
+     */
+    @Excel(name = "年龄")
+    private Integer age;
+
     /**
      * 身份证号码
      */
@@ -223,6 +230,14 @@ public class VaccineInfoOperation extends BaseEntity {
      */
     private List<VaccineInfoUser> vaccineInfoUserList;
 
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
     public List<VaccineInfoUser> getVaccineInfoUserList() {
         return vaccineInfoUserList;
     }

+ 94 - 1
boman-web-core/src/main/java/com/boman/web/core/service/vaccineInfo/impl/VaccineInfoServiceImpl.java

@@ -1,5 +1,6 @@
 package com.boman.web.core.service.vaccineInfo.impl;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
@@ -192,9 +193,11 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
         if (hjInfo == null){
             String idCard = vaccineInfo.getIdCard();
             if (StringUtils.isNotBlank(idCard)){
-                //根据身份证提取出生日和性别
+                //根据身份证提取出生日和性别,年龄
                 String sex = getSex(idCard);
+                Integer age = getAge(idCard);
                 String birthday = getBirthday(idCard);
+                vaccineInfo.setAge(age);
                 vaccineInfo.setGender(sex);
                 vaccineInfo.setBirthday(birthday);
                 return vaccineInfo;
@@ -243,6 +246,96 @@ public class VaccineInfoServiceImpl implements IVaccineInfoService {
     }
 
 
+    /**
+     * 根据身份证号获取年龄
+     * @param IDCard
+     * @return
+     */
+    public static Integer getAge(String IDCard){
+        Integer age = 0;
+        Date date = new Date();
+        if (StringUtils.isNotBlank(IDCard)&& isValid(IDCard)){
+            //15位身份证号
+            if (IDCard.length() == FIFTEEN_ID_CARD){
+                // 身份证上的年份(15位身份证为1980年前的)
+                String uyear = "19" + IDCard.substring(6, 8);
+                // 身份证上的月份
+                String uyue = IDCard.substring(8, 10);
+                // 当前年份
+                String fyear = format.format(date).substring(0, 4);
+                // 当前月份
+                String fyue = format.format(date).substring(5, 7);
+                if (Integer.parseInt(uyue) <= Integer.parseInt(fyue)) {
+                    age = Integer.parseInt(fyear) - Integer.parseInt(uyear) + 1;
+                    // 当前用户还没过生
+                } else {
+                    age = Integer.parseInt(fyear) - Integer.parseInt(uyear);
+                }
+                //18位身份证号
+            }else if(IDCard.length() == EIGHTEEN_ID_CARD){
+                // 身份证上的年份
+                String year = IDCard.substring(6).substring(0, 4);
+                // 身份证上的月份
+                String yue = IDCard.substring(10).substring(0, 2);
+                // 当前年份
+                String fyear = format.format(date).substring(0, 4);
+                // 当前月份
+                String fyue = format.format(date).substring(5, 7);
+                // 当前月份大于用户出身的月份表示已过生日
+                if (Integer.parseInt(yue) <= Integer.parseInt(fyue)) {
+                    age = Integer.parseInt(fyear) - Integer.parseInt(year) + 1;
+                    // 当前用户还没过生日
+                } else {
+                    age = Integer.parseInt(fyear) - Integer.parseInt(year);
+                }
+            }
+        }
+        return age;
+    }
+
+
+
+    /**
+     * 身份证验证
+     * @param id 号码内容
+     * @return 是否有效
+     */
+    public static boolean isValid(String id){
+        Boolean validResult = true;
+        //校验长度只能为15或18
+        int len = id.length();
+        if (len != FIFTEEN_ID_CARD && len != EIGHTEEN_ID_CARD){
+            validResult = false;
+        }
+        //校验生日
+        if (!validDate(id)){
+            validResult = false;
+        }
+        return validResult;
+    }
+
+    /**
+     * 校验生日
+     * @param id
+     * @return
+     */
+    private static boolean validDate(String id)
+    {
+        try
+        {
+            String birth = id.length() == 15 ? "19" + id.substring(6, 12) : id.substring(6, 14);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+            Date birthDate = sdf.parse(birth);
+            if (!birth.equals(sdf.format(birthDate))){
+                return false;
+            }
+        }
+        catch (ParseException e)
+        {
+            return false;
+        }
+        return true;
+    }
     /**
      * 获取出生日期  yyyy年MM月dd日
      * @param IDCard

+ 4 - 6
boman-web-core/src/main/resources/mapper/VaccineInfoMapper.xml

@@ -67,14 +67,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </sql>
 
     <select id="selectVaccineInfoList" parameterType="VaccineInfoOperation" resultMap="VaccineInfoResult">
-
         select vi.id, vi.village_towns, vi.village, vi.villager_group, vi.house_type, vi.domicile, vi.province, vi.city,
         vi.region, vi.user_name, vi.gender, vi.id_card, vi.phone_num, vi.key_industries, vi.is_vaccination, vi.vaccine_name, vi.jici,
         vi.vaccination_time, vi.vaccination_place, vi.contraindication, vi.suspend, vi.death, vi.lost_in_missing,
         vi.should_be, vi.other, vi.progress, vi.remark, vi.status, vi.create_by, vi.create_time, vi.update_by, vi.update_time,
         vi.is_del,vi.code,vi.birthday,vi.work_unit,vi.crowd_classification,vi.manufacturer,vi.now_in,vi.url from vaccine_info vi
-        left join vaccine_info_user viu
-        on vi.id_card = viu.id_card and viu.is_del = 'N'
         <where>
             vi.is_del = 'N'
             <if test="villageTowns != null  and villageTowns != ''"> and vi.village_towns = #{villageTowns}</if>
@@ -91,17 +88,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="phoneNum != null  and phoneNum != ''"> and vi.phone_num = #{phoneNum}</if>
             <if test="keyIndustries != null  and keyIndustries != ''"> and vi.key_industries = #{keyIndustries}</if>
             <if test="isVaccination != null  and isVaccination != ''"> and vi.is_vaccination = #{isVaccination}</if>
-            <if test="vaccineName != null  and vaccineName != ''"> and viu.vaccine_name like concat('%', #{vaccineName}, '%')</if>
+<!--            <if test="vaccineName != null  and vaccineName != ''"> and viu.vaccine_name like concat('%', #{vaccineName}, '%')</if>
             <if test="jici != null  and jici != ''"> and viu.jici = #{jici}</if>
             <if test="vaccinationTime != null "> and viu.vaccination_time = #{vaccinationTime}</if>
-            <if test="vaccinationPlace != null  and vaccinationPlace != ''"> and viu.vaccination_place = #{vaccinationPlace}</if>
+            <if test="vaccinationPlace != null  and vaccinationPlace != ''"> and viu.vaccination_place = #{vaccinationPlace}</if>-->
             <if test="contraindication != null  and contraindication != ''"> and vi.contraindication = #{contraindication}</if>
             <if test="suspend != null  and suspend != ''"> and vi.suspend = #{suspend}</if>
             <if test="death != null  and death != ''"> and vi.death = #{death}</if>
             <if test="lostInMissing != null  and lostInMissing != ''"> and vi.lost_in_missing = #{lostInMissing}</if>
             <if test="shouldBe != null  and shouldBe != ''"> and vi.should_be = #{shouldBe}</if>
             <if test="other != null  and other != ''"> and vi.other = #{other}</if>
-            <if test="progress != null  and progress != ''"> and viu.progress = #{progress}</if>
+<!--            <if test="progress != null  and progress != ''"> and viu.progress = #{progress}</if>-->
             <if test="status != null  and status != ''"> and vi.status = #{status}</if>
             <if test="code != null  and code != ''"> and vi.code = #{code}</if>
             <if test="birthday != null  and birthday != ''"> and vi.birthday = #{birthday}</if>
@@ -121,6 +118,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectVaccineInfoById" parameterType="Long" resultMap="VaccineInfoResult">
         <include refid="selectVaccineInfoVo"/>
         where vi.id = #{id} and vi.is_del = 'N'
+        order by viu.vaccination_time
     </select>
     <select id="selectVaccineInfoByIds" parameterType="Long" resultMap="VaccineInfoResult">
         <include refid="selectVaccineInfoVo"/>