| | |
| | | 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 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; |
| | | |
| | |
| | | private final PartnerService partnerService; |
| | | private final StationService stationService; |
| | | private final UserWechatMapper wechatMapper; |
| | | |
| | | private final GlobalSupplierVariables globalSupplierVariables; |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | public List<SupplierSub> getSubSupplier() { |
| | | List<SupplierSub> supplierSubs = new ArrayList<>(); |
| | | SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); |
| | | if(ObjectUtils.isEmpty(supplierDTO)){ |
| | | if (ObjectUtils.isEmpty(supplierDTO)) { |
| | | throw new ValidationException("供应商信息不存在"); |
| | | } |
| | | return supplierSubMapper.getSubSupplier(String.valueOf(supplierDTO.getId())); |
| | | |
| | | 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) { |
| | | SupplierSub supplierSub = supplierSubMapper.selectById(id); |
| | | String userId = supplierSub.getUserId(); |
| | | 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(); |
| | | |
| | |
| | | } |
| | | }else if(Constants.USER_TYPE.supplier.name().equals(user.getType())){ |
| | | result.setSupplierDTO(supplierService.getCurrentSupplier()); |
| | | SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId()); |
| | | SupplierSub sub = supplierSubMapper.getCurrentSupplier(userId); |
| | | if (!ObjectUtils.isEmpty(sub)) { |
| | | sub.setType(0); |
| | | result.setIsSubSupplier(true); |
| | | result.setSupplierSub(sub); |
| | | result.setSwitchFlag(true); |
| | |
| | | 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; |
| | | } |
| | | } |