|
@@ -3,6 +3,12 @@ package cn.newfeifan.mall.module.trade.service.delivery;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
+import cn.newfeifan.mall.module.system.dal.mysql.user.AdminUserMapper;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import cn.newfeifan.mall.framework.common.pojo.PageResult;
|
|
|
import cn.newfeifan.mall.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.expresstemplate.*;
|
|
@@ -13,6 +19,7 @@ import cn.newfeifan.mall.module.trade.dal.mysql.delivery.DeliveryExpressTemplate
|
|
|
import cn.newfeifan.mall.module.trade.dal.mysql.delivery.DeliveryExpressTemplateFreeMapper;
|
|
|
import cn.newfeifan.mall.module.trade.dal.mysql.delivery.DeliveryExpressTemplateMapper;
|
|
|
import cn.newfeifan.mall.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -22,6 +29,7 @@ import java.util.*;
|
|
|
|
|
|
import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.*;
|
|
|
+import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
import static cn.newfeifan.mall.module.trade.convert.delivery.DeliveryExpressTemplateConvert.INSTANCE;
|
|
|
import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.EXPRESS_TEMPLATE_NAME_DUPLICATE;
|
|
|
import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.EXPRESS_TEMPLATE_NOT_EXISTS;
|
|
@@ -33,6 +41,7 @@ import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.EXPRESS_TE
|
|
|
*/
|
|
|
@Service
|
|
|
@Validated
|
|
|
+@Slf4j
|
|
|
public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTemplateService {
|
|
|
|
|
|
@Resource
|
|
@@ -41,6 +50,11 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla
|
|
|
private DeliveryExpressTemplateChargeMapper expressTemplateChargeMapper;
|
|
|
@Resource
|
|
|
private DeliveryExpressTemplateFreeMapper expressTemplateFreeMapper;
|
|
|
+ @Resource
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserMapper userMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -50,6 +64,9 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla
|
|
|
|
|
|
// 插入
|
|
|
DeliveryExpressTemplateDO template = INSTANCE.convert(createReqVO);
|
|
|
+ ShopBO shop = getShop();
|
|
|
+ template.setShopId(shop.getShopId());
|
|
|
+ template.setMerchantId(shop.getMerId());
|
|
|
expressTemplateMapper.insert(template);
|
|
|
// 插入运费模板计费表
|
|
|
if (CollUtil.isNotEmpty(createReqVO.getCharges())) {
|
|
@@ -147,7 +164,12 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla
|
|
|
* @param id 运费模板编号,可以为 null
|
|
|
*/
|
|
|
private void validateTemplateNameUnique(String name, Long id) {
|
|
|
- DeliveryExpressTemplateDO template = expressTemplateMapper.selectByName(name);
|
|
|
+ ShopBO shop = getShop();
|
|
|
+ QueryWrapper<DeliveryExpressTemplateDO> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda()
|
|
|
+ .eq(DeliveryExpressTemplateDO::getShopId,shop.getShopId())
|
|
|
+ .eq(DeliveryExpressTemplateDO::getName,name);
|
|
|
+ DeliveryExpressTemplateDO template = expressTemplateMapper.selectOne(queryWrapper);
|
|
|
if (template == null) {
|
|
|
return;
|
|
|
}
|
|
@@ -215,4 +237,21 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla
|
|
|
return INSTANCE.convertMap(areaId, templateList, chargeList, freeList);
|
|
|
}
|
|
|
|
|
|
+ private ShopBO getShop() {
|
|
|
+ Long loginUserId = getLoginUserId();
|
|
|
+ String s = stringRedisTemplate.opsForValue().get("shop:" + loginUserId);
|
|
|
+ if (StringUtils.isEmpty(s)) {
|
|
|
+ AdminUserDO adminUserDO = userMapper.selectById(loginUserId);
|
|
|
+ ShopBO shop = new ShopBO();
|
|
|
+ shop.setShopId(adminUserDO.getShopId());
|
|
|
+ shop.setMerId(adminUserDO.getMerchantId());
|
|
|
+ log.info("====shop:{}",shop);
|
|
|
+ return shop;
|
|
|
+ } else {
|
|
|
+ log.info("====shop:{}",s);
|
|
|
+ return JSONObject.parseObject(s, ShopBO.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|