| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | |
| | | |
| | | |
| | | public void addOrUpdateSupplier(SupplierSubDTO dto) { |
| | |
| | | SupplierSub supplierSub; |
| | | if (dto.getId() == null) { |
| | | |
| | | SupplierDTO supplierDTO = supplierMapper.getCurrentSupplier(SecurityUtils.getUserId()); |
| | | SupplierDTO supplierDTO = supplierService.getCurrentSupplier(); |
| | | if(ObjectUtils.isEmpty(supplierDTO)){ |
| | | throw new ValidationException("供应商信息不存在"); |
| | | } |
| | |
| | | |
| | | |
| | | 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; |
| | |
| | | public SupplierSub getById(Long id) { |
| | | return supplierSubMapper.selectById(id); |
| | | } |
| | | |
| | | public CurrentUserDTO getSwitchById(Long id) { |
| | | SupplierSub supplierSub = supplierSubMapper.selectById(id); |
| | | String userId = supplierSub.getUserId(); |
| | | |
| | | 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(SecurityUtils.getUserId()); |
| | | if (!ObjectUtils.isEmpty(sub)) { |
| | | 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); |
| | | } |
| | | } |