| @@ -6,8 +6,12 @@ import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.KwBox; | |||
| import com.iformall.domain.po.KwMeter; | |||
| import com.iformall.enums.EnumBoxStatus; | |||
| import com.iformall.enums.EnumMeterBindStatus; | |||
| import com.iformall.enums.EnumMeterStatus; | |||
| import com.iformall.service.kw.KwBoxService; | |||
| import com.iformall.service.kw.KwMeterService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| @@ -28,6 +32,9 @@ public class KwBoxController extends BaseController { | |||
| @Autowired | |||
| private KwBoxService kwBoxService; | |||
| @Autowired | |||
| private KwMeterService kwMeterService; | |||
| @ApiOperation("设备列表") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -66,6 +73,9 @@ public class KwBoxController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwBox.getId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| kwBox.setImei(null); | |||
| kwBox.setIccid(null); | |||
| kwBox.setComKey(null); | |||
| kwBoxService.saveOrUpdate(kwBox); | |||
| return new ResultData(kwBox); | |||
| } | |||
| @@ -94,6 +104,77 @@ public class KwBoxController extends BaseController { | |||
| kwBox.setId(id); | |||
| kwBox.setStatus(EnumBoxStatus.INVALID.getCode()); | |||
| kwBoxService.saveOrUpdate(kwBox); | |||
| return new ResultData(kwBox); | |||
| kwMeterService.unbindBatch(id); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("绑定设备") | |||
| @PostMapping("bind") | |||
| @SystemControllerLog(description = "电表设备-添加设备") | |||
| public Result bind(@RequestBody KwMeter kwMeter) { | |||
| if (kwMeter == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getBoxId() == null || | |||
| (kwMeter.getId() == null && kwMeter.getIds() == null)) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| KwBox kwBox = kwBoxService.getById(kwMeter.getBoxId()); | |||
| if (kwBox == null || kwBox.getStatus().equals(EnumBoxStatus.INVALID.getCode())) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| KwMeter record = new KwMeter(); | |||
| record.setBoxId(kwMeter.getBoxId()); | |||
| record.setBindStatus(EnumMeterBindStatus.BIND.getCode()); | |||
| record.setStatus(EnumMeterStatus.VALID.getCode()); | |||
| List<KwMeter> KwMeters = kwMeterService.findList(record); | |||
| if (kwMeter.getId() != null) { | |||
| if (KwMeters.size() >= kwBox.getMaxTagNum()) | |||
| return new ResultData(ErrorCode.DEVICE_REACHED_MAX_NUMBER); | |||
| record = kwMeterService.getById(kwMeter.getId()); | |||
| if (record == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| if (record.getBoxId() != 0 && record.getBindStatus().equals(EnumMeterBindStatus.BIND.getCode())) | |||
| return new ResultData(ErrorCode.DEVICE_ALREADY_EXIST); | |||
| kwMeterService.bind(kwMeter.getBoxId(),kwMeter.getId()); | |||
| } else { | |||
| if (kwMeter.getIds() != null) { | |||
| if (KwMeters.size() + kwMeter.getIds().size() > kwBox.getMaxTagNum()) | |||
| return new ResultData(ErrorCode.DEVICE_REACHED_MAX_NUMBER); | |||
| } | |||
| kwMeterService.bindBatch(kwMeter.getBoxId(),kwMeter.getIds()); | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("绑定设备") | |||
| @PostMapping("unbind") | |||
| @SystemControllerLog(description = "电表设备-添加设备") | |||
| public Result unbind(@RequestBody KwMeter kwMeter) { | |||
| if (kwMeter == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getBoxId() == null && kwMeter.getId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getId() != null) { | |||
| KwMeter record = kwMeterService.getById(kwMeter.getId()); | |||
| if (record == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| kwMeterService.unbind(kwMeter.getId()); | |||
| } else { | |||
| if (kwMeter.getBoxId() != null) { | |||
| KwBox kwBox = kwBoxService.getById(kwMeter.getBoxId()); | |||
| if (kwBox == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| kwMeterService.unbindBatch(kwMeter.getBoxId()); | |||
| } | |||
| } | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -98,15 +98,13 @@ public class KwMerchantMeterController extends BaseController { | |||
| if (kwMerchantMeter == null) | |||
| 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); | |||
| if (kwMerchantMeter.getMeterId() != null) { | |||
| kwMerchantMeterService.unbind(kwMerchantMeter.getMeterId()); | |||
| } else { | |||
| kwMerchantMeterService.unbindBatch(kwMerchantMeter); | |||
| kwMerchantMeterService.unbindBatch(kwMerchantMeter.getMerchantId()); | |||
| } | |||
| return new ResultData(); | |||
| @@ -11,7 +11,9 @@ import com.iformall.domain.po.KwMeterData; | |||
| import com.iformall.enums.EnumBoxStatus; | |||
| import com.iformall.enums.EnumMeterBindStatus; | |||
| import com.iformall.enums.EnumMeterStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.kw.KwBoxService; | |||
| import com.iformall.service.kw.KwMerchantMeterService; | |||
| import com.iformall.service.kw.KwMeterDataService; | |||
| import com.iformall.service.kw.KwMeterService; | |||
| import io.swagger.annotations.Api; | |||
| @@ -22,7 +24,10 @@ import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @@ -39,8 +44,7 @@ public class KwMeterController extends BaseController { | |||
| private KwMeterDataService kwMeterDataService; | |||
| @Autowired | |||
| private KwBoxService kwBoxService; | |||
| private KwMerchantMeterService kwMerchantMeterService; | |||
| @ApiOperation("设备列表") | |||
| @GetMapping("list") | |||
| @@ -80,64 +84,6 @@ public class KwMeterController extends BaseController { | |||
| return new ResultData(kwMeter); | |||
| } | |||
| @ApiOperation("绑定设备") | |||
| @PostMapping("bind") | |||
| @SystemControllerLog(description = "电表设备-添加设备") | |||
| public Result bind(@RequestBody KwMeter kwMeter) { | |||
| if (kwMeter == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getBoxId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| KwBox kwBox = kwBoxService.getById(kwMeter.getBoxId()); | |||
| if (kwBox == null || kwBox.getStatus().equals(EnumBoxStatus.INVALID.getCode())) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| KwMeter record = new KwMeter(); | |||
| record.setBoxId(kwMeter.getBoxId()); | |||
| record.setStatus(EnumMeterStatus.VALID.getCode()); | |||
| List<KwMeter> KwMeters = kwMeterService.findList(record); | |||
| if (KwMeters.size() >= kwBox.getMaxTagNum()) | |||
| return new ResultData(ErrorCode.DEVICE_REACHED_MAX_NUMBER); | |||
| record = kwMeterService.getById(kwMeter.getId()); | |||
| if (record == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| if (record.getBoxId() != 0) | |||
| return new ResultData(ErrorCode.DEVICE_ALREADY_EXIST); | |||
| kwMeter.setBindStatus(EnumMeterBindStatus.BIND.getCode()); | |||
| kwMeterService.saveOrUpdate(kwMeter); | |||
| return new ResultData(kwMeter); | |||
| } | |||
| @ApiOperation("绑定设备") | |||
| @PostMapping("unbind") | |||
| @SystemControllerLog(description = "电表设备-添加设备") | |||
| public Result unbind(@RequestBody KwMeter kwMeter) { | |||
| if (kwMeter == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getBoxId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| KwBox kwBox = kwBoxService.getById(kwMeter.getBoxId()); | |||
| if (kwBox == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| KwMeter record = kwMeterService.getById(kwMeter.getId()); | |||
| if (record == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| kwMeter.setBoxId(0L); | |||
| kwMeter.setBindStatus(EnumMeterBindStatus.UNBIND.getCode()); | |||
| kwMeterService.saveOrUpdate(kwMeter); | |||
| return new ResultData(kwMeter); | |||
| } | |||
| @ApiOperation("更新设备") | |||
| @PostMapping("update") | |||
| @@ -147,6 +93,7 @@ public class KwMeterController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (kwMeter.getId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| kwMeter.setAddress(null); | |||
| kwMeterService.saveOrUpdate(kwMeter); | |||
| return new ResultData(kwMeter); | |||
| } | |||
| @@ -173,7 +120,24 @@ public class KwMeterController extends BaseController { | |||
| KwMeter kwMeter = new KwMeter(); | |||
| kwMeter.setId(id); | |||
| kwMeter.setStatus(EnumBoxStatus.INVALID.getCode()); | |||
| kwMeterService.unbind(id); | |||
| kwMerchantMeterService.unbind(id); | |||
| kwMeterService.saveOrUpdate(kwMeter); | |||
| return new ResultData(kwMeter); | |||
| } | |||
| @ApiOperation("导入设备") | |||
| @PostMapping(value = "import", consumes = "multipart/*") | |||
| @SystemControllerLog(description = "电表管理-导入数据") | |||
| public Result importData(@RequestParam("file") MultipartFile mFile) { | |||
| return new ResultData(); | |||
| } | |||
| @RequestMapping("导出模板") | |||
| @SystemControllerLog(description = "电表管理-导出模板") | |||
| public void exportTemplate(HttpServletRequest request, HttpServletResponse response) { | |||
| } | |||
| } | |||
| @@ -18,6 +18,6 @@ public interface KwMerchantMeterMapper extends CommonMapper<KwMerchantMeter, Lon | |||
| KwMerchantMeterVo getById(@Param("merchantId")Long merchantId); | |||
| int unbindBatch(KwMerchantMeter param); | |||
| int unbindBatch(@Param("merchantId")Long merchantId); | |||
| int unbind(@Param("meterId")Long meterId); | |||
| } | |||
| @@ -2,6 +2,7 @@ package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.KwMeter; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import java.util.List; | |||
| @@ -10,4 +11,10 @@ public interface KwMeterMapper extends CommonMapper<KwMeter, Long> { | |||
| List<KwMeter> findList(KwMeter param); | |||
| int updateBatch(KwMeter param); | |||
| int bind(@Param("boxId")Long boxId,@Param("id")Long id); | |||
| int bindBatch(@Param("boxId")Long boxId, @Param("ids")List<Long> ids); | |||
| int unbind(@Param("meterId")Long meterId); | |||
| int unbindBatch(@Param("boxId")Long boxId); | |||
| } | |||
| @@ -82,4 +82,5 @@ public interface KwBoxService { | |||
| KwBox findByImei(String imei); | |||
| void saveMeterData(KwBox record, List<Map<String,String>> metersData, Date deviceTime); | |||
| } | |||
| @@ -53,6 +53,6 @@ public interface KwMerchantMeterService { | |||
| List<KwMerchantMeterDataVo> findDataVoList(KwMerchantMeterDataDto record); | |||
| int selectCount(KwMerchantMeter record); | |||
| int unbindBatch(KwMerchantMeter record); | |||
| int unbind(Long meterId); | |||
| int unbindBatch(Long merchantId); | |||
| } | |||
| @@ -61,4 +61,12 @@ public interface KwMeterService { | |||
| List<KwMeter> findList(KwMeter record); | |||
| int selectCount(KwMeter record); | |||
| int bind(Long boxId, Long meterId); | |||
| int bindBatch(Long boxId, List<Long> meterIds); | |||
| int unbind(Long meterId); | |||
| int unbindBatch(Long boxId); | |||
| } | |||
| @@ -10,6 +10,7 @@ import com.iformall.domain.po.KwMeter; | |||
| import com.iformall.domain.po.KwMeterData; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.KwBoxMapper; | |||
| import com.iformall.mapper.KwMeterMapper; | |||
| import com.iformall.service.kw.KwBoxService; | |||
| import com.iformall.service.kw.KwMeterDataService; | |||
| import com.iformall.service.kw.KwMeterService; | |||
| @@ -37,6 +38,9 @@ public class KwBoxServiceImpl implements KwBoxService { | |||
| @Autowired | |||
| KwMeterService kwMeterService; | |||
| @Autowired | |||
| KwMeterMapper kwMeterMapper; | |||
| @Override | |||
| public PageInfo<KwBox> listAsPage(KwBox record, Integer pageIndex, Integer pageSize) { | |||
| @@ -175,7 +179,7 @@ public class KwBoxServiceImpl implements KwBoxService { | |||
| kwMeter.setBindStatus(EnumMeterBindStatus.BIND.getCode()); | |||
| kwMeter.setStatus(EnumMeterStatus.VALID.getCode()); | |||
| return kwMeterService.findList(kwMeter); | |||
| return kwMeterMapper.findList(kwMeter); | |||
| } | |||
| } | |||
| @@ -78,13 +78,18 @@ public class KwMerchantMeterServiceImpl implements KwMerchantMeterService { | |||
| } | |||
| @Override | |||
| public int unbindBatch(KwMerchantMeter record) { | |||
| if (record == null) | |||
| public int unbind(Long meterId) { | |||
| if (meterId == null) | |||
| return 0; | |||
| if (record.getMeterId() == null | |||
| && record.getMerchantId() == null) | |||
| return kwMerchantMeterMapper.unbind(meterId); | |||
| } | |||
| @Override | |||
| public int unbindBatch(Long merchantId) { | |||
| if (merchantId == null) | |||
| return 0; | |||
| return kwMerchantMeterMapper.unbindBatch(record); | |||
| return kwMerchantMeterMapper.unbindBatch(merchantId); | |||
| } | |||
| } | |||
| @@ -68,4 +68,34 @@ public class KwMeterServiceImpl implements KwMeterService { | |||
| public int selectCount(KwMeter record) { | |||
| return kwMeterMapper.selectCount(record); | |||
| } | |||
| @Override | |||
| public int bind(Long boxId, Long meterId) { | |||
| if (meterId == null || boxId == null) | |||
| return 0; | |||
| return kwMeterMapper.bind(boxId, meterId); | |||
| } | |||
| @Override | |||
| public int bindBatch(Long boxId, List<Long> meterIds) { | |||
| if (meterIds == null || boxId == null) | |||
| return 0; | |||
| return kwMeterMapper.bindBatch(boxId, meterIds); | |||
| } | |||
| @Override | |||
| public int unbind(Long meterId) { | |||
| if (meterId == null) | |||
| return 0; | |||
| return kwMeterMapper.unbind(meterId); | |||
| } | |||
| @Override | |||
| public int unbindBatch(Long boxId) { | |||
| if (boxId == null) | |||
| return 0; | |||
| return kwMeterMapper.unbindBatch(boxId); | |||
| } | |||
| } | |||
| @@ -250,18 +250,18 @@ | |||
| where temp.merchant_id = id | |||
| </select> | |||
| <update id="unbindBatch" parameterType="com.iformall.domain.po.KwMerchantMeter"> | |||
| <update id="unbindBatch" parameterType="java.lang.Long"> | |||
| update kw_merchant_meter set status = 1 | |||
| where status = 0 | |||
| and `merchant_id` = #{merchantId} | |||
| </update> | |||
| <if test=" null != merchantId "> | |||
| and `merchant_id` = #{merchantId} | |||
| </if> | |||
| <if test=" null != meterId "> | |||
| and `meter_id` = #{meterId} | |||
| </if> | |||
| <update id="unbind" parameterType="java.lang.Long"> | |||
| update kw_merchant_meter set status = 1 | |||
| where status = 0 | |||
| and `meter_id` = #{meterId} | |||
| </update> | |||
| </mapper> | |||
| @@ -104,4 +104,30 @@ | |||
| </if> | |||
| </update> | |||
| <update id="unbindBatch" parameterType="java.lang.Long"> | |||
| update kw_merchant_meter set (bind_status = 1, box_id = 0) | |||
| where bind_status = 0 | |||
| and `box_id` = #{boxId} | |||
| </update> | |||
| <update id="unbind" parameterType="java.lang.Long"> | |||
| update kw_merchant_meter set (bind_status = 1, box_id = 0) | |||
| where bind_status = 0 | |||
| and `id` = #{meterId} | |||
| </update> | |||
| <update id="bindBatch" parameterType="map"> | |||
| update kw_merchant_meter set (bind_status = 0, box_id = #{boxId}) | |||
| where id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </update> | |||
| <update id="bind" parameterType="map"> | |||
| update kw_merchant_meter set (bind_status = 0, box_id = #{boxId}) | |||
| where `id` = #{id} | |||
| </update> | |||
| </mapper> | |||