diff --git a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/epdc/common/token/util/IdentityNoAnalysisUtil.java b/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/epdc/common/token/util/IdentityNoAnalysisUtil.java deleted file mode 100644 index ca247743e..000000000 --- a/esua-epdc/epdc-commons/epdc-common-clienttoken/src/main/java/com/elink/esua/epdc/common/token/util/IdentityNoAnalysisUtil.java +++ /dev/null @@ -1,178 +0,0 @@ -package com.elink.esua.epdc.common.token.util; - -import org.apache.commons.lang3.StringUtils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -/** - * 用户工具类 - * - * @author wanggongfeng - * @Date 19-12-16 - */ -public class IdentityNoAnalysisUtil { - /** - * 15位身份证号 - */ - private static final Integer FIFTEEN_ID_CARD=15; - /** - * 18位身份证号 - */ - private static final Integer EIGHTEEN_ID_CARD=18; - private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - - /** - * 从身份证号码中获取生日 - * @param idno - * @return null表示idno错误,未获取到生日 - */ - public static Date getBirthDay(String idno){ - if(!isValid(idno)){ - return null; - } - return toBirthDay(idno.substring(6, 14)); - } - - /** - * 根据身份证号获取性别 - * @param IDCard - * @return - */ - public static String getSex(String IDCard){ - String sex =""; - if (StringUtils.isNotBlank(IDCard)){ - //15位身份证号 - if (IDCard.length() == FIFTEEN_ID_CARD){ - if (Integer.parseInt(IDCard.substring(14, 15)) % 2 == 0) { - sex = "女"; - } else { - sex = "男"; - } - //18位身份证号 - }else if(IDCard.length() == EIGHTEEN_ID_CARD){ - // 判断性别 - if (Integer.parseInt(IDCard.substring(16).substring(0, 1)) % 2 == 0) { - sex = "女"; - } else { - sex = "男"; - } - } - } - return sex; - } - - /** - * 根据身份证号获取年龄 - * @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; - } - - /** - * 转换成日期 - * @param birthday - * @return - */ - private static Date toBirthDay(String birthday){ - try{ - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, Integer.parseInt(birthday.substring(0, 4))); - calendar.set(Calendar.MONTH, Integer.parseInt(birthday.substring(4, 6)) - 1);//月份从0开始,所以减1 - calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(birthday.substring(6, 8))); - //以下设置意义不大 - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - - return calendar.getTime(); - }catch (Exception e){ - return null; - } - } -} diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/enums/UserTagEnum.java b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/enums/UserTagEnum.java index d3471119f..a03ca4e29 100644 --- a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/enums/UserTagEnum.java +++ b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/enums/UserTagEnum.java @@ -1,7 +1,7 @@ package com.elink.esua.epdc.commons.tools.enums; /** - * @Auther: yinzuomei + * @Author: yinzuomei * @Date: 2019/12/17 19:11 * @Description: 用户身份枚举类 */ diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiActUserRelationController.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiActUserRelationController.java index aeacb46c5..0ccfad84a 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiActUserRelationController.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiActUserRelationController.java @@ -6,11 +6,11 @@ import com.elink.esua.epdc.activity.AppActUserClockLogDTO; import com.elink.esua.epdc.activity.AppClockListDTO; import com.elink.esua.epdc.activity.result.AppActInfoDTO; import com.elink.esua.epdc.common.token.dto.TokenDto; -import com.elink.esua.epdc.common.token.util.IdentityNoAnalysisUtil; import com.elink.esua.epdc.commons.tools.annotation.LoginUser; import com.elink.esua.epdc.commons.tools.enums.UserTagEnum; import com.elink.esua.epdc.commons.tools.enums.YesOrNoEnum; import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.utils.IdentityNoUtils; import com.elink.esua.epdc.commons.tools.utils.Result; import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; import com.elink.esua.epdc.dto.epdc.result.EpdcUserInfoResultDTO; @@ -52,7 +52,7 @@ public class ApiActUserRelationController { * @date 2019/12/13 14:41 */ @PostMapping("signup") - public Result activitySignUp(@LoginUser TokenDto tokenDto,String actId) { + public Result activitySignUp(@LoginUser TokenDto tokenDto, String actId) { if (StringUtils.isBlank(actId)) { return new Result().error("活动id不能为空"); } @@ -65,7 +65,7 @@ public class ApiActUserRelationController { } Result userInfo = appUserService.getInfoById(tokenDto); EpdcUserInfoResultDTO epdcUserInfoResultDTO = userInfo.getData(); - String identityNo = epdcUserInfoResultDTO.getIdentityNo(); + ActUserRelationDTO actUserRelationDTO = new ActUserRelationDTO(); actUserRelationDTO.setActId(actId); actUserRelationDTO.setUserId(tokenDto.getUserId()); @@ -76,15 +76,17 @@ public class ApiActUserRelationController { } else { actUserRelationDTO.setPartyFlag(YesOrNoEnum.NO.value()); } - actUserRelationDTO.setRealName(tokenDto.getRealName()); - String sex = IdentityNoAnalysisUtil.getSex(identityNo); // 身份证解析性别 - if ("女".equals(sex)){ - sex = "0"; - }else { - sex = "1"; + + + String identityNo = epdcUserInfoResultDTO.getIdentityNo(); + String identityNoVerification = IdentityNoUtils.IdentityNoVerification(identityNo); + if (StringUtils.isNotBlank(identityNoVerification)) { + return new Result().error(identityNoVerification); } + actUserRelationDTO.setRealName(tokenDto.getRealName()); + String sex = IdentityNoUtils.getSex(identityNo); // 身份证解析性别 actUserRelationDTO.setSex(sex); - actUserRelationDTO.setAge(IdentityNoAnalysisUtil.getAge(identityNo)); + actUserRelationDTO.setAge(IdentityNoUtils.getAge(identityNo)); actUserRelationDTO.setMobile(tokenDto.getMobile()); actUserRelationDTO.setIdentityNo(identityNo); actUserRelationDTO.setStatus("0"); @@ -103,7 +105,7 @@ public class ApiActUserRelationController { * @date 2019/12/13 14:41 */ @PostMapping("cancelsignup") - public Result activityCancelSignUp(@LoginUser TokenDto tokenDto,@RequestBody EpdcAppActUserCancelsignupDTO epdcAppActUserCancelsignupDTO) { + public Result activityCancelSignUp(@LoginUser TokenDto tokenDto, @RequestBody EpdcAppActUserCancelsignupDTO epdcAppActUserCancelsignupDTO) { ValidatorUtils.validateEntity(epdcAppActUserCancelsignupDTO); epdcAppActUserCancelsignupDTO.setUserId(tokenDto.getUserId()); AppActUserCancelsignupDTO actUserCancelsignupDTO = ConvertUtils.sourceToTarget(epdcAppActUserCancelsignupDTO, AppActUserCancelsignupDTO.class); diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java index e1c9aa809..db050dada 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java @@ -9,7 +9,6 @@ import com.alibaba.fastjson.JSONObject; import com.elink.esua.epdc.async.GroupTask; import com.elink.esua.epdc.common.token.dto.TokenDto; import com.elink.esua.epdc.common.token.util.CpUserDetailRedis; -import com.elink.esua.epdc.common.token.util.IdentityNoAnalysisUtil; import com.elink.esua.epdc.commons.tools.constant.NumConstant; import com.elink.esua.epdc.commons.tools.enums.UserSexEnum; import com.elink.esua.epdc.commons.tools.enums.UserTagEnum; @@ -48,7 +47,6 @@ import com.elink.esua.epdc.redis.AppUserRedis; import com.elink.esua.epdc.service.AppUserService; import com.elink.esua.epdc.utils.UserTagUtils; import com.elink.esua.epdc.utils.WxMaServiceUtils; -import com.sun.org.apache.regexp.internal.RE; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; @@ -871,7 +869,10 @@ public class AppUserServiceImpl implements AppUserService { if (YesOrNoEnum.NO.value().equals(partyFlag)) { return null; } - // 党员提交,验证身份证号 + return fixAndCheckIdentityNo(identityNo); + } + + private String fixAndCheckIdentityNo(String identityNo) { identityNo = ModuleUtils.replaceIllegalCharacter(identityNo); if (StringUtils.isBlank(identityNo)) { throw new RenException("身份证号不能为空"); @@ -1288,15 +1289,11 @@ public class AppUserServiceImpl implements AppUserService { @Override public Result volunteerAuthenticate(TokenDto tokenDto, EpdcCompleteVolunteerInfoFormDTO formDto) { logger.info("志愿者认证wxCode=" + formDto.getWxCode() + ";userId=" + tokenDto.getUserId()); - String sex = IdentityNoAnalysisUtil.getSex(formDto.getIdentityNo()); // 身份证解析性别 - if (sex.equals("女")) { - sex = "0"; - } else { - sex = "1"; - } - Date birthday = IdentityNoAnalysisUtil.getBirthDay(formDto.getIdentityNo()); // 身份证解析生日 - formDto.setSex(sex); // 性别 - formDto.setBirthday(birthday); // 生日 + // 处理和验证身份证号码 + String identityNo = fixAndCheckIdentityNo(formDto.getIdentityNo()); + + formDto.setSex(IdentityNoUtils.getSex(identityNo)); // 性别 + formDto.setBirthday(DateUtils.parse(IdentityNoUtils.getBirthday(identityNo), DateUtils.DATE_PATTERN)); // 生日 formDto.setUserId(tokenDto.getUserId()); // 用户ID // 验证是否为志愿者 Result volunteerCountResult = userFeignClient.getVolunteerCountById(tokenDto.getUserId());