Commit de065c29 by 杨林龙

车辆试驾数据

1 parent 4ed46c84
......@@ -24,10 +24,10 @@
<groupId>com.glsx</groupId>
<artifactId>rest-admin-alliance</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.glsx</groupId>-->
<!-- <artifactId>rest-admin-kafka-ancient</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.glsx</groupId>-->
<!-- <artifactId>rest-admin-kafka-ancient</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis</artifactId>
......@@ -73,6 +73,27 @@
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx.poi</groupId>
<artifactId>glsx-poi-jar</artifactId>
<version>2.0.0-SNAPSHOT</version>
<exclusions>
<!-- 拉取版本不对???-->
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
......
......@@ -43,4 +43,47 @@ public class ConstantsElectricFence {
* 电子围栏 修改状态
*/
public static final Integer ELECTRIC_FENCE_UPDATE = 4;
/**
* 今天
*/
public static final int TIMETYPE_TODAY = 1;
/**
* 昨天
*/
public static final int TIMETYPE_YESTERDAY = 2;
/**
* 本周
*/
public static final int TIMETYPE_THISWEEK = 3;
/**
* 上周
*/
public static final int TIMETYPE_LASTWEEK = 4;
/**
* 本月
*/
public static final int TIMETYPE_THISMONTH = 5;
/**
* 上月
*/
public static final int TIMETYPE_LASTMONTH = 6;
/**
* 时间段
*/
public static final int TIMETYPE_SCOPE = 7;
/**
* 近七天
*/
public static final int TIMETYPE_IN_7_DAYS = 10;
/**
* 近30天
*/
public static final int TIMETYPE_IN_30_DAYS = 11;
/**
* 时间段 带时间
*/
public static final int TIMETYPE_SCOPE_WITH_TIME = 12;
}
package cn.com.glsx.admin.modules.controller;
import cn.com.glsx.admin.modules.model.EffectiveTestDriveDTO;
import cn.com.glsx.admin.modules.model.excel.EffectiveTestDriveReportExcel;
import cn.com.glsx.admin.modules.service.EffectiveTestDriveReportService;
import cn.com.glsx.admin.modules.utils.FileIOUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.core.web.R;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
/**
* 项目名:oms-tiger-shield
* 包名: com.glsx.oms.basic.biz.businessmanage.reportmanager.controller
* 作者: Yanglinlong
* 日期: 2021/5/6 10:46
*/
@RestController
@RequestMapping(value = "/report/effectiveTestDriveReport")
public class EffectiveTestDriveReportController {
protected final Logger logger = LoggerFactory.getLogger(EffectiveTestDriveReportController.class);
@Autowired
private EffectiveTestDriveReportService effectiveTestDriveReportService;
@GetMapping("/listEffectiveTestDriveReportPage")
@ResponseBody
public R listGqWindReportPage(EffectiveTestDriveDTO reportRequest, Page page) {
try {
PageHelper.startPage(page.getPageNum(), page.getPageSize(), true);
// 优先查询试驾 d_electric_fence_drive 表获取分页页数
List<EffectiveTestDriveReportExcel> testDrivePageList = effectiveTestDriveReportService.getTestDrivePageList(reportRequest);
// 获取报表详细数据
List<EffectiveTestDriveReportExcel> reportList = effectiveTestDriveReportService.listEffectiveTestDriveReportPage(reportRequest, testDrivePageList);
if (CollectionUtils.isNotEmpty(reportList) && CollectionUtils.isNotEmpty(testDrivePageList)) {
long total = ((Page<EffectiveTestDriveReportExcel>) testDrivePageList).getTotal();
return R.ok();
}
return R.ok();
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@RequestMapping(value = "/exportEffectiveTestDriveReport")
@SysLog("导出试驾车辆数据")
public void exportGqWindReport(EffectiveTestDriveDTO reportRequest, HttpServletResponse response) {
try {
String fileName = "有效试驾次数统计(按日" + DateFormatUtils.format(new Date(), "yyyy-MM-dd") + ")表";
// 优先查询试驾 d_electric_fence_drive 表获取分页页数
List<EffectiveTestDriveReportExcel> testDrivePageList = effectiveTestDriveReportService.getTestDrivePageList(reportRequest);
// 封装数据
InputStream inputStream = effectiveTestDriveReportService.exportEffectiveTestDriveReport(reportRequest, testDrivePageList);
FileIOUtil.download(inputStream, FileIOUtil.MimeType.EXCEL2007, fileName, response);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("exportEffectiveTestDriveReport wrong message:" + e.getMessage());
} finally {
try {
IOUtils.closeQuietly(response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
return;
}
@GetMapping(value = "/getYearWithData")
@ResponseBody
@SysLog("获取下拉选接口")
public R getYearWithData() {
List<String> yearList = effectiveTestDriveReportService.getYearWithData();
return R.ok().data(yearList);
}
}
package cn.com.glsx.admin.modules.entity;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import static javax.persistence.GenerationType.IDENTITY;
/**
* 项目名:oms-tiger-shield
* 包名: com.glsx.oms.basic.biz.businessmanage.reportmanager.model
* 作者: Yanglinlong
* 日期: 2021/5/6 17:01
*/
@Table(name = "d_electric_fence_drive")
public class ElectricFenceDrive implements Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
private Integer id;
@Column(name = "sn")
private String sn;
@Column(name = "fence_id")
private Integer fenceId;
@Column(name = "sve_system_id")
private Integer sveSystemId;
@Column(name = "journey_time")
private Integer journeyTime;
@Column(name = "percent")
private Integer percent;
@Column(name = "create_time")
private Date createTime;
@Column(name = "update_time")
private Date updateTime;
@Transient
private String shopCode;
@Transient
private String shopName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public Integer getFenceId() {
return fenceId;
}
public void setFenceId(Integer fenceId) {
this.fenceId = fenceId;
}
public Integer getSveSystemId() {
return sveSystemId;
}
public void setSveSystemId(Integer sveSystemId) {
this.sveSystemId = sveSystemId;
}
public Integer getJourneyTime() {
return journeyTime;
}
public void setJourneyTime(Integer journeyTime) {
this.journeyTime = journeyTime;
}
public Integer getPercent() {
return percent;
}
public void setPercent(Integer percent) {
this.percent = percent;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getShopCode() {
return shopCode;
}
public void setShopCode(String shopCode) {
this.shopCode = shopCode;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
}
package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.ElectricFenceDrive;
import cn.com.glsx.admin.modules.model.EffectiveTestDriveDTO;
import cn.com.glsx.admin.modules.model.excel.EffectiveTestDriveReportExcel;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 试驾数据Mapper层
*/
@Mapper
public interface EffectiveTestDriveReportMapper extends CommonBaseMapper<ElectricFenceDrive> {
List<EffectiveTestDriveReportExcel> getTestDrivePageList(EffectiveTestDriveDTO reportRequest);
List<EffectiveTestDriveReportExcel> getEffectiveTestDriveData(EffectiveTestDriveDTO reportRequest);
List<String> getYearWithData();
}
package cn.com.glsx.admin.modules.model;
import java.util.List;
/**
* @Desc:报表管理(广汽)页面请求参数实体
* @Author huangxc
* @Date 2021/4/6
*/
public class EffectiveTestDriveDTO {
/**
* 勾选的id
*/
private List<String> idList;
/**
* 限制展示的车辆
*/
private List<String> splitList;
/**
* 广本分组ID
*/
private Integer guangBenClassId;
/**
* sn 号
*/
private String sn;
/**
* 查询年份
*/
private String year;
/**
* 查询月份
*/
private String month;
/**
* 特约店代码
*/
private String shopCode;
/**
* 特约店名称
*/
private String shopName;
public List<String> getIdList() {
return idList;
}
public void setIdList(List<String> idList) {
this.idList = idList;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getShopCode() {
return shopCode;
}
public void setShopCode(String shopCode) {
this.shopCode = shopCode;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public List<String> getSplitList() {
return splitList;
}
public void setSplitList(List<String> splitList) {
this.splitList = splitList;
}
public Integer getGuangBenClassId() {
return guangBenClassId;
}
public void setGuangBenClassId(Integer guangBenClassId) {
this.guangBenClassId = guangBenClassId;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
}
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.modules.model.EffectiveTestDriveDTO;
import cn.com.glsx.admin.modules.model.excel.EffectiveTestDriveReportExcel;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* 试驾数据服务层
*/
public interface EffectiveTestDriveReportService {
List<EffectiveTestDriveReportExcel> getTestDrivePageList(EffectiveTestDriveDTO reportRequest);
List<EffectiveTestDriveReportExcel> listEffectiveTestDriveReportPage(EffectiveTestDriveDTO reportRequest, List<EffectiveTestDriveReportExcel> testDrivePageList);
InputStream exportEffectiveTestDriveReport(EffectiveTestDriveDTO reportRequest, List<EffectiveTestDriveReportExcel> testDrivePageList) throws IOException;
List<String> getYearWithData();
}
......@@ -7,6 +7,7 @@ import cn.com.glsx.admin.modules.mapper.ElectricFenceSnsMapper;
import cn.com.glsx.admin.modules.model.ElectricFenceBO;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.context.utils.PropertiesUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
......
package cn.com.glsx.admin.modules.utils;
import org.apache.commons.io.IOUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
/**
* 项目名:ne-shield-trialdrive-admin
* 包名: cn.com.glsx.admin.modules.utils
* 作者: Yanglinlong
* 日期: 2021/5/18 14:23
*/
public class FileIOUtil {
public enum MimeType {
STREAM("application/octet-stream", "jpg"),
PDF("application/pdf", "pdf"),
ZIP("application/zip", "zip"),
RAR("application/zip", "rar"),
EXCEL2003("application/vnd.ms-excel", "xls"),
EXCEL2007("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx"),
EXE("application/octet-stream", "exe"),
TXT("text/plain", "txt"),
JAVA("text/plain", "java"),
PYTHON("text/plain", "py"),
JAVASCRIPT("text/plain", "js"),
CSS("text/plain", "css"),
JPG("application/x-jpg", "jpg"),
JPEG("image/jpeg", "jpg"),
GIF("image/gif", "gif"),
PNG("application/x-png", "png");
private String contentType;
public final static String CHARSET = "UTF-8";
private String suffix;
public String getContentType() {
return contentType + ";charset=" + CHARSET;
}
private MimeType(String contentType, String suffix) {
this.contentType = contentType;
this.suffix = suffix;
}
public String getSuffix() {
return suffix;
}
}
public static void download(InputStream input, MimeType mime, String fileName, HttpServletResponse response) throws IOException {
if (input == null) {
return;
}
response.setContentType(mime.getContentType());
response.setHeader("Set-Cookie", "fileDownload=true; path=/");
String encodeFileName = fileName + "." + mime.getSuffix();
response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(encodeFileName, "UTF-8"));
long length = input.available();
if (length != -1) {
response.setContentLength((int) length);
}
ServletOutputStream output = response.getOutputStream();
IOUtils.copy(input, output);
output.flush();
}
}
<?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.EffectiveTestDriveReportMapper">
<resultMap id="BaseResultMap"
type="cn.com.glsx.admin.modules.model.excel.EffectiveTestDriveReportExcel">
<result column="shopCode" jdbcType="VARCHAR" property="shopCode"/>
<result column="shopName" jdbcType="VARCHAR" property="shopName"/>
<result column="vehicleTypeName" jdbcType="VARCHAR" property="vehicleTypeName"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="standno" jdbcType="VARCHAR" property="standno"/>
<result column="statDate" jdbcType="VARCHAR" property="statDate"/>
<result column="cnt" jdbcType="INTEGER" property="cnt"/>
<result column="dayCount" jdbcType="INTEGER" property="dayCount"/>
<result column="cnttotal" jdbcType="INTEGER" property="cnttotal"/>
</resultMap>
<resultMap id="PageBaseMap"
type="cn.com.glsx.admin.modules.model.excel.EffectiveTestDriveReportExcel">
<result column="fenceId" jdbcType="INTEGER" property="fenceId"/>
<result column="electricFenceName" jdbcType="VARCHAR" property="electricFenceName"/>
<result column="shopCode" jdbcType="VARCHAR" property="shopCode"/>
<result column="shopName" jdbcType="VARCHAR" property="shopName"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="standno" jdbcType="VARCHAR" property="standno"/>
<result column="vehicleTypeName" jdbcType="VARCHAR" property="vehicleTypeName"/>
</resultMap>
<select id="getTestDrivePageList"
parameterType="com.glsx.oms.basic.biz.businessmanage.reportmanager.model.request.EffectiveTestDriveRequestModel"
resultMap="PageBaseMap">
SELECT
du.username shopCode,
du.userRemark shopName,
defs.sn,
defs.standno,
dvts.vehicle_type_name vehicleTypeName
from d_electric_fence_sns defs
inner join d_electric_fence def on def.id = defs.fenceId
left join d_user du on du.d_LoginUserId = def.loginUserId
left join d_vehicle dv on dv.standno = defs.standno
left join d_vehicle_type_standno dvts on dvts.standno = dv.standno
left join d_class dc on dv.classId = dc.classid
where defs.fenceId = def.id
and def.bizFenceType = 1
<if test="shopCode!=null and shopCode!=''">
and du.username like '%${shopCode}%'
</if>
<if test="shopName!=null and shopName!=''">
and du.userRemark like '%${shopName}%'
</if>
<if test="guangBenClassId != null and guangBenClassId != '' ">
and dc.vehicleGroupId = #{guangBenClassId,jdbcType=INTEGER}
</if>
and dvts.vehicle_type_name IN
<foreach collection="splitList" item="vehicleTypeName" index="index" open="(" close=")" separator=",">
#{vehicleTypeName}
</foreach>
order by def.id
</select>
<select id="getEffectiveTestDriveData"
parameterType="com.glsx.oms.basic.biz.businessmanage.reportmanager.model.request.EffectiveTestDriveRequestModel"
resultMap="BaseResultMap">
SELECT tall.shopCode, tall.shopName, tall.vehicleTypeName, tall.sn, tall.standno, left(tall.statDate,7)
statDate, tall.cnt, day(tall.statDate) dayCount , sum(cnt) cnttotal FROM
(select du.username shopCode, du.userRemark shopName, dvts.vehicle_type_name vehicleTypeName,
defdd.sn,
dv.standno, DATE_FORMAT(defdd.journey_time,'%Y-%m-%d') statDate, sum(case when defdd.percent >= 80 then 1 else 0
end) cnt
from d_electric_fence_drive defdd
left join d_electric_fence def on def.id = defdd.fence_id
left join d_track_info dti on dti.sn = defdd.sn
left join d_vehicle dv on dv.vehicleId = dti.vehicleId
left join d_vehicle_type_standno dvts on dvts.standno = dv.standno
left join d_user du on du.d_LoginUserId = def.loginUserId
<where>
<choose>
<when test="year != null and year != '' and month != null and month != '' ">
left(defdd.journey_time,7) = CONCAT(#{year,jdbcType=VARCHAR},'-',#{month,jdbcType=VARCHAR})
</when>
<otherwise>
<if test="year != null and year != '' ">
left(defdd.journey_time,4) = #{year,jdbcType=VARCHAR}
</if>
<if test="month != null and month != '' ">
right(left(journey_time,7),2) = #{month,jdbcType=VARCHAR}
</if>
</otherwise>
</choose>
<if test="shopCode !=null and shopCode != ''">
and du.username like '%${shopCode}%'
</if>
<if test="shopName !=null and shopName != ''">
and du.userRemark like '%${shopName}%'
</if>
<if test="sn !=null and sn != ''">
and defdd.sn = #{sn,jdbcType=VARCHAR}
</if>
and dvts.vehicle_type_name IN
<foreach collection="splitList" item="vehicleTypeName" index="index" open="(" close=")" separator=",">
#{vehicleTypeName}
</foreach>
</where>
GROUP BY defdd.sn,defdd.fence_id,statDate order by du.username) tall GROUP BY tall.shopCode, tall.sn,
tall.statDate ORDER BY tall.shopCode
</select>
<select id="getYearWithData" resultType="java.lang.String">
select distinct left(journey_time,4) from d_electric_fence_drive
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!