Selaa lähdekoodia

web客户端用户修改

bmmx 1 vuosi sitten
vanhempi
commit
e909c92132

+ 1 - 1
.idea/JavaSceneConfigState.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="SmartInputSourceJavaSceneConfigState">
-    <option name="customChineseScenes" value="{&quot;capsLockState&quot;:false,&quot;code&quot;:&quot;;BadReqException(message);ApiModelProperty(value);ApiOperation()&quot;,&quot;enable&quot;:true,&quot;languageType&quot;:&quot;CHINESE&quot;,&quot;name&quot;:&quot;自定义中文切换&quot;,&quot;tip&quot;:&quot;&quot;}" />
+    <option name="customChineseScenes" value="{&quot;capsLockState&quot;:false,&quot;code&quot;:&quot;;ApiModelProperty(value);ApiOperation();debug(s);BadReqException(message)&quot;,&quot;enable&quot;:true,&quot;languageType&quot;:&quot;CHINESE&quot;,&quot;name&quot;:&quot;自定义中文切换&quot;,&quot;tip&quot;:&quot;&quot;}" />
   </component>
 </project>

+ 26 - 9
.idea/workspace.xml

@@ -4,13 +4,17 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="46b159bd-08ca-42f0-b80f-41d4944a8a29" name="Changes" comment="web品牌管理接口">
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/dto/DistributorDTO.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/dto/DistributorQueryPageDTO.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/vo/DistributorQueryPageVO.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/vo/DistributorVO.java" afterDir="false" />
+    <list default="true" id="46b159bd-08ca-42f0-b80f-41d4944a8a29" name="Changes" comment="web维修厂管理接口">
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/dto/UserQueryPageDTO.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/vo/UserQueryPageVO.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/JavaSceneConfigState.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/JavaSceneConfigState.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/om/controller/admin/AppUserController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/om/controller/admin/AppUserController.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/om/entity/po/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/po/User.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/om/entity/vo/UserAddVO.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/om/entity/vo/UserAddVO.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/om/service/IUserService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/om/service/IUserService.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/om/service/impl/UserServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/om/service/impl/UserServiceImpl.java" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -25,6 +29,7 @@
     </option>
   </component>
   <component name="Git.Settings">
+    <option name="PUSH_AUTO_UPDATE" value="true" />
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
     <option name="UPDATE_TYPE" value="REBASE" />
   </component>
@@ -72,7 +77,7 @@
     &quot;project.structure.last.edited&quot;: &quot;Project&quot;,
     &quot;project.structure.proportion&quot;: &quot;0.15&quot;,
     &quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
-    &quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
+    &quot;settings.editor.selected.configurable&quot;: &quot;MavenSettings&quot;,
     &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
   }
 }</component>
@@ -164,7 +169,10 @@
       <workItem from="1707295344394" duration="5919000" />
       <workItem from="1707355242246" duration="627000" />
       <workItem from="1707355884110" duration="8433000" />
-      <workItem from="1707364400277" duration="8079000" />
+      <workItem from="1707364400277" duration="8765000" />
+      <workItem from="1707387945482" duration="394000" />
+      <workItem from="1707388468820" duration="1399000" />
+      <workItem from="1707438514767" duration="8903000" />
     </task>
     <task id="LOCAL-00001" summary="管理员登录">
       <option name="closed" value="true" />
@@ -214,7 +222,15 @@
       <option name="project" value="LOCAL" />
       <updated>1707363840812</updated>
     </task>
-    <option name="localTasksCounter" value="7" />
+    <task id="LOCAL-00007" summary="web维修厂管理接口">
+      <option name="closed" value="true" />
+      <created>1707379339504</created>
+      <option name="number" value="00007" />
+      <option name="presentableId" value="LOCAL-00007" />
+      <option name="project" value="LOCAL" />
+      <updated>1707379339505</updated>
+    </task>
+    <option name="localTasksCounter" value="8" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
@@ -225,7 +241,8 @@
     <MESSAGE value="初始化运维项目" />
     <MESSAGE value="管理员电话和邮箱修改" />
     <MESSAGE value="web品牌管理接口" />
-    <option name="LAST_COMMIT_MESSAGE" value="web品牌管理接口" />
+    <MESSAGE value="web维修厂管理接口" />
+    <option name="LAST_COMMIT_MESSAGE" value="web维修厂管理接口" />
   </component>
   <component name="XDebuggerManager">
     <breakpoint-manager>

+ 1 - 0
pom.xml

@@ -57,6 +57,7 @@
         </dependency>
 
 
+
         <!--springboot中test启动-->
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 12 - 10
src/main/java/com/om/controller/admin/AppUserController.java

@@ -3,8 +3,10 @@ package com.om.controller.admin;
 
 import com.om.entity.dto.UserLoginDTO;
 import com.om.entity.dto.UserLoginDTO;
+import com.om.entity.dto.UserQueryPageDTO;
 import com.om.entity.po.User;
 import com.om.entity.vo.UserAddVO;
+import com.om.entity.vo.UserQueryPageVO;
 import com.om.service.IUserService;
 import com.om.utils.Result;
 import com.om.utils.UserContext;
@@ -53,19 +55,19 @@ public class AppUserController {
     }
     @GetMapping("/delete")
     @ApiOperation("删除客户端用户")
-    public Result delete(@PathVariable("id")Integer id){
+    public Result delete(@RequestParam Integer id){
 
         return userService.delete(id);
     }
     @GetMapping("/getById")
     @ApiOperation("根据id获取指定的客户端用户")
-    public Result getById(@PathVariable("userId")Integer userId){
+    public Result getById(@RequestParam Integer userId){
 
         return userService.getByUserId(userId);
     }
     @GetMapping("/getListByUserId")
     @ApiOperation("通过user获得vci相关的用户信息(未写)")
-    public Result getListByUserId(@PathVariable("userId")Integer userId){
+    public Result getListByUserId(@RequestParam Integer userId){
 
         //此处未写,主要设计vci
         return userService.getListByUserId(userId);
@@ -73,12 +75,12 @@ public class AppUserController {
 
     @PostMapping("/getPageList")
     @ApiOperation("获取所有的用户List集合")
-    public Result getPageList(@RequestBody UserAddVO user){
+    public Result<UserQueryPageVO> getPageList(@RequestBody UserQueryPageDTO dto){
 
-        return userService.getPageList(user);
+        return userService.getPageList(dto);
     }
     @GetMapping("/relieve(未写)")
-    @ApiOperation("")
+    @ApiOperation("(未写)")
     public Result relieve(){
 
         //这里未写,未知要求
@@ -87,15 +89,15 @@ public class AppUserController {
 
     @GetMapping("/updateState")
     @ApiOperation("更新用户状态")
-    public Result updateState(@RequestBody User user){
+    public Result updateState(@RequestParam Integer id,@RequestParam Integer state){
 
-        return userService.updateState(user);
+        return userService.updateState(id,state);
     }
     @GetMapping("/updateType")
     @ApiOperation("更新类型")
-    Result updateType(@RequestBody User user){
+    Result updateType(@RequestParam Integer id,@RequestParam Integer type){
 
-        return userService.updateType(user);
+        return userService.updateType(id,type);
     }
 
     @GetMapping("/updateUserInfo")

+ 21 - 0
src/main/java/com/om/entity/dto/UserQueryPageDTO.java

@@ -0,0 +1,21 @@
+package com.om.entity.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class UserQueryPageDTO {
+    @ApiModelProperty(value = "当前页码")
+    private Integer pageIndex;
+
+    @ApiModelProperty(value = "每个页码的大小")
+    private Integer pageSize;
+
+    @ApiModelProperty(value = "搜索字段---搜索用户名")
+    private String searchUsername;
+
+    @ApiModelProperty(value = "搜索字段---搜索手机号")
+    private String searchPhone;
+}

+ 4 - 0
src/main/java/com/om/entity/po/User.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import java.time.LocalDateTime;
 import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -66,9 +68,11 @@ public class User implements Serializable {
     private Integer userType;
 
     @ApiModelProperty(value = "创建时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime createTime;
 
     @ApiModelProperty(value = "更新时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime updateTime;
 
 

+ 2 - 0
src/main/java/com/om/entity/vo/UserAddVO.java

@@ -19,4 +19,6 @@ public class UserAddVO extends User {
     @ApiModelProperty("页脚数")
     Integer pageIndex;
 
+
+
 }

+ 32 - 0
src/main/java/com/om/entity/vo/UserQueryPageVO.java

@@ -0,0 +1,32 @@
+package com.om.entity.vo;
+
+import com.om.entity.po.User;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+public class UserQueryPageVO {
+
+    @ApiModelProperty(value = "当前页码")
+    private Integer current;
+
+    @ApiModelProperty(value = "总页码")
+    private Integer pages;
+
+    @ApiModelProperty(value = "每个页码的大小")
+    private Integer size;
+
+    @ApiModelProperty(value = "总数量")
+    private Integer total;
+
+    @ApiModelProperty(value = "是否是查询")
+    private Boolean searchCount = false;
+
+    @ApiModelProperty(value = "结果集")
+    private List<User> records;
+
+}

+ 6 - 3
src/main/java/com/om/service/IUserService.java

@@ -2,9 +2,12 @@ package com.om.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.om.entity.dto.UserLoginDTO;
+import com.om.entity.dto.UserQueryPageDTO;
 import com.om.entity.po.User;
 import com.om.entity.vo.UserAddVO;
+import com.om.entity.vo.UserQueryPageVO;
 import com.om.utils.Result;
+import org.springframework.web.bind.annotation.RequestParam;
 
 /**
  * <p>
@@ -26,13 +29,13 @@ public interface IUserService extends IService<User> {
 
     Result getListByUserId(Integer userId);
 
-    Result getPageList(UserAddVO user);
+    Result<UserQueryPageVO> getPageList(UserQueryPageDTO dto);
 
     Result relieve();
 
-    Result updateState(User user);
+    Result updateState(Integer id, Integer state);
 
-    Result updateType(User user);
+    Result updateType(Integer id, Integer type);
 
     Result updateUserInfo(UserAddVO user);
 }

+ 53 - 31
src/main/java/com/om/service/impl/UserServiceImpl.java

@@ -3,11 +3,14 @@ package com.om.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.ListUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.om.constant.RedisConstant;
 import com.om.entity.dto.UserLoginDTO;
+import com.om.entity.dto.UserQueryPageDTO;
 import com.om.entity.po.User;
 import com.om.entity.vo.UserAddVO;
 import com.om.entity.vo.UserLoginVO;
+import com.om.entity.vo.UserQueryPageVO;
 import com.om.exception.BadReqException;
 import com.om.mapper.UserMapper;
 import com.om.service.IUserService;
@@ -15,6 +18,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.om.utils.JwtUtils;
 import com.om.utils.Result;
 import com.om.utils.UserContext;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
@@ -35,6 +39,7 @@ import java.util.concurrent.TimeUnit;
  * @since 2024-01-29
  */
 @Service
+@Slf4j
 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
 
     @Resource
@@ -59,7 +64,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
 
         //判断数据是否为空
         if (StringUtils.isBlank(username) || StringUtils.isBlank(password) || StringUtils.isBlank(clientNum) ||
-                StringUtils.isBlank(deviceSn) || type == null){
+                StringUtils.isBlank(deviceSn) || type == null) {
             throw new BadReqException("数据为空!!");
         }
 
@@ -69,7 +74,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
                 .one();
 
         //判断用户是否存在
-        if (BeanUtil.isEmpty(user)){
+        if (BeanUtil.isEmpty(user)) {
             throw new BadReqException("该用户不存在!!");
         }
 
@@ -77,7 +82,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
         //密码加密
         password = DigestUtils.md5DigestAsHex(password.getBytes());
         //判断密码是否正确
-        if (!password.equals(user.getPassword())){
+        if (!password.equals(user.getPassword())) {
             throw new BadReqException("密码错误");
         }
         // TODO 判断用户状态
@@ -86,11 +91,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
 
         // 生成token
         Map<String, Object> claims = new HashMap<>();
-        claims.put("u_id",user.getId());
+        claims.put("u_id", user.getId());
         String token = jwtUtils.generateToken(claims);
         //把token存入到redis中
         String key = RedisConstant.USER_TOKEN_PREFIX + user.getId();
-        redisTemplate.opsForValue().set(key,token,RedisConstant.USER_TOKEN_TTL, TimeUnit.SECONDS);
+        redisTemplate.opsForValue().set(key, token, RedisConstant.USER_TOKEN_TTL, TimeUnit.SECONDS);
 
         //封装vo返回
         UserLoginVO userLoginVO = new UserLoginVO();
@@ -110,8 +115,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     @Override
     public Result add(UserAddVO user) {
         User addUser = new User();
-        BeanUtil.copyProperties(user,addUser);
-        if (addUser.getUsername()==null || addUser.getPassword() == null ){
+        BeanUtil.copyProperties(user, addUser);
+        if (addUser.getUsername() == null || addUser.getPassword() == null) {
             return Result.error();
         }
         this.save(addUser);
@@ -123,11 +128,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
 
     @Override
     public Result delete(Integer id) {
-        if (id == null){
+        if (id == null) {
             return Result.error();
         }
         boolean deleteById = this.removeById(id);
-        if (deleteById == false){
+        if (deleteById == false) {
             return Result.error();
         }
         return Result.ok();
@@ -141,20 +146,36 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     }
 
     @Override
-    public Result getPageList(UserAddVO user) {
-
-        List<User> userList = userMapper.selectList(null);
-        if (user.getPageIndex() <=0 || user.getPageSize()<=0 || userList == null){
-            return Result.error();
+    public Result<UserQueryPageVO> getPageList(UserQueryPageDTO dto) {
+        Integer pageIndex = dto.getPageIndex();
+        Integer pageSize = dto.getPageSize();
+        String searchUsername = dto.getSearchUsername();
+        String searchPhone = dto.getSearchPhone();
+
+        Page<User> page = this.lambdaQuery()
+                .like(searchUsername != null, User::getUsername, searchUsername)
+                .like(searchPhone != null, User::getTel, searchPhone)
+                .orderByDesc(User::getCreateTime)
+                .page(new Page<>(pageIndex, pageSize));
+
+        UserQueryPageVO vo = new UserQueryPageVO();
+        vo.setCurrent((int) page.getCurrent());
+        vo.setSize((int) page.getSize());
+        vo.setPages((int) page.getPages());
+        vo.setTotal((int) page.getTotal());
+        if (searchUsername!=null || searchPhone !=null){
+            vo.setSearchCount(true);
         }
-        List<User> list = ListUtil.page(user.getPageIndex(), user.getPageSize(), userList);
-        return Result.ok(list);
+        List<User> records = page.getRecords();
+        vo.setRecords(records);
+
+        return Result.ok(vo);
     }
 
     @Override
     public Result getByUserId(Integer userId) {
         User user = this.getById(userId);
-        if (user == null){
+        if (user == null) {
             return Result.error();
         }
 
@@ -167,25 +188,26 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     }
 
     @Override
-    public Result updateState(User user) {
-        Integer userId = UserContext.getUserId();
+    public Result updateState(Integer id, Integer state) {
+        User selectUser = getById(id);
+        if (BeanUtil.isEmpty(selectUser)){
+            throw new BadReqException("该用户不存在");
+        }
 
-        User selectUser = getById(userId);
-        selectUser.setState(user.getState());
-        userMapper.update(selectUser,null);
+        selectUser.setState(state);
+        userMapper.update(selectUser, null);
 
         return Result.ok();
     }
 
     @Override
-    public Result updateType(User user) {
-        if (user.getUserType()==null){
-            return Result.error();
-        }
-        Integer userId = UserContext.getUserId();
-        User selectUser = getById(userId);
-        selectUser.setUserType(user.getUserType());
-        userMapper.update(selectUser,null);
+    public Result updateType(Integer id, Integer type) {
+         User selectUser = getById(id);
+         if (BeanUtil.isEmpty(selectUser)){
+             throw new BadReqException("该用户不存在");
+         }
+        selectUser.setUserType(type);
+        userMapper.update(selectUser, null);
         return Result.ok();
     }
 
@@ -193,7 +215,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     public Result updateUserInfo(UserAddVO user) {
         Integer userId = UserContext.getUserId();
         User userById = getById(userId);
-        BeanUtil.copyProperties(user,userById);
+        BeanUtil.copyProperties(user, userById);
         userById.setId(userId);
 
         return Result.ok();