package com.glxp.api.controller.auth; import com.github.pagehelper.PageInfo; import com.glxp.api.entity.auth.AuthCheckEntity; import com.glxp.api.req.auth.FilterAuthCheckRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.service.auth.AuthCheckService; import com.glxp.api.util.RsaUtils; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; @RestController public class AuthCheckController { @Resource private AuthCheckService authCheckService; @GetMapping("/udiwms/auth/device/filter") public BaseResponse index(FilterAuthCheckRequest filterAuthCheckRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } List authCheckEntityList = authCheckService.filterDevices(filterAuthCheckRequest); PageInfo authCheckEntityPageInfo = new PageInfo<>(authCheckEntityList); PageSimpleResponse authAdminResponseList = new PageSimpleResponse<>(); authAdminResponseList.setTotal(authCheckEntityPageInfo.getTotal()); authAdminResponseList.setList(authCheckEntityList); return ResultVOUtils.success(authAdminResponseList); } @PostMapping("/udiwms/auth/device/save") public BaseResponse save(@RequestBody @Valid AuthCheckEntity authCheckEntity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } String key = null; try { key = RsaUtils.publicKeyDecrypt(authCheckEntity.getRegisterCode(), RsaUtils.publicKey); if (key != null && key.equals(authCheckEntity.getMachineInfo())) { authCheckService.updateDevices(authCheckEntity); return ResultVOUtils.success("注册成功!"); } else { return ResultVOUtils.error(500, "注册失败,注册码不匹配!"); } } catch (Exception e) { e.printStackTrace(); } return ResultVOUtils.error(500, "注册失败!"); } }