From 21587d964a6a43c4dff50a405b42509ce47504e7 Mon Sep 17 00:00:00 2001 From: liuxm <liuxm@fescotech.com> Date: 星期五, 26 四月 2024 15:14:24 +0800 Subject: [PATCH] 添加权限分页,分类型查询 --- pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PriSv.java | 46 +++++++++++ pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java | 66 ++++++++++++++++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaPrivilegeMapper.java | 8 ++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaPrivilege.java | 7 + pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/QueryVo.java | 17 ++++ pms-parent/pms-global/src/main/resources/mapper/BaPrivilegeMapper.xml | 65 +++++++++++++++- 6 files changed, 205 insertions(+), 4 deletions(-) diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaPrivilegeMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaPrivilegeMapper.java index 0af28a4..de69388 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaPrivilegeMapper.java +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaPrivilegeMapper.java @@ -1,10 +1,13 @@ package com.dy.pmsGlobal.daoBa; +import com.dy.pmsGlobal.pojoBa.BaLog; import com.dy.pmsGlobal.pojoBa.BaPrivilege; +import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Map; @Mapper public interface BaPrivilegeMapper { @@ -16,6 +19,11 @@ * @return List<BaPrivilege> */ List<BaPrivilege> selectAll() ; + + List<BaPrivilege> selectSome(Map<String, Object> params); + + Long selectSomeCount(Map<String, Object> params); + List<BaPrivilege> selectByIds(List<String> ids) ; /** diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaPrivilege.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaPrivilege.java index 2df3dde..0fda674 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaPrivilege.java +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaPrivilege.java @@ -58,4 +58,11 @@ @Length(message = "鏉冮檺绫诲瀷涓嶅ぇ浜巤max}瀛楋紝涓嶅皬浜巤min}瀛�", min = 4, max = 4) public Integer type; + /** + * 绫诲埆鍚嶇О + */ + @NotEmpty(message = "绫诲埆鍚嶇О涓嶈兘涓虹┖") //涓嶈兘涓虹┖涔熶笉鑳戒负null + @Length(message = "鏉冮檺绫诲瀷涓嶅ぇ浜巤max}瀛楋紝涓嶅皬浜巤min}瀛�", min = 3, max = 6) + public String typeName; + } \ No newline at end of file diff --git a/pms-parent/pms-global/src/main/resources/mapper/BaPrivilegeMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/BaPrivilegeMapper.xml index 37fa18a..7fd878d 100644 --- a/pms-parent/pms-global/src/main/resources/mapper/BaPrivilegeMapper.xml +++ b/pms-parent/pms-global/src/main/resources/mapper/BaPrivilegeMapper.xml @@ -8,10 +8,11 @@ <result column="num" property="num" /> <result column="name" property="name" /> <result column="type" property="type" /> + <result column="type_name" property="typeName" /> </resultMap> <sql id="Base_Column_List"> <!--@mbg.generated--> - id, num, `name`, `type` + id, num, `name`, `type`,type_name </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> <!--@mbg.generated--> @@ -67,8 +68,8 @@ <insert id="insert" parameterType="com.dy.pmsGlobal.pojoBa.BaPrivilege"> <!--@mbg.generated--> - insert into ba_privilege (id, num, `name`, `type`) - values (#{id}, #{num}, #{name}, #{type}) + insert into ba_privilege (id, num, `name`, `type`,type_name) + values (#{id}, #{num}, #{name}, #{type}, #{typeName}) </insert> <insert id="insertSelective" parameterType="com.dy.pmsGlobal.pojoBa.BaPrivilege"> <!--@mbg.generated--> @@ -86,6 +87,9 @@ <if test="type != null"> `type`, </if> + <if test="typeName != null"> + type_name, + </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> @@ -99,6 +103,9 @@ </if> <if test="type != null"> #{type}, + </if> + <if test="typeName != null"> + #{typeName}, </if> </trim> </insert> @@ -115,6 +122,9 @@ <if test="type != null"> `type` = #{type}, </if> + <if test="typeName != null"> + type_name = #{typeName}, + </if> </set> where id = #{id} </update> @@ -123,7 +133,8 @@ update ba_privilege set num = #{num}, `name` = #{name}, - `type` = #{type} + `type` = #{type}, + type_name = #{typeName} where id = #{id} </update> @@ -141,4 +152,50 @@ #{id} </foreach> </select> + + <select id="selectSome" resultType="com.dy.pmsGlobal.pojoBa.BaPrivilege"> + select + <include refid="Base_Column_List" /> + from ba_privilege + <trim prefix="where " suffixOverrides="and"> + <if test="num != null and num != ''"> + num = #{num,jdbcType=INTEGER} and + </if> + <if test="name != null and name != ''"> + name like concat('%', #{name}, '%') and + </if> + <if test="typeName != null and typeName != '' "> + type_name like concat('%', #{typeName}, '%') and + </if> + <if test="type != null and type != ''"> + type = #{type,jdbcType=INTEGER} and + </if> + </trim> + order by id desc + <trim prefix="limit " > + <if test="start != null and count != null"> + #{start}, #{count} + </if> + </trim> + </select> + + <select id="selectSomeCount" resultType="java.lang.Long"> + select + count(1) + from ba_privilege + <trim prefix="where " suffixOverrides="and"> + <if test="num != null and num != ''"> + num = #{num,jdbcType=INTEGER} and + </if> + <if test="name != null and name != ''"> + name like concat('%', #{name}, '%') and + </if> + <if test="typeName != null and typeName != '' "> + type_name like concat('%', #{typeName}, '%') and + </if> + <if test="type != null and type != ''"> + type = #{type,jdbcType=INTEGER} and + </if> + </trim> + </select> </mapper> \ No newline at end of file diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PriSv.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PriSv.java new file mode 100644 index 0000000..8339844 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PriSv.java @@ -0,0 +1,46 @@ +package com.dy.pmsBase.privilege; + +import com.dy.common.webUtil.QueryResultVo; +import com.dy.pmsGlobal.daoBa.BaPrivilegeMapper; +import com.dy.pmsGlobal.pojoBa.BaPrivilege; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.common.utils.PojoUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class PriSv { + + private BaPrivilegeMapper dao; + @Autowired + public void setDao(BaPrivilegeMapper dao) { + this.dao = dao; + } + + /** + * 鑾峰彇瑙掕壊鍒楄〃 + */ + public QueryResultVo<List<BaPrivilege>> selectSome(QueryVo queryVo) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); + //鏌ヨ绗﹀悎鏉′欢鐨勮褰曟�绘暟 + Long itemTotal = dao.selectSomeCount(params); + QueryResultVo<List<BaPrivilege>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; + //璁$畻鍒嗛〉绛変俊鎭� + rsVo.calculateAndSet(itemTotal, params); + //鏌ヨ绗﹀悎鏉′欢鐨勮褰� + rsVo.obj = dao.selectSome(params) ; + return rsVo ; + } + + public Map<String, List<BaPrivilege>> selectByType(){ + List<BaPrivilege> priList = dao.selectAll(); + Map<String, List<BaPrivilege>> map = priList.stream() + .collect(Collectors.groupingBy(BaPrivilege::getTypeName)); + return map; + } +} diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java new file mode 100644 index 0000000..307dec3 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java @@ -0,0 +1,66 @@ +package com.dy.pmsBase.privilege; + +import com.dy.common.aop.SsoPowerAop; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; +import com.dy.pmsGlobal.aop.Log; +import com.dy.pmsGlobal.daoBa.BaPrivilegeMapper; +import com.dy.pmsGlobal.pojoBa.BaPrivilege; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 鏉冮檺绠$悊 + */ +@Slf4j +@RestController +@RequestMapping(path="pri") +@SuppressWarnings("unchecked") +public class PrivilegeCtrl { + private PriSv sv; + @Autowired + public PrivilegeCtrl(PriSv sv){ + this.sv = sv; + } + + /** + * 鍒嗙被鍨嬫煡璇㈡潈闄� + * @return + */ + @GetMapping(path="getByType") + @SsoPowerAop(power = "10100010") + public BaseResponse<Map<String, List<BaPrivilege>>> getByType(){ + try { + return BaseResponseUtils.buildSuccess(sv.selectByType()); + }catch (Exception e){ + log.error("鍒嗙被鍨嬭幏鍙栨潈闄�",e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + + /** + * 鍒嗛〉鏌ヨ鏉冮檺 + * @param vo + * @return + */ + @RequestMapping(path="some") + @SsoPowerAop(power = "10100010") + @Log("鏌ヨ鏉冮檺淇℃伅") + public BaseResponse<QueryResultVo<List<BaPrivilege>>> some(@RequestBody QueryVo vo){ + try { + return BaseResponseUtils.buildSuccess(sv.selectSome(vo)); + }catch (Exception e){ + log.error("鍒嗛〉鑾峰彇鏉冮檺",e); + return BaseResponseUtils.buildException(e.getMessage()); + } + } + +} diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/QueryVo.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/QueryVo.java new file mode 100644 index 0000000..e3a44d0 --- /dev/null +++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/QueryVo.java @@ -0,0 +1,17 @@ +package com.dy.pmsBase.privilege; + +import com.dy.common.webUtil.QueryConditionVo; +import lombok.*; + +@Data +@EqualsAndHashCode(callSuper = false) +@ToString(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class QueryVo extends QueryConditionVo { + public String name; + public Integer num; + public Integer type; + public String typeName; +} -- Gitblit v1.8.0