| @@ -0,0 +1,223 @@ | |||||
| package com.iformall.controller.device; | |||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.ErrorCode; | |||||
| 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.KwBoxCmdHistory; | |||||
| import com.iformall.enums.EnumBoxStatus; | |||||
| import com.iformall.service.kw.KwBoxCmdHistoryService; | |||||
| import com.iformall.service.kw.KwBoxService; | |||||
| import io.netty.util.internal.StringUtil; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.Date; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import java.util.stream.Collectors; | |||||
| @RestController | |||||
| @RequestMapping("kwBox/v1") | |||||
| @Api(description="开物盒子") | |||||
| public class KwBoxV1Controller extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private KwBoxService kwBoxService; | |||||
| @Autowired | |||||
| private KwBoxCmdHistoryService kwBoxCmdHistoryService; | |||||
| private void saveCmd(String tenantId, String cmd, String imei, String ccid, Date deviceTime, Map<String,String> paramMap) | |||||
| { | |||||
| KwBoxCmdHistory kwBoxCmdHistory = new KwBoxCmdHistory(); | |||||
| kwBoxCmdHistory.setCmd(cmd); | |||||
| kwBoxCmdHistory.setCreateTime(new Date()); | |||||
| kwBoxCmdHistory.setDeviceTime(deviceTime); | |||||
| kwBoxCmdHistory.setIccid(ccid); | |||||
| kwBoxCmdHistory.setImei(imei); | |||||
| kwBoxCmdHistory.setInfo(JSONObject.toJSON(paramMap).toString()); | |||||
| kwBoxCmdHistory.setTenantId(tenantId); | |||||
| kwBoxCmdHistoryService.saveOrUpdate(kwBoxCmdHistory); | |||||
| } | |||||
| private ResultData cmdRegist(String imei, String ccid, Date deviceTime, Map<String,String> paramMap) | |||||
| { | |||||
| String fwv = paramMap.get("FWV"); | |||||
| if (StringUtil.isNullOrEmpty(fwv)) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| String hwv = paramMap.get("HWV"); | |||||
| if (StringUtil.isNullOrEmpty(hwv)) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| KwBox kwBox = kwBoxService.findByImei(imei); | |||||
| if (kwBox == null) | |||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||||
| if (!kwBox.getStatus().equals(EnumBoxStatus.INIT)) | |||||
| return new ResultData(ErrorCode.DEVICE_ALREADY_EXIST); | |||||
| saveCmd(kwBox.getTenantId(),"regist",imei,ccid,deviceTime,paramMap); | |||||
| KwBox record = new KwBox(); | |||||
| record.setId(kwBox.getId()); | |||||
| record.setIccid(ccid); | |||||
| record.setFwVersion(fwv); | |||||
| record.setHdVersion(hwv); | |||||
| record.setUpdateTime(new Date()); | |||||
| record.setRegisterTime(new Date()); | |||||
| record.setLastOnlineTime(new Date()); | |||||
| record.setStatus(EnumBoxStatus.REGISTERED.getCode()); | |||||
| kwBoxService.saveOrUpdate(record); | |||||
| Map<String,Object> data = new HashMap<>(); | |||||
| data.put("config",kwBox.getConfig()); | |||||
| List<String> meters = kwBoxService.findMeters(kwBox); | |||||
| data.put("meters",meters); | |||||
| return new ResultData(data); | |||||
| } | |||||
| private ResultData cmdLogin(String imei, String ccid, Date deviceTime, Map<String,String> paramMap) | |||||
| { | |||||
| KwBox kwBox = kwBoxService.findByImei(imei); | |||||
| if (kwBox == null) | |||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||||
| if (!kwBox.getStatus().equals(EnumBoxStatus.REGISTERED.getCode())) | |||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||||
| saveCmd(kwBox.getTenantId(),"login",imei,ccid,deviceTime,paramMap); | |||||
| KwBox record = new KwBox(); | |||||
| record.setId(kwBox.getId()); | |||||
| record.setIccid(ccid); | |||||
| record.setUpdateTime(new Date()); | |||||
| record.setLastOnlineTime(new Date()); | |||||
| kwBoxService.saveOrUpdate(record); | |||||
| Map<String,Object> data = new HashMap<>(); | |||||
| data.put("config",kwBox.getConfig()); | |||||
| return new ResultData(data); | |||||
| } | |||||
| private ResultData cmdHb(String imei, String ccid, Date deviceTime, Map<String,String> paramMap) | |||||
| { | |||||
| KwBox kwBox = kwBoxService.findByImei(imei); | |||||
| if (kwBox == null) | |||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||||
| if (!kwBox.getStatus().equals(EnumBoxStatus.REGISTERED)) | |||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||||
| saveCmd(kwBox.getTenantId(),"hb",imei,ccid,deviceTime,paramMap); | |||||
| KwBox record = new KwBox(); | |||||
| record.setId(kwBox.getId()); | |||||
| record.setLastOnlineTime(new Date()); | |||||
| kwBoxService.saveOrUpdate(record); | |||||
| Map<String,Object> resData = new HashMap<>(); | |||||
| List<String> meters = kwBoxService.findMeters(kwBox); | |||||
| String metersDataStr = paramMap.get("meters"); | |||||
| JSONArray ja = JSONObject.parseArray(metersDataStr); | |||||
| boolean updateMeters = false; | |||||
| boolean updateConfig = false; | |||||
| if (ja.size() > 0) { | |||||
| List<HashMap> metersData = ja.toJavaList(HashMap.class); | |||||
| metersData.stream().forEach(m->{ | |||||
| String addr = (String)m.get("addr"); | |||||
| String data = (String)m.get("data"); | |||||
| kwBoxService.saveMeterData(kwBox, deviceTime, addr, data); | |||||
| }); | |||||
| if (metersData.size() != meters.size()) { | |||||
| updateMeters = true; | |||||
| } else { | |||||
| if (!meters.containsAll(metersData.stream().map(m->m.get("addr")).collect(Collectors.toList()))) | |||||
| updateMeters = true; | |||||
| } | |||||
| } else { | |||||
| updateMeters = true; | |||||
| } | |||||
| if (updateMeters) { | |||||
| if (meters.size() > 0) | |||||
| resData.put("meters", meters); | |||||
| } | |||||
| if (updateConfig) { | |||||
| resData.put("config", kwBox.getConfig()); | |||||
| } | |||||
| return new ResultData(resData); | |||||
| } | |||||
| //“TIME”:”19/05/29 08:24:57 +32”, | |||||
| @ApiOperation("广告列表") | |||||
| @PostMapping("command") | |||||
| @SystemControllerLog(description = "开物盒子v1") | |||||
| public Result v1(@RequestBody Map<String,String> paramMap) { | |||||
| String cmd = paramMap.get("CMD"); | |||||
| if (StringUtil.isNullOrEmpty(cmd)) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| String imei = paramMap.get("IMEI"); | |||||
| if (StringUtil.isNullOrEmpty(imei)) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| String ccid = paramMap.get("CCID"); | |||||
| if (StringUtil.isNullOrEmpty(ccid)) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| String time = paramMap.get("TIME"); | |||||
| if (StringUtil.isNullOrEmpty(time)) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yy/MM/dd,hh:mm:ss±zz"); | |||||
| Date deviceTime = null; | |||||
| try { | |||||
| deviceTime=simpleDateFormat.parse(time); | |||||
| } catch(Exception e) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| } | |||||
| switch(cmd) | |||||
| { | |||||
| case "regist": | |||||
| return cmdRegist(imei,ccid,deviceTime,paramMap); | |||||
| case "login": | |||||
| return cmdLogin(imei,ccid,deviceTime,paramMap); | |||||
| case "hb": | |||||
| return cmdHb(imei,ccid,deviceTime,paramMap); | |||||
| } | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| } | |||||
| } | |||||
| @@ -45,10 +45,10 @@ public class KwBox extends BaseEntity { | |||||
| private String place; | private String place; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "固件版本号", name = "fwVersion") | @io.swagger.annotations.ApiModelProperty(value = "固件版本号", name = "fwVersion") | ||||
| private String fw_version; | |||||
| private String fwVersion; | |||||
| @io.swagger.annotations.ApiModelProperty(value = "硬件版本号", name = "hdVersion") | @io.swagger.annotations.ApiModelProperty(value = "硬件版本号", name = "hdVersion") | ||||
| private String hd_version; | |||||
| private String hdVersion; | |||||
| @io.swagger.annotations.ApiModelProperty(value = "注册状态0出厂已注册1", name = "status") | @io.swagger.annotations.ApiModelProperty(value = "注册状态0出厂已注册1", name = "status") | ||||
| private Integer status; | private Integer status; | ||||
| @@ -18,7 +18,7 @@ import java.util.List; | |||||
| @Data | @Data | ||||
| @ToString(callSuper = true) | @ToString(callSuper = true) | ||||
| @EqualsAndHashCode(callSuper = true) | @EqualsAndHashCode(callSuper = true) | ||||
| public class KwMeters extends BaseEntity { | |||||
| public class KwMeter extends BaseEntity { | |||||
| @Id | @Id | ||||
| protected Long id; | protected Long id; | ||||
| @Transient | @Transient | ||||
| @@ -0,0 +1,34 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumBoxMeterStatus { | |||||
| VALID(0, "有效"), | |||||
| INVALID(1, "无效"); | |||||
| public static EnumBoxMeterStatus getEnum(Integer code) { | |||||
| for (EnumBoxMeterStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumBoxMeterStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,34 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumBoxStatus { | |||||
| INIT(0, "出厂"), | |||||
| REGISTERED(1, "注册"); | |||||
| public static EnumBoxStatus getEnum(Integer code) { | |||||
| for (EnumBoxStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumBoxStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -1,13 +1,13 @@ | |||||
| package com.iformall.mapper; | package com.iformall.mapper; | ||||
| import com.iformall.common.CommonMapper; | import com.iformall.common.CommonMapper; | ||||
| import com.iformall.domain.po.KwMeters; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import java.util.List; | import java.util.List; | ||||
| public interface KwMetersMapper extends CommonMapper<KwMeters, Long> { | |||||
| public interface KwMetersMapper extends CommonMapper<KwMeter, Long> { | |||||
| List<KwMeters> findList(KwMeters param); | |||||
| List<KwMeter> findList(KwMeter param); | |||||
| } | } | ||||
| @@ -0,0 +1,57 @@ | |||||
| package com.iformall.service.kw; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwBoxCmdHistory; | |||||
| import java.util.List; | |||||
| public interface KwBoxCmdHistoryService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<KwBoxCmdHistory> listAsPage(KwBoxCmdHistory record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| KwBoxCmdHistory getById(Long id); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| ResultData saveOrUpdate(KwBoxCmdHistory record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| List<KwBoxCmdHistory> findList(KwBoxCmdHistory record); | |||||
| } | |||||
| @@ -0,0 +1,58 @@ | |||||
| package com.iformall.service.kw; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwBoxMeter; | |||||
| import java.util.List; | |||||
| public interface KwBoxMeterService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<KwBoxMeter> listAsPage(KwBoxMeter record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| KwBoxMeter getById(Long id); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| ResultData saveOrUpdate(KwBoxMeter record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| List<KwBoxMeter> findList(KwBoxMeter record); | |||||
| } | |||||
| @@ -0,0 +1,68 @@ | |||||
| package com.iformall.service.kw; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwBox; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import com.iformall.domain.po.KwMeterData; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| public interface KwBoxService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<KwBox> listAsPage(KwBox record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| KwBox getById(Long id); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| ResultData saveOrUpdate(KwBox record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| List<KwBox> findList(KwBox record); | |||||
| List<String> findMeters(KwBox record); | |||||
| KwMeter findMeter(KwBox record, String addr); | |||||
| KwBox findByImei(String imei); | |||||
| KwMeterData saveMeterData(KwBox record, Date deviceTime, String addr, String data); | |||||
| } | |||||
| @@ -0,0 +1,59 @@ | |||||
| package com.iformall.service.kw; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import com.iformall.domain.po.KwMeterData; | |||||
| import java.util.List; | |||||
| public interface KwMeterDataService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<KwMeterData> listAsPage(KwMeterData record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| KwMeterData getById(Long id); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| ResultData saveOrUpdate(KwMeterData record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| List<KwMeterData> findList(KwMeterData record); | |||||
| } | |||||
| @@ -0,0 +1,59 @@ | |||||
| package com.iformall.service.kw; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwBox; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import java.util.List; | |||||
| public interface KwMeterService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<KwMeter> listAsPage(KwMeter record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| KwMeter getById(Long id); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| ResultData saveOrUpdate(KwMeter record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| List<KwMeter> findList(KwMeter record); | |||||
| } | |||||
| @@ -0,0 +1,61 @@ | |||||
| package com.iformall.service.kw.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwBoxCmdHistory; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import com.iformall.mapper.KwBoxCmdHistoryMapper; | |||||
| import com.iformall.service.kw.KwBoxCmdHistoryService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.List; | |||||
| @Service | |||||
| public class KwBoxCmdHistoryServiceImpl implements KwBoxCmdHistoryService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| KwBoxCmdHistoryMapper kwBoxCmdHistoryMapper; | |||||
| @Override | |||||
| public PageInfo<KwBoxCmdHistory> listAsPage(KwBoxCmdHistory record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> kwBoxCmdHistoryMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public KwBoxCmdHistory getById(Long id) { | |||||
| return kwBoxCmdHistoryMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public ResultData saveOrUpdate(KwBoxCmdHistory record) { | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| kwBoxCmdHistoryMapper.insertSelective(record); | |||||
| } else { | |||||
| kwBoxCmdHistoryMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| kwBoxCmdHistoryMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public List<KwBoxCmdHistory> findList(KwBoxCmdHistory record) { | |||||
| return kwBoxCmdHistoryMapper.findList(record); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,60 @@ | |||||
| package com.iformall.service.kw.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwBoxMeter; | |||||
| import com.iformall.mapper.KwBoxMeterMapper; | |||||
| import com.iformall.service.kw.KwBoxMeterService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.List; | |||||
| @Service | |||||
| public class KwBoxMeterServiceImpl implements KwBoxMeterService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| KwBoxMeterMapper kwBoxMeterMapper; | |||||
| @Override | |||||
| public PageInfo<KwBoxMeter> listAsPage(KwBoxMeter record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> kwBoxMeterMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public KwBoxMeter getById(Long id) { | |||||
| return kwBoxMeterMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public ResultData saveOrUpdate(KwBoxMeter record) { | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| kwBoxMeterMapper.insertSelective(record); | |||||
| } else { | |||||
| kwBoxMeterMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| kwBoxMeterMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public List<KwBoxMeter> findList(KwBoxMeter record) { | |||||
| return kwBoxMeterMapper.findList(record); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,150 @@ | |||||
| package com.iformall.service.kw.impl; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwBox; | |||||
| import com.iformall.domain.po.KwBoxMeter; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import com.iformall.domain.po.KwMeterData; | |||||
| import com.iformall.enums.EnumBoxMeterStatus; | |||||
| import com.iformall.mapper.KwBoxMapper; | |||||
| import com.iformall.service.kw.KwBoxMeterService; | |||||
| import com.iformall.service.kw.KwBoxService; | |||||
| import com.iformall.service.kw.KwMeterDataService; | |||||
| import com.iformall.service.kw.KwMeterService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @Service | |||||
| public class KwBoxServiceImpl implements KwBoxService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| KwBoxMapper kwBoxMapper; | |||||
| @Autowired | |||||
| KwMeterDataService kwMeterDataService; | |||||
| @Autowired | |||||
| KwBoxMeterService kwBoxMeterService; | |||||
| @Autowired | |||||
| KwMeterService kwMeterService; | |||||
| @Override | |||||
| public PageInfo<KwBox> listAsPage(KwBox record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> kwBoxMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public KwBox getById(Long id) { | |||||
| return kwBoxMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public ResultData saveOrUpdate(KwBox record) { | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| kwBoxMapper.insertSelective(record); | |||||
| } else { | |||||
| kwBoxMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| kwBoxMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public List<KwBox> findList(KwBox record) { | |||||
| return kwBoxMapper.findList(record); | |||||
| } | |||||
| @Override | |||||
| public KwBox findByImei(String imei) { | |||||
| KwBox kwBox = new KwBox(); | |||||
| kwBox.setImei(imei); | |||||
| List<KwBox> kwBoxes = findList(kwBox); | |||||
| if (kwBoxes.size() > 0) | |||||
| return kwBoxes.get(0); | |||||
| return null; | |||||
| } | |||||
| @Override | |||||
| public KwMeterData saveMeterData(KwBox record, Date deviceTime, String addr, String data){ | |||||
| KwMeter kwMeter = findMeter(record, addr); | |||||
| if (kwMeter==null) return null; | |||||
| KwMeterData kwMeterData = new KwMeterData(); | |||||
| kwMeterData.setTenantId(record.getTenantId()); | |||||
| kwMeterData.setUpdateTime(new Date()); | |||||
| kwMeterData.setAddress(addr); | |||||
| kwMeterData.setBoxId(record.getId()); | |||||
| kwMeterData.setCreateTime(new Date()); | |||||
| kwMeterData.setDeviceTime(deviceTime); | |||||
| kwMeterData.setMeterId(kwMeter.getId()); | |||||
| kwMeterData.setResult(data); | |||||
| kwMeterDataService.saveOrUpdate(kwMeterData); | |||||
| return kwMeterData; | |||||
| } | |||||
| @Override | |||||
| public List<String> findMeters(KwBox record) { | |||||
| KwBoxMeter kwBoxMeter = new KwBoxMeter(); | |||||
| kwBoxMeter.setBoxId(record.getId()); | |||||
| kwBoxMeter.setStatus(EnumBoxMeterStatus.VALID.getCode()); | |||||
| List<KwBoxMeter> kwBoxMeters = kwBoxMeterService.findList(kwBoxMeter); | |||||
| KwMeter kwMeter = new KwMeter(); | |||||
| kwMeter.setIds(kwBoxMeters.stream().map(KwBoxMeter::getMeterId).collect(Collectors.toList())); | |||||
| List<KwMeter> kwMeters = kwMeterService.findList(kwMeter); | |||||
| return kwMeters.stream().map(KwMeter::getAddress).collect(Collectors.toList()); | |||||
| } | |||||
| @Override | |||||
| public KwMeter findMeter(KwBox record, String addr) { | |||||
| KwBoxMeter kwBoxMeter = new KwBoxMeter(); | |||||
| kwBoxMeter.setBoxId(record.getId()); | |||||
| kwBoxMeter.setStatus(EnumBoxMeterStatus.VALID.getCode()); | |||||
| List<KwBoxMeter> kwBoxMeters = kwBoxMeterService.findList(kwBoxMeter); | |||||
| KwMeter kwMeter = new KwMeter(); | |||||
| kwMeter.setAddress(addr); | |||||
| kwMeter.setIds(kwBoxMeters.stream().map(KwBoxMeter::getMeterId).collect(Collectors.toList())); | |||||
| List<KwMeter> kwMeters = kwMeterService.findList(kwMeter); | |||||
| if (kwMeters.size() > 0) | |||||
| return kwMeters.get(0); | |||||
| else | |||||
| return null; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,60 @@ | |||||
| package com.iformall.service.kw.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwMeterData; | |||||
| import com.iformall.mapper.KwMeterDataMapper; | |||||
| import com.iformall.service.kw.KwMeterDataService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.List; | |||||
| @Service | |||||
| public class KwMeterDataServiceImpl implements KwMeterDataService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| KwMeterDataMapper kwMeterDataMapper; | |||||
| @Override | |||||
| public PageInfo<KwMeterData> listAsPage(KwMeterData record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> kwMeterDataMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public KwMeterData getById(Long id) { | |||||
| return kwMeterDataMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public ResultData saveOrUpdate(KwMeterData record) { | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| kwMeterDataMapper.insertSelective(record); | |||||
| } else { | |||||
| kwMeterDataMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| kwMeterDataMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public List<KwMeterData> findList(KwMeterData record) { | |||||
| return kwMeterDataMapper.findList(record); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,60 @@ | |||||
| package com.iformall.service.kw.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.KwMeter; | |||||
| import com.iformall.mapper.KwMetersMapper; | |||||
| import com.iformall.service.kw.KwMeterService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.List; | |||||
| @Service | |||||
| public class KwMeterServiceImpl implements KwMeterService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| KwMetersMapper kwMetersMapper; | |||||
| @Override | |||||
| public PageInfo<KwMeter> listAsPage(KwMeter record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> kwMetersMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public KwMeter getById(Long id) { | |||||
| return kwMetersMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public ResultData saveOrUpdate(KwMeter record) { | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| kwMetersMapper.insertSelective(record); | |||||
| } else { | |||||
| kwMetersMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| kwMetersMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public List<KwMeter> findList(KwMeter record) { | |||||
| return kwMetersMapper.findList(record); | |||||
| } | |||||
| } | |||||
| @@ -37,7 +37,7 @@ | |||||
| <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.KwMeters" resultMap="BaseResultMap"> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.KwMeter" resultMap="BaseResultMap"> | |||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from kw_box_cmd_history | from kw_box_cmd_history | ||||
| @@ -39,7 +39,7 @@ | |||||
| <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.KwMeters" resultMap="BaseResultMap"> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.KwMeter" resultMap="BaseResultMap"> | |||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from kw_box_meter | from kw_box_meter | ||||
| @@ -39,7 +39,7 @@ | |||||
| <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.KwMeters" resultMap="BaseResultMap"> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.KwMeter" resultMap="BaseResultMap"> | |||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from kw_box_meter | from kw_box_meter | ||||
| @@ -37,7 +37,7 @@ | |||||
| <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.KwMeters" resultMap="BaseResultMap"> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.KwMeter" resultMap="BaseResultMap"> | |||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from kw_box_cmd_history | from kw_box_cmd_history | ||||
| @@ -1,7 +1,7 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | <?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"> | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="com.iformall.mapper.KwMetersMapper"> | <mapper namespace="com.iformall.mapper.KwMetersMapper"> | ||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.KwMeters"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.KwMeter"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | <id column="id" jdbcType="BIGINT" property="id"/> | ||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | ||||
| <result column="address" jdbcType="BIGINT" property="address"/> | <result column="address" jdbcType="BIGINT" property="address"/> | ||||
| @@ -60,7 +60,7 @@ | |||||
| <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.KwMeters" resultMap="BaseResultMap"> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.KwMeter" resultMap="BaseResultMap"> | |||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from kw_meters | from kw_meters | ||||