Authored by LUOXC

Merge branch 'dev5.7' into dev_session校验

# Conflicts:
#	order/src/main/java/com/yoho/global/order/service/impl/AddressServiceImpl.java
package com.yoho.global.dal;
import java.util.List;
import com.yoho.global.dal.model.TblCustomerIdcard;
import org.apache.ibatis.annotations.Param;
import com.yoho.global.dal.model.TblCustomerIdcard;
import java.util.List;
public interface TblCustomerIdcardMapper {
int addIdCard(TblCustomerIdcard record);
List<TblCustomerIdcard> selectIdCardBatchByUid(@Param("uid") Integer uid,
@Param("addressIdList") List<Integer> addressIdList);
List<TblCustomerIdcard> selectIdCardBatchByUid(@Param("uid") Integer uid, @Param("addressIdList") List<Integer> addressIdList);
int updateByPrimaryKeySelective(TblCustomerIdcard record);
TblCustomerIdcard selectByUidAndAddressId(@Param("uid") Integer uid, @Param("addressId") Integer addressId);
/**
*
... ...
... ... @@ -23,20 +23,28 @@
from tbl_customer_idcard
where idcard_id = #{idcardId,jdbcType=INTEGER}
</select>
<select id="selectIdCardBatchByUid" resultMap="BaseResultMap" >
select
select
<include refid="Base_Column_List" />
from tbl_customer_idcard
where user_id = #{uid,jdbcType=INTEGER}
<if test="addressIdList != null">
and address_id in
<foreach item="item" index="index" collection="addressIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
and address_id in
<foreach item="item" index="index" collection="addressIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
<select id="selectByUidAndAddressId" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tbl_customer_idcard
where user_id = #{uid,jdbcType=INTEGER}
and address_id = #{addressId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from tbl_customer_idcard
where idcard_id = #{idcardId,jdbcType=INTEGER}
... ...
... ... @@ -17,7 +17,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.global.common.cache.Cachable;
import com.yoho.global.common.cache.CacheEnum;
import com.yoho.global.common.cache.CacheRedis;
import com.yoho.global.common.rest.client.YHMethodContants;
... ... @@ -48,7 +47,13 @@ public class AddressServiceImpl implements AddressService {
public JSONObject addAddress(AddressBO addressBo) {
//校验入参
validGlobalBuyAddressRequest(addressBo);
// 验证身份证号码
if(!IDCardUtil.isIDCard(addressBo.getCardNumber())) {
logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());
throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);
}
//1、添加收货地址
Map<String, String> params = new HashMap<String, String>();
params.put("uid", String.valueOf(addressBo.getUid()));
... ... @@ -92,11 +97,7 @@ public class AddressServiceImpl implements AddressService {
throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_MOBILE_INVALID);
}
}
if(!IDCardUtil.isIDCard(addressBo.getCardNumber())) {
logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());
throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);
}
}
/**
... ... @@ -134,9 +135,24 @@ public class AddressServiceImpl implements AddressService {
public JSONObject editAddress(AddressBO addressBo) {
//校验入参
validGlobalBuyAddressRequest(addressBo);
TblCustomerIdcard customerIdcard = idCardMapper.selectByUidAndAddressId(addressBo.getUid(),addressBo.getAddressId());
// 验证身份证号码
if(addressBo.getCardNumber() == null || addressBo.getCardNumber().contains( "*" )){
if(customerIdcard == null){
logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());
throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);
}
// 不修改身份证号码
addressBo.setCardNumber( null );
} else {
if(!IDCardUtil.isIDCard(addressBo.getCardNumber())) {
logger.warn("globalbuy address params invalid, cardId: {}", addressBo.getCardNumber());
throw new ServiceException(ServiceError.GLOBALBUY_ADDRESS_IDCARD_INVALID);
}
}
//1、添加收货地址
Map<String, String> params = new HashMap<String, String>();
Map<String, String> params = new HashMap<>();
params.put("id", String.valueOf(addressBo.getAddressId()));
params.put("uid", String.valueOf(addressBo.getUid()));
params.put("address", addressBo.getAddress());
... ... @@ -145,12 +161,16 @@ public class AddressServiceImpl implements AddressService {
params.put("consignee", addressBo.getConsignee());
JSONObject addressJson = yhRestCaller.yhbGetMethod(YHMethodContants.YH_ADDRESS_EDIT, params, JSONObject.class);
logger.info("edit globalbuy address to yohobuy: {}", addressJson);
Map<String, String> idCardInfos = addIDCard(addressBo, addressBo.getAddressId());
Map<String, String> idCardInfos;
if(customerIdcard == null){
idCardInfos = addIDCard(addressBo, addressBo.getAddressId());
} else {
idCardInfos = updateIDCard(addressBo, customerIdcard);
}
addressJson.putAll(idCardInfos);
addressJson.put("address_id", addressBo.getAddressId());
addressJson.put("user_id", addressBo.getUid());
clearAddressCache(addressBo.getUid());
return addressJson;
}
... ... @@ -167,6 +187,36 @@ public class AddressServiceImpl implements AddressService {
return respData;
}
/**
* 全球购身份证入库
* @param addressBo
* @param idCardRecord
* @return
*/
private Map<String, String> updateIDCard(AddressBO addressBo, TblCustomerIdcard idCardRecord) {
if(StringUtils.isNotEmpty( addressBo.getCardNumber() )){
idCardRecord.setCardNumber(addressBo.getCardNumber());
}
//必须正反面都有才可以存入
String cardPositive = addressBo.getCardPosition();
String cardNegative = addressBo.getCardNegative();
if(StringUtils.isBlank(cardPositive) || StringUtils.isBlank(cardNegative)) {
cardPositive = "";
cardNegative = "";
}
idCardRecord.setCardPositive(cardPositive);
idCardRecord.setCardNegative(cardNegative);
idCardMapper.updateByPrimaryKeySelective(idCardRecord);
Map<String, String> retMap = formatIdCardRecord(idCardRecord);
clearAddressCache(addressBo.getUid());
logger.info("add IDCard info end: {}", retMap);
return retMap;
}
@Override
//@Cachable(key="globalbuy:order:addressList:{}", expire=300, includeArgs={0}) //不要缓存,依赖user缓存
public JSONArray getAddressList(int uid) {
... ...