|
@@ -0,0 +1,101 @@
|
|
|
|
|
+package com.uas.platform.b2c.common.account.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.uas.platform.b2c.common.account.dao.EnterpriseDao;
|
|
|
|
|
+import com.uas.platform.b2c.common.account.dao.RoleDao;
|
|
|
|
|
+import com.uas.platform.b2c.common.account.dao.UserDao;
|
|
|
|
|
+import com.uas.platform.b2c.common.account.model.Role;
|
|
|
|
|
+import com.uas.platform.b2c.common.account.model.User;
|
|
|
|
|
+import com.uas.platform.b2c.common.account.service.RoleService;
|
|
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
|
|
+import com.uas.platform.core.model.Constant;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class RoleServiceImpl implements RoleService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RoleDao roleDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private EnterpriseDao enterpriseDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UserDao userDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Role> findAll() {
|
|
|
|
|
+ return findByEnterprise(SystemSession.getUser().getEnterprise().getUu());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Role> findByEnterprise(long enUU) {
|
|
|
|
|
+ List<Role> roles = roleDao.findByEnUU(enUU);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(roles)) {
|
|
|
|
|
+ // 角色为空,说明资料未初始化或初始化失败,需重新init
|
|
|
|
|
+ enterpriseDao.callInitProcedure(enUU);
|
|
|
|
|
+ roles = roleDao.findByEnUU(enUU);
|
|
|
|
|
+ }
|
|
|
|
|
+ return roles;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Role save(Role role) {
|
|
|
|
|
+ Assert.notNull(role.getDesc());
|
|
|
|
|
+ long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
|
|
+ // 角色描述不能重复
|
|
|
|
|
+ List<Role> roles = roleDao.findByEnUUAndDesc(enUU, role.getDesc());
|
|
|
|
|
+ if (roles.size() > 0 && !roles.get(0).equals(role))
|
|
|
|
|
+ throw new IllegalOperatorException("角色描述不能重复");
|
|
|
|
|
+ if (role.getName() == null) {
|
|
|
|
|
+ // 自定义角色
|
|
|
|
|
+ role.setName("ROLE_" + System.currentTimeMillis());
|
|
|
|
|
+ role.setEnUU(enUU);
|
|
|
|
|
+ role.setIsdefault(Constant.NO);
|
|
|
|
|
+ role.setIssys(Constant.NO);
|
|
|
|
|
+ }
|
|
|
|
|
+ return roleDao.save(role);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Role findById(long id) {
|
|
|
|
|
+ return roleDao.findOne(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void delete(Role role) {
|
|
|
|
|
+ if (role != null && role.getId() != null) {
|
|
|
|
|
+ List<User> users = userDao.findByRole(role.getId());
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(users)) {
|
|
|
|
|
+ for (User user : users) {
|
|
|
|
|
+ user.getRoles().remove(role);
|
|
|
|
|
+ }
|
|
|
|
|
+ userDao.save(users);
|
|
|
|
|
+ }
|
|
|
|
|
+ roleDao.delete(role);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void delete(long id) {
|
|
|
|
|
+ delete(findById(id));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ModelMap getCurrentRoles() {
|
|
|
|
|
+ return new ModelMap("count", roleDao.findByEnuuAndUseruu(SystemSession.getUser().getEnterprise().getUu(),SystemSession.getUser().getUserUU()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ModelMap isManager() {
|
|
|
|
|
+ return new ModelMap("isManager", roleDao.findByEnuuAndUserUU(SystemSession.getUser().getEnterprise().getUu(),SystemSession.getUser().getUserUU()) > 0 ? true : false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|