|
|
|
|
@ -4,6 +4,7 @@ import com.flossom.common.core.domain.entity.*;
|
|
|
|
|
import com.flossom.common.core.enums.BindingStatusEnums;
|
|
|
|
|
import com.flossom.common.core.enums.SerialValidStatusEnums;
|
|
|
|
|
import com.flossom.common.core.enums.Status;
|
|
|
|
|
import com.flossom.common.core.exception.ServiceException;
|
|
|
|
|
import com.flossom.common.core.exception.ServiceReturnCodeException;
|
|
|
|
|
import com.flossom.common.core.mapper.*;
|
|
|
|
|
import com.flossom.common.core.utils.DateUtils;
|
|
|
|
|
@ -42,9 +43,6 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxUserInstrumentMapper wxUserInstrumentMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxInstrumentSerialLogMapper wxInstrumentSerialLogMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxUserInstrumentLogMapper wxUserInstrumentLogMapper;
|
|
|
|
|
|
|
|
|
|
@ -58,7 +56,6 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
|
|
|
|
|
WxInstrumentSerial wxInstrumentSerial = wxInstrumentSerialMapper.selectEntityListBySerial(query);
|
|
|
|
|
// 序列号唯一
|
|
|
|
|
if (wxInstrumentSerial == null) {
|
|
|
|
|
// 根据序列号没有找到对应的数据
|
|
|
|
|
logger.info("serial:{}, 没有对应的数据", serial);
|
|
|
|
|
throw new ServiceReturnCodeException("没有对应的序列号,跳转联系客服", 203);
|
|
|
|
|
}
|
|
|
|
|
@ -86,22 +83,24 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
|
|
|
|
|
WxUserInstrument userBindInstrumentQuery = new WxUserInstrument();
|
|
|
|
|
userBindInstrumentQuery.setUserId(wxUserMember.getId());
|
|
|
|
|
userBindInstrumentQuery.setInstrumentId(wxInstrumentSerial.getInstrumentId());
|
|
|
|
|
userBindInstrumentQuery.setBindingStatus(BindingStatusEnums.BINDED.getCode());
|
|
|
|
|
userBindInstrumentQuery.setStatus(Status.OK.getCode().longValue());
|
|
|
|
|
List<WxUserInstrument> wxUserInstrumentList = wxUserInstrumentMapper.selectListByUserIdAndInstrumentId(userBindInstrumentQuery);
|
|
|
|
|
// 2.1、当前用户绑定了序列号对应的仪器的序列号
|
|
|
|
|
if (wxUserInstrumentList != null && wxUserInstrumentList.size() > 0) {
|
|
|
|
|
if (wxUserInstrumentList != null) {
|
|
|
|
|
if (wxUserInstrumentList.size() != 1) {
|
|
|
|
|
logger.error("根据 用户id:{} 和 仪器id:{} 查询出来的数据为空或者数据量不止一条", wxUserMember.getId(), wxInstrumentSerial.getInstrumentId());
|
|
|
|
|
throw new ServiceException("绑定失败");
|
|
|
|
|
}
|
|
|
|
|
WxUserInstrument wxUserInstrument = wxUserInstrumentList.get(0);
|
|
|
|
|
/* 2.1.1、判断扫码获取的序列号和用户绑定的序列号是否一致 */
|
|
|
|
|
for (WxUserInstrument userInstrument : wxUserInstrumentList) {
|
|
|
|
|
if (StringUtils.equals(userInstrument.getSerial(), serial)) {
|
|
|
|
|
// 相同序列号,页面重新发起查询用户拥有的仪器列表
|
|
|
|
|
logger.info("相同序列号,页面重新发起查询用户拥有的仪器列表");
|
|
|
|
|
throw new ServiceReturnCodeException("扫码的序列号已被当前用户绑定,请查询仪器列表", 200);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.equals(wxUserInstrument.getSerial(), serial)) {
|
|
|
|
|
logger.info("相同序列号,页面重新发起查询用户拥有的仪器列表");
|
|
|
|
|
throw new ServiceReturnCodeException("扫码的序列号已被当前用户绑定,请查询仪器列表", 200);
|
|
|
|
|
} else {
|
|
|
|
|
/* 2.1.2、绑定过仪器,但不是同一个序列号,询问是否需要换绑 */
|
|
|
|
|
logger.info("绑定过该类型仪器,但当前扫码不是以前绑定的仪器,询问是否换绑仪器");
|
|
|
|
|
throw new ServiceReturnCodeException("绑定过该类型仪器,但当前扫码不是以前绑定的仪器,询问是否换绑仪器", 202);
|
|
|
|
|
}
|
|
|
|
|
/* 2.1.2、绑定过仪器,但不是同一个序列号,询问是否需要换绑 */
|
|
|
|
|
logger.info("绑定过该类型仪器,但当前扫码不是以前绑定的仪器,询问是否换绑仪器");
|
|
|
|
|
throw new ServiceReturnCodeException("绑定过该类型仪器,但当前扫码不是以前绑定的仪器,询问是否换绑仪器", 202);
|
|
|
|
|
}
|
|
|
|
|
// 2.2、用户没有绑定过序列号对应的仪器
|
|
|
|
|
else {
|
|
|
|
|
@ -113,7 +112,6 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
|
|
|
|
|
query.setBindingStatus(BindingStatusEnums.BINDED.getCode());
|
|
|
|
|
Integer num = wxUserInstrumentMapper.selectUiByInstrumentId(query);
|
|
|
|
|
if (num != null && num > 0) {
|
|
|
|
|
// 被别人绑定了,页面跳转联系客服
|
|
|
|
|
logger.info("被别人绑定了,页面跳转联系客服");
|
|
|
|
|
throw new ServiceReturnCodeException("当前序列码被别人绑定了,页面跳转联系客服", 203);
|
|
|
|
|
}
|
|
|
|
|
@ -161,4 +159,96 @@ public class WxInstrumentServiceImpl implements IWxInstrumentService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public void exchangeBinding(String serial) {
|
|
|
|
|
WxUserMember wxUserMember = SecurityUtils.getLoginUser().getWxUserMember();
|
|
|
|
|
/* 1、获取序列号信息 */
|
|
|
|
|
WxInstrumentSerial newInstrumentSerial = getInstrumentInfoBySerial(serial);
|
|
|
|
|
|
|
|
|
|
/* 2、判断序列号是否被别人绑定了 */
|
|
|
|
|
WxUserInstrument query = new WxUserInstrument();
|
|
|
|
|
query.setUserId(wxUserMember.getId());
|
|
|
|
|
query.setSerial(serial);
|
|
|
|
|
query.setStatus(Status.OK.getCode().longValue());
|
|
|
|
|
query.setBindingStatus(BindingStatusEnums.BINDED.getCode());
|
|
|
|
|
Integer num = wxUserInstrumentMapper.selectUiByInstrumentId(query);
|
|
|
|
|
if (num != null && num > 0) {
|
|
|
|
|
logger.info("被别人绑定了,页面跳转联系客服");
|
|
|
|
|
throw new ServiceReturnCodeException("当前序列码被别人绑定了,页面跳转联系客服", 203);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 3、换绑 */
|
|
|
|
|
// 3.1、查询原记录
|
|
|
|
|
WxUserInstrument userInstrumentQuery = new WxUserInstrument();
|
|
|
|
|
userInstrumentQuery.setUserId(wxUserMember.getId());
|
|
|
|
|
userInstrumentQuery.setInstrumentId(newInstrumentSerial.getInstrumentId());
|
|
|
|
|
userInstrumentQuery.setStatus(Status.OK.getCode().longValue());
|
|
|
|
|
List<WxUserInstrument> wxUserInstrumentList = wxUserInstrumentMapper.selectListByUserIdAndInstrumentId(userInstrumentQuery);
|
|
|
|
|
if (wxUserInstrumentList == null || wxUserInstrumentList.size() != 1) {
|
|
|
|
|
logger.error("根据 用户id:{} 和 仪器id:{} 查询出来的数据为空或者数据量不止一条", wxUserMember.getId(), newInstrumentSerial.getInstrumentId());
|
|
|
|
|
throw new ServiceException("换绑失败!");
|
|
|
|
|
}
|
|
|
|
|
WxUserInstrument wxUserInstrument = wxUserInstrumentList.get(0);
|
|
|
|
|
|
|
|
|
|
// 3.2、更新旧的序列号状态为已解绑
|
|
|
|
|
// 当后管解除了用户和仪器的绑定,状态变为已解绑,无需再次修改序列号的绑定状态
|
|
|
|
|
if (BindingStatusEnums.UN_BOUND.getCode() == wxUserInstrument.getBindingStatus()) {
|
|
|
|
|
WxInstrumentSerial oldUpdate = new WxInstrumentSerial();
|
|
|
|
|
oldUpdate.setBindingStatus(BindingStatusEnums.UN_BOUND.getCode());
|
|
|
|
|
oldUpdate.setSerial(wxUserInstrument.getSerial());
|
|
|
|
|
wxInstrumentSerialMapper.updateBySerial(oldUpdate);
|
|
|
|
|
}
|
|
|
|
|
// 3.3、更新新的序列号状态为已绑定
|
|
|
|
|
WxInstrumentSerial newUpdate = new WxInstrumentSerial();
|
|
|
|
|
newUpdate.setBindingStatus(BindingStatusEnums.BINDED.getCode());
|
|
|
|
|
newUpdate.setSerial(serial);
|
|
|
|
|
wxInstrumentSerialMapper.updateBySerial(newUpdate);
|
|
|
|
|
// 3.4、更新用户仪器关联表
|
|
|
|
|
WxUserInstrument updateEntity = new WxUserInstrument();
|
|
|
|
|
updateEntity.setId(wxUserInstrument.getId());
|
|
|
|
|
updateEntity.setSerial(serial);
|
|
|
|
|
if (wxUserInstrument.getGuarantee() != null && wxUserInstrument.getGuarantee() >= 0) {
|
|
|
|
|
Instant instant = LocalDateTime.now().plusYears(wxUserInstrument.getGuarantee()).atZone(ZoneId.systemDefault()).toInstant();
|
|
|
|
|
updateEntity.setGuaranteeEndtime(Date.from(instant));
|
|
|
|
|
}
|
|
|
|
|
// 当后管解除了用户和仪器的绑定,状态变为已解绑,此时就需改为绑定状态
|
|
|
|
|
updateEntity.setBindingStatus(BindingStatusEnums.BINDED.getCode());
|
|
|
|
|
updateEntity.setUpdateBy(wxUserMember.getNickname());
|
|
|
|
|
updateEntity.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
wxUserInstrumentMapper.updateWxUserInstrument(updateEntity);
|
|
|
|
|
// 3.5、用户仪器关联记录表
|
|
|
|
|
// 当后管解除了用户和仪器的绑定,操作记录已记录,无需再次记录
|
|
|
|
|
if (BindingStatusEnums.UN_BOUND.getCode() == wxUserInstrument.getBindingStatus()) {
|
|
|
|
|
WxUserInstrumentLog oldUserInstrumentLog = new WxUserInstrumentLog();
|
|
|
|
|
oldUserInstrumentLog.setUserInstrumentId(wxUserInstrument.getId());
|
|
|
|
|
oldUserInstrumentLog.setUserId(wxUserMember.getId());
|
|
|
|
|
oldUserInstrumentLog.setSerial(wxUserInstrument.getSerial());
|
|
|
|
|
oldUserInstrumentLog.setInstrumentId(wxUserInstrument.getInstrumentId());
|
|
|
|
|
oldUserInstrumentLog.setInstrumentName(wxUserInstrument.getInstrumentName());
|
|
|
|
|
oldUserInstrumentLog.setSerialImage(wxUserInstrument.getSerialImage());
|
|
|
|
|
oldUserInstrumentLog.setGuarantee(wxUserInstrument.getGuarantee());
|
|
|
|
|
oldUserInstrumentLog.setGuaranteeEndtime(wxUserInstrument.getGuaranteeEndtime());
|
|
|
|
|
oldUserInstrumentLog.setBindingStatus(BindingStatusEnums.UN_BOUND.getCode());
|
|
|
|
|
oldUserInstrumentLog.setStatus(Status.OK.getCode().longValue());
|
|
|
|
|
oldUserInstrumentLog.setCreateBy(wxUserMember.getNickname());
|
|
|
|
|
oldUserInstrumentLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
wxUserInstrumentLogMapper.insertWxUserInstrumentLog(oldUserInstrumentLog);
|
|
|
|
|
}
|
|
|
|
|
WxUserInstrumentLog newUserInstrumentLog = new WxUserInstrumentLog();
|
|
|
|
|
newUserInstrumentLog.setUserInstrumentId(wxUserInstrument.getId());
|
|
|
|
|
newUserInstrumentLog.setUserId(wxUserMember.getId());
|
|
|
|
|
newUserInstrumentLog.setSerial(serial);
|
|
|
|
|
newUserInstrumentLog.setInstrumentId(wxUserInstrument.getInstrumentId());
|
|
|
|
|
newUserInstrumentLog.setInstrumentName(wxUserInstrument.getInstrumentName());
|
|
|
|
|
newUserInstrumentLog.setSerialImage(wxUserInstrument.getSerialImage());
|
|
|
|
|
newUserInstrumentLog.setGuarantee(wxUserInstrument.getGuarantee());
|
|
|
|
|
newUserInstrumentLog.setGuaranteeEndtime(updateEntity.getGuaranteeEndtime());
|
|
|
|
|
newUserInstrumentLog.setBindingStatus(BindingStatusEnums.BINDED.getCode());
|
|
|
|
|
newUserInstrumentLog.setStatus(Status.OK.getCode().longValue());
|
|
|
|
|
newUserInstrumentLog.setCreateBy(wxUserMember.getNickname());
|
|
|
|
|
newUserInstrumentLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
wxUserInstrumentLogMapper.insertWxUserInstrumentLog(newUserInstrumentLog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|