Authored by LUOXC

Merge branch 'dev5.7' into dev_session校验

# Conflicts:
#	order/src/main/java/com/yoho/global/order/service/impl/AddressServiceImpl.java
1 package com.yoho.global.dal; 1 package com.yoho.global.dal;
2 2
3 -import java.util.List;  
4 - 3 +import com.yoho.global.dal.model.TblCustomerIdcard;
5 import org.apache.ibatis.annotations.Param; 4 import org.apache.ibatis.annotations.Param;
6 5
7 -import com.yoho.global.dal.model.TblCustomerIdcard; 6 +import java.util.List;
8 7
9 public interface TblCustomerIdcardMapper { 8 public interface TblCustomerIdcardMapper {
10 9
11 int addIdCard(TblCustomerIdcard record); 10 int addIdCard(TblCustomerIdcard record);
12 11
13 - List<TblCustomerIdcard> selectIdCardBatchByUid(@Param("uid") Integer uid,  
14 - @Param("addressIdList") List<Integer> addressIdList);  
15 - 12 + List<TblCustomerIdcard> selectIdCardBatchByUid(@Param("uid") Integer uid, @Param("addressIdList") List<Integer> addressIdList);
  13 +
  14 + int updateByPrimaryKeySelective(TblCustomerIdcard record);
  15 +
  16 + TblCustomerIdcard selectByUidAndAddressId(@Param("uid") Integer uid, @Param("addressId") Integer addressId);
16 17
17 /** 18 /**
18 * 19 *
@@ -23,20 +23,28 @@ @@ -23,20 +23,28 @@
23 from tbl_customer_idcard 23 from tbl_customer_idcard
24 where idcard_id = #{idcardId,jdbcType=INTEGER} 24 where idcard_id = #{idcardId,jdbcType=INTEGER}
25 </select> 25 </select>
26 - 26 +
27 <select id="selectIdCardBatchByUid" resultMap="BaseResultMap" > 27 <select id="selectIdCardBatchByUid" resultMap="BaseResultMap" >
28 - select 28 + select
29 <include refid="Base_Column_List" /> 29 <include refid="Base_Column_List" />
30 from tbl_customer_idcard 30 from tbl_customer_idcard
31 where user_id = #{uid,jdbcType=INTEGER} 31 where user_id = #{uid,jdbcType=INTEGER}
32 <if test="addressIdList != null"> 32 <if test="addressIdList != null">
33 - and address_id in  
34 - <foreach item="item" index="index" collection="addressIdList" open="(" separator="," close=")">  
35 - #{item}  
36 - </foreach>  
37 - </if>  
38 - </select>  
39 - 33 + and address_id in
  34 + <foreach item="item" index="index" collection="addressIdList" open="(" separator="," close=")">
  35 + #{item}
  36 + </foreach>
  37 + </if>
  38 + </select>
  39 +
  40 + <select id="selectByUidAndAddressId" resultMap="BaseResultMap" >
  41 + select
  42 + <include refid="Base_Column_List" />
  43 + from tbl_customer_idcard
  44 + where user_id = #{uid,jdbcType=INTEGER}
  45 + and address_id = #{addressId,jdbcType=INTEGER}
  46 + </select>
  47 +
40 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > 48 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
41 delete from tbl_customer_idcard 49 delete from tbl_customer_idcard
42 where idcard_id = #{idcardId,jdbcType=INTEGER} 50 where idcard_id = #{idcardId,jdbcType=INTEGER}
@@ -17,7 +17,6 @@ import com.alibaba.fastjson.JSONArray; @@ -17,7 +17,6 @@ import com.alibaba.fastjson.JSONArray;
17 import com.alibaba.fastjson.JSONObject; 17 import com.alibaba.fastjson.JSONObject;
18 import com.yoho.error.ServiceError; 18 import com.yoho.error.ServiceError;
19 import com.yoho.error.exception.ServiceException; 19 import com.yoho.error.exception.ServiceException;
20 -import com.yoho.global.common.cache.Cachable;  
21 import com.yoho.global.common.cache.CacheEnum; 20 import com.yoho.global.common.cache.CacheEnum;
22 import com.yoho.global.common.cache.CacheRedis; 21 import com.yoho.global.common.cache.CacheRedis;
23 import com.yoho.global.common.rest.client.YHMethodContants; 22 import com.yoho.global.common.rest.client.YHMethodContants;
@@ -48,7 +47,13 @@ public class AddressServiceImpl implements AddressService { @@ -48,7 +47,13 @@ public class AddressServiceImpl implements AddressService {
48 public JSONObject addAddress(AddressBO addressBo) { 47 public JSONObject addAddress(AddressBO addressBo) {
49 //校验入参 48 //校验入参
50 validGlobalBuyAddressRequest(addressBo); 49 validGlobalBuyAddressRequest(addressBo);
51 - 50 +
  51 + // 验证身份证号码
  52 + if(!IDCardUtil.isIDCard(addressBo.getCardNumber())) {
  53 + logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());
  54 + throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);
  55 + }
  56 +
52 //1、添加收货地址 57 //1、添加收货地址
53 Map<String, String> params = new HashMap<String, String>(); 58 Map<String, String> params = new HashMap<String, String>();
54 params.put("uid", String.valueOf(addressBo.getUid())); 59 params.put("uid", String.valueOf(addressBo.getUid()));
@@ -92,11 +97,7 @@ public class AddressServiceImpl implements AddressService { @@ -92,11 +97,7 @@ public class AddressServiceImpl implements AddressService {
92 throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_MOBILE_INVALID); 97 throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_MOBILE_INVALID);
93 } 98 }
94 } 99 }
95 -  
96 - if(!IDCardUtil.isIDCard(addressBo.getCardNumber())) {  
97 - logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());  
98 - throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);  
99 - } 100 +
100 } 101 }
101 102
102 /** 103 /**
@@ -134,9 +135,24 @@ public class AddressServiceImpl implements AddressService { @@ -134,9 +135,24 @@ public class AddressServiceImpl implements AddressService {
134 public JSONObject editAddress(AddressBO addressBo) { 135 public JSONObject editAddress(AddressBO addressBo) {
135 //校验入参 136 //校验入参
136 validGlobalBuyAddressRequest(addressBo); 137 validGlobalBuyAddressRequest(addressBo);
137 - 138 + TblCustomerIdcard customerIdcard = idCardMapper.selectByUidAndAddressId(addressBo.getUid(),addressBo.getAddressId());
  139 + // 验证身份证号码
  140 + if(addressBo.getCardNumber() == null || addressBo.getCardNumber().contains( "*" )){
  141 + if(customerIdcard == null){
  142 + logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());
  143 + throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);
  144 + }
  145 + // 不修改身份证号码
  146 + addressBo.setCardNumber( null );
  147 + } else {
  148 + if(!IDCardUtil.isIDCard(addressBo.getCardNumber())) {
  149 + logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());
  150 + throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);
  151 + }
  152 + }
  153 +
138 //1、添加收货地址 154 //1、添加收货地址
139 - Map<String, String> params = new HashMap<String, String>(); 155 + Map<String, String> params = new HashMap<>();
140 params.put("id", String.valueOf(addressBo.getAddressId())); 156 params.put("id", String.valueOf(addressBo.getAddressId()));
141 params.put("uid", String.valueOf(addressBo.getUid())); 157 params.put("uid", String.valueOf(addressBo.getUid()));
142 params.put("address", addressBo.getAddress()); 158 params.put("address", addressBo.getAddress());
@@ -145,12 +161,16 @@ public class AddressServiceImpl implements AddressService { @@ -145,12 +161,16 @@ public class AddressServiceImpl implements AddressService {
145 params.put("consignee", addressBo.getConsignee()); 161 params.put("consignee", addressBo.getConsignee());
146 JSONObject addressJson = yhRestCaller.yhbGetMethod(YHMethodContants.YH_ADDRESS_EDIT, params, JSONObject.class); 162 JSONObject addressJson = yhRestCaller.yhbGetMethod(YHMethodContants.YH_ADDRESS_EDIT, params, JSONObject.class);
147 logger.info("edit globalbuy address to yohobuy: {}", addressJson); 163 logger.info("edit globalbuy address to yohobuy: {}", addressJson);
148 -  
149 - Map<String, String> idCardInfos = addIDCard(addressBo, addressBo.getAddressId()); 164 +
  165 + Map<String, String> idCardInfos;
  166 + if(customerIdcard == null){
  167 + idCardInfos = addIDCard(addressBo, addressBo.getAddressId());
  168 + } else {
  169 + idCardInfos = updateIDCard(addressBo, customerIdcard);
  170 + }
150 addressJson.putAll(idCardInfos); 171 addressJson.putAll(idCardInfos);
151 addressJson.put("address_id", addressBo.getAddressId()); 172 addressJson.put("address_id", addressBo.getAddressId());
152 addressJson.put("user_id", addressBo.getUid()); 173 addressJson.put("user_id", addressBo.getUid());
153 -  
154 clearAddressCache(addressBo.getUid()); 174 clearAddressCache(addressBo.getUid());
155 return addressJson; 175 return addressJson;
156 } 176 }
@@ -167,6 +187,36 @@ public class AddressServiceImpl implements AddressService { @@ -167,6 +187,36 @@ public class AddressServiceImpl implements AddressService {
167 return respData; 187 return respData;
168 } 188 }
169 189
  190 + /**
  191 + * 全球购身份证入库
  192 + * @param addressBo
  193 + * @param idCardRecord
  194 + * @return
  195 + */
  196 + private Map<String, String> updateIDCard(AddressBO addressBo, TblCustomerIdcard idCardRecord) {
  197 + if(StringUtils.isNotEmpty( addressBo.getCardNumber() )){
  198 + idCardRecord.setCardNumber(addressBo.getCardNumber());
  199 + }
  200 +
  201 + //必须正反面都有才可以存入
  202 + String cardPositive = addressBo.getCardPosition();
  203 + String cardNegative = addressBo.getCardNegative();
  204 + if(StringUtils.isBlank(cardPositive) || StringUtils.isBlank(cardNegative)) {
  205 + cardPositive = "";
  206 + cardNegative = "";
  207 + }
  208 + idCardRecord.setCardPositive(cardPositive);
  209 + idCardRecord.setCardNegative(cardNegative);
  210 +
  211 + idCardMapper.updateByPrimaryKeySelective(idCardRecord);
  212 +
  213 + Map<String, String> retMap = formatIdCardRecord(idCardRecord);
  214 +
  215 + clearAddressCache(addressBo.getUid());
  216 + logger.info("add IDCard info end: {}", retMap);
  217 + return retMap;
  218 + }
  219 +
170 @Override 220 @Override
171 //@Cachable(key="globalbuy:order:addressList:{}", expire=300, includeArgs={0}) //不要缓存,依赖user缓存 221 //@Cachable(key="globalbuy:order:addressList:{}", expire=300, includeArgs={0}) //不要缓存,依赖user缓存
172 public JSONArray getAddressList(int uid) { 222 public JSONArray getAddressList(int uid) {