From 804747f3e3117f50363ec0908253a3f759ffe4a1 Mon Sep 17 00:00:00 2001 From: quyixiao <2621048238@qq.com> Date: Sat, 19 Sep 2020 16:43:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/StaffRoleController.java | 89 ++++++++++++ .../com/lz/modules/app/dto/StaffRoleResp.java | 11 ++ .../lz/modules/flow/dao/StaffRoleMapper.java | 4 + .../flow/service/StaffRoleService.java | 6 + .../service/impl/StaffRoleServiceImpl.java | 135 +++++++++++++----- .../resources/mapper/flow/StaffRoleMapper.xml | 4 + src/main/resources/sql | 45 ++++++ src/test/java/com/lz/mysql/MysqlMain.java | 2 +- 8 files changed, 259 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/lz/modules/app/controller/StaffRoleController.java create mode 100644 src/main/java/com/lz/modules/app/dto/StaffRoleResp.java create mode 100644 src/main/resources/sql diff --git a/src/main/java/com/lz/modules/app/controller/StaffRoleController.java b/src/main/java/com/lz/modules/app/controller/StaffRoleController.java new file mode 100644 index 00000000..26d55d57 --- /dev/null +++ b/src/main/java/com/lz/modules/app/controller/StaffRoleController.java @@ -0,0 +1,89 @@ +package com.lz.modules.app.controller; + +import java.util.Arrays; +import java.util.Map; + +import com.lz.common.utils.PageUtils; +import com.lz.common.utils.R; +import com.lz.modules.flow.entity.StaffRole; +import com.lz.modules.flow.service.StaffRoleService; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + + + + +/** + * 流转关系表 + * + * @author zgh + * @email zgh@ldxinyong.com + * @date 2020-09-19 15:22:13 + */ +@RestController +@RequestMapping("user/lzstaffrole") +public class StaffRoleController { + @Autowired + private StaffRoleService staffRoleService; + + /** + * 列表 + */ + @RequestMapping("/list") + @RequiresPermissions("user:lzstaffrole:list") + public R list(@RequestParam Map params){ + PageUtils page = staffRoleService.queryPage(params); + return R.ok().put("page", page); + } + + + /** + * 信息 + */ + @RequestMapping("/info/{id}") + @RequiresPermissions("user:lzstaffrole:info") + public R info(@PathVariable("id") Long id){ + StaffRole lzStaffRole = staffRoleService.selectByStaffId(id); + + return R.ok().put("lzStaffRole", lzStaffRole); + } + + /** + * 保存 + */ + @RequestMapping("/save") + @RequiresPermissions("user:lzstaffrole:save") + public R save(@RequestBody StaffRole lzStaffRole){ + staffRoleService.insertStaffRole(lzStaffRole); + + return R.ok(); + } + + /** + * 修改 + */ + @RequestMapping("/update") + @RequiresPermissions("user:lzstaffrole:update") + public R update(@RequestBody StaffRole lzStaffRole){ + staffRoleService.updateById(lzStaffRole); + + return R.ok(); + } + + /** + * 删除 + */ + @RequestMapping("/delete") + @RequiresPermissions("user:lzstaffrole:delete") + public R delete(@RequestBody Long[] ids){ + staffRoleService.deleteBatchIds(Arrays.asList(ids)); + + return R.ok(); + } + +} diff --git a/src/main/java/com/lz/modules/app/dto/StaffRoleResp.java b/src/main/java/com/lz/modules/app/dto/StaffRoleResp.java new file mode 100644 index 00000000..8432dde9 --- /dev/null +++ b/src/main/java/com/lz/modules/app/dto/StaffRoleResp.java @@ -0,0 +1,11 @@ +package com.lz.modules.app.dto; + +import com.lz.modules.flow.entity.StaffRole; +import lombok.Data; + +@Data +public class StaffRoleResp extends StaffRole { + private String staffName; + private String targetRole; + private String resultRole; +} diff --git a/src/main/java/com/lz/modules/flow/dao/StaffRoleMapper.java b/src/main/java/com/lz/modules/flow/dao/StaffRoleMapper.java index 5416878e..b236701a 100644 --- a/src/main/java/com/lz/modules/flow/dao/StaffRoleMapper.java +++ b/src/main/java/com/lz/modules/flow/dao/StaffRoleMapper.java @@ -8,11 +8,13 @@ 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.StaffRole; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Map; @Mapper public interface StaffRoleMapper extends BaseMapper { @@ -36,4 +38,6 @@ public interface StaffRoleMapper extends BaseMapper { StaffRole selectByStaffId(@Param("staffId") Long staffId); List selectByRole(@Param("departmentLevel") String departmentLevel); + + List selectByCondition(@Param("page") IPage page, @Param("params") Map params); } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/flow/service/StaffRoleService.java b/src/main/java/com/lz/modules/flow/service/StaffRoleService.java index 552413ee..7a8414c0 100644 --- a/src/main/java/com/lz/modules/flow/service/StaffRoleService.java +++ b/src/main/java/com/lz/modules/flow/service/StaffRoleService.java @@ -1,9 +1,11 @@ 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.StaffRole; import java.util.List; +import java.util.Map; /** *

@@ -35,4 +37,8 @@ public interface StaffRoleService extends IService { StaffRole selectByStaffId(Long staffId); List selectByRole(String departmentLevel); + + PageUtils queryPage(Map params); + + void deleteBatchIds(List asList); } \ No newline at end of file diff --git a/src/main/java/com/lz/modules/flow/service/impl/StaffRoleServiceImpl.java b/src/main/java/com/lz/modules/flow/service/impl/StaffRoleServiceImpl.java index 569ad598..1c0a3306 100644 --- a/src/main/java/com/lz/modules/flow/service/impl/StaffRoleServiceImpl.java +++ b/src/main/java/com/lz/modules/flow/service/impl/StaffRoleServiceImpl.java @@ -1,73 +1,136 @@ package com.lz.modules.flow.service.impl; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Maps; +import com.lz.common.utils.NumberUtil; +import com.lz.common.utils.PageUtils; +import com.lz.modules.app.dao.StaffDao; +import com.lz.modules.app.dto.StaffRoleResp; +import com.lz.modules.app.entity.StaffEntity; +import com.lz.modules.flow.dao.RecordRoleMapper; import com.lz.modules.flow.dao.StaffRoleMapper; +import com.lz.modules.flow.entity.RecordRole; import com.lz.modules.flow.entity.StaffRole; import com.lz.modules.flow.service.StaffRoleService; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; +import java.util.Map; /** -*

-* 流转关系表 服务类 -*

-* -* @author quyixiao -* @since 2020-08-18 -*/ + *

+ * 流转关系表 服务类 + *

+ * + * @author quyixiao + * @since 2020-08-18 + */ @Service public class StaffRoleServiceImpl extends ServiceImpl implements StaffRoleService { @Autowired - private StaffRoleMapper staffRoleMapper; + private StaffRoleMapper staffRoleMapper; + + @Autowired + private StaffDao staffDao; - - @Override - public StaffRole selectStaffRoleById(Long id){ - return staffRoleMapper.selectStaffRoleById(id); - } + @Autowired + private RecordRoleMapper recordRoleMapper; - - @Override - public Long insertStaffRole(StaffRole staffRole){ - return staffRoleMapper.insertStaffRole(staffRole); - } + @Override + public StaffRole selectStaffRoleById(Long id) { + return staffRoleMapper.selectStaffRoleById(id); + } - - @Override - public int updateStaffRoleById(StaffRole staffRole){ - return staffRoleMapper.updateStaffRoleById(staffRole); - } + @Override + public Long insertStaffRole(StaffRole staffRole) { + return staffRoleMapper.insertStaffRole(staffRole); + } - - @Override - public int updateCoverStaffRoleById(StaffRole staffRole){ - return staffRoleMapper.updateCoverStaffRoleById(staffRole); - } + @Override + public int updateStaffRoleById(StaffRole staffRole) { + return staffRoleMapper.updateStaffRoleById(staffRole); + } + @Override + public int updateCoverStaffRoleById(StaffRole staffRole) { + return staffRoleMapper.updateCoverStaffRoleById(staffRole); + } - @Override - public int deleteStaffRoleById(Long id){ - return staffRoleMapper.deleteStaffRoleById(id); - } + + @Override + public int deleteStaffRoleById(Long id) { + return staffRoleMapper.deleteStaffRoleById(id); + } @Override public StaffRole selectByStaffId(Long staffId) { return staffRoleMapper.selectByStaffId(staffId); } - @Override - public List selectByRole(String departmentLevel) { - return staffRoleMapper.selectByRole(departmentLevel); - } + @Override + public List selectByRole(String departmentLevel) { + return staffRoleMapper.selectByRole(departmentLevel); + } + + @Override + public PageUtils queryPage(Map params) { + PageUtils pageUtils = PageUtils.startPage( + NumberUtil.objToIntDefault(params.get("page"), 1), + NumberUtil.objToIntDefault(params.get("limit"), 10)).doSelect( + page -> staffRoleMapper.selectByCondition(page, params) + ); + List staffRoles = pageUtils.getList(); + List list = new ArrayList<>(); + Map map = Maps.newHashMap(); + for (StaffRole staffRole : staffRoles) { + StaffRoleResp resp = new StaffRoleResp(); + BeanUtils.copyProperties(staffRole, resp); + StaffEntity staffEntity = staffDao.selectStaffById(resp.getStaffId()); + if (staffEntity != null) { + resp.setStaffName(staffEntity.getName()); + } + Map types = JSONObject.parseObject(resp.getTypeRoleIds(), Map.class); + Long type1 = NumberUtil.objToLongDefault(types.get("type1"),0l); + Long type2 = NumberUtil.objToLongDefault(types.get("type2"),0l); + RecordRole recordRoleType1 = map.get(type1); + if (recordRoleType1 == null) { + recordRoleType1 = recordRoleMapper.selectById(type1); + } + RecordRole recordRoleType2 = map.get(type2); + if (recordRoleType2 == null) { + recordRoleType2 = recordRoleMapper.selectById(type2); + } + if (recordRoleType1 != null) { + map.put(recordRoleType1.getId(), recordRoleType1); + resp.setTargetRole(recordRoleType1.getName()); + } + if (recordRoleType2 != null) { + map.put(recordRoleType2.getId(), recordRoleType2); + resp.setResultRole(recordRoleType2.getName()); + } + list.add(resp); + } + pageUtils.setList(list); + return pageUtils; + } + + @Override + public void deleteBatchIds(List asList) { + for (Long a : asList) { + staffRoleMapper.selectByStaffId(a); + } + } } diff --git a/src/main/resources/mapper/flow/StaffRoleMapper.xml b/src/main/resources/mapper/flow/StaffRoleMapper.xml index 7c3ffade..f1ba59da 100644 --- a/src/main/resources/mapper/flow/StaffRoleMapper.xml +++ b/src/main/resources/mapper/flow/StaffRoleMapper.xml @@ -87,6 +87,10 @@ select * from lz_staff_role where is_delete = 0 and department_level = #{departmentLevel} + + diff --git a/src/main/resources/sql b/src/main/resources/sql new file mode 100644 index 00000000..644852f2 --- /dev/null +++ b/src/main/resources/sql @@ -0,0 +1,45 @@ + + + + + +-- 菜单SQL +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + VALUES ('55', '记录表', 'user/lzrecordrole', NULL, '1', 'config', '6'); + +-- 按钮父菜单ID +set @parentId = @@identity; + +-- 菜单对应按钮SQL +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '查看', null, 'user:lzrecordrole:list,user:lzrecordrole:info', '2', null, '6'; +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '新增', null, 'user:lzrecordrole:save', '2', null, '6'; +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '修改', null, 'user:lzrecordrole:update', '2', null, '6'; +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '删除', null, 'user:lzrecordrole:delete', '2', null, '6'; + + + + + + +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + VALUES ('55', '流转关系表', 'user/lzstaffrole', NULL, '1', 'config', '6'); + +-- 按钮父菜单ID +set @parentId = @@identity; + +-- 菜单对应按钮SQL +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '查看', null, 'user:lzstaffrole:list,user:lzstaffrole:info', '2', null, '6'; +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '新增', null, 'user:lzstaffrole:save', '2', null, '6'; +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '修改', null, 'user:lzstaffrole:update', '2', null, '6'; +INSERT INTO `sys_menu` (`parent_id`, `name`, `url`, `perms`, `type`, `icon`, `order_num`) + SELECT @parentId, '删除', null, 'user:lzstaffrole:delete', '2', null, '6'; + + + diff --git a/src/test/java/com/lz/mysql/MysqlMain.java b/src/test/java/com/lz/mysql/MysqlMain.java index b351f187..8b0e88fd 100644 --- a/src/test/java/com/lz/mysql/MysqlMain.java +++ b/src/test/java/com/lz/mysql/MysqlMain.java @@ -63,7 +63,7 @@ public class MysqlMain { } List list = new ArrayList(); - list.add(new TablesBean("lz_result_record")); + list.add(new TablesBean("lz_staff_role")); List list2 = new ArrayList(); Map map = MysqlUtil2ShowCreateTable.getComments();