Commit 3cd9e996 by huangjinxin

fix:用户菜单设置

1 parent 385c258f
package com.dituhui.pea.pojo.user;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import java.io.Serializable;
import java.util.Date;
@Data
public class UserMenuSettingInfo implements Serializable {
private static final long serialVersionUID = 7231322653202273612L;
/**
* 主键
*/
private String id;
/**
* 账号
*/
private String userId;
/**
* 菜单
*/
private String menu;
/**
* 设置
*/
private String setting;
}
...@@ -3,6 +3,7 @@ package com.dituhui.pea.user; ...@@ -3,6 +3,7 @@ package com.dituhui.pea.user;
import com.dituhui.pea.common.PageResult; import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.pojo.*; import com.dituhui.pea.pojo.*;
import com.dituhui.pea.pojo.user.OrgInfo; import com.dituhui.pea.pojo.user.OrgInfo;
import com.dituhui.pea.pojo.user.UserMenuSettingInfo;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
...@@ -184,4 +185,21 @@ public interface IUser { ...@@ -184,4 +185,21 @@ public interface IUser {
@RequestMapping(value = "/pea-user/orgsNoName", method = RequestMethod.GET) @RequestMapping(value = "/pea-user/orgsNoName", method = RequestMethod.GET)
Result<List<OrgInfo>> orgsNoName(@RequestParam("userId") String userId); Result<List<OrgInfo>> orgsNoName(@RequestParam("userId") String userId);
/**
* 获取用户组织
*
* @param userId 查询条件
* @return
*/
@RequestMapping(value = "/pea-user/getSettings", method = RequestMethod.GET)
Result<List<UserMenuSettingInfo>> getSettings(@RequestHeader("userId") String userId);
/**
* 获取用户组织
*
* @return
*/
@RequestMapping(value = "/pea-user/getSettings", method = RequestMethod.POST)
Result saveSetting(@RequestBody UserMenuSettingInfo menuSettingInfo);
} }
...@@ -4,6 +4,7 @@ package com.dituhui.pea.user.controller; ...@@ -4,6 +4,7 @@ package com.dituhui.pea.user.controller;
import com.dituhui.pea.common.PageResult; import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.pojo.*; import com.dituhui.pea.pojo.*;
import com.dituhui.pea.pojo.user.OrgInfo; import com.dituhui.pea.pojo.user.OrgInfo;
import com.dituhui.pea.pojo.user.UserMenuSettingInfo;
import com.dituhui.pea.user.dao.UserOrgDao; import com.dituhui.pea.user.dao.UserOrgDao;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -173,4 +174,24 @@ public class UserController implements IUser { ...@@ -173,4 +174,24 @@ public class UserController implements IUser {
return Result.success(orgInfos); return Result.success(orgInfos);
} }
@Override
public Result<List<UserMenuSettingInfo>> getSettings(String userId) {
if (StringUtils.isBlank(userId)) {
return Result.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
List<UserMenuSettingInfo> settingInfos = userService.getSettings(userId);
return Result.success(settingInfos);
}
@Override
public Result<List<UserMenuSettingInfo>> saveSetting(UserMenuSettingInfo userMenuSettingInfo) {
if (StringUtils.isBlank(userMenuSettingInfo.getSetting()) || StringUtils.isBlank(userMenuSettingInfo.getMenu()) || StringUtils.isBlank(userMenuSettingInfo.getUserId())) {
return Result.failed(StatusCodeEnum.COMMON_PARAM_EMPTY);
}
userService.saveSetting(userMenuSettingInfo);
return Result.success();
}
} }
package com.dituhui.pea.user.dao;
import com.dituhui.pea.user.entity.UserMenuSettingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface UserMenuSettingDao extends JpaRepository<UserMenuSettingEntity, String>, JpaSpecificationExecutor<UserMenuSettingEntity>,
CrudRepository<UserMenuSettingEntity, String> {
List<UserMenuSettingEntity> findByUserId(String userId);
UserMenuSettingEntity findByUserIdAndMenu(String userId, String menu);
}
package com.dituhui.pea.user.entity;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "sys_user_menu_setting")
@Data
@EntityListeners(AuditingEntityListener.class)
public class UserMenuSettingEntity implements Serializable {
private static final long serialVersionUID = 2359135550756920074L;
/**
* 主键
*/
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
@Column(name = "ID", unique = true, nullable = false, length = 32)
private String id;
/**
* 账号
*/
@Column(name = "user_id")
private String userId;
/**
* 菜单
*/
@Column(name = "menu")
private String menu;
/**
* 设置
*/
@Column(name = "setting")
private String setting;
/**
* 创建人
*/
@Column(name = "CREATED_BY")
private String createdBy;
/**
* 创建时间
*/
@Column(name = "CREATED_TIME")
@CreatedDate
private Date createdTime;
/**
* 更新人
*/
@Column(name = "UPDATED_BY")
private String updatedBy;
/**
* 更新时间
*/
@Column(name = "UPDATED_TIME")
@LastModifiedDate
private Date updatedTime;
}
...@@ -14,6 +14,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -14,6 +14,7 @@ import com.alibaba.fastjson.JSONObject;
import com.dituhui.pea.common.PageResult; import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.pojo.*; import com.dituhui.pea.pojo.*;
import com.dituhui.pea.pojo.user.OrgInfo; import com.dituhui.pea.pojo.user.OrgInfo;
import com.dituhui.pea.pojo.user.UserMenuSettingInfo;
import com.dituhui.pea.user.dao.*; import com.dituhui.pea.user.dao.*;
import com.dituhui.pea.user.entity.*; import com.dituhui.pea.user.entity.*;
import com.dituhui.pea.user.utils.LevelUtils; import com.dituhui.pea.user.utils.LevelUtils;
...@@ -100,6 +101,9 @@ public class UserService { ...@@ -100,6 +101,9 @@ public class UserService {
@Autowired @Autowired
UserOrgDao userOrgDao; UserOrgDao userOrgDao;
@Autowired
UserMenuSettingDao userMenuSettingDao;
public Result<UserLoginDTO> userLogin(String account, String password) { public Result<UserLoginDTO> userLogin(String account, String password) {
UserEntity user = userDao.findByLoginnameAndPass(account, SecureUtil.md5(password)); UserEntity user = userDao.findByLoginnameAndPass(account, SecureUtil.md5(password));
log.info("{}/{} login", account, password); log.info("{}/{} login", account, password);
...@@ -915,4 +919,45 @@ public class UserService { ...@@ -915,4 +919,45 @@ public class UserService {
}); });
return orgInfos; return orgInfos;
} }
/**
* 查询用户菜单配置
*
* @param userId
* @return
*/
public List<UserMenuSettingInfo> getSettings(String userId) {
List<UserMenuSettingInfo> settingInfos = new ArrayList<>();
// 获取角色
List<UserMenuSettingEntity> menuSettingEntities = userMenuSettingDao.findByUserId(userId);
if (CollectionUtils.isEmpty(menuSettingEntities)) {
return settingInfos;
}
menuSettingEntities.forEach(e -> {
UserMenuSettingInfo settingInfo = new UserMenuSettingInfo();
settingInfo.setId(e.getId());
settingInfo.setUserId(e.getUserId());
settingInfo.setMenu(e.getMenu());
settingInfo.setSetting(e.getSetting());
settingInfos.add(settingInfo);
});
return settingInfos;
}
/**
* 用户菜单配置新增修改
*
* @param userMenuSettingInfo
* @return
*/
public void saveSetting(UserMenuSettingInfo userMenuSettingInfo) {
UserMenuSettingEntity menuSetting = userMenuSettingDao.findByUserIdAndMenu(userMenuSettingInfo.getUserId(), userMenuSettingInfo.getMenu());
if (ObjectUtil.isNull(menuSetting)) {
menuSetting = new UserMenuSettingEntity();
}
menuSetting.setSetting(userMenuSettingInfo.getSetting());
menuSetting.setUserId(userMenuSettingInfo.getUserId());
menuSetting.setMenu(userMenuSettingInfo.getMenu());
userMenuSettingDao.save(menuSetting);
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!