| package com.moral.api.controller; | 
|   | 
| import com.moral.api.pojo.dto.user.UserDTO; | 
| import com.moral.api.pojo.dto.user.UserQueryDTO; | 
| import com.moral.api.pojo.form.user.UserDeleteForm; | 
| import com.moral.api.pojo.form.user.UserInsertForm; | 
| import com.moral.api.pojo.form.user.UserQueryForm; | 
| import com.moral.api.pojo.form.user.UserUpdateForm; | 
| import com.moral.api.pojo.vo.user.UserQueryVO; | 
| import com.moral.api.service.UserService; | 
| import com.moral.constant.ResponseCodeEnum; | 
| import com.moral.constant.ResultMessage; | 
| import io.swagger.annotations.Api; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| /** | 
|  * @ClassName UserController | 
|  * @Description 用户管理 | 
|  * @Author 陈凯裕 | 
|  * @Date 2021/3/22 13:52 | 
|  * @Version TODO | 
|  **/ | 
| @Slf4j | 
| @Api(tags = {"用户管理模块"}) | 
| @RestController | 
| @RequestMapping("/user") | 
| public class UserController { | 
|     @Autowired | 
|     UserService userService; | 
|   | 
|     @GetMapping("query") | 
|     public ResultMessage query(UserQueryForm form) { | 
|         //判断是否缺少参数 | 
|         if (!form.valid()) | 
|             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|                     ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|   | 
|         //处理查询业务 | 
|         UserQueryDTO dto = userService.queryUsers(form); | 
|   | 
|         //转换前端所需参数 | 
|         UserQueryVO vo = UserQueryVO.convert(dto); | 
|   | 
|         return new ResultMessage(dto.getCode(), dto.getMsg(), vo); | 
|     } | 
|   | 
|     @PostMapping("update") | 
|     public ResultMessage update(@RequestBody UserUpdateForm form){ | 
|   | 
|         //判断是否缺少参数 | 
|         if (!form.valid()) | 
|             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|                     ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|   | 
|         //判断参数是否有效 | 
|         UserDTO conditionDTO = form.paramValid(); | 
|         if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { | 
|             return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); | 
|         } | 
|   | 
|         //处理更新业务 | 
|         UserDTO dto = userService.updateUser(form); | 
|   | 
|         return new ResultMessage(dto.getCode(), dto.getMsg(), null); | 
|     } | 
|   | 
|   | 
|     @PostMapping("insert") | 
|     public ResultMessage insert(@RequestBody UserInsertForm form){ | 
|   | 
|         //判断是否缺少参数 | 
|         if (!form.valid()) | 
|             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|                     ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|   | 
|         //判断参数是否有效 | 
|         UserDTO conditionDTO = form.paramValid(); | 
|         if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { | 
|             return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); | 
|         } | 
|   | 
|         //处理增加业务 | 
|         UserDTO dto = userService.insertUser(form); | 
|   | 
|         return new ResultMessage(dto.getCode(), dto.getMsg(), null); | 
|     } | 
| } |