Merge remote-tracking branch 'origin/feature-20240104' into feature-20240104

master
elliott 2 years ago
commit 684eb94213

@ -0,0 +1,174 @@
package com.flossom.common.core.domain.entity;
import com.flossom.common.core.annotation.Excel;
import com.flossom.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* wx_instrument_serial_log
*
* @author flossom
* @date 2024-01-22
*/
public class WxInstrumentSerialLog extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* $column.columnComment
*/
private Long id;
/**
* id
*/
@Excel(name = "会员id")
private Long userId;
/**
*
*/
@Excel(name = "会员名称")
private String userName;
/**
*
*/
@Excel(name = "会员手机号码")
private String userMobile;
/**
*
*/
@Excel(name = "会员头像")
private String userHeadimg;
/**
* id
*/
@Excel(name = "仪器id")
private Long instrumentId;
/**
*
*/
@Excel(name = "仪器名称")
private String instrumentName;
/**
*
*/
@Excel(name = "序列号")
private String serial;
/**
* 12
*/
@Excel(name = "绑定状态1未绑定2已解绑")
private Integer bindingStatus;
/**
* 0 1
*/
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private Long status;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getUserId() {
return userId;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public void setUserMobile(String userMobile) {
this.userMobile = userMobile;
}
public String getUserMobile() {
return userMobile;
}
public void setUserHeadimg(String userHeadimg) {
this.userHeadimg = userHeadimg;
}
public String getUserHeadimg() {
return userHeadimg;
}
public void setInstrumentId(Long instrumentId) {
this.instrumentId = instrumentId;
}
public Long getInstrumentId() {
return instrumentId;
}
public void setInstrumentName(String instrumentName) {
this.instrumentName = instrumentName;
}
public String getInstrumentName() {
return instrumentName;
}
public void setSerial(String serial) {
this.serial = serial;
}
public String getSerial() {
return serial;
}
public void setBindingStatus(Integer bindingStatus) {
this.bindingStatus = bindingStatus;
}
public Integer getBindingStatus() {
return bindingStatus;
}
public void setStatus(Long status) {
this.status = status;
}
public Long getStatus() {
return status;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("userId", getUserId())
.append("userName", getUserName())
.append("userMobile", getUserMobile())
.append("userHeadimg", getUserHeadimg())
.append("instrumentId", getInstrumentId())
.append("instrumentName", getInstrumentName())
.append("serial", getSerial())
.append("bindingStatus", getBindingStatus())
.append("status", getStatus())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("remark", getRemark())
.toString();
}
}

@ -0,0 +1,27 @@
package com.flossom.common.core.enums;
/**
*
* 012
*
* @author flossom
*/
public enum BindingStatusEnums {
BINDED(0, "已经绑定"), NO_BOUND(1, "未绑定"), UN_BOUND(2, "已解绑");
private final Integer code;
private final String info;
BindingStatusEnums(Integer code, String info) {
this.code = code;
this.info = info;
}
public Integer getCode() {
return code;
}
public String getInfo() {
return info;
}
}

@ -0,0 +1,27 @@
package com.flossom.common.core.enums;
/**
* wx_instrument_serialvalid_status
*
* @author flossom
*/
public enum SerialValidStatusEnums {
INVALID(0, "无效"), EFFECTIVE(1, "有效");
private final Integer code;
private final String info;
SerialValidStatusEnums(Integer code, String info) {
this.code = code;
this.info = info;
}
public Integer getCode() {
return code;
}
public String getInfo() {
return info;
}
}

@ -0,0 +1,64 @@
package com.flossom.common.core.exception;
/**
*
*
* @author flossom
*/
public final class ServiceReturnCodeException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
*
*/
private Integer code;
/**
*
*/
private String message;
/**
*
*/
private String detailMessage;
/**
*
*/
public ServiceReturnCodeException() {
}
public ServiceReturnCodeException(String message) {
this.message = message;
}
public ServiceReturnCodeException(String message, Integer code) {
this.message = message;
this.code = code;
}
public String getDetailMessage() {
return detailMessage;
}
@Override
public String getMessage() {
return message;
}
public Integer getCode() {
return code;
}
public ServiceReturnCodeException setMessage(String message) {
this.message = message;
return this;
}
public ServiceReturnCodeException setDetailMessage(String detailMessage) {
this.detailMessage = detailMessage;
return this;
}
}

@ -0,0 +1,62 @@
package com.flossom.common.core.mapper;
import com.flossom.common.core.domain.entity.WxInstrumentSerialLog;
import java.util.List;
/**
* Mapper
*
* @author flossom
* @date 2024-01-22
*/
public interface WxInstrumentSerialLogMapper {
/**
*
*
* @param id
* @return
*/
public WxInstrumentSerialLog selectWxInstrumentSerialLogById(Long id);
/**
*
*
* @param wxInstrumentSerialLog
* @return
*/
public List<WxInstrumentSerialLog> selectWxInstrumentSerialLogList(WxInstrumentSerialLog wxInstrumentSerialLog);
/**
*
*
* @param wxInstrumentSerialLog
* @return
*/
public int insertWxInstrumentSerialLog(WxInstrumentSerialLog wxInstrumentSerialLog);
/**
*
*
* @param wxInstrumentSerialLog
* @return
*/
public int updateWxInstrumentSerialLog(WxInstrumentSerialLog wxInstrumentSerialLog);
/**
*
*
* @param id
* @return
*/
public int deleteWxInstrumentSerialLogById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteWxInstrumentSerialLogByIds(Long[] ids);
}

@ -73,4 +73,8 @@ public interface WxInstrumentSerialMapper
* @return
*/
public int updateAll(WxInstrumentSerial wxInstrumentSerial);
WxInstrumentSerial selectEntityListBySerial(WxInstrumentSerial wxInstrumentSerial);
void updateBySerial(WxInstrumentSerial wxInstrumentSerial);
}

@ -59,4 +59,8 @@ public interface WxUserInstrumentMapper
* @return
*/
public int deleteWxUserInstrumentByIds(Long[] ids);
Integer selectUiByInstrumentId(WxUserInstrument wxUserInstrument);
List<WxUserInstrument> selectListByUserIdAndInstrumentId(WxUserInstrument wxUserInstrument);
}

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.flossom.common.core.mapper.WxInstrumentSerialLogMapper">
<resultMap type="WxInstrumentSerialLog" id="WxInstrumentSerialLogResult">
<result property="id" column="id" />
<result property="userId" column="user_id" />
<result property="userName" column="user_name" />
<result property="userMobile" column="user_mobile" />
<result property="userHeadimg" column="user_headimg" />
<result property="instrumentId" column="instrument_id" />
<result property="instrumentName" column="instrument_name" />
<result property="serial" column="serial" />
<result property="bindingStatus" column="binding_status" />
<result property="status" column="status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectWxInstrumentSerialLogVo">
select id, user_id, user_name, user_mobile, user_headimg, instrument_id, instrument_name, serial, binding_status, status, create_by, create_time, remark from wx_instrument_serial_log
</sql>
<select id="selectWxInstrumentSerialLogList" parameterType="WxInstrumentSerialLog" resultMap="WxInstrumentSerialLogResult">
<include refid="selectWxInstrumentSerialLogVo"/>
<where>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
<if test="userMobile != null and userMobile != ''"> and user_mobile = #{userMobile}</if>
<if test="userHeadimg != null and userHeadimg != ''"> and user_headimg = #{userHeadimg}</if>
<if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
<if test="instrumentName != null and instrumentName != ''"> and instrument_name like concat('%', #{instrumentName}, '%')</if>
<if test="serial != null and serial != ''"> and serial = #{serial}</if>
<if test="bindingStatus != null "> and binding_status = #{bindingStatus}</if>
<if test="status != null "> and status = #{status}</if>
</where>
</select>
<select id="selectWxInstrumentSerialLogById" parameterType="Long" resultMap="WxInstrumentSerialLogResult">
<include refid="selectWxInstrumentSerialLogVo"/>
where id = #{id}
</select>
<insert id="insertWxInstrumentSerialLog" parameterType="WxInstrumentSerialLog" useGeneratedKeys="true" keyProperty="id">
insert into wx_instrument_serial_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if>
<if test="userName != null">user_name,</if>
<if test="userMobile != null">user_mobile,</if>
<if test="userHeadimg != null">user_headimg,</if>
<if test="instrumentId != null">instrument_id,</if>
<if test="instrumentName != null and instrumentName != ''">instrument_name,</if>
<if test="serial != null and serial != ''">serial,</if>
<if test="bindingStatus != null">binding_status,</if>
<if test="status != null">status,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">#{userId},</if>
<if test="userName != null">#{userName},</if>
<if test="userMobile != null">#{userMobile},</if>
<if test="userHeadimg != null">#{userHeadimg},</if>
<if test="instrumentId != null">#{instrumentId},</if>
<if test="instrumentName != null and instrumentName != ''">#{instrumentName},</if>
<if test="serial != null and serial != ''">#{serial},</if>
<if test="bindingStatus != null">#{bindingStatus},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateWxInstrumentSerialLog" parameterType="WxInstrumentSerialLog">
update wx_instrument_serial_log
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null">user_id = #{userId},</if>
<if test="userName != null">user_name = #{userName},</if>
<if test="userMobile != null">user_mobile = #{userMobile},</if>
<if test="userHeadimg != null">user_headimg = #{userHeadimg},</if>
<if test="instrumentId != null">instrument_id = #{instrumentId},</if>
<if test="instrumentName != null and instrumentName != ''">instrument_name = #{instrumentName},</if>
<if test="serial != null and serial != ''">serial = #{serial},</if>
<if test="bindingStatus != null">binding_status = #{bindingStatus},</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 id = #{id}
</update>
<delete id="deleteWxInstrumentSerialLogById" parameterType="Long">
delete from wx_instrument_serial_log where id = #{id}
</delete>
<delete id="deleteWxInstrumentSerialLogByIds" parameterType="String">
delete from wx_instrument_serial_log where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

@ -44,6 +44,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by create_time desc
</select>
<select id="selectEntityListBySerial" parameterType="WxInstrumentSerial" resultMap="WxInstrumentSerialResult">
<include refid="selectWxInstrumentSerialVo"/>
<where>
<if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
<if test="serial != null and serial != ''"> and serial = #{serial} </if>
<if test="bindingStatus != null "> and binding_status = #{bindingStatus}</if>
<if test="validStatus != null "> and valid_status = #{validStatus}</if>
<if test="status != null "> and status = #{status}</if>
</where>
order by create_time desc
limit 1
</select>
<select id="selectWxInstrumentSerialById" parameterType="Long" resultMap="WxInstrumentSerialResult">
<include refid="selectWxInstrumentSerialVo"/>
where id = #{id}
@ -94,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

@ -42,12 +42,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by create_time desc
</select>
<select id="selectListByUserIdAndInstrumentId" parameterType="WxUserInstrument" resultMap="WxUserInstrumentResult">
<include refid="selectWxUserInstrumentVo"/>
<where>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="serial != null and serial != ''"> and serial = #{serial}</if>
<if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
<if test="bindingStatus != null "> and binding_status = #{bindingStatus}</if>
<if test="status != null "> and status = #{status}</if>
</where>
order by create_time desc
</select>
<select id="selectUiByInstrumentId" parameterType="WxUserInstrument" resultType="Integer">
select count(1) from wx_user_instrument
<where>
<if test="userId != null "> and user_id != #{userId}</if>
<if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
<if test="bindingStatus != null "> and binding_status = #{bindingStatus}</if>
<if test="status != null "> and status = #{status}</if>
</where>
</select>
<select id="selectWxUserInstrumentById" parameterType="Long" resultMap="WxUserInstrumentResult">
<include refid="selectWxUserInstrumentVo"/>
where id = #{id}
</select>
<insert id="insertWxUserInstrument" parameterType="WxUserInstrument" useGeneratedKeys="true" keyProperty="id">
<selectKey keyProperty="id" resultType="Long" order="AFTER">
SELECT LAST_INSERT_ID()
</selectKey>
insert into wx_user_instrument
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if>

@ -4,6 +4,7 @@ import com.flossom.common.core.constant.HttpStatus;
import com.flossom.common.core.exception.DemoModeException;
import com.flossom.common.core.exception.InnerAuthException;
import com.flossom.common.core.exception.ServiceException;
import com.flossom.common.core.exception.ServiceReturnCodeException;
import com.flossom.common.core.exception.auth.NotPermissionException;
import com.flossom.common.core.exception.auth.NotRoleException;
import com.flossom.common.core.utils.StringUtils;
@ -73,6 +74,18 @@ public class GlobalExceptionHandler
return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
}
/**
*
*/
@ExceptionHandler(ServiceReturnCodeException.class)
public AjaxResult handleServiceReturnCodeException(ServiceReturnCodeException e, HttpServletRequest request)
{
log.info(e.getMessage());
Integer code = e.getCode();
return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
}
/**
*
*/

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

@ -0,0 +1,58 @@
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;
/**
* Controller
*
* @author flossom
* @date 2024-01-06
*/
@RestController
@RequestMapping("/instrument")
public class WxInstrumentController extends BaseController {
@Autowired
private IWxInstrumentService wxInstrumentService;
/**
*
*
* @return 203
*/
@GetMapping(value = "/getInstrumentInfoBySerial")
public R getInstrumentInfoBySerial(@NotBlank(message = "序列号不能为空") @RequestParam("serial") String serial) {
return R.ok(wxInstrumentService.getInstrumentInfoBySerial(serial));
}
/**
*
*/
@GetMapping(value = "/binding")
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();
}
}

@ -0,0 +1,17 @@
package com.flossom.miniProgram.service;
import com.flossom.common.core.domain.entity.WxInstrumentSerial;
/**
* Service
*
* @author flossom
* @date 2024-01-06
*/
public interface IWxInstrumentService {
WxInstrumentSerial getInstrumentInfoBySerial(String serial);
void binding(String serial);
void exchangeBinding(String serial);
}

@ -0,0 +1,20 @@
package com.flossom.miniProgram.service.impl;
import com.flossom.common.core.mapper.WxInstrumentSerialMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service
*
* @author flossom
* @date 2024-01-10
*/
@Service
public class WxInstrumentSerialServiceImpl {
@Autowired
private WxInstrumentSerialMapper wxInstrumentSerialMapper;
}

@ -0,0 +1,254 @@
package com.flossom.miniProgram.service.impl;
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;
import com.flossom.common.core.utils.StringUtils;
import com.flossom.common.security.utils.SecurityUtils;
import com.flossom.miniProgram.service.IWxInstrumentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
/**
* Service
*
* @author flossom
* @date 2024-01-06
*/
@Service
public class WxInstrumentServiceImpl implements IWxInstrumentService {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private WxInstrumentMapper wxInstrumentMapper;
@Autowired
private WxInstrumentSerialMapper wxInstrumentSerialMapper;
@Autowired
private WxUserInstrumentMapper wxUserInstrumentMapper;
@Autowired
private WxUserInstrumentLogMapper wxUserInstrumentLogMapper;
@Override
public WxInstrumentSerial getInstrumentInfoBySerial(String serial) {
WxInstrumentSerial query = new WxInstrumentSerial();
query.setSerial(serial);
query.setValidStatus(SerialValidStatusEnums.EFFECTIVE.getCode());
query.setStatus(Status.OK.getCode().longValue());
WxInstrumentSerial wxInstrumentSerial = wxInstrumentSerialMapper.selectEntityListBySerial(query);
// 序列号唯一
if (wxInstrumentSerial == null) {
logger.info("serial:{}, 没有对应的数据", serial);
throw new ServiceReturnCodeException("没有对应的序列号,跳转联系客服", 203);
}
return wxInstrumentSerial;
}
@Override
@Transactional
public void binding(String serial) {
WxUserMember wxUserMember = SecurityUtils.getLoginUser().getWxUserMember();
/* 1、获取序列号信息 */
WxInstrumentSerial wxInstrumentSerial = getInstrumentInfoBySerial(serial);
/**
* 2
*
*
* 1
* 2
*
* 1
* 2
*/
// 获取用户绑定了对应仪器的序列号
WxUserInstrument userBindInstrumentQuery = new WxUserInstrument();
userBindInstrumentQuery.setUserId(wxUserMember.getId());
userBindInstrumentQuery.setInstrumentId(wxInstrumentSerial.getInstrumentId());
userBindInstrumentQuery.setStatus(Status.OK.getCode().longValue());
List<WxUserInstrument> wxUserInstrumentList = wxUserInstrumentMapper.selectListByUserIdAndInstrumentId(userBindInstrumentQuery);
// 2.1、当前用户绑定了序列号对应的仪器的序列号
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、判断扫码获取的序列号和用户绑定的序列号是否一致 */
if (StringUtils.equals(wxUserInstrument.getSerial(), serial)) {
logger.info("相同序列号,页面重新发起查询用户拥有的仪器列表");
throw new ServiceReturnCodeException("扫码的序列号已被当前用户绑定,请查询仪器列表", 200);
} else {
/* 2.1.2、绑定过仪器,但不是同一个序列号,询问是否需要换绑 */
logger.info("绑定过该类型仪器,但当前扫码不是以前绑定的仪器,询问是否换绑仪器");
throw new ServiceReturnCodeException("绑定过该类型仪器,但当前扫码不是以前绑定的仪器,询问是否换绑仪器", 202);
}
}
// 2.2、用户没有绑定过序列号对应的仪器
else {
/* 2.2.1、判断序列号是否被别人绑定了 */
WxUserInstrument query = new WxUserInstrument();
query.setUserId(wxUserMember.getId());
query.setInstrumentId(wxInstrumentSerial.getInstrumentId());
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);
}
/* 2.2.2、绑定仪器 */
else {
WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(wxInstrumentSerial.getInstrumentId());
WxUserInstrument saveEntity = new WxUserInstrument();
saveEntity.setUserId(wxUserMember.getId());
saveEntity.setSerial(serial);
saveEntity.setInstrumentId(wxInstrumentSerial.getInstrumentId());
saveEntity.setInstrumentName(wxInstrumentSerial.getInstrumentName());
saveEntity.setGuarantee(wxInstrument.getGuarantee());
if (wxInstrument.getGuarantee() != null && wxInstrument.getGuarantee() >= 0) {
Instant instant = LocalDateTime.now().plusYears(wxInstrument.getGuarantee()).atZone(ZoneId.systemDefault()).toInstant();
saveEntity.setGuaranteeEndtime(Date.from(instant));
}
saveEntity.setBindingStatus(BindingStatusEnums.BINDED.getCode());
saveEntity.setStatus(Status.OK.getCode().longValue());
saveEntity.setCreateBy(wxUserMember.getNickname());
saveEntity.setCreateTime(DateUtils.getNowDate());
wxUserInstrumentMapper.insertWxUserInstrument(saveEntity);
// 更新仪器序列号绑定状态
WxInstrumentSerial saveSerial = new WxInstrumentSerial();
saveSerial.setId(wxInstrumentSerial.getId());
saveSerial.setBindingStatus(BindingStatusEnums.BINDED.getCode());
saveSerial.setUpdateBy(wxUserMember.getNickname());
saveSerial.setUpdateTime(DateUtils.getNowDate());
wxInstrumentSerialMapper.updateWxInstrumentSerial(saveSerial);
// 保存绑定记录
WxUserInstrumentLog wxUserInstrumentLog = new WxUserInstrumentLog();
wxUserInstrumentLog.setUserInstrumentId(saveEntity.getId());
wxUserInstrumentLog.setUserId(wxUserMember.getId());
wxUserInstrumentLog.setSerial(serial);
wxUserInstrumentLog.setInstrumentId(wxInstrument.getId());
wxUserInstrumentLog.setInstrumentName(wxInstrument.getName());
wxUserInstrumentLog.setGuarantee(wxInstrument.getGuarantee());
wxUserInstrumentLog.setGuaranteeEndtime(saveEntity.getGuaranteeEndtime());
wxUserInstrumentLog.setBindingStatus(BindingStatusEnums.BINDED.getCode());
wxUserInstrumentLog.setStatus(Status.OK.getCode().longValue());
wxUserInstrumentLog.setCreateBy(wxUserMember.getNickname());
wxUserInstrumentLog.setCreateTime(DateUtils.getNowDate());
wxUserInstrumentLogMapper.insertWxUserInstrumentLog(wxUserInstrumentLog);
}
}
}
@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