Browse Source

权限字段替换

huangqizheng/feature-20250721170818-后端周末修改
sunjiabei 4 weeks ago
parent
commit
9b646b9f49
  1. 4
      src/main/java/com/example/demo/mapper/PermissionMapper.java
  2. 7
      src/main/java/com/example/demo/serviceImpl/PermissionServiceImpl.java
  3. 49
      src/main/resources/mapper/PermissionMapper.xml

4
src/main/java/com/example/demo/mapper/PermissionMapper.java

@ -25,9 +25,9 @@ public interface PermissionMapper {
Integer updatePermission(Admin admin); Integer updatePermission(Admin admin);
Integer addPermission(Admin admin); Integer addPermission(Admin admin);
List<Role> getRole(String token); List<Role> getRole(String token);
Integer addadminRole(AdminRole adminRole);
// Integer addadminRole(AdminRole adminRole);
Integer deleteAdmin(Integer id); Integer deleteAdmin(Integer id);
Integer deleteAdminRole(Integer id);
// Integer deleteAdminRole(Integer id);
Integer updateAdminRole(AdminRole adminRole); Integer updateAdminRole(AdminRole adminRole);
Integer updateAdmin(Admin admin); Integer updateAdmin(Admin admin);
} }

7
src/main/java/com/example/demo/serviceImpl/PermissionServiceImpl.java

@ -94,11 +94,7 @@ public class PermissionServiceImpl implements PermissionService {
// 将地区列表转换为逗号分隔的字符串 // 将地区列表转换为逗号分隔的字符串
String markets = String.join(",", admin.getMarket()); String markets = String.join(",", admin.getMarket());
admin.setMarket(Collections.singletonList(markets)); admin.setMarket(Collections.singletonList(markets));
permissionMapper.addPermission(admin);
AdminRole adminRole = new AdminRole();
adminRole.setAdminId(admin.getId());
adminRole.setRoleId(admin.getRoleId());
return permissionMapper.addadminRole(adminRole);
return permissionMapper.addPermission(admin);
} }
} }
@ -114,7 +110,6 @@ public class PermissionServiceImpl implements PermissionService {
return -1; return -1;
} }
permissionMapper.deleteAdminRole(id);
return permissionMapper.deleteAdmin(id); return permissionMapper.deleteAdmin(id);
} }

49
src/main/resources/mapper/PermissionMapper.xml

@ -2,13 +2,13 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.PermissionMapper"> <mapper namespace="com.example.demo.mapper.PermissionMapper">
<insert id="addPermission" useGeneratedKeys="true" keyProperty="id" keyColumn="id"> <insert id="addPermission" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
insert into admin(admin_name,machine_id,account,password,market,postiton,remark,admin_status)
values(#{adminName},#{machineId},#{account},#{password},#{market[0]},#{postiton},#{remark},1)
</insert>
<insert id="addadminRole">
insert into admin_role(admin_id,role_id)
values(#{adminId},#{roleId})
insert into admin(admin_name, machine_id, account, password, market, postiton, remark, admin_status, role_id)
values (#{adminName}, #{machineId}, #{account}, #{password}, #{market[0]}, #{postiton}, #{remark}, 1 ,#{roleId})
</insert> </insert>
<!-- <insert id="addadminRole">-->
<!-- insert into admin_role(admin_id, role_id)-->
<!-- values (#{adminId}, #{roleId})-->
<!-- </insert>-->
<update id="updatePermission"> <update id="updatePermission">
update admin update admin
<set> <set>
@ -19,13 +19,13 @@
where id=#{id} where id=#{id}
</update> </update>
<update id="updateAdminRole"> <update id="updateAdminRole">
update admin_role
update admin
<set> <set>
<if test="roleId!=null"> <if test="roleId!=null">
role_id= #{roleId}, role_id= #{roleId},
</if> </if>
</set> </set>
where admin_id= #{id}
where id= #{adminId}
</update> </update>
<update id="updateAdmin"> <update id="updateAdmin">
@ -43,44 +43,53 @@
<if test="remark!=null"> <if test="remark!=null">
remark= #{remark}, remark= #{remark},
</if> </if>
market= #{market[0]}
market= #{market[0]}
</set> </set>
where account= #{account} where account= #{account}
</update> </update>
<delete id="deleteAdmin"> <delete id="deleteAdmin">
delete from admin where id=#{id}
</delete>
<delete id="deleteAdminRole">
delete from admin_role where admin_id= #{id}
delete
from admin
where id = #{id}
</delete> </delete>
<!-- <delete id="deleteAdminRole">-->
<!-- delete-->
<!-- from admin_role-->
<!-- where admin_id = #{id}-->
<!-- </delete>-->
<select id="getposition" resultType="java.lang.String"> <select id="getposition" resultType="java.lang.String">
select distinct postiton from admin
select distinct postiton
from admin
</select> </select>
<select id="getmarket" resultType="java.lang.String"> <select id="getmarket" resultType="java.lang.String">
select distinct market from admin
select distinct market
from admin
</select> </select>
<select id="getPermission" resultType="com.example.demo.domain.vo.Permission"> <select id="getPermission" resultType="com.example.demo.domain.vo.Permission">
select admin.id as id,admin.admin_name as name,admin.account,admin.market,admin.postiton,admin.remark,admin.admin_status as adminStatus,role.role_name as roleName,role.id as roleId
select admin.id as id,admin.admin_name as
name,admin.account,admin.market,admin.postiton,admin.remark,admin.admin_status as adminStatus,role.role_name as
roleName,role.id as roleId
from admin from admin
left join role on admin.role_id=role.id left join role on admin.role_id=role.id
<where> <where>
<if test="account!=null and account.length>0"> <if test="account!=null and account.length>0">
and admin.account=#{account}
and admin.account=#{account}
</if> </if>
<if test="market!=null and market.length>0"> <if test="market!=null and market.length>0">
and admin.market=#{market}
and admin.market=#{market}
</if> </if>
<if test="postiton!=null and postiton.length>0"> <if test="postiton!=null and postiton.length>0">
and admin.postiton=#{postiton}
and admin.postiton=#{postiton}
</if> </if>
</where> </where>
order by admin.admin_status desc order by admin.admin_status desc
</select> </select>
<select id="getRole" resultType="com.example.demo.domain.entity.Role"> <select id="getRole" resultType="com.example.demo.domain.entity.Role">
select * from role
select *
from role
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save