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.
udi-cpt-java/src/main/java/com/glxp/api/controller/system/DeviceKeyController.java

130 lines
4.9 KiB
Java

package com.glxp.api.controller.system;
import com.github.pagehelper.PageInfo;
import com.glxp.api.entity.system.SysPdaKeyEntity;
import com.glxp.api.req.system.DeleteRequest;
import com.glxp.api.req.system.FilterDeviceKeyRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.service.auth.SysPdaKeyService;
import com.glxp.api.util.DateUtil;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import lombok.extern.slf4j.Slf4j;
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.security.MessageDigest;
import java.util.List;
@ApiIgnore
@Slf4j
@RestController
public class DeviceKeyController {
// @Value("${spring.mail.username}")
// private String mail;
// @Value("${toMail}")
// private String toMail;
@Resource
SysPdaKeyService sysPdaKeyService;
// @Resource
// private JavaMailSender javaMailSender;
@GetMapping("sale/device/registerList")
public BaseResponse registerList(FilterDeviceKeyRequest filterDeviceKeyRequest) {
List<SysPdaKeyEntity> deviceKeyEntities = sysPdaKeyService.findDeviceKey(filterDeviceKeyRequest);
PageInfo<SysPdaKeyEntity> pageInfo;
pageInfo = new PageInfo<>(deviceKeyEntities);
PageSimpleResponse<SysPdaKeyEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(deviceKeyEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@PostMapping("sale/device/check")
public BaseResponse checkRegister(@RequestBody @Valid SysPdaKeyEntity sysPdaKeyEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
sysPdaKeyEntity.setDate(DateUtil.getDate());
sysPdaKeyService.updateDeviceKey(sysPdaKeyEntity);
return ResultVOUtils.success("审核成功");
}
@PostMapping("/sale/info/registerKey")
public BaseResponse registerKey(@RequestBody SysPdaKeyEntity sysPdaKeyEntity) {
String key = md5("glxp2020" + sysPdaKeyEntity.getImei());
FilterDeviceKeyRequest filterDeviceKeyRequest = new FilterDeviceKeyRequest();
filterDeviceKeyRequest.setImei(sysPdaKeyEntity.getImei());
SysPdaKeyEntity sysPdaKeyEntity1 = sysPdaKeyService.findDeviceByImei(filterDeviceKeyRequest);
if (sysPdaKeyEntity1 == null) {
return ResultVOUtils.success("1");
} else if (sysPdaKeyEntity1.getIsCheck() == 0) {
return ResultVOUtils.success("0");
} else {
return ResultVOUtils.success(key);
}
}
@PostMapping("/sale/info/deleterKey")
public BaseResponse deleterKey(@RequestBody DeleteRequest deleteRequest) {
sysPdaKeyService.deleteDeviceKey(deleteRequest);
return ResultVOUtils.success("删除成功");
}
@PostMapping("sale/device/register")
public BaseResponse saveRegister(@RequestBody SysPdaKeyEntity sysPdaKeyEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
sysPdaKeyEntity.setDate(DateUtil.getDateTime());
sysPdaKeyEntity.setIsCheck(0);
sysPdaKeyService.insertDeviceKey(sysPdaKeyEntity);
return ResultVOUtils.success("1");
}
// public void sendMail(String title, String content, String to) {
// SimpleMailMessage message = new SimpleMailMessage();
// message.setFrom(mail);
// message.setTo(to);
// message.setSubject(title);
// message.setText(content);
// javaMailSender.send(message);
// }
public String md5(String password) {
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] bytes = digest.digest(password.getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
int c = b & 0xff; //负数转换成正数
String result = Integer.toHexString(c); //把十进制的数转换成十六进制的书
if (result.length() < 2) {
sb.append(0); //让十六进制全部都是两位数
}
sb.append(result);
}
return sb.toString(); //返回加密后的密文
} catch (Exception ex) {
ex.printStackTrace();
return "";
}
}
}