Commit f7f7c94e by 杨林龙

优化试驾报表查询和数据导出

1 parent d0c261c3
...@@ -5,13 +5,11 @@ import cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch; ...@@ -5,13 +5,11 @@ import cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch;
import cn.com.glsx.admin.modules.service.TrialDriveReportService; import cn.com.glsx.admin.modules.service.TrialDriveReportService;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils; import com.glsx.plat.office.excel.EasyExcelUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -48,13 +46,7 @@ public class TrialDriveReportController { ...@@ -48,13 +46,7 @@ public class TrialDriveReportController {
// 优先查询试驾 d_electric_fence_drive 表获取分页页数 // 优先查询试驾 d_electric_fence_drive 表获取分页页数
List<TrialDriveReportExport> testDrivePageList = trialDriveReportService.search(search); List<TrialDriveReportExport> testDrivePageList = trialDriveReportService.search(search);
// 获取报表详细数据 return R.ok().data(testDrivePageList);
List<TrialDriveReportExport> reportList = trialDriveReportService.listEffectiveTestDriveReportPage(search, testDrivePageList);
if (CollectionUtils.isNotEmpty(testDrivePageList) && CollectionUtils.isNotEmpty(reportList)) {
return R.ok().putPageData(reportList, page.getTotal());
}
return R.ok().data("没有查询到任何数据");
} }
@GetMapping(value = "/export") @GetMapping(value = "/export")
...@@ -64,10 +56,8 @@ public class TrialDriveReportController { ...@@ -64,10 +56,8 @@ public class TrialDriveReportController {
String fileName = "有效试驾次数统计(按日" + DateFormatUtils.format(new Date(), "yyyy-MM-dd") + ")表"; String fileName = "有效试驾次数统计(按日" + DateFormatUtils.format(new Date(), "yyyy-MM-dd") + ")表";
// 优先查询试驾 d_electric_fence_drive 表获取分页页数 // 优先查询试驾 d_electric_fence_drive 表获取分页页数
List<TrialDriveReportExport> testDrivePageList = trialDriveReportService.search(search); List<TrialDriveReportExport> testDrivePageList = trialDriveReportService.search(search);
// 封装数据
List<TrialDriveReportExport> testDriveReportExcels = trialDriveReportService.exportEffectiveTestDriveReport(search, testDrivePageList); EasyExcelUtils.writeExcel(response, testDrivePageList, fileName, "有效试驾次数统计(按日)表", TrialDriveReportExport.class);
// 调用公用方法导出 excel表格
EasyExcelUtils.writeExcel(response, testDriveReportExcels, fileName, "有效试驾次数统计(按日)表", TrialDriveReportExport.class);
log.info("试驾报表导出===end"); log.info("试驾报表导出===end");
} }
......
package cn.com.glsx.admin.modules.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
* 试驾统计数据表
* @TableName t_statistics_fence_drive
*/
@Table(name="t_statistics_fence_drive")
@Data
public class StatisticsDrive implements Serializable {
/**
*
*/
@Id
private Integer id;
/**
* 设备号
*/
private String sn;
/**
* 有效试驾次数
*/
@Column(name = "drive_num")
private Integer driveNum;
/**
* 试驾日期
*/
@Column(name = "drive_time")
private String driveTime;
/**
* 创建时间
*/
@Column(name = "created_time")
private Date createdTime;
/**
* 更新时间
*/
@Column(name = "updated_time")
private Date updatedTime;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.StatisticsDrive;
import cn.com.glsx.admin.modules.model.export.TrialDriveReportExport;
import cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Entity generator.domain.StatisticsFenceDrive
*/
@Mapper
public interface StatisticsDriveMapper extends CommonBaseMapper<StatisticsDrive> {
List<TrialDriveReportExport> getTestDriveData(TrialDriveReportSearch search);
}
...@@ -14,7 +14,7 @@ import java.util.List; ...@@ -14,7 +14,7 @@ import java.util.List;
*/ */
@Mapper @Mapper
public interface TrialDriveReportMapper extends CommonBaseMapper<ElectricFenceDrive> { public interface TrialDriveReportMapper extends CommonBaseMapper<ElectricFenceDrive> {
@DataPerm(showSql = true) // @DataPerm(showSql = true)
List<TrialDriveReportExport> getTestDrivePageList(TrialDriveReportSearch search); List<TrialDriveReportExport> getTestDrivePageList(TrialDriveReportSearch search);
List<TrialDriveReportExport> getEffectiveTestDriveData(TrialDriveReportSearch search); List<TrialDriveReportExport> getEffectiveTestDriveData(TrialDriveReportSearch search);
......
package cn.com.glsx.admin.modules.model.export; package cn.com.glsx.admin.modules.model.export;
import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data; import lombok.Data;
...@@ -14,10 +13,6 @@ import lombok.Data; ...@@ -14,10 +13,6 @@ import lombok.Data;
public class TrialDriveReportExport { public class TrialDriveReportExport {
// 每种类型的统计数量 // 每种类型的统计数量
@ExcelIgnore @ExcelIgnore
private Integer cnt;
// 符合条件的所有的统计字段
@ExcelIgnore
private Integer cnttotal; private Integer cnttotal;
// 获取当前天数 // 获取当前天数
......
<?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">
<mapper namespace="cn.com.glsx.admin.modules.mapper.StatisticsDriveMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.admin.modules.entity.StatisticsDrive">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="sn" column="sn" jdbcType="VARCHAR"/>
<result property="driveNum" column="drive_num" jdbcType="INTEGER"/>
<result property="driveTime" column="drive_time" jdbcType="VARCHAR"/>
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
<result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,sn,drive_num,
drive_time,created_time,updated_time
</sql>
<select id="getTestDriveData" parameterType="cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch"
resultType="cn.com.glsx.admin.modules.model.export.TrialDriveReportExport">
select tsfd.drive_num as cnttotal,
left(tsfd.drive_time,7) as statDate,
day(str_to_date(tsfd.drive_time, '%Y-%m-%d')) as dayCount
from t_statistics_fence_drive tsfd
<where>
<choose>
<when test="year != null and year != '' and month != null and month != '' ">
left(tsfd.drive_time,7) = CONCAT(#{year},'-',#{month})
</when>
<otherwise>
<if test="year != null and year != '' ">
left(tsfd.drive_time,4) = #{year}
</if>
<if test="month != null and month != '' ">
right(left(tsfd.drive_time,7),2) = #{month}
</if>
</otherwise>
</choose>
<if test="sn != null and sn !=''">
and tsfd.sn = #{sn}
</if>
</where>
</select>
</mapper>
package cn.com.glsx.admin.modules.service; package cn.com.glsx.admin.modules.service;
import cn.com.glsx.Application; import cn.com.glsx.Application;
import cn.com.glsx.admin.modules.mapper.StatisticsDriveMapper;
import cn.com.glsx.admin.modules.model.export.TrialDriveReportExport; import cn.com.glsx.admin.modules.model.export.TrialDriveReportExport;
import cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch; import cn.com.glsx.admin.modules.model.param.TrialDriveReportSearch;
import cn.com.glsx.usercenter.api.dto.response.Organization; import cn.com.glsx.usercenter.api.dto.response.Organization;
import cn.com.glsx.usercenter.api.feign.OrganizationService; import cn.com.glsx.usercenter.api.feign.OrganizationService;
import cn.com.glsx.usercenter.api.feign.UserService; import cn.com.glsx.usercenter.api.feign.UserService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
...@@ -15,7 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,7 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
...@@ -32,10 +37,13 @@ public class TrialDriveReportServiceTest { ...@@ -32,10 +37,13 @@ public class TrialDriveReportServiceTest {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private StatisticsDriveMapper statisticsDriveMapper;
@Test @Test
public void search() { public void search() {
TrialDriveReportSearch trialDriveReportSearch = new TrialDriveReportSearch(); TrialDriveReportSearch trialDriveReportSearch = new TrialDriveReportSearch();
trialDriveReportSearch.setMonth("2"); // trialDriveReportSearch.setMonth("2");
List<TrialDriveReportExport> searchList = trialDriveReportService.search(trialDriveReportSearch); List<TrialDriveReportExport> searchList = trialDriveReportService.search(trialDriveReportSearch);
System.out.println("search = " + JSON.toJSONString(searchList)); System.out.println("search = " + JSON.toJSONString(searchList));
} }
...@@ -43,7 +51,7 @@ public class TrialDriveReportServiceTest { ...@@ -43,7 +51,7 @@ public class TrialDriveReportServiceTest {
@Test @Test
public void listEffectiveTestDriveReportPage() { public void listEffectiveTestDriveReportPage() {
TrialDriveReportSearch trialDriveReportSearch = new TrialDriveReportSearch(); TrialDriveReportSearch trialDriveReportSearch = new TrialDriveReportSearch();
trialDriveReportSearch.setMonth("02"); trialDriveReportSearch.setMonth("08");
List<TrialDriveReportExport> searchList = trialDriveReportService.search(trialDriveReportSearch); List<TrialDriveReportExport> searchList = trialDriveReportService.search(trialDriveReportSearch);
List<TrialDriveReportExport> reportExportList = trialDriveReportService.listEffectiveTestDriveReportPage(trialDriveReportSearch, searchList); List<TrialDriveReportExport> reportExportList = trialDriveReportService.listEffectiveTestDriveReportPage(trialDriveReportSearch, searchList);
System.out.println("reportExportList = " + JSON.toJSONString(reportExportList)); System.out.println("reportExportList = " + JSON.toJSONString(reportExportList));
...@@ -61,7 +69,31 @@ public class TrialDriveReportServiceTest { ...@@ -61,7 +69,31 @@ public class TrialDriveReportServiceTest {
userIdList.add(Long.parseLong("6576")); userIdList.add(Long.parseLong("6576"));
userIdList.add(Long.parseLong("6577")); userIdList.add(Long.parseLong("6577"));
R<List<Organization>> listR = organizationService.getOrgsByUserIds(userIdList); R<List<Organization>> listR = organizationService.getOrgsByUserIds(userIdList);
System.out.println(" = " +JSON.toJSONString(listR)); System.out.println(" = " + JSON.toJSONString(listR));
}
@Test
public void test05() {
Date date = DateUtils.addDays(new Date(), -1);
System.out.println("date = " + date);
}
@Test
public void test06() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
System.out.println("cal = " + new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));
}
@Test
public void test07() {
TrialDriveReportSearch search = new TrialDriveReportSearch();
search.setSn("8700922794");
search.setYear("2021");
search.setMonth("08");
List<TrialDriveReportExport> testDriveData = statisticsDriveMapper.getTestDriveData(search);
System.out.println("testDriveData = " + JSON.toJSONString(testDriveData));
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!