From 3496e5390b866618efafd56159f36c91d0d22689 Mon Sep 17 00:00:00 2001 From: Administrator <zhubaomin> Date: 星期三, 10 一月 2024 16:32:53 +0800 Subject: [PATCH] 2024-01-10 朱宝民 重构分水房3个接口 --- pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java | 5 pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java | 29 + pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoRole.java | 42 ++ pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/QueryVo.java | 4 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/DtoRole.java | 48 ++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java | 89 +--- pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaRole.java | 57 +- pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java | 177 +++++--- pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/result/ProjectResultCode.java | 2 pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml | 188 +++++---- pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRolePermissionsMapper.xml | 1 pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java | 487 +++++++++++++++--------- 12 files changed, 696 insertions(+), 433 deletions(-) diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java index 9d07534..dee40df 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaRoleMapper.java @@ -1,84 +1,49 @@ package com.dy.pipIrrGlobal.daoBa; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.dy.pipIrrGlobal.pojoBa.BaRole; -import org.apache.ibatis.annotations.Mapper; +import com.dy.pipIrrGlobal.voBa.VoRole; import org.apache.ibatis.annotations.Param; import java.util.List; import java.util.Map; -@Mapper -public interface BaRoleMapper extends BaseMapper<BaRole> { +/** + * @author ZhuBaoMin + * @date 2024-01-10 11:00 + * @LastEditTime 2024-01-10 11:00 + * @Description + */ +public interface BaRoleMapper { + int deleteByPrimaryKey(Long id); - /** - * 鏌ヨ鍏ㄩ儴 - * @return List<BaRole> - */ - List<BaRole> selectAll() ; + int insert(BaRole record); - /** - * 鏌ヨ鏌愪釜鐢ㄦ埛鎵�闅跺睘浜庣殑瑙掕壊 - * @param userId 鐢ㄦ埛ID - * @return List<BaRole> - */ - List<BaRole> selectByUserId(@Param("userId") Long userId) ; - - - /** - * 鏌ヨ鎬绘暟 - * @param params 鏌ヨ鏉′欢 - * @return 鎬绘暟 - */ - Long selectTotal(Map<?, ?> params) ; - - /** - * 鍒嗛〉鏌ヨ涓�浜� - * @param params 鏌ヨ鏉′欢 - * @return 瀹炰綋闆嗗悎 - */ - List<BaRole> selectSome(Map<?, ?> params) ; - - - /** - * insert record to table - * @param record the record - * @return insert count - */ - int putin(BaRole record); - - /** - * insert record to table selective - * @param record the record - * @return insert count - */ int insertSelective(BaRole record); - /** - * update record selective - * @param record the updated record - * @return update count - */ + BaRole selectByPrimaryKey(Long id); + int updateByPrimaryKeySelective(BaRole record); - /** - * update record - * @param record the updated record - * @return update count - */ int updateByPrimaryKey(BaRole record); /** - * delete by primary key - * @param id primaryKey - * @return deleteCount + * 鏍规嵁瑙掕壊鍚嶇О鏌ヨ璁板綍鏁伴噺 + * @param roleName + * @return */ - int deleteByPrimaryKey(Long id); + Integer getRecordCountByName(@Param("roleName") String roleName); /** - * 閫昏緫鍒犻櫎 - * @param id primaryKey - * @return update count + * 鏍规嵁鎸囧畾鏉′欢鑾峰彇瑙掕壊璁板綍鏁� + * @param params + * @return */ - int deleteLogicById(Long id); + Long getRecordCount(Map<?, ?> params); + + /** + * 鏍规嵁鎸囧畾鏉′欢鑾峰彇瑙掕壊璁板綍 + * @param params + * @return + */ + List<VoRole> getRoles(Map<?, ?> params); } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaRole.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaRole.java index 742e247..373c4e7 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaRole.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaRole.java @@ -1,24 +1,26 @@ package com.dy.pipIrrGlobal.pojoBa; - import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.writer.ObjectWriterImplToString; import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.dy.common.mybatis.envm.Deleted; import com.dy.common.po.BaseEntity; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Positive; import lombok.*; import org.hibernate.validator.constraints.Length; -import java.util.List; +import java.util.Date; /** - * 瑙掕壊瀹炰綋 + * @author ZhuBaoMin + * @date 2024-01-10 11:00 + * @LastEditTime 2024-01-10 11:00 + * @Description */ + @TableName(value="ba_role", autoResultMap = true) @Data @Builder @@ -27,33 +29,40 @@ @AllArgsConstructor @Schema(name = "瑙掕壊瀹炰綋") public class BaRole implements BaseEntity { + public static final long serialVersionUID = 1L; - public static final long serialVersionUID = 202310211546001L; - + /** + * 涓婚敭 + */ @JSONField(serializeUsing= ObjectWriterImplToString.class) @TableId(type = IdType.INPUT) @Schema(description = "瀹炰綋id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - public Long id ; + private Long id; /** - * 瑙掕壊鍚嶇О - */ + * 瑙掕壊鍚嶇О + */ @Schema(description = "鍚嶇О", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "鍚嶇О涓嶈兘涓虹┖") //涓嶈兘涓虹┖涔熶笉鑳戒负null @Length(message = "鍚嶇О涓嶅ぇ浜巤max}瀛楋紝涓嶅皬浜巤min}瀛�", min = 2, max = 25) - public String name ; + @NotBlank(message = "鍚嶇О涓嶈兘涓虹┖") + private String name; /** - * 鏄惁鍒犻櫎: 0琛ㄧず鏈垹闄� 1琛ㄧず鍒犻櫎. - */ + * 鎿嶄綔浜虹紪鍙� + */ + @Schema(description = "鎿嶄綔浜虹紪鍙�", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Positive(message = "鎿嶄綔浜虹紪鍙峰繀椤讳负澶т簬0鐨勬暣鏁�") + private Long operator; + + /** + * 鎿嶄綔鏃堕棿 + */ + @Schema(description = "鎿嶄綔鏃堕棿", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Date operateDt; + + /** + * 閫昏緫鍒犻櫎鏍囪瘑;0-鏈垹闄わ紝1-鍒犻櫎 + */ @Schema(description = "鍒犻櫎鏍囪瘑锛岃〃鍗曚笉鐢ㄥ~鍐�", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - public Deleted deleted; - - - /** - * 瑙掕壊鎵�鎷ユ湁鐨勬潈闄� - */ - @TableField(exist = false) - public List<BaPrivilege> priviList ; - + private Byte deleted; } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoRole.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoRole.java new file mode 100644 index 0000000..966e73e --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voBa/VoRole.java @@ -0,0 +1,42 @@ +package com.dy.pipIrrGlobal.voBa; + +import com.dy.common.po.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @author ZhuBaoMin + * @date 2024-01-10 15:13 + * @LastEditTime 2024-01-10 15:13 + * @Description + */ + +@Data +@Schema(title = "瑙掕壊淇℃伅瑙嗗浘瀵硅薄") +public class VoRole implements BaseEntity { + private static final long serialVersionUID = 1L; + + @Schema(title = "ID") + private Long id; + + @Schema(title = "瑙掕壊缂栧彿") + private Long roleId; + + @Schema(title = "瑙掕壊鍚嶇О") + private String roleName; + + @Schema(title = "鏉冮檺鍒楄〃") + private String permissions; + + @Schema(title = "鎿嶄綔浜�") + private String operator; + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @Schema(title = "鎿嶄綔鏃堕棿") + private Date operateDt; +} diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml index 79c6dfa..da62340 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRoleMapper.xml @@ -1,84 +1,42 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.dy.pipIrrGlobal.daoBa.BaRoleMapper"> - <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaRole"> - <result column="id" jdbcType="BIGINT" property="id" /> + <!--@mbg.generated--> + <!--@Table ba_role--> + <id column="id" jdbcType="BIGINT" property="id" /> <result column="name" jdbcType="VARCHAR" property="name" /> - <result property="deleted" column="deleted" typeHandler="com.dy.common.mybatis.envm.EnumCodeTypeHandler" javaType="com.dy.common.mybatis.envm.Deleted"/> + <result column="operator" jdbcType="BIGINT" property="operator" /> + <result column="operate_dt" jdbcType="TIMESTAMP" property="operateDt" /> + <result column="deleted" jdbcType="TINYINT" property="deleted" /> </resultMap> - - <resultMap id="partResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaRole"> - <result column="id" jdbcType="BIGINT" property="id" /> - <result column="name" jdbcType="VARCHAR" property="name" /> - </resultMap> - - <resultMap id="someResultMap" extends="partResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaRole"> - <collection property="priviList" fetchType="eager" column="{roleId=id}" select="com.dy.pipIrrGlobal.daoBa.BaPrivilegeMapper.selectPrivilegeByRoleId" /> - </resultMap> - <sql id="Base_Column_List"> - id, name, deleted + <!--@mbg.generated--> + id, `name`, `operator`, operate_dt, deleted </sql> - - <sql id="part_Column_List"> - id, name, deleted - </sql> - - <select id="selectAll" resultMap="BaseResultMap"> - select - <include refid="part_Column_List" /> + <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> + <!--@mbg.generated--> + select + <include refid="Base_Column_List" /> from ba_role - where deleted!=1 + where id = #{id,jdbcType=BIGINT} </select> + <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> + <!--@mbg.generated--> + delete from ba_role + where id = #{id,jdbcType=BIGINT} + </delete> - <select id="selectByUserId" resultMap="partResultMap"> - select <include refid="part_Column_List" /> - from ba_role r - inner join ba_user_role ur on r.id = ur.roleId - where r.deleted != 1 - <if test="userId != null"> - and ur.userId = #{userId,jdbcType=BIGINT} - </if> - </select> - - <select id="selectTotal" parameterType="java.util.Map" resultType="java.lang.Long"> - select - count(*) - from ba_role where deleted!=1 - <trim prefix="and" suffixOverrides="and"> - <if test="name != null and name != ''"> - name like concat('%', #{name}, '%') - </if> - </trim> - </select> - - <select id="selectSome" parameterType="java.util.Map" resultMap="someResultMap"> - select - <include refid="part_Column_List" /> - from ba_role where deleted!=1 - <trim prefix="and" suffixOverrides="and"> - <if test="name != null and name != ''"> - name like concat('%', #{name}, '%') - </if> - </trim> - order by id DESC - <trim prefix="limit " > - <if test="start != null and count != null"> - #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER} - </if> - </trim> - </select> - - <insert id="putin" parameterType="com.dy.pipIrrGlobal.pojoBa.BaRole"> - insert into ba_role (<include refid="Base_Column_List" />) - values (#{id,jdbcType=BIGINT}, - #{name,jdbcType=VARCHAR}, - #{deleted, typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT} - ) + <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoBa.BaRole"> + <!--@mbg.generated--> + insert into ba_role (id, `name`, `operator`, + operate_dt, deleted) + values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{operator,jdbcType=BIGINT}, + #{operateDt,jdbcType=TIMESTAMP}, #{deleted,jdbcType=TINYINT}) </insert> <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaRole"> + <!--@mbg.generated--> insert into ba_role <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> @@ -86,6 +44,12 @@ </if> <if test="name != null"> `name`, + </if> + <if test="operator != null"> + `operator`, + </if> + <if test="operateDt != null"> + operate_dt, </if> <if test="deleted != null"> deleted, @@ -98,41 +62,103 @@ <if test="name != null"> #{name,jdbcType=VARCHAR}, </if> + <if test="operator != null"> + #{operator,jdbcType=BIGINT}, + </if> + <if test="operateDt != null"> + #{operateDt,jdbcType=TIMESTAMP}, + </if> <if test="deleted != null"> - #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT}, + #{deleted,jdbcType=TINYINT}, </if> </trim> </insert> - - <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaRole"> + <!--@mbg.generated--> update ba_role <set> <if test="name != null"> `name` = #{name,jdbcType=VARCHAR}, </if> + <if test="operator != null"> + `operator` = #{operator,jdbcType=BIGINT}, + </if> + <if test="operateDt != null"> + operate_dt = #{operateDt,jdbcType=TIMESTAMP}, + </if> <if test="deleted != null"> - deleted = #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT}, + deleted = #{deleted,jdbcType=TINYINT}, </if> </set> where id = #{id,jdbcType=BIGINT} </update> - <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoBa.BaRole"> + <!--@mbg.generated--> update ba_role set `name` = #{name,jdbcType=VARCHAR}, - deleted = #{deleted,typeHandler=com.dy.common.mybatis.envm.EnumCodeTypeHandler, jdbcType=TINYINT} + `operator` = #{operator,jdbcType=BIGINT}, + operate_dt = #{operateDt,jdbcType=TIMESTAMP}, + deleted = #{deleted,jdbcType=TINYINT} where id = #{id,jdbcType=BIGINT} </update> + <!--鏍规嵁瑙掕壊鍚嶇О鏌ヨ璁板綍鏁伴噺锛屾坊鍔犺鑹叉椂鍒ゆ柇鏄惁閲嶅悕--> + <select id="getRecordCountByName" resultType="java.lang.Integer"> + SELECT + COUNT(*) AS recordCount + FROM ba_role + WHERE name = #{roleName} + </select> - <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> - delete from ba_role - where id = #{id,jdbcType=BIGINT} - </delete> + <!--鏍规嵁鎸囧畾鏉′欢鑾峰彇瑙掕壊璁板綍鏁�--> + <select id="getRecordCount" resultType="java.lang.Long"> + SELECT + COUNT(*) AS recordCount + FROM ba_role role + LEFT JOIN ba_role_permissions per ON per.roleId = role.id + <where> + AND role.deleted = 0 - <delete id="deleteLogicById" parameterType="java.lang.Long"> - update ba_role set deleted = 1 - where id = #{id,jdbcType=BIGINT} - </delete> + <if test = "roleId != null and roleId > 0"> + AND role.id = ${roleId} + </if> + + <if test = "roleName != null and roleName !=''"> + AND role.name LIKE CONCAT('%',#{roleName},'%') + </if> + </where> + </select> + + <!--鏍规嵁鎸囧畾鏉′欢鑾峰彇瑙掕壊璁板綍--> + <select id="getRoles" resultType="com.dy.pipIrrGlobal.voBa.VoRole"> + SELECT + (@i:=@i+1) AS id, + t.* FROM + ( + SELECT + role.id AS roleId, + role.name AS roleName, + per.permissions, + (SELECT `name` FROM ba_user WHERE id = role.operator) AS operator, + role.operate_dt AS operateDt + FROM ba_role role + LEFT JOIN ba_role_permissions per ON per.roleId = role.id + <where> + AND role.deleted = 0 + + <if test = "roleId != null and roleId > 0"> + AND role.id = ${roleId} + </if> + + <if test = "roleName != null and roleName !=''"> + AND role.name LIKE CONCAT('%',#{roleName},'%') + </if> + </where> + ORDER BY role.operate_dt DESC + <if test="pageCurr != null and pageSize != null"> + LIMIT ${pageCurr}, ${pageSize} + </if> + ) t + , (SELECT @i:=0) AS itable + </select> </mapper> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRolePermissionsMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRolePermissionsMapper.xml index f91308f..9fa4b68 100644 --- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRolePermissionsMapper.xml +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaRolePermissionsMapper.xml @@ -37,6 +37,7 @@ values (#{id,jdbcType=BIGINT}, #{roleid,jdbcType=BIGINT}, #{permissions,jdbcType=VARCHAR} ) </insert> + <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaRolePermissions"> <!--@mbg.generated--> insert into ba_role_permissions diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java index bc30e74..dda4a73 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/result/SystemResultCode.java @@ -16,7 +16,10 @@ /** * 瑙掕壊 */ - PERMISSION_ERROR(10001, "鎺堟潈閿欒"); + PERMISSION_ERROR(10001, "鎺堟潈閿欒"), + ADD_ROLE_FAIL(10002, "瑙掕壊娣诲姞澶辫触"), + ROLE_NAME_EXIST(10003, "瑙掕壊鍚嶇О宸插瓨鍦�"), + NO_ROLES(10004, "娌℃湁绗﹀悎鏉′欢鐨勮鑹茶褰�"); private final Integer code; private final String message; diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/DtoRole.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/DtoRole.java new file mode 100644 index 0000000..1a07e74 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/DtoRole.java @@ -0,0 +1,48 @@ +package com.dy.pipIrrBase.role; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Positive; +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +/** + * @author ZhuBaoMin + * @date 2024-01-10 9:16 + * @LastEditTime 2024-01-10 9:16 + * @Description + */ + +@Data +@Schema(name = "瑙掕壊浼犲叆瀵硅薄") +public class DtoRole { + public static final long serialVersionUID = 1L; + + /** + * 瑙掕壊缂栧彿 + */ + @Schema(description = "瑙掕壊缂栧彿", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Positive(message = "瑙掕壊缂栧彿蹇呴』涓哄ぇ浜�0鐨勬暣鏁�") + private Long roleid; + + /** + * 瑙掕壊鍚嶇О + */ + @Schema(description = "瑙掕壊鍚嶇О", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "瑙掕壊鍚嶇О涓嶈兘涓虹┖") + @Length(max = 25, message = "瑙掕壊鍚嶇О鏈�澶�25瀛�") + private String roleName; + + /** + * 鏉冮檺鍒楄〃 + */ + @Schema(description = "鏉冮檺鍒楄〃", requiredMode = Schema.RequiredMode.REQUIRED) + private String permissions; + + /** + * 鎿嶄綔浜虹紪鍙� + */ + @Schema(description = "鎿嶄綔浜虹紪鍙�", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Positive(message = "鎿嶄綔浜虹紪鍙峰繀椤讳负澶т簬0鐨勬暣鏁�") + private Long operator; +} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/QueryVo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/QueryVo.java index fd9bc41..b762c50 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/QueryVo.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/QueryVo.java @@ -13,8 +13,10 @@ @Builder @Schema(name = "瑙掕壊鏌ヨ鏉′欢") public class QueryVo extends QueryConditionVo { + @Schema(description = "瑙掕壊ID") + public Long roleId; @Schema(description = "瑙掕壊鍚嶇О") - public String name; + public String roleName; } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java index be75abb..dbd6ed1 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleCtrl.java @@ -7,9 +7,10 @@ import com.dy.common.webUtil.QueryResultVo; import com.dy.common.webUtil.ResultCodeMsg; import com.dy.pipIrrBase.result.SystemResultCode; -import com.dy.pipIrrBase.user.QueryVo; import com.dy.pipIrrGlobal.pojoBa.BaRole; import com.dy.pipIrrGlobal.pojoBa.BaRolePermissions; +import com.dy.pipIrrGlobal.voBa.VoRole; +import com.dy.pipIrrGlobal.voSe.VoActiveCard; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -19,12 +20,12 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -37,90 +38,158 @@ @SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked") public class RoleCtrl { - private RoleSv sv ; + //private RoleSv sv ; private final RoleSv roleSv; - @Autowired - private void setSv(RoleSv sv){ - this.sv = sv ; + //@Autowired + //private void setSv(RoleSv sv){ + // this.sv = sv ; + //} + + /** + * 鏍规嵁鎸囧畾鏉′欢锛堣鑹茬紪鍙枫�佽鑹插悕绉帮級鑾峰彇瑙掕壊鍒楄〃 + * 褰撹幏鍙栦竴鏉¤褰曟椂锛屼紶鍏oleId鍗冲彲 + * @param vo + * @return + */ + @Operation(summary = "鑾峰緱涓�椤佃鑹茶褰�", description = "杩斿洖涓�椤佃鑹叉暟鎹�") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�椤垫帶鍒跺櫒鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = VoActiveCard.class))} + ) + }) + @GetMapping(path = "/roles") + @SsoAop() + public BaseResponse<QueryResultVo<List<VoRole>>> getRoles(QueryVo vo){ + try { + QueryResultVo<List<VoRole>> res = roleSv.getRoles(vo); + if(res.itemTotal != null && res.itemTotal > 0) { + return BaseResponseUtils.buildSuccess(res); + }else { + return BaseResponseUtils.buildFail(SystemResultCode.NO_ROLES.getMessage()); + } + } catch (Exception e) { + log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } } /** * 瀹㈡埛绔姹傚緱鍒版墍鏈夎鑹叉暟鎹� * @return 鎵�鏈夎鑹叉暟鎹� */ - @Operation(summary = "鑾峰緱鍏ㄩ儴瑙掕壊", description = "杩斿洖鍏ㄩ儴瑙掕壊鏁版嵁") - @ApiResponses(value = { - @ApiResponse( - responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, - description = "杩斿洖鍏ㄩ儴瑙掕壊鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�", - content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = BaRole.class))} - ) - }) - @GetMapping(path = "all") - @SsoAop() - public BaseResponse<QueryResultVo<List<BaRole>>> all(){ - try { - QueryResultVo<List<BaRole>> res = this.sv.selectAll() ; - return BaseResponseUtils.buildSuccess(res); - } catch (Exception e) { - log.error("鏌ヨ瑙掕壊寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()) ; - } - } + //@Operation(summary = "鑾峰緱鍏ㄩ儴瑙掕壊", description = "杩斿洖鍏ㄩ儴瑙掕壊鏁版嵁") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "杩斿洖鍏ㄩ儴瑙掕壊鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = BaRole.class))} + // ) + //}) + //@GetMapping(path = "all") + //@SsoAop() + //public BaseResponse<QueryResultVo<List<BaRole>>> all(){ + // try { + // QueryResultVo<List<BaRole>> res = this.sv.selectAll() ; + // return BaseResponseUtils.buildSuccess(res); + // } catch (Exception e) { + // log.error("鏌ヨ瑙掕壊寮傚父", e); + // return BaseResponseUtils.buildException(e.getMessage()) ; + // } + //} /** * 瀹㈡埛绔姹傚緱鍒颁竴椤佃鑹叉暟鎹� * @return 鎵�鏈夎鑹叉暟鎹� */ - @Operation(summary = "鑾峰緱涓�椤佃鑹�", description = "杩斿洖涓�椤佃鑹叉暟鎹�") - @ApiResponses(value = { - @ApiResponse( - responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, - description = "杩斿洖涓�椤佃鑹叉暟鎹紙BaseResponse.content:QueryResultVo[{}]锛�", - content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = BaRole.class))} - ) - }) - @PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) - @SsoAop() - public BaseResponse<QueryResultVo<List<BaRole>>> some(@RequestBody @Valid QueryVo vo){ - try { - QueryResultVo<List<BaRole>> res = this.sv.selectSome(vo) ; - return BaseResponseUtils.buildSuccess(res); - } catch (Exception e) { - log.error("鏌ヨ瑙掕壊寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()) ; - } - } + //@Operation(summary = "鑾峰緱涓�椤佃鑹�", description = "杩斿洖涓�椤佃鑹叉暟鎹�") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "杩斿洖涓�椤佃鑹叉暟鎹紙BaseResponse.content:QueryResultVo[{}]锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = BaRole.class))} + // ) + //}) + //@PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE) + //@SsoAop() + //public BaseResponse<QueryResultVo<List<BaRole>>> some(@RequestBody @Valid QueryVo vo){ + // try { + // QueryResultVo<List<BaRole>> res = this.sv.selectSome(vo) ; + // return BaseResponseUtils.buildSuccess(res); + // } catch (Exception e) { + // log.error("鏌ヨ瑙掕壊寮傚父", e); + // return BaseResponseUtils.buildException(e.getMessage()) ; + // } + //} /** * 寰楀埌涓�涓鑹叉暟鎹� * @return 涓�涓鑹叉暟鎹� */ - @Operation(summary = "涓�涓鑹�", description = "寰楀埌涓�涓鑹叉暟鎹�") - @ApiResponses(value = { - @ApiResponse( - responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, - description = "杩斿洖涓�涓鑹叉暟鎹紙BaseResponse.content:{}锛�", - content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = BaRole.class))} - ) - }) - //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) - @GetMapping(path = "one") - @SsoAop() - public BaseResponse<BaRole> one(Long id){ - return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); - } + //@Operation(summary = "涓�涓鑹�", description = "寰楀埌涓�涓鑹叉暟鎹�") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "杩斿洖涓�涓鑹叉暟鎹紙BaseResponse.content:{}锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = BaRole.class))} + // ) + //}) + ////@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) + //@GetMapping(path = "one") + //@SsoAop() + //public BaseResponse<BaRole> one(Long id){ + // return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); + //} /** * 淇濆瓨瑙掕壊 * @param po 淇濆瓨瑙掕壊form琛ㄥ崟瀵硅薄 * @return 鏄惁鎴愬姛 */ - @Operation(summary = "淇濆瓨瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇濆瓨") + //@Operation(summary = "淇濆瓨瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇濆瓨") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = Boolean.class))} + // ) + //}) + //@PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) + //@SsoAop() + //public BaseResponse<Boolean> save(@RequestBody @Valid BaRole po, BindingResult bindingResult){ + // if(bindingResult != null && bindingResult.hasErrors()){ + // return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + // } + // po.id = null ; + // Long count; + // try { + // po.deleted = Deleted.NO ;//榛樿涓嶅垹闄� + // count = this.sv.save(po); + // } catch (Exception e) { + // log.error("淇濆瓨瑙掕壊寮傚父", e); + // return BaseResponseUtils.buildException(e.getMessage()) ; + // } + // if(count <= 0){ + // return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; + // }else{ + // return BaseResponseUtils.buildSuccess(true) ; + // } + //} + + /** + * 娣诲姞瑙掕壊鍙婃潈闄愬垪琛紝娣诲姞鍓嶅垽鏂鑹插悕鏄惁宸插瓨鍦� + * @param po 瑙掕壊浼犲叆瀵硅薄锛屽寘鎷鑹插悕绉般�佹潈闄愬垪琛ㄣ�佹搷浣滀汉缂栧彿 + * @param bindingResult + * @return + */ + @Operation(summary = "娣诲姞瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁鍙婃潈闄愭暟鎹紝杩涜淇濆瓨") @ApiResponses(value = { @ApiResponse( responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, @@ -130,136 +199,57 @@ ) }) @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) @SsoAop() - public BaseResponse<Boolean> save(@RequestBody @Valid BaRole po, BindingResult bindingResult){ + public BaseResponse<Boolean> save(@RequestBody @Valid DtoRole po, BindingResult bindingResult){ if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } - po.id = null ; - Long count; + + // 鑾峰彇瑙掕壊鍚嶇О绾ф潈闄愬垪琛� + String roleName = Optional.ofNullable(po.getRoleName()).orElse(""); + String permissions = Optional.ofNullable(po.getPermissions()).orElse(""); + Long operator = Optional.ofNullable(po.getOperator()).orElse(0L); + + // 鍒ゆ柇瑙掕壊鍚嶇О鏄惁閲嶅悕 + Integer recordCount = Optional.ofNullable(roleSv.getRecordCountByName(roleName)).orElse(0); + if(recordCount > 0) + return BaseResponseUtils.buildFail(SystemResultCode.ROLE_NAME_EXIST.getMessage()); + + // 娣诲姞瑙掕壊 + BaRole baRole = new BaRole(); + Long roleId = 0L; try { - po.deleted = Deleted.NO ;//榛樿涓嶅垹闄� - count = this.sv.save(po); + baRole.setName(roleName); + baRole.setOperator(operator); + Date operateTime = new Date(); + baRole.setOperateDt(operateTime); + baRole.setDeleted(Deleted.NO.getCode()); + roleId = roleSv.addRole(baRole); } catch (Exception e) { - log.error("淇濆瓨瑙掕壊寮傚父", e); return BaseResponseUtils.buildException(e.getMessage()) ; } - if(count <= 0){ - return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; - }else{ - return BaseResponseUtils.buildSuccess(true) ; - } - } - /** - * 缂栬緫淇敼瑙掕壊 - * @param po 淇濆瓨瑙掕壊form琛ㄥ崟瀵硅薄 - * @return 鏄惁鎴愬姛 - */ - @Operation(summary = "缂栬緫淇敼瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇敼") - @ApiResponses(value = { - @ApiResponse( - responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, - description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", - content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = Boolean.class))} - ) - }) - @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) - @SsoAop() - public BaseResponse<Boolean> update(@RequestBody @Valid BaRole po, BindingResult bindingResult){ - if(bindingResult != null && bindingResult.hasErrors()){ - return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); - } - if(po.id == null){ - return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D") ; - } - int count; - try { - po.deleted = null ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂� - count = this.sv.update(po); - } catch (Exception e) { - log.error("淇濆瓨瑙掕壊寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()) ; - } - if(count <= 0){ - return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; - }else{ - return BaseResponseUtils.buildSuccess(true) ; - } - } + if(roleId <= 0) + return BaseResponseUtils.buildFail(SystemResultCode.ADD_ROLE_FAIL.getMessage()); - - - /** - * 璁剧疆瑙掕壊鏉冮檺 - * @param id 瑙掕壊ID - * @return 鏄惁鎴愬姛 - */ - @Operation(summary = "璁剧疆瑙掕壊鏉冮檺", description = "鎻愪氦瑙掕壊ID锛屽強鎵�閫夋嫨鐨勬潈闄怚D闆嗗悎锛堟暟缁勶級") - @ApiResponses(value = { - @ApiResponse( - responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, - description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", - content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = Boolean.class))} - ) - }) - //@GetMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) - @PostMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) - @SsoAop() - public BaseResponse<Boolean> setPrivileges(Long id, Long[] privIds){ - Long[] privIds_lg = null ; - if(privIds != null && privIds.length > 0){ - privIds_lg = new Long[privIds.length] ; - int index = 0 ; - for(Long privId : privIds){ - privIds_lg[index++] = privId ; - } - } - try { - this.sv.setRoles(id, privIds_lg); - } catch (Exception e) { - log.error("淇濆瓨鐢ㄦ埛寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()) ; + // 娣诲姞鏉冮檺鍒楄〃 + BaRolePermissions baRolePermissions = new BaRolePermissions(); + baRolePermissions.setRoleid(roleId); + baRolePermissions.setPermissions(permissions); + Integer rc = Optional.ofNullable(roleSv.addPermissions(baRolePermissions)).orElse(0); + if(rc <= 0) { + return BaseResponseUtils.buildFail(SystemResultCode.ADD_ROLE_FAIL.getMessage()); } return BaseResponseUtils.buildSuccess(true) ; } - /** - * 鍒犻櫎瑙掕壊 - * @param id 瑙掕壊ID - * @return 鏄惁鎴愬姛 - */ - @Operation(summary = "鍒犻櫎瑙掕壊", description = "鎻愪氦瑙掕壊ID锛岃繘琛岄�昏緫鍒犻櫎") - @ApiResponses(value = { - @ApiResponse( - responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, - description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", - content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = Boolean.class))} - ) - }) - //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) - @GetMapping(path = "delete") - @SsoAop() - public BaseResponse<Boolean> delete(Long id){ - if(id == null){ - return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ; - } - int count; - try { - count = this.sv.delete(id); - } catch (Exception e) { - log.error("淇濆瓨瑙掕壊寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()) ; - } - if(count <= 0){ - return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; - }else{ - return BaseResponseUtils.buildSuccess(true) ; - } - } + /** + * 瑙掕壊鎺堟潈锛屽綋瑙掕壊缂栧彿涓虹┖鏃讹紝瀹為檯涓烘坊鍔犺鑹插強鏉冮檺鍒楄〃 + * @param po + * @param bindingResult + * @return + */ @Operation(summary = "鎺堟潈", description = "鎺堟潈") @ApiResponses(value = { @ApiResponse( @@ -272,7 +262,7 @@ @PostMapping(path = "addPermissions", consumes = MediaType.APPLICATION_JSON_VALUE) @Transactional(rollbackFor = Exception.class) @SsoAop() - public BaseResponse<Boolean> permission(@RequestBody @Valid BaRolePermissions po, BindingResult bindingResult){ + public BaseResponse<Boolean> permission(@RequestBody @Valid DtoRole po, BindingResult bindingResult){ if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } @@ -287,28 +277,149 @@ * 2. 娣诲姞瑙掕壊銆佹潈闄愯褰� */ - Long roleid = Optional.ofNullable(po.getRoleid()).orElse(0L); + Long roleId = Optional.ofNullable(po.getRoleid()).orElse(0L); String roleName = Optional.ofNullable(po.getRoleName()).orElse(""); String permissions = Optional.ofNullable(po.getPermissions()).orElse(""); + Long operator = Optional.ofNullable(po.getOperator()).orElse(0L); - if(roleid == 0 && roleName.length() == 0) { + if(roleId == 0 && roleName.length() == 0) return BaseResponseUtils.buildFail(SystemResultCode.PERMISSION_ERROR.getMessage()); - } // 鏂板缓瑙掕壊涓旀巿鏉� - if(roleid == 0) { + if(roleId == 0) { BaRole baRole = new BaRole(); baRole.setName(roleName); - roleid = Optional.ofNullable(roleSv.save(baRole)).orElse(0L); - po.setRoleid(roleid); - roleSv.addPermissions(po); + baRole.setOperator(operator); + Date operateTime = new Date(); + baRole.setOperateDt(operateTime); + baRole.setDeleted(Deleted.NO.getCode()); + roleId = Optional.ofNullable(roleSv.addRole(baRole)).orElse(0L); + + BaRolePermissions baRolePermissions = new BaRolePermissions(); + baRolePermissions.setRoleid(roleId); + baRolePermissions.setPermissions(permissions); + roleSv.addPermissions(baRolePermissions); return BaseResponseUtils.buildSuccess(true) ; } // 淇敼瑙掕壊鎺堟潈 - roleSv.delPermissionsByRoleId(roleid); - roleSv.addPermissions(po); + BaRolePermissions baRolePermissions = new BaRolePermissions(); + baRolePermissions.setRoleid(roleId); + baRolePermissions.setPermissions(permissions); + roleSv.delPermissionsByRoleId(roleId); + roleSv.addPermissions(baRolePermissions); return BaseResponseUtils.buildSuccess(true) ; } + /** + * 缂栬緫淇敼瑙掕壊 + * @param po 淇濆瓨瑙掕壊form琛ㄥ崟瀵硅薄 + * @return 鏄惁鎴愬姛 + */ + //@Operation(summary = "缂栬緫淇敼瑙掕壊", description = "鎻愪氦瑙掕壊鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇敼") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = Boolean.class))} + // ) + //}) + //@PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE) + //@SsoAop() + //public BaseResponse<Boolean> update(@RequestBody @Valid BaRole po, BindingResult bindingResult){ + // if(bindingResult != null && bindingResult.hasErrors()){ + // return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + // } + // if(po.id == null){ + // return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D") ; + // } + // int count; + // try { + // po.deleted = null ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂� + // count = this.sv.update(po); + // } catch (Exception e) { + // log.error("淇濆瓨瑙掕壊寮傚父", e); + // return BaseResponseUtils.buildException(e.getMessage()) ; + // } + // if(count <= 0){ + // return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; + // }else{ + // return BaseResponseUtils.buildSuccess(true) ; + // } + //} + + + + ///** + // * 璁剧疆瑙掕壊鏉冮檺 + // * @param id 瑙掕壊ID + // * @return 鏄惁鎴愬姛 + // */ + //@Operation(summary = "璁剧疆瑙掕壊鏉冮檺", description = "鎻愪氦瑙掕壊ID锛屽強鎵�閫夋嫨鐨勬潈闄怚D闆嗗悎锛堟暟缁勶級") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = Boolean.class))} + // ) + //}) + ////@GetMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) + //@PostMapping(path = "setPrivs", consumes = MediaType.APPLICATION_JSON_VALUE) + //@SsoAop() + //public BaseResponse<Boolean> setPrivileges(Long id, Long[] privIds){ + // Long[] privIds_lg = null ; + // if(privIds != null && privIds.length > 0){ + // privIds_lg = new Long[privIds.length] ; + // int index = 0 ; + // for(Long privId : privIds){ + // privIds_lg[index++] = privId ; + // } + // } + // try { + // this.sv.setRoles(id, privIds_lg); + // } catch (Exception e) { + // log.error("淇濆瓨鐢ㄦ埛寮傚父", e); + // return BaseResponseUtils.buildException(e.getMessage()) ; + // } + // return BaseResponseUtils.buildSuccess(true) ; + //} + ///** + // * 鍒犻櫎瑙掕壊 + // * @param id 瑙掕壊ID + // * @return 鏄惁鎴愬姛 + // */ + //@Operation(summary = "鍒犻櫎瑙掕壊", description = "鎻愪氦瑙掕壊ID锛岃繘琛岄�昏緫鍒犻櫎") + //@ApiResponses(value = { + // @ApiResponse( + // responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + // description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + // content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + // schema = @Schema(implementation = Boolean.class))} + // ) + //}) + ////@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) + //@GetMapping(path = "delete") + //@SsoAop() + //public BaseResponse<Boolean> delete(Long id){ + // if(id == null){ + // return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ; + // } + // int count; + // try { + // count = this.sv.delete(id); + // } catch (Exception e) { + // log.error("淇濆瓨瑙掕壊寮傚父", e); + // return BaseResponseUtils.buildException(e.getMessage()) ; + // } + // if(count <= 0){ + // return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; + // }else{ + // return BaseResponseUtils.buildSuccess(true) ; + // } + //} + + + } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java index 073fe7d..af117e5 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/role/RoleSv.java @@ -1,51 +1,87 @@ package com.dy.pipIrrBase.role; import com.dy.common.webUtil.QueryResultVo; -import com.dy.pipIrrBase.user.QueryVo; import com.dy.pipIrrGlobal.daoBa.BaRoleMapper; import com.dy.pipIrrGlobal.daoBa.BaRolePermissionsMapper; -import com.dy.pipIrrGlobal.daoBa.BaRolePrivilegeMapper; import com.dy.pipIrrGlobal.pojoBa.BaRole; import com.dy.pipIrrGlobal.pojoBa.BaRolePermissions; -import com.dy.pipIrrGlobal.pojoBa.BaRolePrivilege; +import com.dy.pipIrrGlobal.voBa.VoRole; 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 org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; + +/** + * @author ZhuBaoMin + * @date 2024-01-10 11:00 + * @LastEditTime 2024-01-10 11:00 + * @Description + */ @Slf4j @Service public class RoleSv { - private BaRoleMapper dao; - private BaRolePrivilegeMapper rolePrivDao ; + //private BaRoleMapper baRoleMapper; + //private BaRolePrivilegeMapper rolePrivDao ; - @Autowired - private void setDao(BaRoleMapper dao){ - this.dao = dao; - } + //@Autowired + //private void setDao(BaRoleMapper dao){ + // this.dao = dao; + //} + //@Autowired + //private void setRolePrivDao(BaRolePrivilegeMapper dao){ + // this.rolePrivDao = dao; + //} @Autowired - private void setRolePrivDao(BaRolePrivilegeMapper dao){ - this.rolePrivDao = dao; - } + private BaRoleMapper baRoleMapper; @Autowired private BaRolePermissionsMapper baRolePermissionsMapper; /** + * 鏍规嵁鎸囧畾鏉′欢锛堣鑹茬紪鍙枫�佽鑹插悕绉帮級鑾峰彇瑙掕壊鍒楄〃 + * 褰撹幏鍙栦竴鏉¤褰曟椂锛屼紶鍏oleId鍗冲彲 + * @param queryVo + * @return + */ + public QueryResultVo<List<VoRole>> getRoles(QueryVo queryVo) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); + + Long itemTotal = baRoleMapper.getRecordCount(params); + + QueryResultVo<List<VoRole>> rsVo = new QueryResultVo<>() ; + Integer pageCurr = 0; + Integer pageSize = 10000; + rsVo.pageCurr = 1; + rsVo.pageSize = 10000; + if(queryVo.pageSize != null && queryVo.pageCurr != null) { + rsVo.pageSize = queryVo.pageSize ; + rsVo.pageCurr = queryVo.pageCurr; + pageSize = queryVo.pageSize ; + pageCurr = (Integer.parseInt(params.get("pageCurr").toString()) - 1) * Integer.parseInt(params.get("pageSize").toString()); + } + params.put("pageCurr", pageCurr); + params.put("pageSize", pageSize); + + rsVo.calculateAndSet(itemTotal, params); + rsVo.obj = baRoleMapper.getRoles(params); + return rsVo ; + } + + /** * 寰楀埌鎵�鏈夎鑹� * @return 鎵�鏈夎鑹查泦鍚� */ - public QueryResultVo<List<BaRole>> selectAll(){ - QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>() ; - rsVo.obj = this.dao.selectAll() ; - return rsVo ; - } + //public QueryResultVo<List<BaRole>> selectAll(){ + // QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>() ; + // rsVo.obj = this.dao.selectAll() ; + // return rsVo ; + //} /** @@ -53,44 +89,47 @@ * @param id 瑙掕壊ID * @return 瑙掕壊瀹炰綋 */ - public BaRole selectById(Long id){ - return this.dao.selectById(id) ; - } + //public BaRole selectById(Long id){ + // return this.dao.selectById(id) ; + //} /** * 寰楀埌涓�涓敤鎴� - * @param vo 鏌ヨ鏉′欢鍊煎璞� + //* @param vo 鏌ヨ鏉′欢鍊煎璞� * @return 鐢ㄦ埛瀹炰綋 */ @SuppressWarnings("unchecked") - public QueryResultVo<List<BaRole>> selectSome(QueryVo vo){ - Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ; - Long itemTotal = this.dao.selectTotal(params) ; + //public QueryResultVo<List<BaRole>> selectSome(QueryVo vo){ + // Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo) ; + // Long itemTotal = this.dao.selectTotal(params) ; + // + // QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>() ; + // rsVo.pageSize = vo.pageSize ; + // rsVo.pageCurr = vo.pageCurr ; + // rsVo.calculateAndSet(itemTotal, params); + // rsVo.obj = this.dao.selectSome(params) ; + // + // return rsVo ; + //} - QueryResultVo<List<BaRole>> rsVo = new QueryResultVo<>() ; - rsVo.pageSize = vo.pageSize ; - rsVo.pageCurr = vo.pageCurr ; - rsVo.calculateAndSet(itemTotal, params); - rsVo.obj = this.dao.selectSome(params) ; - - return rsVo ; + /** + * 娣诲姞瑙掕壊 + * @param po 瑙掕壊瀹炰綋 + * @return 瑙掕壊ID + */ + public Long addRole(BaRole po){ + baRoleMapper.insert(po); + return po.getId(); } /** - * 淇濆瓨瀹炰綋 - * @param po 瀹炰綋 - * @return 褰卞搷璁板綍鏁伴噺 + * 鏍规嵁瑙掕壊鍚嶇О鏌ヨ璁板綍鏁伴噺锛屾坊鍔犺鑹插墠鍒ゆ柇鏄惁閲嶅悕 + * @param roleName 瑙掕壊鍚嶇О + * @return 绗﹀悎鏉′欢璁板綍鏁� */ - - /** - * 12鏈�20鏃� 鏈卞疂姘戜慨鏀硅繑鍥炲�硷紝娣诲姞瑙掕壊鍚庤繑鍥炰富閿� - */ - @Transactional - public Long save(BaRole po){ - //return this.dao.putin(po) ; - this.dao.putin(po) ; - return po.getId(); + public Integer getRecordCountByName(String roleName) { + return baRoleMapper.getRecordCountByName(roleName); } /** @@ -98,10 +137,10 @@ * @param po 瀹炰綋 * @return 褰卞搷璁板綍鏁伴噺 */ - @Transactional - public int update(BaRole po){ - return this.dao.updateByPrimaryKeySelective(po) ; - } + //@Transactional + //public int update(BaRole po){ + // return this.dao.updateByPrimaryKeySelective(po) ; + //} /** * 璁剧疆瑙掕壊鏉冮檺 @@ -109,35 +148,36 @@ * @param priviIds 閫夋嫨鐨勬潈闄恑d闆嗗悎 * @return 鎻掑叆瑙掕壊涓庢潈闄愬叧鑱旇褰曟暟閲� */ - public int setRoles(Long roleId, Long[] priviIds){ - this.rolePrivDao.deleteByRoleId(roleId) ; - int count = 0 ; - if(priviIds != null && priviIds.length > 0){ - for(Long privId : priviIds){ - count += this.rolePrivDao.insertSelective(new BaRolePrivilege(roleId, privId)) ; - } - } - return count ; - } + //public int setRoles(Long roleId, Long[] priviIds){ + // this.rolePrivDao.deleteByRoleId(roleId) ; + // int count = 0 ; + // if(priviIds != null && priviIds.length > 0){ + // for(Long privId : priviIds){ + // count += this.rolePrivDao.insertSelective(new BaRolePrivilege(roleId, privId)) ; + // } + // } + // return count ; + //} /** * 淇濆瓨淇敼瀹炰綋 * @param id 瀹炰綋ID * @return 褰卞搷璁板綍鏁伴噺 */ - @Transactional - public int delete(Long id){ - //int count = this.dao.deleteLogicById(id) ; - //閫昏緫鍒犻櫎锛屾墍浠ヤ笉瀹為檯鍒犻櫎鍏跺叧鑱旂殑鏉冮檺 - //if(count > 0){ - // this.rolePrivDao.deleteByRoleId(id) ; - //} - //return count ; - return this.dao.deleteLogicById(id) ; - } + //@Transactional + //public int delete(Long id){ + // //int count = this.dao.deleteLogicById(id) ; + // //閫昏緫鍒犻櫎锛屾墍浠ヤ笉瀹為檯鍒犻櫎鍏跺叧鑱旂殑鏉冮檺 + // //if(count > 0){ + // // this.rolePrivDao.deleteByRoleId(id) ; + // //} + // //return count ; + // return this.dao.deleteLogicById(id) ; + //} /** * 娣诲姞鎺堟潈璁板綍 + * @Auth 鏈卞疂姘� * @param po * @return */ @@ -147,6 +187,7 @@ /** * 渚濇嵁瑙掕壊缂栧彿鍒犻櫎鎺堟潈璁板綍 + * @Auth 鏈卞疂姘� * @param roleid * @return */ diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java index 5483b23..d89f165 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java @@ -68,7 +68,11 @@ public BaseResponse<QueryResultVo<List<VoDivide>>> getDivides(QueryVo vo){ try { QueryResultVo<List<VoDivide>> res = divideSv.getDivides(vo); - return BaseResponseUtils.buildSuccess(res); + if(res.itemTotal != null && res.itemTotal > 0) { + return BaseResponseUtils.buildSuccess(res); + }else { + return BaseResponseUtils.buildFail(ProjectResultCode.NO_DIVIDES.getMessage()); + } } catch (Exception e) { log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e); return BaseResponseUtils.buildException(e.getMessage()) ; @@ -94,7 +98,11 @@ public BaseResponse<PrDivide> getOneDivide(@PathVariable("id") Long id){ try { PrDivide res = divideSv.getOneDivide(id); - return BaseResponseUtils.buildSuccess(res); + if(res != null) { + return BaseResponseUtils.buildSuccess(res); + }else { + return BaseResponseUtils.buildFail(ProjectResultCode.NO_DIVIDES.getMessage()); + } } catch (Exception e) { log.error("鏌ヨ鍐滄埛寮傚父", e); return BaseResponseUtils.buildException(e.getMessage()) ; @@ -153,7 +161,7 @@ /** * 鏍规嵁鍒嗘按鎴縄D閫昏緫鍒犻櫎鍒嗘按鎴� - * @param id + * @param map * @return */ @Operation(summary = "鍒犻櫎涓�涓垎姘存埧", description = "鍒犻櫎涓�涓垎姘存埧鏁版嵁") @@ -166,14 +174,19 @@ ) }) - @GetMapping(path = "/delone/{id}") + //@GetMapping(path = "/delone/{id}") + @PostMapping(path = "delete", consumes = MediaType.APPLICATION_JSON_VALUE) @SsoAop() - public BaseResponse<Boolean> deleteDivideById(@PathVariable("id") Long id){ + public BaseResponse<Boolean> deleteDivideById(@RequestBody Map map){ + Long id = Optional.ofNullable(Long.parseLong(map.get("id").toString())).orElse(0L); + if(id == 0) + return BaseResponseUtils.buildException(ProjectResultCode.DELETE_DIVIDE_FAIL.getMessage()); + try { Integer res = Optional.ofNullable(divideSv.deleteDivideById(id)).orElse(0); - if(res == 0) { - return BaseResponseUtils.buildFail("鍒嗘按鎴垮垹闄ゅけ璐�"); - } + if(res == 0) + return BaseResponseUtils.buildFail(ProjectResultCode.DELETE_DIVIDE_FAIL.getMessage()); + return BaseResponseUtils.buildSuccess(true); } catch (Exception e) { log.error("鍒犻櫎鍒嗘按鎴垮紓甯�", e); diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/result/ProjectResultCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/result/ProjectResultCode.java index d56066c..c1aa0bf 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/result/ProjectResultCode.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/result/ProjectResultCode.java @@ -17,6 +17,8 @@ * 鍒嗘按鎴� */ DIVIDE_FAIL(10001, "鍒嗘按鎴挎坊鍔犲け璐�"), + DELETE_DIVIDE_FAIL(10001, "鍒嗘按鎴垮垹闄ゅけ璐�"), + NO_DIVIDES(10001, "鏃犵鍚堟潯浠剁殑鍒嗘按鎴胯褰�"), /** * 鍙栨按鍙� -- Gitblit v1.8.0