Commit a2f19790 authored by wujiang's avatar wujiang

添加同步接口

parent e0da6229
package com.yeejoin.amos.boot.module.hygf.api.tdenginemapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
......@@ -31,4 +32,16 @@ public interface TdHygfJpCollectorHistoryMapper extends BaseMapper<TdHygfJpColle
List<JpCollectorHistoryAllDto> allList(@Param("snCode") String snCode,
@Param("thirdStationId") String thirdStationId);
List<Map<String, Object>> dayToMonth(@Param("startTime") long startTime, @Param("endTime") long endTime);
List<Map<String, Object>> monthToYear(@Param("month") String month);
List<Map<String, Object>> yearToAll(@Param("year") String year);
void updateMonth(@Param("list") List<Map<String, Object>> list);
void updateYear(@Param("list") List<Map<String, Object>> list);
void updateAll(@Param("list") List<Map<String, Object>> list);
}
......@@ -11,7 +11,7 @@
AND `third_station_id` = #{thirdStationId}
</if>
<if test="startTime!=null and endTime!=null">
AND time BETWEEN #{startTime} AND #{endTime}
AND time &gt;= #{startTime} AND time &lt;= #{endTime}
</if>
</where>
</select>
......@@ -54,4 +54,49 @@
</if>
</where>
</select>
<select id="dayToMonth" resultType="Map">
SELECT sn_code,AVG(signal_strength) AS signal_strength,third_station_id,third_code FROM house_pv_data.td_hygf_jp_collector_history
<where>
<if test="startTime!=null and endTime!=null">
AND time &gt;= #{startTime} AND time &lt;= #{endTime}
</if>
</where>
GROUP BY sn_code,third_station_id,third_code
</select>
<select id="monthToYear" resultType="Map">
SELECT sn_code,AVG(signal_strength) AS signal_strength,third_station_id,third_code FROM house_pv_data.td_hygf_jp_collector_history_month
<where>
<if test="month!=null">
AND year_month = #{month}
</if>
</where>
GROUP BY sn_code,third_station_id,third_code
</select>
<select id="yearToAll" resultType="Map">
SELECT sn_code,AVG(signal_strength) AS signal_strength,third_station_id,third_code FROM house_pv_data.td_hygf_jp_collector_history_year
<where>
<if test="year!=null">
AND year = #{year}
</if>
</where>
GROUP BY sn_code,third_station_id,third_code
</select>
<insert id="updateMonth">
INSERT INTO house_pv_data.td_hygf_jp_collector_history_month VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.created_time},#{item.sn_code},#{item.signal_strength},#{item.third_station_id},#{item.third_code},#{item.day},#{item.year_month})
</foreach>
</insert>
<insert id="updateYear">
INSERT INTO house_pv_data.td_hygf_jp_collector_history_year VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.created_time},#{item.sn_code},#{item.signal_strength},#{item.third_station_id},#{item.third_code},#{item.month},#{item.year})
</foreach>
</insert>
<insert id="updateAll">
INSERT INTO house_pv_data.td_hygf_jp_collector_history_all VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.created_time},#{item.sn_code},#{item.signal_strength},#{item.third_station_id},#{item.third_code},#{item.year})
</foreach>
</insert>
</mapper>
......@@ -11,7 +11,7 @@
AND `third_station_id` = #{thirdStationId}
</if>
<if test="date!=null">
AND `date` LIKE '%'#{date}'%'
AND `date` LIKE #{date}
</if>
</where>
</select>
......
package com.yeejoin.amos.boot.module.hygf.biz.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import java.util.List;
import com.yeejoin.amos.boot.module.hygf.biz.service.impl.JpInverterElectricityServiceImpl;
......@@ -110,7 +109,7 @@ public class JpInverterElectricityController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET",value = "户用光伏监盘逆变器电能表列表全部数据查询", notes = "户用光伏监盘逆变器电能表列表全部数据查询")
@GetMapping(value = "/list")
public ResponseModel<List<JpInverterElectricityDto>> selectForList() {
return ResponseHelper.buildResponse(jpInverterElectricityServiceImpl.queryForJpInverterElectricityList());
public ResponseModel<List<JpInverterElectricityDto>> selectForList(@RequestParam(value = "id") String id) {
return ResponseHelper.buildResponse(jpInverterElectricityServiceImpl.queryForJpInverterElectricityList(id));
}
}
......@@ -171,4 +171,16 @@ public class TdHygfJpCollectorHistoryController extends BaseController {
public ResponseModel<List<JpCollectorHistoryAllDto>> allList(@RequestParam(value = "id") long id) {
return ResponseHelper.buildResponse(tdHygfJpCollectorHistoryServiceImpl.allList(id));
}
/**
* 列表全部数据查询
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "户用光伏监盘采集器历史表列表全部数据查询", notes = "户用光伏监盘采集器历史表列表全部数据查询")
@GetMapping(value = "/syncData")
public ResponseModel<Object> syncData() {
return ResponseHelper.buildResponse(tdHygfJpCollectorHistoryServiceImpl.syncData());
}
}
......@@ -135,7 +135,7 @@ public class TdHygfJpInverterHistoryController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "户用光伏监盘逆变器历史表列表全部数据查询", notes = "户用光伏监盘逆变器历史表列表全部数据查询")
@GetMapping(value = "/statistics")
public ResponseModel<Map<String, Object>> day(@RequestParam(value = "id") Long id,
public ResponseModel<Map<String, Object>> day(@RequestParam(value = "id") String id,
@RequestParam(value = "type") String type, @RequestParam(value = "date") String date) {
return ResponseHelper.buildResponse(tdHygfJpInverterHistoryServiceImpl.statistics(id,type,date));
}
......
package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import com.yeejoin.amos.boot.module.hygf.api.entity.JpInverter;
import com.yeejoin.amos.boot.module.hygf.api.entity.JpInverterElectricity;
import com.yeejoin.amos.boot.module.hygf.api.mapper.JpInverterElectricityMapper;
import com.yeejoin.amos.boot.module.hygf.api.service.IJpInverterElectricityService;
import com.yeejoin.amos.boot.module.hygf.api.dto.JpInverterElectricityDto;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
......@@ -16,7 +21,9 @@ import java.util.List;
* @date 2023-09-19
*/
@Service
public class JpInverterElectricityServiceImpl extends BaseService<JpInverterElectricityDto,JpInverterElectricity,JpInverterElectricityMapper> implements IJpInverterElectricityService {
public class JpInverterElectricityServiceImpl
extends BaseService<JpInverterElectricityDto, JpInverterElectricity, JpInverterElectricityMapper>
implements IJpInverterElectricityService {
/**
* 分页查询
*/
......@@ -27,7 +34,10 @@ public class JpInverterElectricityServiceImpl extends BaseService<JpInverterElec
/**
* 列表查询 示例
*/
public List<JpInverterElectricityDto> queryForJpInverterElectricityList() {
return this.queryForList("" , false);
public List<JpInverterElectricityDto> queryForJpInverterElectricityList(String id) {
LambdaQueryWrapper<JpInverterElectricity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(JpInverterElectricity::getInverterId, id);
List<JpInverterElectricity> list = this.list(wrapper);
return Bean.toModels(list, this.getModelClass());
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -59,10 +61,11 @@ public class TdHygfJpCollectorHistoryServiceImpl
*/
public List<JpCollectorHistoryMonthDto> monthList(long id, Date month) {
JpCollector collector = jpCollectorServiceImpl.getById(id);
Calendar cal = Calendar.getInstance();
cal.setTime(month);
String monthStr = String.valueOf(cal.get(Calendar.YEAR)) + "-" + String.valueOf(cal.get(Calendar.MONTH) + 1);
if (collector != null) {
return this.baseMapper.monthList(collector.getSnCode(), collector.getThirdStationId(),
month.toString());
return this.baseMapper.monthList(collector.getSnCode(), collector.getThirdStationId(), monthStr);
}
return new ArrayList<>();
}
......@@ -72,10 +75,11 @@ public class TdHygfJpCollectorHistoryServiceImpl
*/
public List<JpCollectorHistoryYearDto> yearList(long id, Date year) {
JpCollector collector = jpCollectorServiceImpl.getById(id);
Calendar cal = Calendar.getInstance();
cal.setTime(year);
String yearStr = String.valueOf(cal.get(Calendar.YEAR));
if (collector != null) {
return this.baseMapper.yearList(collector.getSnCode(), collector.getThirdStationId(),
year.toString());
return this.baseMapper.yearList(collector.getSnCode(), collector.getThirdStationId(), yearStr);
}
return new ArrayList<>();
}
......@@ -91,4 +95,38 @@ public class TdHygfJpCollectorHistoryServiceImpl
}
return new ArrayList<>();
}
public Object syncData() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
Date dayTime = cal.getTime();
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
// 月表
List<Map<String, Object>> monthList = this.baseMapper.dayToMonth(TimeUtil.getStartTimeOfDay(dayTime),
TimeUtil.getEndTimeOfDay(dayTime));
for (int i = 0; i < monthList.size(); i++) {
monthList.get(i).put("created_time", dayTime.getTime() + i);
monthList.get(i).put("day", day);
monthList.get(i).put("year_month", year + "-" + month);
}
this.baseMapper.updateMonth(monthList);
// 年表
List<Map<String, Object>> yearList = this.baseMapper.monthToYear(String.valueOf(year + "-" + month));
for (int i = 0; i < yearList.size(); i++) {
yearList.get(i).put("created_time", dayTime.getTime() + i);
yearList.get(i).put("month", month);
yearList.get(i).put("year", year);
}
this.baseMapper.updateYear(yearList);
// 总表
List<Map<String, Object>> allList = this.baseMapper.yearToAll(String.valueOf(year));
for (int i = 0; i < allList.size(); i++) {
allList.get(i).put("created_time", dayTime.getTime() + i);
allList.get(i).put("year", year);
}
this.baseMapper.updateAll(allList);
return null;
}
}
\ No newline at end of file
......@@ -45,11 +45,12 @@ public class TdHygfJpInverterHistoryServiceImpl
return this.queryForList("", false);
}
public Map<String, Object> statistics(Long id, String type, String date) {
public Map<String, Object> statistics(String id, String type, String date) {
JpInverter inverter = jpInverterServiceImpl.getById(id);
Double power = null, dailyReturn = null, hours = null;
Map<String, Object> map = new HashMap();
if (inverter != null) {
date = "%" + date + "%";
if ("day".equals(type)) {
map = this.baseMapper.sum(inverter.getSnCode(), inverter.getThirdStationId(), date);
} else if ("month".equals(type)) {
......@@ -60,6 +61,10 @@ public class TdHygfJpInverterHistoryServiceImpl
map = this.baseMapper.sum(inverter.getSnCode(), inverter.getThirdStationId(), date);
}
}
if(!map.containsKey("return"))
{
map.put("return", null);
}
if (map == null) {
map = new HashMap();
map.put("power", power);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment