From ae1471f378f399f76518539ec8992e64a3673436 Mon Sep 17 00:00:00 2001 From: 陶杰 <1378534974@qq.com> Date: 星期三, 08 一月 2025 15:26:06 +0800 Subject: [PATCH] 1.订单提交:订单最小金额配置 --- src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java | 207 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 196 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java b/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java index 2a439d2..fff21cd 100644 --- a/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java +++ b/src/main/java/com/mzl/flower/service/supplier/SupplierSubService.java @@ -3,26 +3,41 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.base.cache.StringCacheClient; +import com.mzl.flower.config.GlobalSupplierVariables; import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.constant.Constants; import com.mzl.flower.dto.request.register.RegisterDTO; import com.mzl.flower.dto.request.supplier.QuerySupplierSubDTO; import com.mzl.flower.dto.request.supplier.SupplierSubDTO; +import com.mzl.flower.dto.response.current.CurrentUserDTO; import com.mzl.flower.dto.response.supplier.SupplierDTO; import com.mzl.flower.dto.response.supplier.SupplierSubVO; +import com.mzl.flower.dto.response.system.MenuTreeDTO; +import com.mzl.flower.entity.point.CustomerPoint; import com.mzl.flower.entity.supplier.SupplierSub; +import com.mzl.flower.entity.system.Role; import com.mzl.flower.entity.system.User; +import com.mzl.flower.entity.system.UserWechat; +import com.mzl.flower.mapper.point.CustomerPointMapper; import com.mzl.flower.mapper.supplier.SupplierMapper; import com.mzl.flower.mapper.supplier.SupplierSubMapper; +import com.mzl.flower.mapper.system.MenuMapper; +import com.mzl.flower.mapper.system.PartnerMenuMapper; import com.mzl.flower.mapper.system.UserMapper; +import com.mzl.flower.mapper.system.UserWechatMapper; import com.mzl.flower.service.BaseService; +import com.mzl.flower.service.customer.CustomerService; +import com.mzl.flower.service.partner.PartnerService; +import com.mzl.flower.service.system.RoleService; +import com.mzl.flower.utils.TreeBuilderUtil; import com.mzl.flower.utils.UUIDGenerator; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -48,23 +63,38 @@ public static final String SEPARATOR = ":"; private final SupplierMapper supplierMapper; + private final SupplierService supplierService; + private final RoleService roleService; + private final MenuMapper menuMapper; + private final PartnerMenuMapper partnerMenuMapper; + private final CustomerService customerService; + private final CustomerPointMapper customerPointMapper; + private final PartnerService partnerService; + private final StationService stationService; + private final UserWechatMapper wechatMapper; + + private final GlobalSupplierVariables globalSupplierVariables; + + 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; if (dto.getId() == null) { - SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); + SupplierDTO supplierDTO = supplierService.getCurrentSupplier(); if(ObjectUtils.isEmpty(supplierDTO)){ throw new ValidationException("供应商信息不存在"); } @@ -81,6 +111,7 @@ supplierSub = new SupplierSub(); BeanUtils.copyProperties(dto, supplierSub, "id"); + supplierSub.setSupplierId(supplierDTO.getId()); supplierSub.create(SecurityUtils.getUserId()); supplierSub.setIsEnabled(true); @@ -153,7 +184,7 @@ private boolean checkExistName(String name, Long supplierId) { - if (StringUtils.isEmpty(name)) { + if (!StringUtils.isEmpty(name)) { LambdaQueryWrapper<SupplierSub> lambdaQueryWrapper = new LambdaQueryWrapper(); lambdaQueryWrapper.eq(SupplierSub::getName, name).eq(SupplierSub::getSupplierId, supplierId); return supplierSubMapper.selectCount(lambdaQueryWrapper) > 0; @@ -162,7 +193,7 @@ } - public Page<SupplierDTO> querySupplier(QuerySupplierSubDTO dto, Page page) { + public Page<SupplierSubVO> querySupplier(QuerySupplierSubDTO dto, Page page) { List<SupplierSubVO> list = supplierSubMapper.querySupplierSub(dto, page); page.setRecords(list); return page; @@ -219,4 +250,158 @@ supplierSubMapper.deleteById(id); } } + + public List<SupplierSub> getSubSupplier() { + List<SupplierSub> supplierSubs = new ArrayList<>(); + SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); + if (ObjectUtils.isEmpty(supplierDTO)) { + throw new ValidationException("供应商信息不存在"); + } + + List<SupplierSub> subSupplier = supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId())); + if (!CollectionUtils.isEmpty(subSupplier)) { + subSupplier.forEach(s -> { + s.setIsSub(true); + s.setType(0); + }); + supplierSubs.addAll(subSupplier); + } + return supplierSubs; + } + + public SupplierSub getById(Long id) { + return supplierSubMapper.selectById(id); + } + + public CurrentUserDTO getSwitchById(Long id, int type) { + String userId = ""; + if (type == 1) { + userId = SecurityUtils.getUserId(); + SupplierDTO currentSupplier = supplierMapper.getCurrentSupplier(userId); + //切换主账号 + String supplier = globalSupplierVariables.getSupplier(String.valueOf(currentSupplier.getId())); + if (!StringUtils.isEmpty(supplier)) { + globalSupplierVariables.removeSupplier(String.valueOf(currentSupplier.getId())); + } + } else { + SupplierSub supplierSub = supplierSubMapper.selectById(id); + supplierSub.setType(0); + userId = supplierSub.getUserId(); + //切换子账号 + String supplier = globalSupplierVariables.getSupplier(String.valueOf(supplierSub.getSupplierId())); + if (!StringUtils.isEmpty(supplier)) { + globalSupplierVariables.removeSupplier(String.valueOf(supplierSub.getSupplierId())); + } + globalSupplierVariables.setSupplier(String.valueOf(supplierSub.getSupplierId()), userId); + } + + CurrentUserDTO result = new CurrentUserDTO(); + + //获取用户信息 + User user = getUserById(userId); + if(user == null){ + throw new ValidationException("用户不存在"); + } + result.setLoginName(user.getLoginName()); + result.setNickName(user.getNickName()); + result.setTel(user.getTel()); + result.setPicture(user.getPicture()); + result.setType(user.getType()); + + //获取用户角色信息 + List<String> roleIds = new ArrayList<>(); + List<Role> roleList = roleService.getUserRoleList(userId); + for (Role role : roleList) { + roleIds.add(role.getId()); + } + result.setRoles(roleIds); + + //根据用户角色获取用户菜单 + List<MenuTreeDTO> menus = null; + if(Constants.USER_TYPE.admin.name().equals(user.getType())){ + if (roleIds.contains(Constants.ROLE_SYS_ADMIN)) { + menus = menuMapper.selectListOrderBySeq(); + } else if (roleIds.size() > 0) { + menus = menuMapper.selectOperationList(roleIds); + } + }else if(Constants.USER_TYPE.partner.name().equals(user.getType())){ + menus = partnerMenuMapper.selectListOrderBySeq(); + } + if(menus != null) { + for (MenuTreeDTO menu : menus) { + menu.setPath(menu.getMenuHref()); + menu.setName(menu.getMenuName()); + menu.setLabel(menu.getMenuName()); + } + menus = (List<MenuTreeDTO>) TreeBuilderUtil.buildListToTree(menus); + } + result.setMenus(menus); + result.setId(userId); + + if(Constants.USER_TYPE.customer.name().equals(user.getType())){ + result.setCustomerDTO(customerService.getCurrentCustomer()); + //查询积分 + CustomerPoint customerPoint = customerPointMapper.selectOne(new LambdaQueryWrapper<CustomerPoint>() + .eq(CustomerPoint::getUserId, userId)); + if(customerPoint == null){ + result.setCurrentPoint(0); + }else{ + Integer currentPoint =customerPoint.getTotalPoint()-customerPoint.getUsedPoint()-customerPoint.getExpiredPoint()-customerPoint.getDeductionPoint(); + result.setCurrentPoint(currentPoint>=0?currentPoint:0); + } + }else if(Constants.USER_TYPE.supplier.name().equals(user.getType())){ + result.setSupplierDTO(supplierService.getCurrentSupplier()); + SupplierSub sub = supplierSubMapper.getCurrentSupplier(userId); + if (!ObjectUtils.isEmpty(sub)) { + sub.setType(0); + result.setIsSubSupplier(true); + result.setSupplierSub(sub); + result.setSwitchFlag(true); + } else { + result.setIsSubSupplier(false); + result.setSupplierSub(null); + result.setSwitchFlag(true); + } + }else if(Constants.USER_TYPE.partner.name().equals(user.getType())){ + result.setPartnerDTO(partnerService.getCurrentPartner()); + }else if (Constants.USER_TYPE.admin.name().equals(user.getType())){ + result.setMainWarehouse(stationService.getMainWarehouse(user.getId())); + } + result.setBindWechat(wechatMapper.selectCount(new LambdaQueryWrapper<UserWechat>() + .eq(UserWechat::getUserId, userId)) > 0); + + return result; + + } + + public User getUserById(String id){ + return userMapper.selectById(id); + } + + public List<SupplierSub> getAllSupplier() { + List<SupplierSub> supplierSubs = new ArrayList<>(); + SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); + if (!ObjectUtils.isEmpty(supplierDTO)) { + SupplierSub subParent = new SupplierSub(); + subParent.setId((long) -1); + subParent.setUserId(supplierDTO.getUserId()); + subParent.setSupplierId(supplierDTO.getId()); + subParent.setName(supplierDTO.getName()); + subParent.setContact(supplierDTO.getContactName()); + subParent.setPhone(supplierDTO.getContactTel()); + subParent.setIsEnabled(supplierDTO.getIsEnabled()); + subParent.setIsSub(false); + subParent.setType(1); + supplierSubs.add(subParent); + } + List<SupplierSub> subSupplier = supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId())); + if (!CollectionUtils.isEmpty(subSupplier)) { + subSupplier.forEach(s->{ + s.setIsSub(true); + s.setType(0); + }); + supplierSubs.addAll(subSupplier); + } + return supplierSubs; + } } -- Gitblit v1.9.3