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.
72 lines
2.8 KiB
Java
72 lines
2.8 KiB
Java
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 springfox.documentation.annotations.ApiIgnore;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.validation.Valid;
|
|
import java.util.List;
|
|
|
|
@ApiIgnore
|
|
@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<AuthCheckEntity> authCheckEntityList = authCheckService.filterDevices(filterAuthCheckRequest);
|
|
|
|
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, "注册失败!");
|
|
|
|
}
|
|
|
|
|
|
}
|