You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.7 KiB
Java
70 lines
2.7 KiB
Java
3 years ago
|
package com.glxp.api.controller.auth;
|
||
|
|
||
|
import com.github.pagehelper.PageInfo;
|
||
|
import com.glxp.api.entity.auth.AuthCheckEntity;
|
||
|
import com.glxp.api.req.auth.AuthCheckRequest;
|
||
|
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(AuthCheckRequest authCheckRequest,
|
||
|
BindingResult bindingResult) {
|
||
|
if (bindingResult.hasErrors()) {
|
||
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
||
|
}
|
||
|
List<AuthCheckEntity> authCheckEntityList = authCheckService.filterDevices(authCheckRequest);
|
||
|
|
||
|
PageInfo<AuthCheckEntity> authCheckEntityPageInfo = new PageInfo<>(authCheckEntityList);
|
||
|
PageSimpleResponse<AuthCheckEntity> 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, "注册失败!");
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|