小程序-绑定仪器优化和换绑仪器

master
382696293@qq.com 2 years ago
parent c3809e3512
commit 4bfd0a9d0f

@ -75,4 +75,6 @@ public interface WxInstrumentSerialMapper
public int updateAll(WxInstrumentSerial wxInstrumentSerial);
WxInstrumentSerial selectEntityListBySerial(WxInstrumentSerial wxInstrumentSerial);
void updateBySerial(WxInstrumentSerial wxInstrumentSerial);
}

@ -107,6 +107,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
<update id="updateBySerial" parameterType="WxInstrumentSerial">
update wx_instrument_serial
<trim prefix="SET" suffixOverrides=",">
<if test="instrumentId != null">instrument_id = #{instrumentId},</if>
<if test="instrumentName != null and instrumentName != ''">instrument_name = #{instrumentName},</if>
<if test="source != null and source != ''">`source` = #{source},</if>
<if test="bindingStatus != null">binding_status = #{bindingStatus},</if>
<if test="validStatus != null">valid_status = #{validStatus},</if>
<if test="status != null">status = #{status},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where serial = #{serial}
</update>
<update id="updateAll" parameterType="WxInstrumentSerial">
update wx_instrument_serial

@ -1,18 +0,0 @@
package com.flossom.miniProgram.controller;
import com.flossom.common.core.web.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller
*
* @author flossom
* @date 2024-01-15
*/
@RestController
@RequestMapping("/instrument")
public class WxInstrumenController extends BaseController {
}

@ -1,12 +1,16 @@
package com.flossom.miniProgram.controller;
import com.flossom.common.core.domain.R;
import com.flossom.common.core.exception.ServiceException;
import com.flossom.common.core.utils.StringUtils;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.miniProgram.service.IWxInstrumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
/**
@ -25,22 +29,30 @@ public class WxInstrumentController extends BaseController {
/**
*
*
* @return null
* @return 203
*/
@GetMapping(value = "/getInstrumentInfoBySerial")
public R getInstrumentInfoBySerial(@RequestParam("serial") @NotBlank(message = "序列号不能为空") String serial) {
public R getInstrumentInfoBySerial(@NotBlank(message = "序列号不能为空") @RequestParam("serial") String serial) {
return R.ok(wxInstrumentService.getInstrumentInfoBySerial(serial));
}
/**
*
*
* @return Boolean: ture false
*/
@GetMapping(value = "/binding")
public R binding(@RequestParam("serial") @NotBlank(message = "序列号不能为空") String serial) {
public R binding(@NotBlank(message = "序列号不能为空") @RequestParam("serial") String serial) {
wxInstrumentService.binding(serial);
return R.ok();
}
/**
*
*/
@GetMapping(value = "/exchangeBinding")
public R exchangeBinding(@NotBlank(message = "序列号不能为空") @RequestParam("serial") String serial) {
wxInstrumentService.exchangeBinding(serial);
return R.ok();
}
}

@ -12,4 +12,6 @@ public interface IWxInstrumentService {
WxInstrumentSerial getInstrumentInfoBySerial(String serial);
void binding(String serial);
void exchangeBinding(String serial);
}

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

Loading…
Cancel
Save