提交修改

This commit is contained in:
quyixiao 2020-09-19 15:15:41 +08:00
parent d5c055f819
commit e28747425a
14 changed files with 342 additions and 35 deletions

View File

@ -0,0 +1,199 @@
package com.lz.modules.app.controller;
import com.lz.common.utils.NumberUtil;
import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.modules.flow.entity.FlowDepartment;
import com.lz.modules.flow.entity.RecordAuth;
import com.lz.modules.flow.entity.RecordRole;
import com.lz.modules.flow.entity.RecordRoleAuth;
import com.lz.modules.flow.service.RecordAuthService;
import com.lz.modules.flow.service.RecordRoleAuthService;
import com.lz.modules.flow.service.RecordRoleService;
import com.lz.modules.sys.entity.SysMenuEntity;
import com.lz.modules.sys.entity.SysRoleEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 记录表
*
* @author zgh
* @email zgh@ldxinyong.com
* @date 2020-09-18 16:33:18
*/
@RestController
@RequestMapping("user/lzrecordrole")
public class RecordRoleController {
@Autowired
private RecordRoleService lzRecordRoleService;
@Autowired
private RecordAuthService recordAuthService;
@Autowired
private RecordRoleAuthService recordRoleAuthService;
/**
* 列表
*/
@RequestMapping("/list")
@RequiresPermissions("user:lzrecordrole:list")
public R list(@RequestParam Map<String, Object> params) {
PageUtils page = lzRecordRoleService.queryPage(params);
return R.ok().put("page", page);
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id) {
RecordRole lzRecordRole = lzRecordRoleService.selectRecordRoleById(id);
SysRoleEntity role = new SysRoleEntity();
role.setRoleId(lzRecordRole.getId());
role.setRoleName(lzRecordRole.getName());
//查询角色对应的菜单
List<Long> menuIdList = recordRoleAuthService.queryMenuIdList(id);
role.setMenuIdList(menuIdList);
return R.ok().put("role", role);
}
@RequestMapping("/menu/list")
public List<SysMenuEntity> menuList() {
List<SysMenuEntity> list = new ArrayList<>();
List<RecordAuth> recordAuths = recordAuthService.selectAll();
for (int i = 0; i < recordAuths.size(); i++) {
RecordAuth recordAuth = recordAuths.get(i);
Long parentId = recordAuth.getId();
if (i + 1 < recordAuths.size()) {
RecordAuth child = recordAuths.get(i + 1);
if (child.getIdentity().equals(recordAuth.getIdentity())) {
parentId = NumberUtil.objToLong(recordAuth.getId() + "000000");
}
}
SysMenuEntity sysMenuEntity = buildMenuEntity(parentId, recordAuth.getName(), 0l, "");
list.add(sysMenuEntity);
if (i + 1 < recordAuths.size()) {
RecordAuth child = recordAuths.get(i + 1);
if (!child.getIdentity().equals(recordAuth.getIdentity())) {
continue;
}
for (int j = i; j < recordAuths.size(); j++) {
child = recordAuths.get(j);
if (!child.getIdentity().equals(recordAuth.getIdentity())) {
if (j == recordAuths.size() - 1) {
i = j;
} else {
i = j - 1;
}
break;
}
String name = "不可见";
if (child.getStatus().equals(1)) {
name = "可见";
} else if (child.getStatus().equals(2)) {
name = "可编辑";
}
SysMenuEntity childMenuEntity = buildMenuEntity(child.getId(), name, parentId, recordAuth.getName());
list.add(childMenuEntity);
if (j == recordAuths.size() - 1) {
i = j;
}
}
}
}
return list;
}
/**
* 修改角色
*/
@PostMapping("/updateOrAdd")
public R update(@RequestBody SysRoleEntity role) {
RecordRole recordRole = null;
if (role.getRoleId() != null) {
recordRole = lzRecordRoleService.getById(role.getRoleId());
recordRole.setName(role.getRoleName());
lzRecordRoleService.updateRecordRoleById(recordRole);
}else{
recordRole = new RecordRole();
recordRole.setName(role.getRoleName());
lzRecordRoleService.insertRecordRole(recordRole);
}
List<RecordRoleAuth> recordRoleAuths = recordRoleAuthService.selectByRoleId(role.getRoleId());
List<Long> menuIds = role.getMenuIdList();
for (RecordRoleAuth roleAuth : recordRoleAuths) {
if (!menuIds.contains(roleAuth.getAuthId())) {
recordRoleAuthService.deleteRecordRoleAuth(roleAuth.getId());
}
}
recordRoleAuths = recordRoleAuthService.selectByRoleId(role.getRoleId());
Map<Long, RecordRoleAuth> staffEntityMap = recordRoleAuths.stream().collect(Collectors.toMap(RecordRoleAuth::getAuthId,p->p));
for(Long menuId:menuIds){
if(menuId <= 0 ){
continue;
}
RecordRoleAuth recordRoleAuth = staffEntityMap.get(menuId);
if(recordRoleAuth == null){
recordRoleAuth = new RecordRoleAuth();
recordRoleAuth.setRoleId(recordRole.getId());
recordRoleAuth.setAuthId(menuId);
recordRoleAuthService.insertRecordRoleAuth(recordRoleAuth);
}
}
return R.ok();
}
public SysMenuEntity buildMenuEntity(Long id, String name, Long parentId, String parentName) {
SysMenuEntity sysMenuEntity = new SysMenuEntity();
sysMenuEntity.setMenuId(id);
sysMenuEntity.setName(name);
sysMenuEntity.setParentId(parentId);
sysMenuEntity.setParentName(parentName);
return sysMenuEntity;
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("user:lzrecordrole:save")
public R save(@RequestBody RecordRole lzRecordRole) {
lzRecordRoleService.insertRecordRole(lzRecordRole);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("user:lzrecordrole:update")
public R update(@RequestBody RecordRole lzRecordRole) {
lzRecordRoleService.updateRecordRoleById(lzRecordRole);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("user:lzrecordrole:delete")
public R delete(@RequestBody Long[] ids) {
lzRecordRoleService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
}

View File

@ -35,4 +35,6 @@ public interface RecordAuthMapper extends BaseMapper<RecordAuth> {
List<RecordAuth> selectAuthInfo(@Param("roleId") Long roleId);
List<RecordAuth> selectAll();
}

View File

@ -11,6 +11,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lz.modules.flow.entity.RecordRoleAuth;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface RecordRoleAuthMapper extends BaseMapper<RecordRoleAuth> {
@ -30,4 +33,9 @@ public interface RecordRoleAuthMapper extends BaseMapper<RecordRoleAuth> {
int deleteRecordRoleAuthById(@Param("id")Long id);
List<Long> queryMenuIdList(@Param("roleId") Long roleId);
List<RecordRoleAuth> selectByRoleId(@Param("roleId") Long roleId);
void deleteRecordRoleAuth(@Param("id") Long id);
}

View File

@ -8,9 +8,14 @@ package com.lz.modules.flow.dao;
* @since 2020-08-18
*/
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lz.modules.flow.entity.RecordRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface RecordRoleMapper extends BaseMapper<RecordRole> {
@ -29,5 +34,7 @@ public interface RecordRoleMapper extends BaseMapper<RecordRole> {
int deleteRecordRoleById(@Param("id")Long id);
List<RecordRole> selectByCondition(@Param("page") IPage page, @Param("params") Map<String, Object> params);
List<RecordRole> selectAll();
}

View File

@ -41,4 +41,6 @@ public interface RecordAuthService extends IService<RecordAuth> {
Auth getAuth(List<RecordAuth> listAuth);
String selectByStaffId(Long staffId);
List<RecordAuth> selectAll();
}

View File

@ -3,6 +3,8 @@ package com.lz.modules.flow.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.modules.flow.entity.RecordRoleAuth;
import java.util.List;
/**
* <p>
* 权限角色表 服务类
@ -30,6 +32,9 @@ public interface RecordRoleAuthService extends IService<RecordRoleAuth> {
int deleteRecordRoleAuthById(Long id);
List<Long> queryMenuIdList(Long id);
List<RecordRoleAuth> selectByRoleId(Long roleId);
void deleteRecordRoleAuth(Long id);
}

View File

@ -1,7 +1,12 @@
package com.lz.modules.flow.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.common.utils.PageUtils;
import com.lz.modules.flow.entity.RecordRole;
import com.lz.modules.sys.entity.app.ResultRecord;
import java.util.List;
import java.util.Map;
/**
* <p>
@ -30,5 +35,9 @@ public interface RecordRoleService extends IService<RecordRole> {
int deleteRecordRoleById(Long id);
void deleteBatchIds(List<Long> asList);
PageUtils queryPage(Map<String, Object> params);
List<RecordRole> selectAll();
}

View File

@ -170,6 +170,12 @@ public class RecordAuthServiceImpl extends ServiceImpl<RecordAuthMapper, RecordA
}
}
@Override
public List<RecordAuth> selectAll() {
return recordAuthMapper.selectAll();
}
public StaffEntity getLeader(String departmentId){
DepartmentsStaffRelateEntity leader = departmentsStaffRelateService.selectLeaderByDepartmentId(departmentId);
if(leader !=null && leader.getIsLeader().equals(1)){

View File

@ -7,57 +7,68 @@ import com.lz.modules.flow.service.RecordRoleAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 权限角色表 服务类
* </p>
*
* @author quyixiao
* @since 2020-08-18
*/
* <p>
* 权限角色表 服务类
* </p>
*
* @author quyixiao
* @since 2020-08-18
*/
@Service
public class RecordRoleAuthServiceImpl extends ServiceImpl<RecordRoleAuthMapper, RecordRoleAuth> implements RecordRoleAuthService {
@Autowired
private RecordRoleAuthMapper recordRoleAuthMapper;
private RecordRoleAuthMapper recordRoleAuthMapper;
@Override
public RecordRoleAuth selectRecordRoleAuthById(Long id){
return recordRoleAuthMapper.selectRecordRoleAuthById(id);
}
@Override
public RecordRoleAuth selectRecordRoleAuthById(Long id) {
return recordRoleAuthMapper.selectRecordRoleAuthById(id);
}
@Override
public Long insertRecordRoleAuth(RecordRoleAuth recordRoleAuth){
return recordRoleAuthMapper.insertRecordRoleAuth(recordRoleAuth);
}
@Override
public Long insertRecordRoleAuth(RecordRoleAuth recordRoleAuth) {
return recordRoleAuthMapper.insertRecordRoleAuth(recordRoleAuth);
}
@Override
public int updateRecordRoleAuthById(RecordRoleAuth recordRoleAuth){
return recordRoleAuthMapper.updateRecordRoleAuthById(recordRoleAuth);
}
@Override
public int updateRecordRoleAuthById(RecordRoleAuth recordRoleAuth) {
return recordRoleAuthMapper.updateRecordRoleAuthById(recordRoleAuth);
}
@Override
public int updateCoverRecordRoleAuthById(RecordRoleAuth recordRoleAuth){
return recordRoleAuthMapper.updateCoverRecordRoleAuthById(recordRoleAuth);
}
@Override
public int updateCoverRecordRoleAuthById(RecordRoleAuth recordRoleAuth) {
return recordRoleAuthMapper.updateCoverRecordRoleAuthById(recordRoleAuth);
}
@Override
public int deleteRecordRoleAuthById(Long id) {
return recordRoleAuthMapper.deleteRecordRoleAuthById(id);
}
@Override
public int deleteRecordRoleAuthById(Long id){
return recordRoleAuthMapper.deleteRecordRoleAuthById(id);
}
@Override
public List<Long> queryMenuIdList(Long id) {
return recordRoleAuthMapper.queryMenuIdList(id);
}
@Override
public List<RecordRoleAuth> selectByRoleId(Long roleId) {
return recordRoleAuthMapper.selectByRoleId(roleId);
}
@Override
public void deleteRecordRoleAuth(Long id) {
recordRoleAuthMapper.deleteRecordRoleAuth(id);
}
}

View File

@ -1,12 +1,18 @@
package com.lz.modules.flow.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.common.utils.NumberUtil;
import com.lz.common.utils.PageUtils;
import com.lz.modules.flow.dao.RecordRoleMapper;
import com.lz.modules.flow.entity.RecordRole;
import com.lz.modules.flow.service.RecordRoleService;
import com.lz.modules.sys.entity.app.ResultRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* <p>
* 记录表 服务类
@ -58,8 +64,27 @@ public class RecordRoleServiceImpl extends ServiceImpl<RecordRoleMapper, RecordR
return recordRoleMapper.deleteRecordRoleById(id);
}
@Override
public void deleteBatchIds(List<Long> asList) {
for(Long id :asList){
deleteRecordRoleById(id);
}
}
@Override
public PageUtils queryPage(Map<String, Object> params) {
PageUtils pageUtils = PageUtils.startPage(
NumberUtil.objToIntDefault(params.get("page"),1),
NumberUtil.objToIntDefault(params.get("limit"),10)).doSelect(
page -> recordRoleMapper.selectByCondition(page, params)
);
return pageUtils;
}
@Override
public List<RecordRole> selectAll() {
return recordRoleMapper.selectAll();
}
}

View File

@ -93,5 +93,10 @@
</select>
<select id="selectAll" resultType="com.lz.modules.flow.entity.RecordAuth">
select * from lz_record_auth order by parent_id asc ,status asc
</select>
</mapper>

View File

@ -19,8 +19,6 @@
</sql>
<select id="selectRecordRoleAuthById" resultType="RecordRoleAuth" >
select * from lz_record_role_auth where id=#{id} and is_delete = 0 limit 1
</select>
@ -74,5 +72,19 @@
update lz_record_role_auth set is_delete = 1 where id=#{id} limit 1
</update>
<select id="queryMenuIdList" resultType="java.lang.Long">
select auth_id from lz_record_role_auth where role_id = #{roleId}
</select>
<select id="selectByRoleId" resultType="com.lz.modules.flow.entity.RecordRoleAuth">
select * from lz_record_role_auth where role_id = #{roleId}
</select>
<delete id="deleteRecordRoleAuth">
delete from lz_record_role_auth where id = #{id}
</delete>
</mapper>

View File

@ -25,6 +25,7 @@
</select>
<insert id="insertRecordRole" parameterType="RecordRole" useGeneratedKeys="true" keyProperty="id" >
insert into lz_record_role(
<if test="name != null">name, </if>
@ -69,5 +70,20 @@
update lz_record_role set is_delete = 1 where id=#{id} limit 1
</update>
<select id="selectByCondition" resultType="com.lz.modules.flow.entity.RecordRole">
select * from lz_record_role where 1 = 1
<if test="params.name != null and params.name !='' ">
AND name LIKE CONCAT('%',#{params.name},'%')
</if>
order by id desc
</select>
<select id="selectAll" resultType="com.lz.modules.flow.entity.RecordRole">
select * from lz_record_role
</select>
</mapper>

View File

@ -51,7 +51,7 @@ public class Create {
}
public static void main(String[] args) {
Create ot=new Create();
String [] tableNames = {"lz_result_record"};
String [] tableNames = {"lz_record_role"};
try {
ot.generatorCode(tableNames);
} catch (Exception e) {