|
|
@@ -0,0 +1,175 @@
|
|
|
+package com.gree.mall.manager.logic.user;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.gree.mall.manager.bean.admin.AdminUserCom;
|
|
|
+import com.gree.mall.manager.bean.user.UserLevelBean;
|
|
|
+import com.gree.mall.manager.bean.user.UserLevelVO;
|
|
|
+import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
+import com.gree.mall.manager.commonmapper.UserLevelMapper;
|
|
|
+import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
+import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
+import com.gree.mall.manager.plus.entity.User;
|
|
|
+import com.gree.mall.manager.plus.entity.UserLevel;
|
|
|
+import com.gree.mall.manager.plus.entity.UserLevelGoods;
|
|
|
+import com.gree.mall.manager.plus.entity.UserLevelRela;
|
|
|
+import com.gree.mall.manager.plus.service.UserLevelGoodsService;
|
|
|
+import com.gree.mall.manager.plus.service.UserLevelRelaService;
|
|
|
+import com.gree.mall.manager.plus.service.UserLevelService;
|
|
|
+import com.gree.mall.manager.plus.service.UserService;
|
|
|
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
|
|
|
+import com.gree.mall.manager.zfire.util.FieldUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class UserLevelLogic {
|
|
|
+
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
+ private final UserLevelService userLevelService;
|
|
|
+ private final UserLevelRelaService userLevelRelaService;
|
|
|
+ private final UserLevelGoodsService userLevelGoodsService;
|
|
|
+ private final UserService userService;
|
|
|
+ private final UserLevelMapper userLevelMapper;
|
|
|
+
|
|
|
+ public IPage<UserLevelVO> page(ZfireParamBean zfireParamBean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, UserLevelVO.class, adminUser);
|
|
|
+ IPage<UserLevelVO> list = commonMapper.userLevelList(new Page(zfireParamBean.getPageNum(),
|
|
|
+ zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public UserLevelBean detail(String id) {
|
|
|
+ final UserLevel userLevel = userLevelService.getById(id);
|
|
|
+ if (Objects.isNull(userLevel)) {
|
|
|
+ throw new RemoteServiceException("会员等级有误");
|
|
|
+ }
|
|
|
+ UserLevelBean bean = new UserLevelBean();
|
|
|
+ BeanUtils.copyProperties(userLevel, bean);
|
|
|
+ final List<UserLevelRela> relaList = userLevelRelaService.lambdaQuery()
|
|
|
+ .eq(UserLevelRela::getUserLevelId, id)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(relaList)) {
|
|
|
+ final List<String> ids = relaList.stream().map(UserLevelRela::getUserId).collect(Collectors.toList());
|
|
|
+ final List<User> userList = userService.lambdaQuery()
|
|
|
+ .in(User::getUserId, ids)
|
|
|
+ .list();
|
|
|
+ bean.setUserList(userList);
|
|
|
+ }
|
|
|
+
|
|
|
+ final List<UserLevelGoods> userLevelGoods = userLevelGoodsService.lambdaQuery()
|
|
|
+ .eq(UserLevelGoods::getUserLevelId, id)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ bean.setGoodsSpecList(userLevelGoods);
|
|
|
+
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void del(String id) {
|
|
|
+ if (userLevelGoodsService.lambdaQuery()
|
|
|
+ .eq(UserLevelGoods::getUserLevelId, id)
|
|
|
+ .count() > 0) {
|
|
|
+ throw new RemoteServiceException("请清空商品关系后再删除等级");
|
|
|
+ }
|
|
|
+ userLevelService.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void add(UserLevel userLevel) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ String loginCompanyWechatId = adminUser.getCompanyWechatId();
|
|
|
+ if (StringUtils.isBlank(loginCompanyWechatId)) {
|
|
|
+ throw new RemoteServiceException("无添加会员等级权限");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(userLevel.getSort())) {
|
|
|
+ throw new RemoteServiceException("排序不能为空");
|
|
|
+ }
|
|
|
+ if (userLevelService.lambdaQuery()
|
|
|
+ .eq(UserLevel::getCompanyWechatId,adminUser.getCompanyWechatId())
|
|
|
+ .eq(UserLevel::getSort, userLevel.getSort())
|
|
|
+ .count() > 0)
|
|
|
+ throw new RemoteServiceException("排序重复,请修改");
|
|
|
+
|
|
|
+ userLevel.setCompanyWechatId(loginCompanyWechatId);
|
|
|
+ userLevel.setCompanyWechatName(adminUser.getCompanyName());
|
|
|
+ userLevel.insert();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void edit(UserLevel userLevel) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ String loginCompanyWechatId = adminUser.getCompanyWechatId();
|
|
|
+ if (StringUtils.isBlank(loginCompanyWechatId)) {
|
|
|
+ throw new RemoteServiceException("无编辑会员等级权限");
|
|
|
+ }
|
|
|
+ String id = userLevel.getId();
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ throw new RemoteServiceException("无效会员等级");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.isNull(userLevel.getSort())) {
|
|
|
+ throw new RemoteServiceException("排序不能为空");
|
|
|
+ }
|
|
|
+ if (userLevelService.lambdaQuery()
|
|
|
+ .eq(UserLevel::getCompanyWechatId, adminUser.getCompanyWechatId())
|
|
|
+ .eq(UserLevel::getSort, userLevel.getSort())
|
|
|
+ .ne(UserLevel::getId, userLevel.getId())
|
|
|
+ .count() > 0)
|
|
|
+ throw new RemoteServiceException("排序重复,请修改");
|
|
|
+
|
|
|
+ //更新
|
|
|
+ userLevel.updateById();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void addUser(UserLevelBean userLevel) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ String loginCompanyWechatId = adminUser.getCompanyWechatId();
|
|
|
+ if (StringUtils.isBlank(loginCompanyWechatId)) {
|
|
|
+ throw new RemoteServiceException("无添加会员关系权限");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先清空会员关系
|
|
|
+ userLevelRelaService.lambdaUpdate()
|
|
|
+ .eq(UserLevelRela::getUserLevelId, userLevel.getId())
|
|
|
+ .remove();
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(userLevel.getUserList())) {
|
|
|
+ List<UserLevelRela> relaList = new ArrayList<>();
|
|
|
+ for (UserLevelRela userLevelRela : userLevel.getRelaList()) {
|
|
|
+ UserLevelRela rela = new UserLevelRela();
|
|
|
+ // 如果会员在其他等级里就阻止
|
|
|
+ final UserLevel existUserLevel = userLevelMapper.existUserInUserLevel(loginCompanyWechatId, userLevelRela.getUserId(), userLevel.getId());
|
|
|
+
|
|
|
+ if (Objects.nonNull(existUserLevel)) {
|
|
|
+ final User user = userService.getById(userLevelRela.getUserId());
|
|
|
+ throw new RemoteServiceException(user.getNickName() + "已在" + existUserLevel.getLevelName() + "建立关系");
|
|
|
+ }
|
|
|
+ rela.setCompanyWechatId(userLevel.getCompanyWechatId())
|
|
|
+ .setUserId(userLevelRela.getUserId())
|
|
|
+ .setUserLevelId(userLevel.getId());
|
|
|
+
|
|
|
+ relaList.add(rela);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|