Commit 7de8608d authored by wujiang's avatar wujiang

添加曲线接口

parent a2f19790
package com.yeejoin.amos.boot.module.hygf.api.tdenginemapper; package com.yeejoin.amos.boot.module.hygf.api.tdenginemapper;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -31,4 +32,16 @@ public interface TdHygfJpInvertorElecHistoryMapper extends BaseMapper<TdHygfJpIn ...@@ -31,4 +32,16 @@ public interface TdHygfJpInvertorElecHistoryMapper extends BaseMapper<TdHygfJpIn
List<JpInvertorElecHistoryAllDto> allList(@Param("snCode") String snCode, List<JpInvertorElecHistoryAllDto> allList(@Param("snCode") String snCode,
@Param("thirdStationId") String thirdStationId); @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);
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<if test="snCode!=null"> <if test="snCode!=null">
AND `sn_code` = #{snCode} AND `sn_code` = #{snCode}
</if> </if>
<if test="thirdStationId!=null"> <if test="thirdStationId!=null">
AND `third_station_id` = #{thirdStationId} AND `third_station_id` = #{thirdStationId}
</if> </if>
<if test="startTime!=null and endTime!=null"> <if test="startTime!=null and endTime!=null">
...@@ -54,4 +54,55 @@ ...@@ -54,4 +54,55 @@
</if> </if>
</where> </where>
</select> </select>
<select id="dayToMonth" resultType="Map">
SELECT sn_code,AVG(u_ac_voltage) AS u_ac_voltage,AVG(v_ac_voltage) AS v_ac_voltage,AVG(w_ac_voltage) AS w_ac_voltage,
AVG(u_ac_current) AS u_ac_current,AVG(v_ac_current) AS v_ac_current,AVG(w_ac_current) AS w_ac_current,third_station_id,third_code FROM house_pv_data.td_hygf_jp_invertor_elec_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(u_ac_voltage) AS u_ac_voltage,AVG(v_ac_voltage) AS v_ac_voltage,AVG(w_ac_voltage) AS w_ac_voltage,
AVG(u_ac_current) AS u_ac_current,AVG(v_ac_current) AS v_ac_current,AVG(w_ac_current) AS w_ac_current,third_station_id,third_code FROM house_pv_data.td_hygf_jp_invertor_elec_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(u_ac_voltage) AS u_ac_voltage,AVG(v_ac_voltage) AS v_ac_voltage,AVG(w_ac_voltage) AS w_ac_voltage,
AVG(u_ac_current) AS u_ac_current,AVG(v_ac_current) AS v_ac_current,AVG(w_ac_current) AS w_ac_current,third_station_id,third_code FROM house_pv_data.td_hygf_jp_invertor_elec_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_invertor_elec_history_month VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.created_time},#{item.sn_code},#{item.u_ac_voltage},#{item.v_ac_voltage},#{item.w_ac_voltage},
#{item.u_ac_current},#{item.v_ac_current},#{item.w_ac_current},#{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_invertor_elec_history_year VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.created_time},#{item.sn_code},#{item.u_ac_voltage},#{item.v_ac_voltage},#{item.w_ac_voltage},
#{item.u_ac_current},#{item.v_ac_current},#{item.w_ac_current},#{item.third_station_id},#{item.third_code},#{item.month},#{item.year})
</foreach>
</insert>
<insert id="updateAll">
INSERT INTO house_pv_data.td_hygf_jp_invertor_elec_history_all VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.created_time},#{item.sn_code},#{item.u_ac_voltage},#{item.v_ac_voltage},#{item.w_ac_voltage},
#{item.u_ac_current},#{item.v_ac_current},#{item.w_ac_current},#{item.third_station_id},#{item.third_code},#{item.year})
</foreach>
</insert>
</mapper> </mapper>
...@@ -171,4 +171,16 @@ public class TdHygfJpInvertorElecHistoryController extends BaseController { ...@@ -171,4 +171,16 @@ public class TdHygfJpInvertorElecHistoryController extends BaseController {
public ResponseModel<List<JpInvertorElecHistoryAllDto>> allList(@RequestParam(value = "id") long id) { public ResponseModel<List<JpInvertorElecHistoryAllDto>> allList(@RequestParam(value = "id") long id) {
return ResponseHelper.buildResponse(tdHygfJpInvertorElecHistoryServiceImpl.allList(id)); return ResponseHelper.buildResponse(tdHygfJpInvertorElecHistoryServiceImpl.allList(id));
} }
/**
* 列表全部数据查询
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "户用光伏监盘采集器历史表列表全部数据查询", notes = "户用光伏监盘采集器历史表列表全部数据查询")
@GetMapping(value = "/syncData")
public ResponseModel<Object> syncData() {
return ResponseHelper.buildResponse(tdHygfJpInvertorElecHistoryServiceImpl.syncData());
}
} }
package com.yeejoin.amos.boot.module.hygf.biz.service.impl; package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -59,9 +61,11 @@ public class TdHygfJpInvertorElecHistoryServiceImpl extends ...@@ -59,9 +61,11 @@ public class TdHygfJpInvertorElecHistoryServiceImpl extends
*/ */
public List<JpInvertorElecHistoryMonthDto> monthList(long id, Date month) { public List<JpInvertorElecHistoryMonthDto> monthList(long id, Date month) {
JpInverter invertor = jpInvertorServiceImpl.getById(id); JpInverter invertor = jpInvertorServiceImpl.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 (invertor != null) { if (invertor != null) {
return this.baseMapper.monthList(invertor.getSnCode(), invertor.getThirdStationId(), month.toString()); return this.baseMapper.monthList(invertor.getSnCode(), invertor.getThirdStationId(), monthStr);
} }
return new ArrayList<>(); return new ArrayList<>();
} }
...@@ -71,9 +75,11 @@ public class TdHygfJpInvertorElecHistoryServiceImpl extends ...@@ -71,9 +75,11 @@ public class TdHygfJpInvertorElecHistoryServiceImpl extends
*/ */
public List<JpInvertorElecHistoryYearDto> yearList(long id, Date year) { public List<JpInvertorElecHistoryYearDto> yearList(long id, Date year) {
JpInverter invertor = jpInvertorServiceImpl.getById(id); JpInverter invertor = jpInvertorServiceImpl.getById(id);
Calendar cal = Calendar.getInstance();
cal.setTime(year);
String yearStr = String.valueOf(cal.get(Calendar.YEAR));
if (invertor != null) { if (invertor != null) {
return this.baseMapper.yearList(invertor.getSnCode(), invertor.getThirdStationId(), year.toString()); return this.baseMapper.yearList(invertor.getSnCode(), invertor.getThirdStationId(), yearStr);
} }
return new ArrayList<>(); return new ArrayList<>();
} }
...@@ -89,4 +95,39 @@ public class TdHygfJpInvertorElecHistoryServiceImpl extends ...@@ -89,4 +95,39 @@ public class TdHygfJpInvertorElecHistoryServiceImpl extends
} }
return new ArrayList<>(); 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
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