cloudroam
2024-12-09 2c5a0e133b64bb0a46b1419c48e9b62a4779e268
add: 供应商子账号
已修改7个文件
90 ■■■■ 文件已修改
src/main/java/com/mzl/flower/dto/request/supplier/SupplierSubDTO.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/current/CurrentUserDTO.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/BaseService.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/supplier/SupplierService.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/system/UserService.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/supplier/SupplierSubController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/supplier/SupplierSubDTO.java
@@ -26,4 +26,7 @@
    @ApiModelProperty("验证码")
    private String smsCode;
    @ApiModelProperty("验证码类型,小程序不传")
    private String type;
}
src/main/java/com/mzl/flower/dto/response/current/CurrentUserDTO.java
@@ -5,6 +5,7 @@
import com.mzl.flower.dto.response.partner.PartnerDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.dto.response.system.MenuTreeDTO;
import com.mzl.flower.entity.supplier.SupplierSub;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -56,4 +57,11 @@
    @ApiModelProperty(value = "是否总仓权限")
    private Boolean mainWarehouse;
    @ApiModelProperty(value = "是否是子供应商")
    public Boolean isSubSupplier;
    @ApiModelProperty(value = "子供应商信息")
    private SupplierSub supplierSub;
}
src/main/java/com/mzl/flower/service/BaseService.java
@@ -18,11 +18,13 @@
import com.mzl.flower.entity.payment.OrderItemSales;
import com.mzl.flower.entity.payment.OrderSalesItem;
import com.mzl.flower.entity.supplier.Supplier;
import com.mzl.flower.entity.supplier.SupplierSub;
import com.mzl.flower.mapper.customer.CustomerMapper;
import com.mzl.flower.mapper.flower.FlowerCategoryMapper;
import com.mzl.flower.mapper.member.MemberMapper;
import com.mzl.flower.mapper.partner.PartnerMapper;
import com.mzl.flower.mapper.supplier.SupplierMapper;
import com.mzl.flower.mapper.supplier.SupplierSubMapper;
import com.mzl.flower.mapper.system.UserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +33,7 @@
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -53,6 +56,9 @@
    @Autowired
    protected SupplierMapper supplierMapper;
    @Autowired
    protected SupplierSubMapper supplierSubMapper;
    @Autowired
    protected PartnerMapper partnerMapper;
@@ -552,14 +558,19 @@
        return p;
    }
    public Supplier getCurrentSupplier(){
    public Supplier getCurrentSupplier() {
        String userId = SecurityUtils.getUserId();
        Supplier s = supplierMapper.selectOne(new QueryWrapper<Supplier>()
                .eq("user_id", userId));
        if(s == null){
            throw new ValidationException("供应商信息未认证,请到个人中心进行认证");
        if (s == null) {
            SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId());
            if (!ObjectUtils.isEmpty(sub)) {
                s = supplierMapper.selectById(sub.getSupplierId());
                return s;
            } else {
                throw new ValidationException("供应商信息未认证,请到个人中心进行认证");
            }
        }
        return s;
    }
src/main/java/com/mzl/flower/service/supplier/SupplierService.java
@@ -10,7 +10,9 @@
import com.mzl.flower.dto.request.supplier.*;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.entity.supplier.Supplier;
import com.mzl.flower.entity.supplier.SupplierSub;
import com.mzl.flower.mapper.supplier.SupplierMapper;
import com.mzl.flower.mapper.supplier.SupplierSubMapper;
import com.mzl.flower.service.BaseService;
import com.mzl.flower.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
@@ -21,6 +23,7 @@
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
@@ -35,6 +38,9 @@
    private final static String SUPPLIER_STATUS_REJECT = "R"; // 审核拒绝
    private final SupplierMapper supplierMapper;
    @Resource
    private SupplierSubMapper supplierSubMapper;
    @Resource
    private BaseService baseService;
@@ -162,6 +168,16 @@
            throw new ValidationException("当前登录用户不是供应商账号");
        }
        SupplierDTO dto = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId());
        //如果是空 查询子账号的供应商ID
        if (ObjectUtils.isEmpty(dto)) {
            SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId());
            if (!ObjectUtils.isEmpty(sub)) {
                dto = supplierMapper.findSupplierDetail(sub.getSupplierId());
            }
        }
        if(ObjectUtils.isEmpty(dto)){
            throw new ValidationException("供应商信息不存在");
        }
        return dto;
    }
src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java
@@ -51,14 +51,16 @@
    public void addOrUpdateSupplier(SupplierSubDTO dto) {
        if(StringUtils.isEmpty(dto.getSmsCode())){
            throw new ValidationException("手机验证码为空");
        }
        String smsCode = dto.getSmsCode();
        //从缓存中获取验证码
        String smsCacheCode = stringCacheClient.get(SMS_CODE_KEY + SEPARATOR + Constants.USER_TYPE.supplier.name() + SEPARATOR + dto.getPhone());
        if (!org.apache.commons.lang3.StringUtils.equals(smsCode, smsCacheCode)) {
            throw new ValidationException("手机验证码不正确");
        if (StringUtils.isEmpty(dto.getType())) {
            if (StringUtils.isEmpty(dto.getSmsCode())) {
                throw new ValidationException("手机验证码为空");
            }
            String smsCode = dto.getSmsCode();
            //从缓存中获取验证码
            String smsCacheCode = stringCacheClient.get(SMS_CODE_KEY + SEPARATOR + Constants.USER_TYPE.supplier.name() + SEPARATOR + dto.getPhone());
            if (!org.apache.commons.lang3.StringUtils.equals(smsCode, smsCacheCode)) {
                throw new ValidationException("手机验证码不正确");
            }
        }
        SupplierSub supplierSub;
@@ -81,6 +83,7 @@
            supplierSub = new SupplierSub();
            BeanUtils.copyProperties(dto, supplierSub, "id");
            supplierSub.setSupplierId(supplierDTO.getId());
            supplierSub.create(SecurityUtils.getUserId());
            supplierSub.setIsEnabled(true);
@@ -227,4 +230,8 @@
        }
        return supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId()));
    }
    public SupplierSub getById(Long id) {
        return supplierSubMapper.selectById(id);
    }
}
src/main/java/com/mzl/flower/service/system/UserService.java
@@ -14,9 +14,11 @@
import com.mzl.flower.dto.response.system.UserDetailsDTO;
import com.mzl.flower.dto.response.system.UserListDTO;
import com.mzl.flower.entity.point.CustomerPoint;
import com.mzl.flower.entity.supplier.SupplierSub;
import com.mzl.flower.entity.system.*;
import com.mzl.flower.enums.TrueOrFalseEnum;
import com.mzl.flower.mapper.point.CustomerPointMapper;
import com.mzl.flower.mapper.supplier.SupplierSubMapper;
import com.mzl.flower.mapper.system.*;
import com.mzl.flower.service.customer.CustomerService;
import com.mzl.flower.service.partner.PartnerService;
@@ -32,6 +34,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
@@ -82,6 +85,9 @@
    private CustomerPointMapper customerPointMapper;
    @Autowired
    private StationService stationService;
    @Autowired
    private SupplierSubMapper supplierSubMapper;
    public User findUserByOpenId(String openId, String sessionKey, String unionId
@@ -209,6 +215,14 @@
            }
        }else if(Constants.USER_TYPE.supplier.name().equals(user.getType())){
            result.setSupplierDTO(supplierService.getCurrentSupplier());
            SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId());
            if (!ObjectUtils.isEmpty(sub)) {
                result.setIsSubSupplier(true);
                result.setSupplierSub(sub);
            } else {
                result.setIsSubSupplier(false);
                result.setSupplierSub(null);
            }
        }else if(Constants.USER_TYPE.partner.name().equals(user.getType())){
            result.setPartnerDTO(partnerService.getCurrentPartner());
        }else if (Constants.USER_TYPE.admin.name().equals(user.getType())){
src/main/java/com/mzl/flower/web/supplier/SupplierSubController.java
@@ -67,4 +67,11 @@
    public ResponseEntity<ReturnDataDTO<List<SupplierSub>>> getSubSupplier() {
        return returnData(R.SUCCESS.getCode(), supplierSubService.getSubSupplier());
    }
    @GetMapping("/getById")
    @ApiOperation(value = "通过ID查询子账号", notes = "通过ID查询子账号")
    public ResponseEntity<ReturnDataDTO<SupplierSub>> getById(@NotNull(message = "id不能为空") Long id) {
        SupplierSub supplierSub = supplierSubService.getById(id);
        return returnData(R.SUCCESS.getCode(), supplierSub);
    }
}