|
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.gree.mall.manager.bean.admin.AdminUserCom;
|
|
|
+import com.gree.mall.manager.bean.user.RoleTypeBean;
|
|
|
import com.gree.mall.manager.enums.RoleTypeEnum;
|
|
|
import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
import com.gree.mall.manager.logic.common.CommonLogic;
|
|
@@ -18,8 +19,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.Date;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class AdminRoleLogic {
|
|
@@ -42,19 +44,19 @@ public class AdminRoleLogic {
|
|
|
|
|
|
List<String> companyWechatIds = adminUser.getCompanyWechatIds();
|
|
|
|
|
|
- final AdminRole role = adminRoleService.getById(adminUser.getRoleId());
|
|
|
- Integer type = role.getType();
|
|
|
+ Integer type = adminUser.getType();
|
|
|
|
|
|
- if("admin".equals(adminUser.getUserName())){
|
|
|
- type = RoleTypeEnum.ADMIN.getCode();
|
|
|
- } else if ("企业负责人".equals(role.getName())) {
|
|
|
- type = RoleTypeEnum.ADMIN.getCode();
|
|
|
+ Integer level = null;
|
|
|
+ if (adminUser.getType() == 0 && adminUser.getIsMaster()) {
|
|
|
+ final AdminRole adminRole = adminRoleService.getById(adminUser.getRoleId());
|
|
|
+ level = adminRole.getLevel();
|
|
|
}
|
|
|
|
|
|
Page<AdminRole> rolePage = adminRoleService.lambdaQuery()
|
|
|
.like(StringUtils.isNotBlank(companyWechatName), AdminRole::getCompanyName, companyWechatName)
|
|
|
.le(AdminRole::getType, type)
|
|
|
.in(CollectionUtils.isNotEmpty(companyWechatIds), AdminRole::getCompanyWechatId, companyWechatIds)
|
|
|
+ .eq(Objects.nonNull(level), AdminRole::getLevel, level)
|
|
|
.orderByDesc(AdminRole::getType)
|
|
|
.page(new Page<>(pageNo, pageSize));
|
|
|
|
|
@@ -65,14 +67,26 @@ public class AdminRoleLogic {
|
|
|
* 新增角色
|
|
|
*/
|
|
|
public void add(HttpServletRequest request, AdminRole adminRole) {
|
|
|
-
|
|
|
//默认部门角色
|
|
|
adminRole.setType(RoleTypeEnum.WEBSIT.getCode());
|
|
|
-
|
|
|
AdminUserCom adminUser = commonLogic.getAdminUser(request);
|
|
|
+
|
|
|
+ if (adminUser.getType() == 1
|
|
|
+ && Objects.nonNull(adminRole.getLevel())
|
|
|
+ && adminRole.getLevel() != 0) {
|
|
|
+ final Integer count = adminRoleService.lambdaQuery()
|
|
|
+ .eq(AdminRole::getCompanyWechatId, adminUser.getCompanyWechatId())
|
|
|
+ .eq(AdminRole::getType, 1)
|
|
|
+ .eq(AdminRole::getLevel, adminRole.getLevel())
|
|
|
+ .count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw new RemoteServiceException("已存在同级别的角色不能再添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
adminRole.setCompanyWechatId(adminUser.getCompanyWechatId());
|
|
|
adminRole.setCompanyName(adminUser.getCompanyName());
|
|
|
- adminRole.setCreateTime(new Date());
|
|
|
adminRoleService.save(adminRole);
|
|
|
}
|
|
|
|
|
@@ -81,6 +95,20 @@ public class AdminRoleLogic {
|
|
|
*/
|
|
|
@Transactional
|
|
|
public void update(AdminRole adminRole) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ if (adminUser.getType() == 1
|
|
|
+ && Objects.nonNull(adminRole.getLevel())
|
|
|
+ && adminRole.getLevel() != 0) {
|
|
|
+ final Integer count = adminRoleService.lambdaQuery()
|
|
|
+ .eq(AdminRole::getCompanyWechatId, adminUser.getCompanyWechatId())
|
|
|
+ .eq(AdminRole::getType, 1)
|
|
|
+ .eq(AdminRole::getLevel, adminRole.getLevel())
|
|
|
+ .ne(AdminRole::getAdminRoleId, adminRole.getAdminRoleId())
|
|
|
+ .count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw new RemoteServiceException("已存在同级别的角色不能再添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
adminRoleService.updateById(adminRole);
|
|
|
|
|
|
if (adminRole.getName() != null) {
|
|
@@ -93,6 +121,10 @@ public class AdminRoleLogic {
|
|
|
* 删除角色
|
|
|
*/
|
|
|
public void delete(String adminRoleId) throws RemoteServiceException {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ if (adminUser.getType() == 0) {
|
|
|
+ throw new RemoteServiceException("网点账号不能删除角色");
|
|
|
+ }
|
|
|
//不允许删除使用该角色的帐号
|
|
|
Integer count = adminUserService.lambdaQuery().eq(AdminUser::getRoleId, adminRoleId).count();
|
|
|
if (count > 0) {
|
|
@@ -109,4 +141,25 @@ public class AdminRoleLogic {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public List<RoleTypeBean> getRoleType() {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ List<RoleTypeBean> list = new ArrayList<>();
|
|
|
+ if (adminUser.getType() == 0) {
|
|
|
+ RoleTypeBean bean = new RoleTypeBean();
|
|
|
+ bean.setCode(2);
|
|
|
+ bean.setName("平台");
|
|
|
+ list.add(bean);
|
|
|
+ }
|
|
|
+ RoleTypeBean bean2 = new RoleTypeBean();
|
|
|
+ bean2.setCode(1);
|
|
|
+ bean2.setName("平台");
|
|
|
+ list.add(bean2);
|
|
|
+
|
|
|
+ RoleTypeBean bean3 = new RoleTypeBean();
|
|
|
+ bean3.setCode(0);
|
|
|
+ bean3.setName("网点");
|
|
|
+ list.add(bean3);
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|