|  |  |  | 
|---|
|  |  |  | package com.moral.api.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.api.pojo.dto.account.AccountDeleteDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.account.AccountInsertDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.account.AccountQueryDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.account.AccountUpdateDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.login.LoginDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.form.*; | 
|---|
|  |  |  | import com.moral.api.pojo.vo.account.AccountDeleteVO; | 
|---|
|  |  |  | import com.moral.api.pojo.vo.account.AccountInsertVO; | 
|---|
|  |  |  | 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.pojo.vo.account.AccountUpdateVO; | 
|---|
|  |  |  | import com.moral.api.pojo.vo.login.LoginVO; | 
|---|
|  |  |  | 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 com.moral.util.KaptchaUtils; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Api(tags = {"后台账户管理"}) | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @CrossOrigin(origins = "*", maxAge = 3600) | 
|---|
|  |  |  | @RequestMapping("/account") | 
|---|
|  |  |  | public class AccountController { | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ManageAccountService accountService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("login") | 
|---|
|  |  |  | public ResultMessage login(@RequestBody LoginForm loginForm) { | 
|---|
|  |  |  | if (!loginForm.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LoginDTO loginDTO = accountService.login(loginForm); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LoginVO loginVO = LoginVO.convert(loginDTO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(loginDTO.getCode(),loginDTO.getMsg(),loginVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("logout") | 
|---|
|  |  |  | public ResultMessage logout (@RequestBody LogoutForm logoutForm, HttpServletRequest request) { | 
|---|
|  |  |  | if(!logoutForm.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | String token = request.getHeader("token"); | 
|---|
|  |  |  | logoutForm.setToken(token); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(accountService.logout(logoutForm)) | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  | return ResultMessage.fail(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ManageAccountRoleService manageAccountRoleService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("insert") | 
|---|
|  |  |  | public ResultMessage insert(@RequestBody AccountInsertForm accountInsertForm){ | 
|---|
|  |  |  | if(!accountInsertForm.valid()) | 
|---|
|  |  |  | public ResultMessage insert(@RequestBody AccountInsertForm form) { | 
|---|
|  |  |  | //判断是否缺少参数 | 
|---|
|  |  |  | if (!form.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | //判断参数是否符合条件 | 
|---|
|  |  |  | AccountInsertDTO conditionDTO = accountInsertForm.paramValid(); | 
|---|
|  |  |  | if(conditionDTO.getCode()!=ResponseCodeEnum.SUCCESS.getCode()){ | 
|---|
|  |  |  | return new ResultMessage(conditionDTO.getCode(),conditionDTO.getMsg(),null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断参数是否有效 | 
|---|
|  |  |  | AccountDTO conditionDTO = form.paramValid(); | 
|---|
|  |  |  | if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { | 
|---|
|  |  |  | return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountInsertDTO accountInsertDTO = accountService.insertAccount(accountInsertForm); | 
|---|
|  |  |  | //处理插入业务 | 
|---|
|  |  |  | AccountDTO dto = accountService.insertAccount(form); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountInsertVO accountInsertVO = AccountInsertVO.convert(accountInsertDTO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(accountInsertDTO.getCode(),accountInsertDTO.getMsg(),accountInsertVO); | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("query") | 
|---|
|  |  |  | public ResultMessage query(AccountQueryForm accountQueryForm){ | 
|---|
|  |  |  | if(!accountQueryForm.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountQueryDTO accountQueryDTO = accountService.queryAccount(accountQueryForm); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountQueryVO accountQueryVO = AccountQueryVO.convert(accountQueryDTO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(accountQueryDTO.getCode(),accountQueryDTO.getMsg(),accountQueryVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("update") | 
|---|
|  |  |  | public ResultMessage update(@RequestBody AccountUpdateForm accountUpdateRequest){ | 
|---|
|  |  |  | if(!accountUpdateRequest.valid()) | 
|---|
|  |  |  | public ResultMessage update(@RequestBody AccountUpdateForm form) { | 
|---|
|  |  |  | //判断是否缺少参数 | 
|---|
|  |  |  | if (!form.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断参数是否符合条件 | 
|---|
|  |  |  | AccountUpdateDTO conditionDTO = accountUpdateRequest.paramValid(); | 
|---|
|  |  |  | if(conditionDTO.getCode()!=ResponseCodeEnum.SUCCESS.getCode()){ | 
|---|
|  |  |  | return new ResultMessage(conditionDTO.getCode(),conditionDTO.getMsg(),null); | 
|---|
|  |  |  | //判断参数是否有效 | 
|---|
|  |  |  | AccountDTO conditionDTO = form.paramValid(); | 
|---|
|  |  |  | if (conditionDTO.getCode() != ResponseCodeEnum.SUCCESS.getCode()) { | 
|---|
|  |  |  | return new ResultMessage(conditionDTO.getCode(), conditionDTO.getMsg(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountUpdateDTO accountUpdateDTO = accountService.updateAccount(accountUpdateRequest); | 
|---|
|  |  |  | //处理更新业务 | 
|---|
|  |  |  | AccountDTO dto = accountService.updateAccount(form); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountUpdateVO accountUpdateVO = AccountUpdateVO.convert(accountUpdateDTO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(accountUpdateDTO.getCode(),accountUpdateDTO.getMsg(),accountUpdateVO); | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("delete") | 
|---|
|  |  |  | public ResultMessage delete(@RequestBody AccountDeleteForm accountDeleteForm){ | 
|---|
|  |  |  | if(!accountDeleteForm.valid()) | 
|---|
|  |  |  | public ResultMessage delete(@RequestBody AccountDeleteForm form) { | 
|---|
|  |  |  | //判断是否缺少参数 | 
|---|
|  |  |  | if (!form.valid()) | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), | 
|---|
|  |  |  | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountDeleteDTO accountDeleteDTO = accountService.deleteAccount(accountDeleteForm); | 
|---|
|  |  |  | //处理删除业务 | 
|---|
|  |  |  | AccountDTO dto = accountService.deleteAccount(form); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountDeleteVO accountDeleteVO = AccountDeleteVO.convert(accountDeleteDTO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultMessage(accountDeleteDTO.getCode(),accountDeleteDTO.getMsg(),accountDeleteVO); | 
|---|
|  |  |  | return new ResultMessage(dto.getCode(), dto.getMsg(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("yanzhengma") | 
|---|
|  |  |  | public String yanzhengma(HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | KaptchaUtils.createVerificationCode(); | 
|---|
|  |  |  | TokenUtils.getToken("1",1); | 
|---|
|  |  |  | return 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|