Commit 405ce916 by 杨林龙

优化不在店统计逻辑,将不在店每天统计数据落库

1 parent 708d7b85
...@@ -82,5 +82,11 @@ public class ElectricInStoreDrive implements Serializable { ...@@ -82,5 +82,11 @@ public class ElectricInStoreDrive implements Serializable {
@Transient @Transient
private Integer instoreCnt; private Integer instoreCnt;
/**
* 每天在店数据的年月信息
*/
@Transient
private String statDate;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,6 @@ import cn.com.glsx.admin.modules.entity.ElectricInStoreDrive; ...@@ -4,7 +4,6 @@ import cn.com.glsx.admin.modules.entity.ElectricInStoreDrive;
import cn.com.glsx.admin.modules.mapper.ElectricInStoreDriveMapper; import cn.com.glsx.admin.modules.mapper.ElectricInStoreDriveMapper;
import cn.com.glsx.admin.modules.model.export.ElectricInStoreExport; import cn.com.glsx.admin.modules.model.export.ElectricInStoreExport;
import cn.com.glsx.admin.modules.model.param.ElectricInStoreSearch; import cn.com.glsx.admin.modules.model.param.ElectricInStoreSearch;
import cn.hutool.core.date.DateUtil;
import com.glsx.plat.common.utils.StringUtils; import com.glsx.plat.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -73,7 +72,7 @@ public class ElectricInStoreDriveService { ...@@ -73,7 +72,7 @@ public class ElectricInStoreDriveService {
// 组合每一天的数据 // 组合每一天的数据
for (ElectricInStoreDrive inStoreDrive : inStoreDataList) { for (ElectricInStoreDrive inStoreDrive : inStoreDataList) {
// 设置报表统计时间 // 设置报表统计时间
electricInStoreExport.setStatDate(DateUtil.format(inStoreDrive.getGpsTime(), "yyyy-MM")); electricInStoreExport.setStatDate(inStoreDrive.getStatDate());
summation = summation + inStoreDrive.getInstoreCnt(); summation = summation + inStoreDrive.getInstoreCnt();
switch (inStoreDrive.getDayOfMonth()) { switch (inStoreDrive.getDayOfMonth()) {
case 1: case 1:
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<resultMap id="InStoreDataMap" type="cn.com.glsx.admin.modules.entity.ElectricInStoreDrive"> <resultMap id="InStoreDataMap" type="cn.com.glsx.admin.modules.entity.ElectricInStoreDrive">
<result property="instoreCnt" column="instoreCnt" jdbcType="INTEGER"/> <result property="instoreCnt" column="instoreCnt" jdbcType="INTEGER"/>
<result property="gpsTime" column="gps_time" jdbcType="TIMESTAMP"/> <result property="statDate" column="statDate" jdbcType="VARCHAR"/>
<result property="dayOfMonth" column="dayOfMonth" jdbcType="INTEGER"/> <result property="dayOfMonth" column="dayOfMonth" jdbcType="INTEGER"/>
</resultMap> </resultMap>
...@@ -61,19 +61,33 @@ ...@@ -61,19 +61,33 @@
order by tu.account order by tu.account
</select> </select>
<!-- <select id="getInStoreDataList" resultMap="InStoreDataMap">-->
<!-- select-->
<!-- case when sum(case when teid.gps_state = 2 then 1 else 0 end) = count(1) then 1 else 0 end as instoreCnt,-->
<!-- teid.gps_time ,-->
<!-- day(teid.gps_time) as dayOfMonth-->
<!-- from t_electric_instore_drive teid-->
<!-- left join t_vehicle_device tvd on tvd.id = teid.vd_id-->
<!-- <where>-->
<!-- <if test="year != null and year != '' and month != null and month != '' ">-->
<!-- left(teid.gps_time,7) = CONCAT(#{year},'-',#{month})-->
<!-- </if>-->
<!-- and tvd.vehicle_id = #{vehicleId}-->
<!-- </where>-->
<!-- group by left(teid.gps_time,10)-->
<!-- </select>-->
<select id="getInStoreDataList" resultMap="InStoreDataMap"> <select id="getInStoreDataList" resultMap="InStoreDataMap">
select select tsid.instore_num as instoreCnt,
case when sum(case when teid.gps_state = 2 then 1 else 0 end) = count(1) then 1 else 0 end as instoreCnt, left(tsid.instore_time, 7) as statDate,
teid.gps_time , day(str_to_date(tsid.instore_time, '%Y-%m-%d')) as dayOfMonth
day(teid.gps_time) as dayOfMonth from t_statistics_instore_drive tsid
from t_electric_instore_drive teid left join t_vehicle_device tvd on tvd.id = tsid.vd_id
left join t_vehicle_device tvd on tvd.id = teid.vd_id
<where> <where>
<if test="year != null and year != '' and month != null and month != '' "> <if test="year != null and year != '' and month != null and month != '' ">
left(teid.gps_time,7) = CONCAT(#{year},'-',#{month}) left(tsid.instore_time,7) = CONCAT(#{year},'-',#{month})
</if> </if>
and tvd.vehicle_id = #{vehicleId} and tvd.vehicle_id = #{vehicleId}
</where> </where>
group by left(teid.gps_time,10)
</select> </select>
</mapper> </mapper>
...@@ -300,7 +300,7 @@ public class ElectricInStoreDriveServiceTest { ...@@ -300,7 +300,7 @@ public class ElectricInStoreDriveServiceTest {
@Test @Test
public void test03() { public void test03() {
ElectricInStoreSearch search = new ElectricInStoreSearch(); ElectricInStoreSearch search = new ElectricInStoreSearch();
search.setVehicleId(5498L); search.setVehicleId(39L);
List<ElectricInStoreDrive> inStoreDataList = inStoreDriveMapper.getInStoreDataList(search); List<ElectricInStoreDrive> inStoreDataList = inStoreDriveMapper.getInStoreDataList(search);
System.out.println("inStoreDataList = " + JSON.toJSONString(inStoreDataList)); System.out.println("inStoreDataList = " + JSON.toJSONString(inStoreDataList));
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!