|  |  |  | 
|---|
|  |  |  | 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.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @ClassName UserController | 
|---|
|  |  |  | 
|---|
|  |  |  | @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(){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|