1、绑定仪器增加不立即绑定

2、获取设备升级数据
master
382696293@qq.com 2 years ago
parent d95cf290f9
commit 7e37d48f50

@ -35,6 +35,8 @@ public class MimeTypeUtils
"rar", "zip", "gz", "bz2",
// 视频格式
"mp4", "avi", "rmvb",
// bin文件
"bin",
// pdf
"pdf" };

@ -31,12 +31,21 @@ public class WxInstrumentController extends BaseController {
@Autowired
private RemoteFileService remoteFileService;
/**
*
*/
@GetMapping(value = "/isBindingSerial")
public R isBindingSerial(@NotBlank(message = "序列号不能为空") @RequestParam("serial") String serial) {
wxInstrumentService.binding(serial, null, false);
return R.ok();
}
/**
*
*/
@GetMapping(value = "/binding")
public R binding(@NotBlank(message = "序列号不能为空") @RequestParam("serial") String serial) {
wxInstrumentService.binding(serial, null);
wxInstrumentService.binding(serial, null, true);
return R.ok();
}
@ -68,7 +77,7 @@ public class WxInstrumentController extends BaseController {
serialImage = result.getData().getUrl();
}
wxInstrumentService.determineSerialIsSameInstrument(serial, instrumentId);
wxInstrumentService.binding(serial, serialImage);
wxInstrumentService.binding(serial, serialImage, true);
return R.ok();
}
@ -129,4 +138,14 @@ public class WxInstrumentController extends BaseController {
return R.ok(wxInstrumentService.getInstrumentModeByInstrumentId(instrumentId));
}
/**
*
*
* 1
*/
@GetMapping(value = "/upgrade")
public R upgrade(@RequestParam("instrumentId") Long instrumentId) {
return R.ok(wxInstrumentService.upgrade(instrumentId));
}
}

@ -14,7 +14,7 @@ import java.util.List;
public interface IWxInstrumentService {
WxInstrumentSerial getInstrumentInfoBySerial(String serial);
void binding(String serial, String serialImage);
void binding(String serial, String serialImage, Boolean isImmediatelyBinding);
void exchangeBinding(String serial);
@ -27,4 +27,6 @@ public interface IWxInstrumentService {
List<WxModeRet> getInstrumentModeByInstrumentId(Long instrumentId);
WxInstrumentSerial determineSerialIsSameInstrument(String serial, Long instrumentId);
String upgrade(Long instrumentId);
}

@ -17,7 +17,11 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import javax.xml.bind.DatatypeConverter;
import java.io.*;
import java.net.URL;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
@ -125,9 +129,14 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
return wxInstrumentSerial;
}
/**
* @param serial
* @param serialImage
* @param isImmediatelyBinding
*/
@Override
@Transactional
public void binding(String serial, String serialImage) {
public void binding(String serial, String serialImage, Boolean isImmediatelyBinding) {
WxUserMember wxUserMember = wxUserMemberMapper.selectWxUserMemberById(SecurityUtils.getLoginUser().getWxUserMember().getId());
/* 1、获取序列号信息 */
WxInstrumentSerial wxInstrumentSerial = getInstrumentInfoBySerial(serial);
@ -149,7 +158,7 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
userBindInstrumentQuery.setStatus(Status.OK.getCode().longValue());
List<WxUserInstrument> wxUserInstrumentList = wxUserInstrumentMapper.selectListByUserIdAndInstrumentId(userBindInstrumentQuery);
// 2.1、当前用户绑定过序列号对应的仪器ID
if (wxUserInstrumentList != null) {
if (wxUserInstrumentList != null && wxUserInstrumentList.size() > 0) {
if (wxUserInstrumentList.size() != 1) {
logger.error("根据 用户id:{} 和 仪器id:{} 查询出来的数据为空或者数据量不止一条", wxUserMember.getId(), wxInstrumentSerial.getInstrumentId());
throw new ServiceException("绑定失败");
@ -165,6 +174,12 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
}
// 2.2、用户没有绑定过序列号对应的仪器ID
else {
// 不立即绑定
if (!isImmediatelyBinding) {
logger.info("可以绑定,但是不立即绑定,页面需要询问用户是否绑定");
throw new ServiceReturnCodeException("可以绑定,但是不立即绑定,页面需要询问用户是否绑定", 201);
}
/* 2.2.1、判断序列号是否被别人绑定了 */
WxUserInstrument query = new WxUserInstrument();
query.setUserId(wxUserMember.getId());
@ -403,4 +418,23 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
}
return wxInstrumentSerial;
}
@Override
public String upgrade(Long instrumentId) {
WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(instrumentId);
if (wxInstrument != null && StringUtils.isNotBlank(wxInstrument.getIotUpgradeData())) {
// 读取文件系统中的文件
try {
byte[] byteArray = FileCopyUtils.copyToByteArray(new URL(wxInstrument.getIotUpgradeData()).openStream());
return DatatypeConverter.printHexBinary(byteArray);
} catch (FileNotFoundException e) {
logger.error("instrumentId:{} 升级失败: {}", instrumentId, e.getMessage());
throw new ServiceException("升级失败");
} catch (IOException e) {
logger.error("instrumentId:{} 升级失败: {}", instrumentId, e.getMessage());
throw new ServiceException("升级失败");
}
}
return null;
}
}

Loading…
Cancel
Save