From c6a2bd5781fc2306182bcebe8b3867e7eb347b12 Mon Sep 17 00:00:00 2001 From: "382696293@qq.com" <382696293@qq.com> Date: Thu, 1 Feb 2024 14:19:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F-=E4=BB=AA=E5=99=A8?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/enums/InstrumentHttpCodeEnum.java | 30 +++++++++++++++++ .../service/impl/WxInstrumentServiceImpl.java | 33 +++++++++++++------ 2 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/enums/InstrumentHttpCodeEnum.java diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/enums/InstrumentHttpCodeEnum.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/enums/InstrumentHttpCodeEnum.java new file mode 100644 index 0000000..ba6ff48 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/enums/InstrumentHttpCodeEnum.java @@ -0,0 +1,30 @@ +package com.flossom.common.core.enums; + +public enum InstrumentHttpCodeEnum { + + TWO_HUNDRED_AND_ONE(201, "可以绑定,但是不立即绑定,页面需要询问用户是否绑定"), + TWO_HUNDRED_AND_TWO(202, "绑定过该类型仪器,但当前扫码的序列号与以前绑定的仪器的序列号不一致,询问用户是否换绑仪器"), + TWO_HUNDRED_AND_THREE(203, "当前序列码被别人绑定了,联系客服"), + TWO_HUNDRED_AND_FOUR(204, "用户选择的仪器与序列号对应的仪器不一致"), + TWO_HUNDRED_AND_FIVE(205, "序列号不存在,联系客服"), + TWO_HUNDRED_AND_SIX(206, "绑定失败,不存在该仪器,请联系客服"), + ; + + private final Integer code; + private final String info; + + InstrumentHttpCodeEnum(Integer code, String info) { + this.code = code; + this.info = info; + } + + public Integer getCode() { + return code; + } + + public String getInfo() { + return info; + } + + +} diff --git a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxInstrumentServiceImpl.java b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxInstrumentServiceImpl.java index 1296c3d..c9e8de1 100644 --- a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxInstrumentServiceImpl.java +++ b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxInstrumentServiceImpl.java @@ -80,16 +80,15 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService { @Override public List bindingInstrumentList() { - // TODO: 仪器隐藏???? - /* 绑定了的仪器 不受 "可见小程序标签/可见外部标签" 影响 */ + /* 绑定了的仪器 不受 "可见小程序标签/可见外部标签" 影响, 去除仪器隐藏的 */ return wxInstrumentMapper.selectBindingInstrumentListByUserId(SecurityUtils.getLoginUser().getWxUserMember().getId()); } @Override public List unbindingInstrumentInfoList() { List returnList = new ArrayList<>(); + /* 去除仪器隐藏的 */ List wxInstrumentList = wxInstrumentMapper.selectUnbindingInstrumentListByUserId(SecurityUtils.getLoginUser().getWxUserMember().getId()); - // TODO: 仪器隐藏???? /* 未绑定的仪器 受 "可见小程序标签/可见外部标签" 影响,需要用户拥有全部对应的标签才可见 */ if (wxInstrumentList != null && wxInstrumentList.size() > 0) { // 用户拥有的标签 @@ -128,8 +127,8 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService { WxInstrumentSerial wxInstrumentSerial = wxInstrumentSerialMapper.selectEntityListBySerial(query); // 序列号唯一 if (wxInstrumentSerial == null) { - logger.info("serial:{}, 没有对应的数据", serial); - throw new ServiceReturnCodeException("没有对应的序列号,跳转联系客服", 203); + logger.info("serial:{}, 序列号不存在", serial); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_FIVE.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_FIVE.getCode()); } return wxInstrumentSerial; } @@ -175,7 +174,7 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService { if (!StringUtils.equals(wxUserInstrument.getSerial(), serial)) { /* 2.1.2、绑定过仪器,但不是同一个序列号,询问是否需要换绑 */ logger.info("绑定过该类型仪器,但当前扫码的序列号与以前绑定的仪器的序列号不一致,询问用户是否换绑仪器"); - throw new ServiceReturnCodeException("绑定过该类型仪器,但当前扫码的序列号与以前绑定的仪器的序列号不一致,询问用户是否换绑仪器", 202); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_TWO.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_TWO.getCode()); } logger.info("扫码序列号与当前用户绑定的序列号一致,无需绑定,返回响应"); } @@ -184,7 +183,7 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService { // 不立即绑定 if (!isImmediatelyBinding) { logger.info("可以绑定,但是不立即绑定,页面需要询问用户是否绑定"); - throw new ServiceReturnCodeException("可以绑定,但是不立即绑定,页面需要询问用户是否绑定", 201); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_ONE.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_ONE.getCode()); } /* 2.2.1、判断序列号是否被别人绑定了 */ @@ -196,11 +195,15 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService { Integer num = wxUserInstrumentMapper.selectUiByInstrumentId(query); if (num != null && num > 0) { logger.info("被别人绑定了,页面跳转联系客服"); - throw new ServiceReturnCodeException("当前序列码被别人绑定了,页面跳转联系客服", 203); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_THREE.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_THREE.getCode()); } /* 2.2.2、绑定仪器 */ else { WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(wxInstrumentSerial.getInstrumentId()); + if (wxInstrument != null && wxInstrument.getStatus().intValue() == Status.DISABLE.getCode()) { + logger.info("仪器({})被隐藏了,无法绑定", wxInstrumentSerial.getInstrumentId()); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_SIX.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_SIX.getCode()); + } WxUserInstrument saveEntity = new WxUserInstrument(); saveEntity.setUserId(wxUserMember.getId()); saveEntity.setSerial(serial); @@ -293,7 +296,12 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService { Integer num = wxUserInstrumentMapper.selectUiByInstrumentId(query); if (num != null && num > 0) { logger.info("被别人绑定了,页面跳转联系客服"); - throw new ServiceReturnCodeException("当前序列码被别人绑定了,页面跳转联系客服", 203); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_THREE.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_THREE.getCode()); + } + WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(newInstrumentSerial.getInstrumentId()); + if (wxInstrument != null && wxInstrument.getStatus().intValue() == Status.DISABLE.getCode()) { + logger.info("仪器({})被隐藏了,无法绑定", newInstrumentSerial.getInstrumentId()); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_SIX.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_SIX.getCode()); } /* 3、换绑 */ @@ -425,7 +433,12 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService { WxInstrumentSerial wxInstrumentSerial = getInstrumentInfoBySerial(serial); if (wxInstrumentSerial.getInstrumentId() != instrumentId) { logger.info("用户选择的仪器与序列号对应的仪器不一致,序列号:{}, 仪器ID:{}", serial, instrumentId); - throw new ServiceReturnCodeException("用户选择的仪器与序列号对应的仪器不一致", 204); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_FOUR.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_FOUR.getCode()); + } + WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(wxInstrumentSerial.getInstrumentId()); + if (wxInstrument != null && wxInstrument.getStatus().intValue() == Status.DISABLE.getCode()) { + logger.info("仪器({})被隐藏了,无法绑定", wxInstrumentSerial.getInstrumentId()); + throw new ServiceReturnCodeException(InstrumentHttpCodeEnum.TWO_HUNDRED_AND_SIX.getInfo(), InstrumentHttpCodeEnum.TWO_HUNDRED_AND_SIX.getCode()); } return wxInstrumentSerial; }