| @@ -33,8 +33,6 @@ public class KwMerchantMeterController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private KwMerchantMeterService kwMerchantMeterService; | private KwMerchantMeterService kwMerchantMeterService; | ||||
| @Autowired | |||||
| private KwMeterDataService kwMeterDataService; | |||||
| @ApiOperation("设备列表") | @ApiOperation("设备列表") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @@ -7,10 +7,12 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.KwBox; | import com.iformall.domain.po.KwBox; | ||||
| import com.iformall.domain.po.KwMeter; | import com.iformall.domain.po.KwMeter; | ||||
| import com.iformall.domain.po.KwMeterData; | |||||
| import com.iformall.enums.EnumBoxStatus; | import com.iformall.enums.EnumBoxStatus; | ||||
| import com.iformall.enums.EnumMeterBindStatus; | import com.iformall.enums.EnumMeterBindStatus; | ||||
| import com.iformall.enums.EnumMeterStatus; | import com.iformall.enums.EnumMeterStatus; | ||||
| import com.iformall.service.kw.KwBoxService; | import com.iformall.service.kw.KwBoxService; | ||||
| import com.iformall.service.kw.KwMeterDataService; | |||||
| import com.iformall.service.kw.KwMeterService; | import com.iformall.service.kw.KwMeterService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -21,6 +23,7 @@ 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.ArrayList; | |||||
| import java.util.List; | import java.util.List; | ||||
| @RestController | @RestController | ||||
| @@ -32,6 +35,9 @@ public class KwMeterController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private KwMeterService kwMeterService; | private KwMeterService kwMeterService; | ||||
| @Autowired | |||||
| private KwMeterDataService kwMeterDataService; | |||||
| @Autowired | @Autowired | ||||
| private KwBoxService kwBoxService; | private KwBoxService kwBoxService; | ||||
| @@ -154,7 +160,7 @@ public class KwMeterController extends BaseController { | |||||
| KwMeter kwMeter = kwMeterService.getById(id); | KwMeter kwMeter = kwMeterService.getById(id); | ||||
| if (kwMeter == null) | if (kwMeter == null) | ||||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | ||||
| kwMeter.setLatestRecord(kwMeterDataService.findLastRecord(id)); | |||||
| return new ResultData(kwMeter); | return new ResultData(kwMeter); | ||||
| } | } | ||||
| @@ -0,0 +1,110 @@ | |||||
| package com.iformall.domain.dto; | |||||
| import com.iformall.domain.po.BaseEntity; | |||||
| import lombok.Data; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Data | |||||
| public class KwMerchantMeterDto extends BaseEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户名",name="name") | |||||
| private String merchantName; | |||||
| @io.swagger.annotations.ApiModelProperty(value="联系人",name="linkPerson") | |||||
| private String linkPerson; | |||||
| @io.swagger.annotations.ApiModelProperty(value="联系方式",name="linkPhone") | |||||
| private String linkPhone; | |||||
| @io.swagger.annotations.ApiModelProperty(value="状态0使用1作废",name="status") | |||||
| private Integer status; | |||||
| @io.swagger.annotations.ApiModelProperty(value="经营业态ID:参照wx_business表",name="businessId") | |||||
| private Integer businessId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="子业态",name="subBusinessId") | |||||
| private Integer subBusinessId; | |||||
| protected String sortColumns; | |||||
| @Override | |||||
| public String getSortColumns() { | |||||
| super.setSortColumns(this.sortColumns); | |||||
| return super.getSortColumns(); | |||||
| } | |||||
| @io.swagger.annotations.ApiModelProperty(value = "商户ID", name = "merchantId") | |||||
| private Long merchantId; | |||||
| public static enum Field { | |||||
| RecordStartTime_ASC("`recordStartTime` ASC"), | |||||
| RecordStartTime_DESC("`recordStartTime` DESC"), | |||||
| RecordEndTime_ASC("`recordEndTime` ASC"), | |||||
| RecordEndTime_DESC("`recordEndTime` DESC"), | |||||
| UsedPower_ASC("`usedPower` ASC"), | |||||
| UsedPower_DESC("`usedPower` DESC"), | |||||
| TotalEndTime_ASC("`totalPower` ASC"), | |||||
| TotalEndTime_DESC("`totalPower` DESC"), | |||||
| ReportTime_ASC("`reportTime` ASC"), | |||||
| ReportTime_DESC("`reportTime` DESC"); | |||||
| private String value; | |||||
| Field(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| public String getValue() { | |||||
| return value; | |||||
| } | |||||
| public void setCol(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return this.getValue(); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(Field... fields) { | |||||
| if (fields == null || fields.length == 0) { | |||||
| return; | |||||
| } | |||||
| for (int k = 0; k < fields.length; k++) { | |||||
| if (fields[k] == null) { | |||||
| return; | |||||
| } | |||||
| } | |||||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||||
| for (int k = 1; k < fields.length; k++) { | |||||
| sb.append(","); | |||||
| sb.append(fields[k].toString()); | |||||
| } | |||||
| this.sortColumns = sb.toString(); | |||||
| } | |||||
| public void setSortColumns(String sortColumns) { | |||||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||||
| return; | |||||
| } | |||||
| if (sortColumns.contains(",")) { | |||||
| String[] cols = sortColumns.split(","); | |||||
| List<Field> fList = new ArrayList(); | |||||
| for (int k = 0; k < cols.length; k++) { | |||||
| fList.add(Field.valueOf(cols[k])); | |||||
| } | |||||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||||
| } else { | |||||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -77,6 +77,9 @@ public class KwMeter extends BaseEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value = "状态0绑定1未绑定", name = "bindStatus") | @io.swagger.annotations.ApiModelProperty(value = "状态0绑定1未绑定", name = "bindStatus") | ||||
| private Integer bindStatus; | private Integer bindStatus; | ||||
| @Transient | |||||
| protected KwMeterData latestRecord; | |||||
| public static enum Field { | public static enum Field { | ||||
| Id_ASC("`id` ASC"), | Id_ASC("`id` ASC"), | ||||
| Id_DESC("`id` DESC"), | Id_DESC("`id` DESC"), | ||||
| @@ -4,6 +4,7 @@ import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.dto.KwMeterDataDto; | import com.iformall.domain.dto.KwMeterDataDto; | ||||
| import com.iformall.domain.po.KwMeterData; | import com.iformall.domain.po.KwMeterData; | ||||
| import com.iformall.domain.vo.KwMeterDataVo; | import com.iformall.domain.vo.KwMeterDataVo; | ||||
| import org.apache.ibatis.annotations.Param; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -19,6 +19,8 @@ public interface KwMeterDataService { | |||||
| List<KwMeterData> findLastRecordList(KwMeterData kwMeterData); | List<KwMeterData> findLastRecordList(KwMeterData kwMeterData); | ||||
| KwMeterData findLastRecord(Long meterId); | |||||
| int save(List<KwMeterData> recordList); | int save(List<KwMeterData> recordList); | ||||
| KwMeterDataVo getPower(KwMeterDataDto dto); | KwMeterDataVo getPower(KwMeterDataDto dto); | ||||
| @@ -64,6 +64,17 @@ public class KwMeterDataServiceImpl implements KwMeterDataService { | |||||
| return kwMeterDataMapper.findLastRecordList(kwMeterData); | return kwMeterDataMapper.findLastRecordList(kwMeterData); | ||||
| } | } | ||||
| @Override | |||||
| public KwMeterData findLastRecord(Long meterId) { | |||||
| KwMeterData kwMeterData = new KwMeterData(); | |||||
| kwMeterData.setMeterId(meterId); | |||||
| List<KwMeterData> list = kwMeterDataMapper.findLastRecordList(kwMeterData); | |||||
| if (list.size() > 0) | |||||
| return list.get(0); | |||||
| else return new KwMeterData(); | |||||
| } | |||||
| @Override | @Override | ||||
| public KwMeterDataVo getPower(KwMeterDataDto dto) | public KwMeterDataVo getPower(KwMeterDataDto dto) | ||||
| { | { | ||||
| @@ -62,7 +62,7 @@ | |||||
| <include refid="dynamicWhereConditions"/> | <include refid="dynamicWhereConditions"/> | ||||
| </select> | </select> | ||||
| <select id="findLastRecordList" parameterType="com.iformall.domain.po.KwMeter" resultMap="BaseResultMap"> | |||||
| <select id="findLastRecordList" parameterType="com.iformall.domain.po.KwMeterData" resultMap="BaseResultMap"> | |||||
| select | select | ||||
| <include refid="allColumns"/> | <include refid="allColumns"/> | ||||
| from kw_meter_data | from kw_meter_data | ||||
| @@ -74,10 +74,16 @@ | |||||
| from kw_meter_data | from kw_meter_data | ||||
| where | where | ||||
| `total_power` is not null | `total_power` is not null | ||||
| and `meter_id` in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| <if test=" null != meterId "> | |||||
| and `meter_id` = #{meterId} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and `meter_id` in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| group by `meter_id` | group by `meter_id` | ||||
| ) temp | ) temp | ||||
| where | where | ||||