| @@ -7,6 +7,8 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.KwMerchantMeter; | import com.iformall.domain.po.KwMerchantMeter; | ||||
| import com.iformall.enums.EnumMerchantMeterStatus; | |||||
| import com.iformall.enums.EnumMerchantStatus; | |||||
| import com.iformall.service.kw.KwMerchantMeterService; | import com.iformall.service.kw.KwMerchantMeterService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -17,6 +19,8 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.List; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("kwMerchantMeter") | @RequestMapping("kwMerchantMeter") | ||||
| @@ -36,8 +40,7 @@ public class KwMerchantMeterController extends BaseController { | |||||
| @SystemControllerLog(description = "电表设备-设备列表") | @SystemControllerLog(description = "电表设备-设备列表") | ||||
| public Result list(@ModelAttribute KwMerchantMeter kwMerchantMeter, Integer pageNum, Integer pageSize) { | public Result list(@ModelAttribute KwMerchantMeter kwMerchantMeter, Integer pageNum, Integer pageSize) { | ||||
| if (kwMerchantMeter == null) kwMerchantMeter = new KwMerchantMeter(); | if (kwMerchantMeter == null) kwMerchantMeter = new KwMerchantMeter(); | ||||
| return new ResultData(); | |||||
| return new ResultData(kwMerchantMeterService.listAsPage(kwMerchantMeter, pageNum, pageSize)); | |||||
| } | } | ||||
| @ApiOperation("绑定设备") | @ApiOperation("绑定设备") | ||||
| @@ -47,6 +50,20 @@ public class KwMerchantMeterController extends BaseController { | |||||
| if (kwMerchantMeter == null) | if (kwMerchantMeter == null) | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | ||||
| if (kwMerchantMeter.getMerchantId() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| if (kwMerchantMeter.getMeterId() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| KwMerchantMeter record = new KwMerchantMeter(); | |||||
| record.setMeterId(kwMerchantMeter.getMeterId()); | |||||
| record.setStatus(EnumMerchantMeterStatus.VALID.getCode()); | |||||
| if (kwMerchantMeterService.selectCount(record) > 0) | |||||
| return new ResultData(ErrorCode.DEVICE_HAS_BEEN_BOUND); | |||||
| kwMerchantMeter.setTenantId(getTenantId()); | |||||
| kwMerchantMeter.setStatus(EnumMerchantMeterStatus.VALID.getCode()); | |||||
| kwMerchantMeterService.saveOrUpdate(kwMerchantMeter); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -58,6 +75,17 @@ public class KwMerchantMeterController extends BaseController { | |||||
| if (kwMerchantMeter == null) | if (kwMerchantMeter == null) | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | ||||
| if (kwMerchantMeter.getMerchantId() == null | |||||
| && kwMerchantMeter.getId() == null | |||||
| && kwMerchantMeter.getMeterId() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| if (kwMerchantMeter.getId() != null) { | |||||
| kwMerchantMeter.setStatus(EnumMerchantMeterStatus.INVALID.getCode()); | |||||
| kwMerchantMeterService.saveOrUpdate(kwMerchantMeter); | |||||
| } else { | |||||
| kwMerchantMeterService.unbindBatch(kwMerchantMeter); | |||||
| } | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -407,6 +407,7 @@ public enum ErrorCode{ | |||||
| DEVICE_ALREADY_EXIST(26001, "设备已经存在"), | DEVICE_ALREADY_EXIST(26001, "设备已经存在"), | ||||
| DEVICE_QRCODE_GET_FAILED(26002, "微信二维码生成失败,请重试"), | DEVICE_QRCODE_GET_FAILED(26002, "微信二维码生成失败,请重试"), | ||||
| DEVICE_REACHED_MAX_NUMBER(26003, "设备已经达到最大数量"), | DEVICE_REACHED_MAX_NUMBER(26003, "设备已经达到最大数量"), | ||||
| DEVICE_HAS_BEEN_BOUND(26004, "设备已经绑定到其他商户"), | |||||
| /** | /** | ||||
| * 消息组件 | * 消息组件 | ||||
| */ | */ | ||||
| @@ -0,0 +1,23 @@ | |||||
| package com.iformall.domain.vo; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import lombok.Data; | |||||
| import java.util.List; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Data | |||||
| public class KwMerchantMeterVo extends KwMeter { | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户名",name="name") | |||||
| private String merchantName; | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户联系方式",name="linkPhone") | |||||
| private String merchantLinkPhone; | |||||
| @io.swagger.annotations.ApiModelProperty(value = "店铺列表", name = "shopVoList") | |||||
| private List<WxShopVo> shopVoList; | |||||
| } | |||||
| @@ -0,0 +1,35 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumMerchantMeterStatus { | |||||
| VALID(0, "有效"), | |||||
| INVALID(1, "无效"),; | |||||
| public static EnumMerchantMeterStatus getEnum(Integer code) { | |||||
| for (EnumMerchantMeterStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumMerchantMeterStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -2,12 +2,14 @@ package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | import com.iformall.common.CommonMapper; | ||||
| import com.iformall.domain.po.KwMerchantMeter; | import com.iformall.domain.po.KwMerchantMeter; | ||||
| import com.iformall.domain.vo.KwMerchantMeterVo; | |||||
| import java.util.List; | import java.util.List; | ||||
| public interface KwMerchantMeterMapper extends CommonMapper<KwMerchantMeter, Long> { | public interface KwMerchantMeterMapper extends CommonMapper<KwMerchantMeter, Long> { | ||||
| List<KwMerchantMeter> findList(KwMerchantMeter param); | List<KwMerchantMeter> findList(KwMerchantMeter param); | ||||
| List<KwMerchantMeterVo> findListVo(KwMerchantMeter param); | |||||
| int unbindBatch(KwMerchantMeter param); | |||||
| } | } | ||||
| @@ -4,6 +4,7 @@ package com.iformall.service.kw; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.KwMerchantMeter; | import com.iformall.domain.po.KwMerchantMeter; | ||||
| import com.iformall.domain.vo.KwMerchantMeterVo; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -18,7 +19,7 @@ public interface KwMerchantMeterService { | |||||
| * @param pageSize | * @param pageSize | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| PageInfo<KwMerchantMeter> listAsPage(KwMerchantMeter record, Integer pageIndex, Integer pageSize); | |||||
| PageInfo<KwMerchantMeterVo> listAsPage(KwMerchantMeter record, Integer pageIndex, Integer pageSize); | |||||
| /** | /** | ||||
| @@ -37,14 +38,6 @@ public interface KwMerchantMeterService { | |||||
| ResultData saveOrUpdate(KwMerchantMeter record); | ResultData saveOrUpdate(KwMerchantMeter record); | ||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| /** | /** | ||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| * | * | ||||
| @@ -52,6 +45,7 @@ public interface KwMerchantMeterService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| List<KwMerchantMeter> findList(KwMerchantMeter record); | List<KwMerchantMeter> findList(KwMerchantMeter record); | ||||
| List<KwMerchantMeterVo> findListVo(KwMerchantMeter record); | |||||
| int selectCount(KwMerchantMeter record); | |||||
| int unbindBatch(KwMerchantMeter record); | |||||
| } | } | ||||
| @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.KwMerchantMeter; | import com.iformall.domain.po.KwMerchantMeter; | ||||
| import com.iformall.domain.vo.KwMerchantMeterVo; | |||||
| import com.iformall.mapper.KwMerchantMeterMapper; | import com.iformall.mapper.KwMerchantMeterMapper; | ||||
| import com.iformall.service.kw.KwMerchantMeterService; | import com.iformall.service.kw.KwMerchantMeterService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -12,6 +13,7 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -23,8 +25,8 @@ public class KwMerchantMeterServiceImpl implements KwMerchantMeterService { | |||||
| KwMerchantMeterMapper kwMerchantMeterMapper; | KwMerchantMeterMapper kwMerchantMeterMapper; | ||||
| @Override | @Override | ||||
| public PageInfo<KwMerchantMeter> listAsPage(KwMerchantMeter record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> kwMerchantMeterMapper.findList(record)); | |||||
| public PageInfo<KwMerchantMeterVo> listAsPage(KwMerchantMeter record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> kwMerchantMeterMapper.findListVo(record)); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -38,8 +40,11 @@ public class KwMerchantMeterServiceImpl implements KwMerchantMeterService { | |||||
| if (record.getId() == null) { | if (record.getId() == null) { | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| record.setCreateTime(new Date()); | |||||
| record.setUpdateTime(new Date()); | |||||
| kwMerchantMeterMapper.insertSelective(record); | kwMerchantMeterMapper.insertSelective(record); | ||||
| } else { | } else { | ||||
| record.setUpdateTime(new Date()); | |||||
| kwMerchantMeterMapper.updateByPrimaryKeySelective(record); | kwMerchantMeterMapper.updateByPrimaryKeySelective(record); | ||||
| } | } | ||||
| return new ResultData(); | return new ResultData(); | ||||
| @@ -47,13 +52,27 @@ public class KwMerchantMeterServiceImpl implements KwMerchantMeterService { | |||||
| @Override | @Override | ||||
| public void deleteById(Long id) { | |||||
| kwMerchantMeterMapper.deleteByPrimaryKey(id); | |||||
| public List<KwMerchantMeter> findList(KwMerchantMeter record) { | |||||
| return kwMerchantMeterMapper.findList(record); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public List<KwMerchantMeter> findList(KwMerchantMeter record) { | |||||
| return kwMerchantMeterMapper.findList(record); | |||||
| public List<KwMerchantMeterVo> findListVo(KwMerchantMeter record) { | |||||
| return kwMerchantMeterMapper.findListVo(record); | |||||
| } | |||||
| @Override | |||||
| public int selectCount(KwMerchantMeter record) { | |||||
| return kwMerchantMeterMapper.selectCount(record); | |||||
| } | |||||
| @Override | |||||
| public int unbindBatch(KwMerchantMeter record) { | |||||
| if (record == null) | |||||
| return 0; | |||||
| if (record.getMeterId() == null && record.getMerchantId() == null) | |||||
| return 0; | |||||
| return kwMerchantMeterMapper.unbindBatch(record); | |||||
| } | } | ||||
| @@ -9,6 +9,8 @@ | |||||
| <result column="status" jdbcType="INTEGER" property="status"/> | <result column="status" jdbcType="INTEGER" property="status"/> | ||||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | ||||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | ||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| @@ -21,11 +23,19 @@ | |||||
| <if test=" null != id "> | <if test=" null != id "> | ||||
| and `id` = #{id} | and `id` = #{id} | ||||
| </if> | </if> | ||||
| <if test=" null != tenantId "> | <if test=" null != tenantId "> | ||||
| and `tenant_id` = #{tenantId} | and `tenant_id` = #{tenantId} | ||||
| </if> | </if> | ||||
| <if test=" null != merchantId "> | |||||
| and `merchant_id` = #{merchantId} | |||||
| </if> | |||||
| <if test=" null != meterId "> | |||||
| and `meter_id` = #{meterId} | |||||
| </if> | |||||
| <if test=" null != status "> | <if test=" null != status "> | ||||
| and `status` = #{status} | and `status` = #{status} | ||||
| </if> | </if> | ||||
| @@ -39,12 +49,56 @@ | |||||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | <if test=" null != sortColumns">order by ${sortColumns}</if> | ||||
| </sql> | </sql> | ||||
| <select id="findList" parameterType="com.iformall.domain.po.KwMeter" resultMap="BaseResultMap"> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.KwMerchantMeter" resultMap="BaseResultMap"> | |||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from kw_box_meter | |||||
| from kw_merchant_meter | |||||
| <include refid="dynamicWhereConditions"/> | <include refid="dynamicWhereConditions"/> | ||||
| </select> | </select> | ||||
| <resultMap id="BaseResultMapVo" type="com.iformall.domain.vo.KwMerchantMeterVo"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
| <result column="meter_id" jdbcType="BIGINT" property="meterId"/> | |||||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/> | |||||
| <result column="status" jdbcType="INTEGER" property="status"/> | |||||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | |||||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | |||||
| <result column="name" jdbcType="VARCHAR" property="merchantName"/> | |||||
| <result column="link_phone" jdbcType="VARCHAR" property="merchantLinkPhone"/> | |||||
| <collection column="{merchantId=id}" property="shopVoList" | |||||
| ofType="com.iformall.domain.vo.WxShopVo" | |||||
| javaType="java.util.List" | |||||
| select="com.iformall.mapper.WxShopMapper.findShopVoList"> | |||||
| </collection> | |||||
| </resultMap> | |||||
| <sql id="allColumnsVo"> | |||||
| `id`,`tenant_id`,`meter_id`,`merchant_id`,`status`,`create_time`,`update_time`, `name`, `link_phone` | |||||
| </sql> | |||||
| <select id="findListVo" parameterType="com.iformall.domain.po.KwMerchantMeter" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumnsVo"/> | |||||
| from kw_merchant_meter, wx_merchant | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| <update id="unbindBatch" parameterType="com.iformall.domain.po.KwMerchantMeter"> | |||||
| update kw_merchant_meter set status = 1 | |||||
| where status = 0 | |||||
| <if test=" null != merchantId "> | |||||
| and `merchant_id` = #{merchantId} | |||||
| </if> | |||||
| <if test=" null != meterId "> | |||||
| and `meter_id` = #{meterId} | |||||
| </if> | |||||
| </update> | |||||
| </mapper> | </mapper> | ||||