Browse Source

代码修改提交

gjs 4 years ago
parent
commit
36fa682dae

+ 0 - 4
src/main/java/com/macro/mall/tiny/modules/business/controller/FileController.java

@@ -56,10 +56,6 @@ public class FileController {
     @Autowired
     private FileService fileService;
 
-    @Value("${system.charset:gbk}")
-    private String charset;
-
-
     /**
      * @param fileUploadParam
      * @return void

+ 8 - 8
src/main/java/com/macro/mall/tiny/modules/ums/controller/UmsAdminController.java

@@ -7,6 +7,7 @@ import com.macro.mall.tiny.common.api.CommonResult;
 import com.macro.mall.tiny.modules.ums.dto.UmsAdminLoginParam;
 import com.macro.mall.tiny.modules.ums.dto.UmsAdminParam;
 import com.macro.mall.tiny.modules.ums.dto.UpdateAdminPasswordParam;
+import com.macro.mall.tiny.modules.ums.dto.UpdateAdminRoleParam;
 import com.macro.mall.tiny.modules.ums.model.UmsAdmin;
 import com.macro.mall.tiny.modules.ums.model.UmsRole;
 import com.macro.mall.tiny.modules.ums.service.UmsAdminService;
@@ -87,7 +88,7 @@ public class UmsAdminController {
     @RequestMapping(value = "/info", method = RequestMethod.GET)
     @ResponseBody
     public CommonResult getAdminInfo(Principal principal) {
-        if(principal==null){
+        if (principal == null) {
             return CommonResult.unauthorized(null);
         }
         String username = principal.getName();
@@ -97,9 +98,9 @@ public class UmsAdminController {
         data.put("menus", roleService.getMenuList(umsAdmin.getId()));
         data.put("icon", umsAdmin.getIcon());
         List<UmsRole> roleList = adminService.getRoleList(umsAdmin.getId());
-        if(CollUtil.isNotEmpty(roleList)){
+        if (CollUtil.isNotEmpty(roleList)) {
             List<String> roles = roleList.stream().map(UmsRole::getName).collect(Collectors.toList());
-            data.put("roles",roles);
+            data.put("roles", roles);
         }
         return CommonResult.success(data);
     }
@@ -172,10 +173,10 @@ public class UmsAdminController {
     @ApiOperation("修改帐号状态")
     @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
     @ResponseBody
-    public CommonResult updateStatus(@PathVariable Long id,@RequestParam(value = "status") Integer status) {
+    public CommonResult updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) {
         UmsAdmin umsAdmin = new UmsAdmin();
         umsAdmin.setStatus(status);
-        boolean success = adminService.update(id,umsAdmin);
+        boolean success = adminService.update(id, umsAdmin);
         if (success) {
             return CommonResult.success(null);
         }
@@ -185,9 +186,8 @@ public class UmsAdminController {
     @ApiOperation("给用户分配角色")
     @RequestMapping(value = "/role/update", method = RequestMethod.POST)
     @ResponseBody
-    public CommonResult updateRole(@RequestParam("adminId") Long adminId,
-                                   @RequestParam("roleIds") List<Long> roleIds) {
-        int count = adminService.updateRole(adminId, roleIds);
+    public CommonResult updateRole(@RequestBody UpdateAdminRoleParam updateAdminRoleParam) {
+        int count = adminService.updateRole(updateAdminRoleParam.getAdminId(), updateAdminRoleParam.getRoleIds());
         if (count >= 0) {
             return CommonResult.success(count);
         }

+ 26 - 0
src/main/java/com/macro/mall/tiny/modules/ums/dto/UpdateAdminRoleParam.java

@@ -0,0 +1,26 @@
+package com.macro.mall.tiny.modules.ums.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @author gjs
+ * @description
+ * @date 2021/4/17 11:28
+ */
+@Getter
+@Setter
+public class UpdateAdminRoleParam {
+    @NotNull
+    @ApiModelProperty(value = "用户ID", required = true)
+    private Long adminId;
+
+    @NotEmpty
+    @ApiModelProperty(value = "赋予角色列表", required = true)
+    private List<Long> roleIds;
+}

+ 5 - 1
src/main/java/com/macro/mall/tiny/modules/ums/mapper/UmsAdminMapper.java

@@ -1,7 +1,9 @@
 package com.macro.mall.tiny.modules.ums.mapper;
 
-import com.macro.mall.tiny.modules.ums.model.UmsAdmin;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.macro.mall.tiny.modules.ums.model.UmsAdmin;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -21,4 +23,6 @@ public interface UmsAdminMapper extends BaseMapper<UmsAdmin> {
      */
     List<Long> getAdminIdList(@Param("resourceId") Long resourceId);
 
+    Page<UmsAdmin> findListByKey(Page<UmsAdmin> page, @Param("keyword") String keyword);
+
 }

+ 9 - 4
src/main/java/com/macro/mall/tiny/modules/ums/model/UmsAdmin.java

@@ -1,17 +1,19 @@
 package com.macro.mall.tiny.modules.ums.model;
 
-import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.IdType;
-import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
-import java.io.Serializable;
-
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
 /**
  * <p>
  * 后台用户表
@@ -58,5 +60,8 @@ public class UmsAdmin implements Serializable {
     @ApiModelProperty(value = "帐号启用状态:0->禁用;1->启用")
     private Integer status;
 
+    @ApiModelProperty(value = "角色列表")
+    @TableField(exist = false)
+    private List<UmsRole> roleList;
 
 }

+ 10 - 7
src/main/java/com/macro/mall/tiny/modules/ums/service/impl/UmsAdminServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.macro.mall.tiny.common.exception.Asserts;
@@ -59,6 +60,8 @@ public class UmsAdminServiceImpl extends ServiceImpl<UmsAdminMapper,UmsAdmin> im
     @Autowired
     private UmsRoleMapper roleMapper;
     @Autowired
+    private UmsAdminMapper adminMapper;
+    @Autowired
     private UmsResourceMapper resourceMapper;
 
     @Override
@@ -154,13 +157,13 @@ public class UmsAdminServiceImpl extends ServiceImpl<UmsAdminMapper,UmsAdmin> im
     @Override
     public Page<UmsAdmin> list(String keyword, Integer pageSize, Integer pageNum) {
         Page<UmsAdmin> page = new Page<>(pageNum,pageSize);
-        QueryWrapper<UmsAdmin> wrapper = new QueryWrapper<>();
-        LambdaQueryWrapper<UmsAdmin> lambda = wrapper.lambda();
-        if(StrUtil.isNotEmpty(keyword)){
-            lambda.like(UmsAdmin::getUsername,keyword);
-            lambda.or().like(UmsAdmin::getNickName,keyword);
-        }
-        return page(page,wrapper);
+//        QueryWrapper<UmsAdmin> wrapper = new QueryWrapper<>();
+//        LambdaQueryWrapper<UmsAdmin> lambda = wrapper.lambda();
+//        if(StrUtil.isNotEmpty(keyword)){
+//            lambda.like(UmsAdmin::getUsername,keyword);
+//            lambda.or().like(UmsAdmin::getNickName,keyword);
+//        }
+        return adminMapper.findListByKey(page, keyword);
     }
 
     @Override

+ 1 - 0
src/main/resources/application-prod.yml

@@ -16,6 +16,7 @@ system:
 logging:
   file:
     path: /var/logs
+    max-size: 1GB
   level:
     root: info
     com.macro.mall: info

+ 55 - 16
src/main/resources/mapper/ums/UmsAdminMapper.xml

@@ -4,25 +4,64 @@
 
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.macro.mall.tiny.modules.ums.model.UmsAdmin">
-        <id column="id" property="id" />
-        <result column="username" property="username" />
-        <result column="password" property="password" />
-        <result column="icon" property="icon" />
-        <result column="email" property="email" />
-        <result column="nick_name" property="nickName" />
-        <result column="note" property="note" />
-        <result column="create_time" property="createTime" />
-        <result column="login_time" property="loginTime" />
-        <result column="status" property="status" />
+        <id column="id" property="id"/>
+        <result column="username" property="username"/>
+        <result column="password" property="password"/>
+        <result column="icon" property="icon"/>
+        <result column="email" property="email"/>
+        <result column="nick_name" property="nickName"/>
+        <result column="note" property="note"/>
+        <result column="create_time" property="createTime"/>
+        <result column="login_time" property="loginTime"/>
+        <result column="status" property="status"/>
+    </resultMap>
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap2" type="com.macro.mall.tiny.modules.ums.model.UmsAdmin">
+        <id column="id" property="id"/>
+        <result column="username" property="username"/>
+        <result column="password" property="password"/>
+        <result column="icon" property="icon"/>
+        <result column="email" property="email"/>
+        <result column="nick_name" property="nickName"/>
+        <result column="note" property="note"/>
+        <result column="create_time" property="createTime"/>
+        <result column="login_time" property="loginTime"/>
+        <result column="status" property="status"/>
+        <collection property="roleList" ofType="com.macro.mall.tiny.modules.ums.model.UmsRole" column="id">
+            <id column="r_id" property="id"/>
+            <result column="r_name" property="name"/>
+        </collection>
     </resultMap>
 
     <select id="getAdminIdList" resultType="java.lang.Long">
-        SELECT
-            DISTINCT ar.admin_id
-        FROM
-            ums_role_resource_relation rr
-                LEFT JOIN ums_admin_role_relation ar ON rr.role_id = ar.role_id
-        WHERE rr.resource_id=#{resourceId}
+        SELECT DISTINCT ar.admin_id
+        FROM ums_role_resource_relation rr
+                 LEFT JOIN ums_admin_role_relation ar ON rr.role_id = ar.role_id
+        WHERE rr.resource_id = #{resourceId}
+    </select>
+
+    <select id="findListByKey" resultMap="BaseResultMap2">
+        SELECT a.id,
+        a.username,
+        a.password,
+        a.icon,
+        a.email,
+        a.nick_name,
+        a.note,
+        a.create_time,
+        a.login_time,
+        a.status,
+        r.id r_id,
+        r.name r_name
+        FROM ums_admin a
+        LEFT JOIN ums_admin_role_relation ar ON ar.admin_id = a.id
+        LEFT JOIN ums_role r ON ar.role_id = r.id
+        WHERE 1 = 1
+        <if test="keyword!=null and keyword!=''">
+            AND a.username like CONCAT('%', #{keyword}, '%')
+            OR a.nick_name like concat('%', #{keyword}, '%');
+        </if>
     </select>
 
 </mapper>