| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.moral.api.pojo.dto.AccountDTO; |
| | | import com.moral.api.pojo.dto.LoginDTO; |
| | | import com.moral.api.pojo.request.AccountAddRequest; |
| | | import com.moral.api.pojo.request.LoginRequest; |
| | | import com.moral.api.pojo.request.LogoutRequest; |
| | | import com.moral.api.pojo.vo.AccountVO; |
| | | import com.moral.api.pojo.vo.LoginVO; |
| | | import com.moral.api.pojo.dto.account.*; |
| | | import com.moral.api.pojo.dto.accountRole.AccountRoleDTO; |
| | | import com.moral.api.pojo.form.account.*; |
| | | import com.moral.api.pojo.form.accountRole.AccountRoleUpdateForm; |
| | | import com.moral.api.pojo.vo.account.AccountQueryVO; |
| | | import com.moral.api.service.ManageAccountRoleService; |
| | | import com.moral.api.service.ManageAccountService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import io.swagger.annotations.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"后台账户管理"}) |
| | | @RestController |
| | | @CrossOrigin(origins = "*", maxAge = 3600) |
| | | @RequestMapping("/account") |
| | | public class AccountController { |
| | | @Resource |
| | | @Autowired |
| | | ManageAccountService accountService; |
| | | @Autowired |
| | | @Qualifier("tokenRedisTemplate") |
| | | RedisTemplate redisTemplate; |
| | | ManageAccountRoleService manageAccountRoleService; |
| | | |
| | | @PostMapping("insert") |
| | | public ResultMessage insert(@RequestBody AccountInsertForm form) { |
| | | //判断是否缺少参数 |
| | | if (!form.valid()) |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | |
| | | @PostMapping("login") |
| | | public ResultMessage login(@RequestBody LoginRequest loginRequest) { |
| | | if (!loginRequest.valid()) |
| | | return ResultMessage.fail(Constants.CODE_PARAMETER_IS_MISSING,Constants.MSG_PARAMETER_IS_MISSING); |
| | | //判断参数是否有效 |
| | | AccountDTO conditionDTO = form.paramValid(); |
| | | if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { |
| | | return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); |
| | | } |
| | | |
| | | LoginDTO loginDTO = accountService.login(loginRequest); |
| | | //处理插入业务 |
| | | AccountDTO dto = accountService.insertAccount(form); |
| | | |
| | | LoginVO loginVO = LoginVO.convert(loginDTO); |
| | | |
| | | if(loginVO.getCode().equals(loginVO.SUCCESS)) |
| | | return ResultMessage.ok(loginVO); |
| | | return ResultMessage.fail(loginVO); |
| | | return new ResultMessage(dto.getCode(), dto.getMsg(), null); |
| | | } |
| | | |
| | | @PostMapping("update") |
| | | public ResultMessage update(@RequestBody AccountUpdateForm form) { |
| | | //判断是否缺少参数 |
| | | if (!form.valid()) |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | |
| | | @PostMapping("logout") |
| | | public ResultMessage logout(@RequestBody LogoutRequest logoutRequest, HttpServletRequest request) { |
| | | if(!logoutRequest.valid()) |
| | | return ResultMessage.fail(Constants.CODE_PARAMETER_IS_MISSING,Constants.MSG_PARAMETER_IS_MISSING); |
| | | String token = request.getHeader("token"); |
| | | logoutRequest.setToken(token); |
| | | //判断参数是否有效 |
| | | AccountDTO conditionDTO = form.paramValid(); |
| | | if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { |
| | | return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); |
| | | } |
| | | |
| | | if(accountService.logout(logoutRequest)) |
| | | return ResultMessage.ok("注销成功"); |
| | | return ResultMessage.fail("注销异常"); |
| | | //处理更新业务 |
| | | AccountDTO dto = accountService.updateAccount(form); |
| | | |
| | | return new ResultMessage(dto.getCode(), dto.getMsg(), null); |
| | | } |
| | | |
| | | @PostMapping("add") |
| | | public ResultMessage add(@RequestBody AccountAddRequest accountAddRequest){ |
| | | if(!accountAddRequest.valid()) |
| | | return ResultMessage.fail(Constants.CODE_PARAMETER_IS_MISSING,Constants.MSG_PARAMETER_IS_MISSING); |
| | | @PostMapping("delete") |
| | | public ResultMessage delete(@RequestBody AccountDeleteForm form) { |
| | | //判断是否缺少参数 |
| | | if (!form.valid()) |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | |
| | | AccountDTO accountDTO = accountService.addAccount(accountAddRequest); |
| | | //处理删除业务 |
| | | AccountDTO dto = accountService.deleteAccount(form); |
| | | |
| | | AccountVO accountVO = AccountVO.convertToInsertPage(accountDTO); |
| | | |
| | | if(accountVO.getCode().equals(accountVO.SUCCESS)) |
| | | return ResultMessage.ok(accountVO); |
| | | return ResultMessage.fail(accountVO); |
| | | return new ResultMessage(dto.getCode(), dto.getMsg(), null); |
| | | } |
| | | |
| | | @GetMapping("query") |
| | | public ResultMessage query(AccountQueryForm form) { |
| | | //判断是否缺少参数 |
| | | if (!form.valid()) |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | |
| | | //处理查询业务 |
| | | AccountQueryDTO accountQueryDTO = accountService.queryAccount(form); |
| | | |
| | | //转换前端需要的参数 |
| | | AccountQueryVO accountQueryVO = AccountQueryVO.convert(accountQueryDTO); |
| | | |
| | | |
| | | return new ResultMessage(accountQueryDTO.getCode(), accountQueryDTO.getMsg(), accountQueryVO); |
| | | } |
| | | |
| | | @PostMapping("updateRole") |
| | | public ResultMessage updateRole(@RequestBody AccountRoleUpdateForm form){ |
| | | |
| | | //判断是否缺少参数 |
| | | if (!form.valid()) |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | |
| | | //处理更新业务 |
| | | AccountRoleDTO dto = manageAccountRoleService.updateAccountRole(form); |
| | | |
| | | return new ResultMessage(dto.getCode(), dto.getMsg(), null); |
| | | } |
| | | |
| | | } |