Commit 27e5c86a authored by huangcb's avatar huangcb

新增接口:新增货主帐号

parent f846009e
package com.esv.freight.customer.common.component;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.component.ErrorMessageComponent
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/18 10:04
* @version:1.0
*/
@Component
@RefreshScope
public class ErrorMessageComponent {
@Value("${error-message.goodsowner.account.add.1001}")
public String goodsOwnerAccountAdd1001;
}
package com.esv.freight.customer.common.util;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.util.regex.Pattern.*;
/**
* @description: 电话号码/身份证号码校验工具类
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.util.VerifyUtils
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/18 11:13
* @version:1.0
*/
public class VerifyUtils {
/**
* description 校验是否有效18位身份证号码
* param [idCard]
* return boolean
* author Administrator
* createTime 2020/04/18 11:18
**/
public static boolean isValidIdCard18(String idCard) {
Pattern pattern1 = compile("^(\\d{6})(19|20)(\\d{2})(1[0-2]|0[1-9])(0[1-9]|[1-2][0-9]|3[0-1])(\\d{3})(\\d|X|x)?$");
Matcher matcher = pattern1.matcher(idCard);
int[] prefix = new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
int[] suffix = new int[]{1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2};
if (matcher.matches()) {
Map<String, String> cityMap = initCityMap();
if (cityMap.get(idCard.substring(0, 2)) == null) {
return false;
}
// 用来保存前17位各自乖以加权因子后的总和
int idCardWiSum = 0;
for (int i = 0; i < 17; i++) {
idCardWiSum += Integer.valueOf(idCard.substring(i, i + 1)) * prefix[i];
}
// 计算出校验码所在数组的位置
int idCardMod = idCardWiSum % 11;
// 得到最后一位身份证号码
String idCardLast = idCard.substring(17);
// 如果等于2,则说明校验码是10,身份证号码最后一位应该是X
if (idCardMod == 2) {
if (idCardLast.equalsIgnoreCase("x")) {
return true;
} else {
return false;
}
} else {
// 用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码
if (idCardLast.equals(suffix[idCardMod] + "")) {
return true;
} else {
return false;
}
}
}
return false;
}
private static Map<String, String> initCityMap(){
Map<String, String> cityMap = new HashMap<>(31);
cityMap.put("11", "北京");
cityMap.put("12", "天津");
cityMap.put("13", "河北");
cityMap.put("14", "山西");
cityMap.put("15", "内蒙古");
cityMap.put("21", "辽宁");
cityMap.put("22", "吉林");
cityMap.put("23", "黑龙江");
cityMap.put("31", "上海");
cityMap.put("32", "江苏");
cityMap.put("33", "浙江");
cityMap.put("34", "安徽");
cityMap.put("35", "福建");
cityMap.put("36", "江西");
cityMap.put("37", "山东");
cityMap.put("41", "河南");
cityMap.put("42", "湖北");
cityMap.put("43", "湖南");
cityMap.put("44", "广东");
cityMap.put("45", "广西");
cityMap.put("46", "海南");
cityMap.put("50", "重庆");
cityMap.put("51", "四川");
cityMap.put("52", "贵州");
cityMap.put("53", "云南");
cityMap.put("54", "西藏");
cityMap.put("61", "陕西");
cityMap.put("62", "甘肃");
cityMap.put("63", "青海");
cityMap.put("64", "宁夏");
cityMap.put("65", "新疆");
return cityMap;
}
}
......@@ -17,4 +17,17 @@ public class GoodsOwnerConstants {
public static final String OWNER_TYPE_PERSONAL = "1";
public static final String OWNER_TYPE_COMPANY = "2";
/**
* 货主帐号创建来源:1-平台创建、2-自行注册
**/
public static final String OWNER_SOURCE_TYPE_PLATFORM = "1";
public static final String OWNER_SOURCE_TYPE_REGISTER = "2";
/**
* 货主帐号审核状态:0-待审核、1-审核成功,2-审核失败,APP自行注册需要平台审核
**/
public static final Integer OWNER_AUDIT_STATUS_UNAUDITED = 0;
public static final Integer OWNER_AUDIT_STATUS_SUCCESS = 1;
public static final Integer OWNER_AUDIT_STATUS_FAILURE = 2;
}
......@@ -2,8 +2,10 @@ package com.esv.freight.customer.module.goodsowner.controller;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.common.response.EResponse;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.common.util.VerifyUtils;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
......@@ -59,6 +61,10 @@ public class GoodsOwnerController {
String[] notBlankParams = new String[] {"ownerFullName", "uniCreditCode", "creditCopyUrl", "legalPerson"};
ReqUtils.checkParamsNotBlank(JSONObject.parseObject(form.toString()), notBlankParams);
}
// 校验身份证号码
if (!VerifyUtils.isValidIdCard18(form.getIdCard())) {
throw new EException(ECode.PARAM_ERROR.code(), "无效的身份证号码");
}
/****************************** 参数校验 ******************************/
return EResponse.ok(accountService.createAccountByManager(form));
......
......@@ -57,10 +57,9 @@ public class AccountEntity implements Serializable {
*/
private String accountStatus;
/**
* 审核状态:1-未审核、2-审核通过,3-审核不通过
APP自行注册需要平台审核
* 货主帐号审核状态:0-待审核、1-审核成功,2-审核失败,APP自行注册需要平台审核
*/
private String auditStatus;
private Integer auditStatus;
/**
* 上报状态:字典表
*/
......
......@@ -21,7 +21,6 @@ import javax.validation.constraints.Pattern;
@Data
public class AccountInfoForm {
private Long id;
/**
* (个人或企业联系人手机号)帐号
*/
......
......@@ -3,27 +3,47 @@ package com.esv.freight.customer.module.goodsowner.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.util.FeignUtils;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.feign.FeignBaseService;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.dao.AccountDao;
import com.esv.freight.customer.module.goodsowner.entity.AccountEntity;
import com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity;
import com.esv.freight.customer.module.goodsowner.entity.InfoEntity;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.service.AccountService;
import com.esv.freight.customer.module.goodsowner.service.AuditHistoryService;
import com.esv.freight.customer.module.goodsowner.service.InfoService;
import com.esv.gateway.common.GatewayHeaders;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.UUID;
@Service("accountService")
public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> implements AccountService {
private FeignBaseService feignBaseService;
private ErrorMessageComponent errorMessageComponent;
private InfoService infoService;
private AuditHistoryService auditHistoryService;
@Autowired
public AccountServiceImpl(FeignBaseService feignBaseService) {
public AccountServiceImpl(FeignBaseService feignBaseService, ErrorMessageComponent errorMessageComponent, InfoService infoService, AuditHistoryService auditHistoryService) {
this.feignBaseService = feignBaseService;
this.errorMessageComponent = errorMessageComponent;
this.infoService = infoService;
this.auditHistoryService = auditHistoryService;
}
@Override
......@@ -40,7 +60,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
// 1.判断帐号是否已存在
AccountEntity accountEntity = this.getAccountRecordByAccount(form.getAccount());
if (null != accountEntity) {
throw new EException(1001, "帐号已存在");
throw new EException(1001, errorMessageComponent.goodsOwnerAccountAdd1001);
} else {
accountEntity = new AccountEntity();
}
......@@ -60,13 +80,40 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
String ownerNumber = batchIdResJson.getString("batchId");
// 3.新增帐号
BeanUtils.copyProperties(form, accountEntity);
String salt = UUID.randomUUID().toString().replace("-", "");
String password = DigestUtils.md5Hex(form.getPassword() + salt);
accountEntity.setSalt(salt);
accountEntity.setPassword(password);
accountEntity.setSourceType(GoodsOwnerConstants.OWNER_SOURCE_TYPE_PLATFORM);
accountEntity.setAuditStatus(GoodsOwnerConstants.OWNER_AUDIT_STATUS_SUCCESS);
int accountId = this.baseMapper.insert(accountEntity);
// 4.新增帐号信息
InfoEntity infoEntity = new InfoEntity();
BeanUtils.copyProperties(form, infoEntity);
// 货主为个人
if (GoodsOwnerConstants.OWNER_TYPE_PERSONAL.equals(form.getOwnerType())) {
infoEntity.setOwnerFullName(null);
infoEntity.setOwnerBriefName(null);
infoEntity.setUniCreditCode(null);
infoEntity.setCreditOriginalUrl(null);
infoEntity.setCreditCopyUrl(null);
infoEntity.setCreditExpireDate(null);
infoEntity.setLegalPerson(null);
infoEntity.setLegalPhone(null);
}
infoEntity.setOwnerNumber(ownerNumber);
infoEntity.setAccountId(Long.parseLong(String.valueOf(accountId)));
infoService.getBaseMapper().insert(infoEntity);
// 5.新增帐号审核记录
AuditHistoryEntity auditHistoryEntity = new AuditHistoryEntity();
auditHistoryEntity.setAccountId(Long.parseLong(String.valueOf(accountId)));
auditHistoryEntity.setAuditStatus(GoodsOwnerConstants.OWNER_AUDIT_STATUS_SUCCESS);
auditHistoryEntity.setOperateUser(ReqUtils.getRequestHeader(GatewayHeaders.USER_ACCOUNT));
auditHistoryService.getBaseMapper().insert(auditHistoryEntity);
return 0;
return accountId;
}
}
\ No newline at end of file
......@@ -45,3 +45,8 @@ ribbon:
eager-load:
enabled: true
clients: freight-base-service
error-message:
goodsowner:
account:
add:
1001: 帐号已存在
\ No newline at end of file
package com.esv.freight.customer.common.util;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.util.VerifyUtilsTest
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/18 11:23
* @version:1.0
*/
@SpringBootTest
@Slf4j
public class VerifyUtilsTest {
@Test
public void isValidIdCard18_test() {
String idCard = "360721198712030856";
log.info("{}={}", idCard, VerifyUtils.isValidIdCard18(idCard));
idCard = "900721198712030856";
log.info("{}={}", idCard, VerifyUtils.isValidIdCard18(idCard));
idCard = "36072119871203085x";
log.info("{}={}", idCard, VerifyUtils.isValidIdCard18(idCard));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment