liuxm
2024-04-26 21587d964a6a43c4dff50a405b42509ce47504e7
添加权限分页,分类型查询
3个文件已修改
3个文件已添加
209 ■■■■■ 已修改文件
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoBa/BaPrivilegeMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoBa/BaPrivilege.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/BaPrivilegeMapper.xml 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PriSv.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/QueryVo.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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) ;
    /**
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;
}
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>
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PriSv.java
New file
@@ -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;
    }
}
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java
New file
@@ -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());
        }
    }
}
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/QueryVo.java
New file
@@ -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;
}