|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|