Commit de065c29 by 杨林龙

车辆试驾数据

1 parent 4ed46c84
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
<groupId>com.glsx</groupId> <groupId>com.glsx</groupId>
<artifactId>rest-admin-alliance</artifactId> <artifactId>rest-admin-alliance</artifactId>
</dependency> </dependency>
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>com.glsx</groupId>--> <!-- <groupId>com.glsx</groupId>-->
<!-- <artifactId>rest-admin-kafka-ancient</artifactId>--> <!-- <artifactId>rest-admin-kafka-ancient</artifactId>-->
<!-- </dependency>--> <!-- </dependency>-->
<dependency> <dependency>
<groupId>com.glsx</groupId> <groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis</artifactId> <artifactId>rest-admin-mybatis</artifactId>
...@@ -73,6 +73,27 @@ ...@@ -73,6 +73,27 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </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> </dependencies>
<build> <build>
......
...@@ -43,4 +43,47 @@ public class ConstantsElectricFence { ...@@ -43,4 +43,47 @@ public class ConstantsElectricFence {
* 电子围栏 修改状态 * 电子围栏 修改状态
*/ */
public static final Integer ELECTRIC_FENCE_UPDATE = 4; 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.model.excel;
import com.glsx.excel.poi.Version;
import com.glsx.excel.poi.annotation.ExcelColumn;
import com.glsx.excel.poi.annotation.ExcelExport;
/**
* @Desc:有效试驾次数统计(按日)表导出
* @Author yangll
* @Date 2021/1/19
*/
@ExcelExport(version = Version.EXCEL2007, autoWidth = true)
public class EffectiveTestDriveReportExcel {
// 围栏Id
private Integer fenceId;
// 围栏名
private String electricFenceName;
// 每种类型的统计数量
private Integer cnt;
// 符合条件的所有的统计字段
private Integer cnttotal;
// 获取当前天数
private Integer dayCount;
@ExcelColumn(value = "特约店代码", index = 0)
private String shopCode;
@ExcelColumn(value = "特约店名称", index = 1)
private String shopName;
@ExcelColumn(value = "车型", index = 2)
private String vehicleTypeName;
@ExcelColumn(value = "设备号", index = 3)
private String sn;
@ExcelColumn(value = "车架号VIN码", index = 4)
private String standno;
private String journeyTime;
// 年月
@ExcelColumn(value = "时间", index = 5)
private String statDate;
@ExcelColumn(value = "1日", index = 6)
private Integer dayNum1;
@ExcelColumn(value = "2日", index = 7)
private Integer dayNum2;
@ExcelColumn(value = "3日", index = 8)
private Integer dayNum3;
@ExcelColumn(value = "4日", index = 9)
private Integer dayNum4;
@ExcelColumn(value = "5日", index = 10)
private Integer dayNum5;
@ExcelColumn(value = "6日", index = 11)
private Integer dayNum6;
@ExcelColumn(value = "7日", index = 12)
private Integer dayNum7;
@ExcelColumn(value = "8日", index = 13)
private Integer dayNum8;
@ExcelColumn(value = "9日", index = 14)
private Integer dayNum9;
@ExcelColumn(value = "10日", index = 15)
private Integer dayNum10;
@ExcelColumn(value = "11日", index = 16)
private Integer dayNum11;
@ExcelColumn(value = "12日", index = 17)
private Integer dayNum12;
@ExcelColumn(value = "13日", index = 18)
private Integer dayNum13;
@ExcelColumn(value = "14日", index = 19)
private Integer dayNum14;
@ExcelColumn(value = "15日", index = 20)
private Integer dayNum15;
@ExcelColumn(value = "16日", index = 21)
private Integer dayNum16;
@ExcelColumn(value = "17日", index = 22)
private Integer dayNum17;
@ExcelColumn(value = "18日", index = 23)
private Integer dayNum18;
@ExcelColumn(value = "19日", index = 24)
private Integer dayNum19;
@ExcelColumn(value = "20日", index = 25)
private Integer dayNum20;
@ExcelColumn(value = "21日", index = 26)
private Integer dayNum21;
@ExcelColumn(value = "22日", index = 27)
private Integer dayNum22;
@ExcelColumn(value = "23日", index = 28)
private Integer dayNum23;
@ExcelColumn(value = "24日", index = 29)
private Integer dayNum24;
@ExcelColumn(value = "25日", index = 30)
private Integer dayNum25;
@ExcelColumn(value = "26日", index = 31)
private Integer dayNum26;
@ExcelColumn(value = "27日", index = 32)
private Integer dayNum27;
@ExcelColumn(value = "28日", index = 33)
private Integer dayNum28;
@ExcelColumn(value = "29日", index = 34)
private Integer dayNum29;
@ExcelColumn(value = "30日", index = 35)
private Integer dayNum30;
@ExcelColumn(value = "31日", index = 36)
private Integer dayNum31;
@ExcelColumn(value = "总计", index = 37)
private Integer summation;
public Integer getFenceId() {
return fenceId;
}
public void setFenceId(Integer fenceId) {
this.fenceId = fenceId;
}
public String getElectricFenceName() {
return electricFenceName;
}
public void setElectricFenceName(String electricFenceName) {
this.electricFenceName = electricFenceName;
}
public String getStatDate() {
return statDate;
}
public void setStatDate(String statDate) {
this.statDate = statDate;
}
public Integer getCnt() {
return cnt;
}
public void setCnt(Integer cnt) {
this.cnt = cnt;
}
public Integer getCnttotal() {
return cnttotal;
}
public void setCnttotal(Integer cnttotal) {
this.cnttotal = cnttotal;
}
public Integer getDayCount() {
return dayCount;
}
public void setDayCount(Integer dayCount) {
this.dayCount = dayCount;
}
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 String getVehicleTypeName() {
return vehicleTypeName;
}
public void setVehicleTypeName(String vehicleTypeName) {
this.vehicleTypeName = vehicleTypeName;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getStandno() {
return standno;
}
public void setStandno(String standno) {
this.standno = standno;
}
public String getJourneyTime() {
return journeyTime;
}
public void setJourneyTime(String journeyTime) {
this.journeyTime = journeyTime;
}
public Integer getDayNum1() {
return dayNum1;
}
public void setDayNum1(Integer dayNum1) {
this.dayNum1 = dayNum1;
}
public Integer getDayNum2() {
return dayNum2;
}
public void setDayNum2(Integer dayNum2) {
this.dayNum2 = dayNum2;
}
public Integer getDayNum3() {
return dayNum3;
}
public void setDayNum3(Integer dayNum3) {
this.dayNum3 = dayNum3;
}
public Integer getDayNum4() {
return dayNum4;
}
public void setDayNum4(Integer dayNum4) {
this.dayNum4 = dayNum4;
}
public Integer getDayNum5() {
return dayNum5;
}
public void setDayNum5(Integer dayNum5) {
this.dayNum5 = dayNum5;
}
public Integer getDayNum6() {
return dayNum6;
}
public void setDayNum6(Integer dayNum6) {
this.dayNum6 = dayNum6;
}
public Integer getDayNum7() {
return dayNum7;
}
public void setDayNum7(Integer dayNum7) {
this.dayNum7 = dayNum7;
}
public Integer getDayNum8() {
return dayNum8;
}
public void setDayNum8(Integer dayNum8) {
this.dayNum8 = dayNum8;
}
public Integer getDayNum9() {
return dayNum9;
}
public void setDayNum9(Integer dayNum9) {
this.dayNum9 = dayNum9;
}
public Integer getDayNum10() {
return dayNum10;
}
public void setDayNum10(Integer dayNum10) {
this.dayNum10 = dayNum10;
}
public Integer getDayNum11() {
return dayNum11;
}
public void setDayNum11(Integer dayNum11) {
this.dayNum11 = dayNum11;
}
public Integer getDayNum12() {
return dayNum12;
}
public void setDayNum12(Integer dayNum12) {
this.dayNum12 = dayNum12;
}
public Integer getDayNum13() {
return dayNum13;
}
public void setDayNum13(Integer dayNum13) {
this.dayNum13 = dayNum13;
}
public Integer getDayNum14() {
return dayNum14;
}
public void setDayNum14(Integer dayNum14) {
this.dayNum14 = dayNum14;
}
public Integer getDayNum15() {
return dayNum15;
}
public void setDayNum15(Integer dayNum15) {
this.dayNum15 = dayNum15;
}
public Integer getDayNum16() {
return dayNum16;
}
public void setDayNum16(Integer dayNum16) {
this.dayNum16 = dayNum16;
}
public Integer getDayNum17() {
return dayNum17;
}
public void setDayNum17(Integer dayNum17) {
this.dayNum17 = dayNum17;
}
public Integer getDayNum18() {
return dayNum18;
}
public void setDayNum18(Integer dayNum18) {
this.dayNum18 = dayNum18;
}
public Integer getDayNum19() {
return dayNum19;
}
public void setDayNum19(Integer dayNum19) {
this.dayNum19 = dayNum19;
}
public Integer getDayNum20() {
return dayNum20;
}
public void setDayNum20(Integer dayNum20) {
this.dayNum20 = dayNum20;
}
public Integer getDayNum21() {
return dayNum21;
}
public void setDayNum21(Integer dayNum21) {
this.dayNum21 = dayNum21;
}
public Integer getDayNum22() {
return dayNum22;
}
public void setDayNum22(Integer dayNum22) {
this.dayNum22 = dayNum22;
}
public Integer getDayNum23() {
return dayNum23;
}
public void setDayNum23(Integer dayNum23) {
this.dayNum23 = dayNum23;
}
public Integer getDayNum24() {
return dayNum24;
}
public void setDayNum24(Integer dayNum24) {
this.dayNum24 = dayNum24;
}
public Integer getDayNum25() {
return dayNum25;
}
public void setDayNum25(Integer dayNum25) {
this.dayNum25 = dayNum25;
}
public Integer getDayNum26() {
return dayNum26;
}
public void setDayNum26(Integer dayNum26) {
this.dayNum26 = dayNum26;
}
public Integer getDayNum27() {
return dayNum27;
}
public void setDayNum27(Integer dayNum27) {
this.dayNum27 = dayNum27;
}
public Integer getDayNum28() {
return dayNum28;
}
public void setDayNum28(Integer dayNum28) {
this.dayNum28 = dayNum28;
}
public Integer getDayNum29() {
return dayNum29;
}
public void setDayNum29(Integer dayNum29) {
this.dayNum29 = dayNum29;
}
public Integer getDayNum30() {
return dayNum30;
}
public void setDayNum30(Integer dayNum30) {
this.dayNum30 = dayNum30;
}
public Integer getDayNum31() {
return dayNum31;
}
public void setDayNum31(Integer dayNum31) {
this.dayNum31 = dayNum31;
}
public Integer getSummation() {
return summation;
}
public void setSummation(Integer summation) {
this.summation = summation;
}
}
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; ...@@ -7,6 +7,7 @@ import cn.com.glsx.admin.modules.mapper.ElectricFenceSnsMapper;
import cn.com.glsx.admin.modules.model.ElectricFenceBO; import cn.com.glsx.admin.modules.model.ElectricFenceBO;
import cn.com.glsx.auth.utils.ShieldContextHolder; import cn.com.glsx.auth.utils.ShieldContextHolder;
import com.glsx.plat.common.utils.DateUtils; import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.context.utils.PropertiesUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
......
package cn.com.glsx.admin.modules.service.impl;
import cn.com.glsx.admin.modules.controller.EffectiveTestDriveReportController;
import cn.com.glsx.admin.modules.mapper.EffectiveTestDriveReportMapper;
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.DateUtil;
import com.glsx.excel.poi.ExcelUtil;
import com.glsx.excel.poi.Version;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.context.utils.PropertiesUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
/**
* @Desc:
* @Author huangxc
* @Date 2021/2/26
*/
@Service
public class EffectiveTestDriveReportImpl implements EffectiveTestDriveReportService {
protected final Logger logger = LoggerFactory.getLogger(EffectiveTestDriveReportController.class);
@Autowired
private EffectiveTestDriveReportMapper effectiveTestDriveReportMapper;
@Override
public List<EffectiveTestDriveReportExcel> getTestDrivePageList(EffectiveTestDriveDTO reportRequest) {
String needToShowVehicleTypeList = PropertiesUtils.getProperty("glsx.effectivetestdrive.needtoshow");
Integer guangBenClassId = Integer.parseInt(PropertiesUtils.getProperty("glsx.effectivetestdrive.guangBenClassId"));
String[] splitArr = needToShowVehicleTypeList.split(",");
List<String> splitList = Arrays.asList(splitArr);
reportRequest.setSplitList(splitList);
reportRequest.setGuangBenClassId(guangBenClassId);
return effectiveTestDriveReportMapper.getTestDrivePageList(reportRequest);
}
@Override
public List<EffectiveTestDriveReportExcel> listEffectiveTestDriveReportPage(EffectiveTestDriveDTO reportRequest, List<EffectiveTestDriveReportExcel> testDrivePageList) {
String month = reportRequest.getMonth();
if (StringUtils.isNotEmpty(month) && StringUtils.isNotBlank(month) && Integer.parseInt(month) < 10) {
month = ("0").concat(month);
reportRequest.setMonth(month);
}
HashMap<String, EffectiveTestDriveReportExcel> excelHashMap = new HashMap<>();
// 需要展示的车型
String needToShowVehicleTypeList = PropertiesUtils.getProperty("glsx.effectivetestdrive.needtoshow");
String[] splitArr = needToShowVehicleTypeList.split(",");
List<String> splitList = Arrays.asList(splitArr);
for (EffectiveTestDriveReportExcel testDrivePage : testDrivePageList) {
reportRequest.setSplitList(splitList);
reportRequest.setSn(testDrivePage.getSn());
List<EffectiveTestDriveReportExcel> testDriveDataOneList = effectiveTestDriveReportMapper.getEffectiveTestDriveData(reportRequest);
excelHashMap = makeDriveData(testDriveDataOneList, testDrivePageList, reportRequest.getYear(), reportRequest.getMonth());
}
testDrivePageList = new ArrayList<>(excelHashMap.values());
// 将数据集合按照店代码排序
testDrivePageList.sort(new Comparator<EffectiveTestDriveReportExcel>() {
@Override
public int compare(EffectiveTestDriveReportExcel o1, EffectiveTestDriveReportExcel o2) {
return o1.getShopCode().compareToIgnoreCase(o2.getShopCode());
}
});
return testDrivePageList;
}
@Override
public InputStream exportEffectiveTestDriveReport(EffectiveTestDriveDTO reportRequest, List<EffectiveTestDriveReportExcel> testDrivePageList) throws IOException {
//获取查询的月参数
String month = reportRequest.getMonth();
if (StringUtils.isNotEmpty(month) && StringUtils.isNotBlank(month) && Integer.parseInt(month) < 10) {
month = ("0").concat(month);
reportRequest.setMonth(month);
}
HashMap<String, EffectiveTestDriveReportExcel> excelHashMap = new HashMap<>();
// 需要展示的车型
String needToShowVehicleTypeList = PropertiesUtils.getProperty("glsx.effectivetestdrive.needtoshow");
String[] splitArr = needToShowVehicleTypeList.split(",");
List<String> splitList = Arrays.asList(splitArr);
for (EffectiveTestDriveReportExcel testDrivePage : testDrivePageList) {
reportRequest.setSplitList(splitList);
reportRequest.setSn(testDrivePage.getSn());
List<EffectiveTestDriveReportExcel> testDriveDataOneList = effectiveTestDriveReportMapper.getEffectiveTestDriveData(reportRequest);
excelHashMap = makeDriveData(testDriveDataOneList, testDrivePageList, reportRequest.getYear(), reportRequest.getMonth());
}
List<EffectiveTestDriveReportExcel> effectiveTestDriveList = new ArrayList<>(excelHashMap.values());
if (CollectionUtils.isEmpty(effectiveTestDriveList)) {
return null;
}
// 将数据集合按照店代码排序
testDrivePageList.sort(new Comparator<EffectiveTestDriveReportExcel>() {
@Override
public int compare(EffectiveTestDriveReportExcel o1, EffectiveTestDriveReportExcel o2) {
return o1.getShopCode().compareToIgnoreCase(o2.getShopCode());
}
});
ExcelUtil<EffectiveTestDriveReportExcel> exportExcelUtil = new ExcelUtil<>(Version.EXCEL2007);
exportExcelUtil.exportDefaultStyle("有效试驾次数统计(按日)表", effectiveTestDriveList);
return exportExcelUtil.toInputStream();
}
@Override
public List<String> getYearWithData() {
// 获取有数据的年份
return effectiveTestDriveReportMapper.getYearWithData();
}
/**
* 集中处理一个sn每天的试驾数据
*
* @param testDriveDataOneList 一个Sn的试驾数据
* @param testDrivePageList 所有sn的数据
* @param year
* @param month
* @return
*/
private HashMap<String, EffectiveTestDriveReportExcel> makeDriveData(List<EffectiveTestDriveReportExcel> testDriveDataOneList, List<EffectiveTestDriveReportExcel> testDrivePageList, String year, String month) {
//获取查询的年月参数
String yearAndMonth = null;
if (StringUtils.isNotEmpty(year) && StringUtils.isNotBlank(year) && StringUtils.isNotEmpty(month) && StringUtils.isNotBlank(month)) {
yearAndMonth = year.concat("-").concat(month);
} else {
if (StringUtils.isNotEmpty(year) && StringUtils.isNotBlank(year)) {
yearAndMonth = year.concat("-01");
}
if (StringUtils.isNotEmpty(month) && StringUtils.isNotBlank(month)) {
yearAndMonth = DateUtil.getYearOfNow().concat("-").concat(month);
}
}
HashMap<String, EffectiveTestDriveReportExcel> excelHashMap = new HashMap<>();
HashMap<String, Integer> sumHashMap = new HashMap<>();
// 试驾表格需要展示的车辆类型
try {
// 初始化map中的每个对象
for (EffectiveTestDriveReportExcel drivePageExcel : testDrivePageList) {
excelHashMap.put(drivePageExcel.getShopCode() + drivePageExcel.getSn(), drivePageExcel);
sumHashMap.put(drivePageExcel.getShopCode() + drivePageExcel.getSn(), 0);
}
// 填充每一个有试驾车辆的数据
for (EffectiveTestDriveReportExcel driveDataOne : testDriveDataOneList) {
EffectiveTestDriveReportExcel driveReportData = new EffectiveTestDriveReportExcel();
int summation = 0;
switch (driveDataOne.getDayCount()) {
case 1:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum1(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 2:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum2(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 3:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum3(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 4:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum4(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 5:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum5(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 6:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum6(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 7:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum7(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 8:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum8(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 9:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum9(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 10:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum10(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 11:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum11(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 12:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum12(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 13:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum13(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 14:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum14(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 15:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum15(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 16:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum16(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 17:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum17(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 18:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum18(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 19:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum19(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 20:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum20(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 21:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum21(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 22:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum22(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 23:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum23(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 24:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum24(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 25:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum25(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 26:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum26(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 27:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum27(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 28:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum28(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 29:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum29(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 30:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum30(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
case 31:
driveReportData = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
driveReportData.setDayNum31(driveDataOne.getCnttotal());
summation = sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
summation += driveDataOne.getCnttotal();
sumHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), summation);
break;
default:
driveReportData.setDayNum1(0);
}
EffectiveTestDriveReportExcel testDriveReportExcel = excelHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn());
// 设置总计数量
testDriveReportExcel.setSummation(sumHashMap.get(driveDataOne.getShopCode() + driveDataOne.getSn()));
// 填充行程时间
testDriveReportExcel.setStatDate(driveDataOne.getStatDate());
// 将计算的数据重新放回map里面
excelHashMap.put(driveDataOne.getShopCode() + driveDataOne.getSn(), testDriveReportExcel);
}
// 将没有数据的部分用 O 替代
for (EffectiveTestDriveReportExcel drivePageExcel : testDrivePageList) {
// 获取当天的最大天数
int maxDayNum = 31;
if (StringUtils.isNotEmpty(year) && StringUtils.isNotBlank(year) && StringUtils.isNotEmpty(month) && StringUtils.isNotBlank(month)) {
maxDayNum = DateUtil.getDaysByYearMonth(Integer.parseInt(year), Integer.parseInt(month));
} else if (StringUtils.isNotEmpty(month) && StringUtils.isNotBlank(month)) {
maxDayNum = DateUtil.getDaysByYearMonth(Integer.parseInt(DateUtil.getYearOfNow()), Integer.parseInt(month));
}
if (maxDayNum >= 1) {
drivePageExcel.setDayNum1(replaceDayCount(drivePageExcel.getDayNum1()));
}
if (maxDayNum >= 2) {
drivePageExcel.setDayNum2(replaceDayCount(drivePageExcel.getDayNum2()));
}
if (maxDayNum >= 3) {
drivePageExcel.setDayNum3(replaceDayCount(drivePageExcel.getDayNum3()));
}
if (maxDayNum >= 4) {
drivePageExcel.setDayNum4(replaceDayCount(drivePageExcel.getDayNum4()));
}
if (maxDayNum >= 5) {
drivePageExcel.setDayNum5(replaceDayCount(drivePageExcel.getDayNum5()));
}
if (maxDayNum >= 6) {
drivePageExcel.setDayNum6(replaceDayCount(drivePageExcel.getDayNum6()));
}
if (maxDayNum >= 7) {
drivePageExcel.setDayNum7(replaceDayCount(drivePageExcel.getDayNum7()));
}
if (maxDayNum >= 8) {
drivePageExcel.setDayNum8(replaceDayCount(drivePageExcel.getDayNum8()));
}
if (maxDayNum >= 9) {
drivePageExcel.setDayNum9(replaceDayCount(drivePageExcel.getDayNum9()));
}
if (maxDayNum >= 10) {
drivePageExcel.setDayNum10(replaceDayCount(drivePageExcel.getDayNum10()));
}
if (maxDayNum >= 11) {
drivePageExcel.setDayNum11(replaceDayCount(drivePageExcel.getDayNum11()));
}
if (maxDayNum >= 12) {
drivePageExcel.setDayNum12(replaceDayCount(drivePageExcel.getDayNum12()));
}
if (maxDayNum >= 13) {
drivePageExcel.setDayNum13(replaceDayCount(drivePageExcel.getDayNum13()));
}
if (maxDayNum >= 14) {
drivePageExcel.setDayNum14(replaceDayCount(drivePageExcel.getDayNum14()));
}
if (maxDayNum >= 15) {
drivePageExcel.setDayNum15(replaceDayCount(drivePageExcel.getDayNum15()));
}
if (maxDayNum >= 16) {
drivePageExcel.setDayNum16(replaceDayCount(drivePageExcel.getDayNum16()));
}
if (maxDayNum >= 17) {
drivePageExcel.setDayNum17(replaceDayCount(drivePageExcel.getDayNum17()));
}
if (maxDayNum >= 18) {
drivePageExcel.setDayNum18(replaceDayCount(drivePageExcel.getDayNum18()));
}
if (maxDayNum >= 19) {
drivePageExcel.setDayNum19(replaceDayCount(drivePageExcel.getDayNum19()));
}
if (maxDayNum >= 20) {
drivePageExcel.setDayNum20(replaceDayCount(drivePageExcel.getDayNum20()));
}
if (maxDayNum >= 21) {
drivePageExcel.setDayNum21(replaceDayCount(drivePageExcel.getDayNum21()));
}
if (maxDayNum >= 22) {
drivePageExcel.setDayNum22(replaceDayCount(drivePageExcel.getDayNum22()));
}
if (maxDayNum >= 23) {
drivePageExcel.setDayNum23(replaceDayCount(drivePageExcel.getDayNum23()));
}
if (maxDayNum >= 24) {
drivePageExcel.setDayNum24(replaceDayCount(drivePageExcel.getDayNum24()));
}
if (maxDayNum >= 25) {
drivePageExcel.setDayNum25(replaceDayCount(drivePageExcel.getDayNum25()));
}
if (maxDayNum >= 26) {
drivePageExcel.setDayNum26(replaceDayCount(drivePageExcel.getDayNum26()));
}
if (maxDayNum >= 27) {
drivePageExcel.setDayNum27(replaceDayCount(drivePageExcel.getDayNum27()));
}
if (maxDayNum >= 28) {
drivePageExcel.setDayNum28(replaceDayCount(drivePageExcel.getDayNum28()));
}
if (maxDayNum >= 29) {
drivePageExcel.setDayNum29(replaceDayCount(drivePageExcel.getDayNum29()));
}
if (maxDayNum >= 30) {
drivePageExcel.setDayNum30(replaceDayCount(drivePageExcel.getDayNum30()));
}
if (maxDayNum >= 31) {
drivePageExcel.setDayNum31(replaceDayCount(drivePageExcel.getDayNum31()));
}
// 填充行程时间
drivePageExcel.setStatDate(replaceStatDate(drivePageExcel.getStatDate(), yearAndMonth));
// 设置总计算数
drivePageExcel.setSummation(replaceDayCount(drivePageExcel.getSummation()));
excelHashMap.put(drivePageExcel.getShopCode() + drivePageExcel.getSn(), drivePageExcel);
}
return excelHashMap;
} catch (Exception e) {
e.printStackTrace();
logger.info("EffectiveTestDriveReport error :" + e.getMessage());
}
logger.info("===== EffectiveTestDriveReport ====end====");
return excelHashMap;
}
private Integer replaceDayCount(Integer dayCount) {
return dayCount == null ? 0 : dayCount;
}
private String replaceStatDate(String statDate, String yearAndMonth) {
if (StringUtils.isNotEmpty(statDate)) {
return statDate;
}
if (StringUtils.isNotEmpty(yearAndMonth)) {
return yearAndMonth;
}
return DateUtil.getYearAndMonthYesterday();
}
public static void main(String[] args) {
String year = " ";
if (StringUtils.isNullOrEmpty(year) || StringUtils.isBlank(year)) {
System.out.println("true");
}
}
}
package cn.com.glsx.admin.modules.utils;
import cn.com.glsx.admin.common.constants.ConstantsElectricFence;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.utils.DateUtils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 日期工具类
*
* @author liuyf@didihu.com.cn
* @version 1.0
* @history 2017年9月7日 create by liuyf@didihu.com.cn
*/
public class DateUtil extends org.apache.commons.lang.time.DateUtils {
public static String YMDHMS = "yyyy-MM-dd HH:mm:ss";
public static String YMD = "yyyy-MM-dd";
public final static String[] pattern = {"yyyy-MM-dd HH:mm:ss"};
public enum TimeUnitType {
DAY(1), HOUR(2), MINUTE(3), SECOND(4);
private int value = 0;
TimeUnitType(int value) {
this.value = value;
}
public int value() {
return value;
}
}
public enum CustomTimeType {
TIMETYPE_TODAY(1),
/**
* 今天
*/
TIMETYPE_YESTERDAY(2),
/**
* 昨天
*/
TIMETYPE_THISWEEK(3),
/**
* 本周
*/
TIMETYPE_LASTWEEK(4),
/**
* 上周
*/
TIMETYPE_THISMONTH(5),
/**
* 本月
*/
TIMETYPE_LASTMONTH(6),
/**
* 上月
*/
TIMETYPE_SCOPE(7);
/**
* 时间段
*/
private int value = 0;
CustomTimeType(int value) {
this.value = value;
}
public int value() {
return value;
}
}
/**
* 获取当前时间
*
* @return
*/
public static Date getCurrentDate() {
return new Date(System.currentTimeMillis());
}
/**
* 格式化日期
*
* @param date
* @return
*/
public static Date parseDate(String date) {
return parseDate(date, "yyyy-MM-dd HH:mm:ss");
}
public static Date parseDateYmd(String date) {
return parseDate(date, "yyyy-MM-dd");
}
public static String formatDateYm(Date date) {
return formatDate(date, "yyyyMM");
}
public static String formatDate(Date date) {
return formatDate(date, "yyyy-MM-dd HH:mm:ss");
}
/**
* 返回格式 yyyy年MM月dd日HH时
*
* @param date
* @return
*/
public static String formatDateChineseYmdh(Date date) {
return formatDate(date, "yyyy年MM月dd日HH时");
}
/**
* 返回格式 yyyy年MM月dd日HH时mm分ss秒
*
* @param date
* @return
*/
public static String formatDateChineseYmdhms(Date date) {
return formatDate(date, "yyyy年MM月dd日HH时mm分ss秒");
}
public static String formatSerial(Date date) {
return formatDate(date, "yyyyMMddHHmmss");
}
public static String formatDateYmd(Date date) {
return formatDate(date, "yyyy-MM-dd");
}
public static String formatDate(Date date, String pattern) {
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
try {
return formatter.format(date);
} catch (Exception e) {
// TODO: handle exception
return null;
}
}
public static Date getBeforeOrAfterTime(Date date, TimeUnitType timeUnitType, int num) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if (TimeUnitType.SECOND.value() == timeUnitType.value()) {
cal.add(Calendar.SECOND, num);
} else if (TimeUnitType.MINUTE.value() == timeUnitType.value()) {
cal.add(Calendar.MINUTE, num);
} else if (TimeUnitType.HOUR.value() == timeUnitType.value()) {
cal.add(Calendar.HOUR, num);
} else if (TimeUnitType.DAY.value() == timeUnitType.value()) {
cal.add(Calendar.DATE, num);
}
return cal.getTime();
}
public static String getBeforeOrAfterTimeString(Date date, TimeUnitType timeUnitType, int num) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if (TimeUnitType.SECOND.value() == timeUnitType.value()) {
cal.add(Calendar.SECOND, num);
} else if (TimeUnitType.MINUTE.value() == timeUnitType.value()) {
cal.add(Calendar.MINUTE, num);
} else if (TimeUnitType.HOUR.value() == timeUnitType.value()) {
cal.add(Calendar.HOUR, num);
} else if (TimeUnitType.DAY.value() == timeUnitType.value()) {
cal.add(Calendar.DATE, num);
}
return formatDate(cal.getTime());
}
public static Date parseDate(String date, String pattern) {
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
try {
return formatter.parse(date);
} catch (ParseException e) {
return null;
}
}
/**
* 将时间置为23时59分钟59秒
*
* @param date
* @return
*/
public static Date setFullPassDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
}
/**
* 将时间后退2小时
*
* @param date
* @return
*/
public static Date getFallBack2Hour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY,
calendar.get(Calendar.HOUR_OF_DAY) - 2);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 将时间精确到小时
*
* @param date
* @return
*/
public static Date getTimeHour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 获取两个时间间隔的天数
*
* @param startDate
* @param endDate
* @return
*/
public static long getDiffDays(Date startDate, Date endDate) {
long difftime = endDate.getTime() - startDate.getTime();
return difftime / (24L * 60L * 60L * 1000L);
}
/**
* 根据日期获取当天起始时间
*
* @param date
* @return
*/
public static Date getStartDateOfCurrentDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
public static Date getStartYesterday(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, -1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 根据日期获取下一天起始时间
*
* @param date
* @return
*/
public static Date getStartDateOfNextDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 根据日期当前日期顺延一周后的起始时间
*
* @param date
* @return
*/
public static Date getStartDateOfNextSevenDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, 7);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 根据日期当前日期顺延一周后的起始时间
*
* @param date
* @return
*/
public static Date getStartDateOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 根据日期当前日期顺延一月后的起始时间
*
* @param date
* @return
*/
public static Date getStartDateOfNextMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/*
* 封装一天只能的时间区域
*/
public static List<Date> getStaticByDateDateArea(Date date) {
List<Date> dates = new ArrayList<Date>();
Date startdate = getStartDateOfCurrentDay(date);
Date nextday = getStartDateOfNextDay(date);
int step = 2;
dates.add(startdate);
for (int i = 1; i < 12; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startdate);
calendar.add(Calendar.HOUR_OF_DAY, i * step);
dates.add(calendar.getTime());
}
dates.add(nextday);
return dates;
}
/*
* 封装一周之内时间区域
*/
public static List<Date> getStaticByWeekDateArea(Date date) {
List<Date> dates = new ArrayList<Date>();
Date startdate = getStartDateOfCurrentDay(date);
Date nextday = getStartDateOfNextSevenDay(date);
dates.add(startdate);
for (int i = 1; i < 7; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startdate);
calendar.add(Calendar.DAY_OF_MONTH, i);
dates.add(calendar.getTime());
}
dates.add(nextday);
return dates;
}
/*
* 封装一周之内时间区域List<String>
*/
public static List<String> getStaticByWeekLabel(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd");
List<String> dates = new ArrayList<String>();
Date startdate = getStartDateOfCurrentDay(date);
dates.add(dateFormat.format(startdate));
for (int i = 1; i < 7; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startdate);
calendar.add(Calendar.DAY_OF_MONTH, i);
dates.add(dateFormat.format(calendar.getTime()));
}
return dates;
}
/*
* 封装一月之内时间区域
*/
public static List<Date> getStaticByMonthDateArea(Date date) {
List<Date> dates = new ArrayList<Date>();
Date startdate = getStartDateOfMonth(date);
Date nextday = getStartDateOfNextMonth(date);
long daydiff = getDiffDays(startdate, nextday);
dates.add(startdate);
for (int i = 1; i < daydiff; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startdate);
calendar.add(Calendar.DAY_OF_MONTH, i);
dates.add(calendar.getTime());
}
dates.add(nextday);
return dates;
}
/*
*封装一点时间之内的时间区域(天)
*/
public static List<Date> getStaticBySE(Date startDate, Date endDate) {
List<Date> dates = new ArrayList<Date>();
long daydiff = getDiffDays(startDate, endDate);
dates.add(startDate);
for (int i = 1; i < daydiff; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
calendar.add(Calendar.DAY_OF_MONTH, i);
dates.add(calendar.getTime());
}
dates.add(endDate);
return dates;
}
public static List<String> getStaticYMD(Date startDate, Date endDate) {
List<Date> dates = new ArrayList<Date>();
List<String> dateStr = new ArrayList<String>();
long daydiff = getDiffDays(startDate, endDate);
dateStr.add(DateUtils.formatDate(startDate, "YYYY-MM-dd"));
for (int i = 1; i < daydiff; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
calendar.add(Calendar.DAY_OF_MONTH, i);
dateStr.add(DateUtils.formatDate(calendar.getTime(), "YYYY-MM-dd"));
}
dateStr.add(DateUtils.formatDate(endDate, "YYYY-MM-dd"));
return dateStr;
}
/*
* 封装一月之内时间区域
*/
public static List<String> getStaticByMonthLabel(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd");
List<String> dates = new ArrayList<String>();
Date startdate = getStartDateOfMonth(date);
Date nextday = getStartDateOfNextMonth(date);
long daydiff = getDiffDays(startdate, nextday);
dates.add(dateFormat.format(startdate));
for (int i = 1; i < daydiff; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(startdate);
calendar.add(Calendar.DAY_OF_MONTH, i);
dates.add(dateFormat.format(calendar.getTime()));
}
return dates;
}
public static String formatDate(String format, Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
}
/**
* 根据时间段拼装sql语句
* 时间段查询,例:DateUtils.appendSqlByTimeRange(Constants.TIMETYPE_SCOPE, "t.createtime", "2014-09-17", "2014-09-18");
*
* @param timeRange 查询时间:全部-0、今天-1、昨天-2、本周-3、上周-4、本月-5、上月-6、时间段-7、近12小时-8、近24小时-9、近7天-10、近30天-11
* @param field 字段名,例:t.createtime
* @param times 时间段查询,开始时间和结束时间
* @return 2017.9.7 mym 修改 新增 近7天 近30天
*/
public static String appendSqlByTimeRange(Integer timeRange, String field, String... times) {
if (StringUtils.isEmpty(field)) {
return "";
}
String appendSql = "";
if (timeRange != null) {
switch (timeRange) {
case ConstantsElectricFence.TIMETYPE_TODAY://今天
appendSql += " and date_format(" + field + ",'%Y-%m-%d') = date_format(NOW(),'%Y-%m-%d')";
break;
case ConstantsElectricFence.TIMETYPE_YESTERDAY:// 昨天
appendSql += " and date_format(" + field + ",'%Y-%m-%d')=date_format(DATE_ADD(NOW(),INTERVAL -1 DAY),'%Y-%m-%d')";
break;
case ConstantsElectricFence.TIMETYPE_THISWEEK:// 本周
appendSql += " and YEARWEEK(date_format(" + field + ",'%Y-%m-%d'),5) = YEARWEEK(now(),5) ";
break;
case ConstantsElectricFence.TIMETYPE_LASTWEEK:// 上周
appendSql += " and YEARWEEK(date_format(" + field + ",'%Y-%m-%d'),5) = YEARWEEK(now(),5)-1 ";
break;
case ConstantsElectricFence.TIMETYPE_THISMONTH:// 本月
appendSql += " and date_format(" + field + ",'%Y-%m')=date_format(now(),'%Y-%m') ";
break;
case ConstantsElectricFence.TIMETYPE_LASTMONTH:// 上月
appendSql += " and date_format(" + field + ",'%Y-%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y-%m') ";
break;
case ConstantsElectricFence.TIMETYPE_IN_7_DAYS:// 近7天
appendSql += " and date_sub(curdate(), INTERVAL 7 DAY) <= date(" + field + ") ";
break;
case ConstantsElectricFence.TIMETYPE_IN_30_DAYS:// 近30天
appendSql += " and date_sub(curdate(), INTERVAL 30 DAY) <= date(" + field + ") ";
break;
case ConstantsElectricFence.TIMETYPE_SCOPE:// 时间段
try {
if (null != times && times.length == 2) {
String stime = times[0];
String etime = times[1];
//时间校验
Date sdate = parseDate(stime, "yyyy-MM-dd");
Date edate = parseDate(etime, "yyyy-MM-dd");
if (null != sdate && null != edate && (edate.after(sdate) || sdate.equals(edate))) {
appendSql += " and " + field + " >= '" + stime + "' and " + field + " <= '" + getToCondtionDay(parseDate(etime, "yyyy-MM-dd")) + "'";
}
}
break;
} catch (Exception ex) {
break;
}
case ConstantsElectricFence.TIMETYPE_SCOPE_WITH_TIME:
try {
if (null != times && times.length == 2) {
String stime = times[0];
String etime = times[1];
//时间校验
Date sdate = parseDate(stime);
Date edate = parseDate(etime);
if (null != sdate && null != edate && (edate.after(sdate) || sdate.equals(edate))) {
appendSql += " and " + field + " >= '" + stime + "' and " + field + " <= '" + getToCondtionDay(parseDate(etime)) + "'";
}
}
break;
} catch (Exception ex) {
break;
}
}
}
return appendSql;
}
public static String getCurrentTime(String format) {
if (format == "" || format == null) {
format = YMDHMS;
}
Date date = new Date();
SimpleDateFormat dateFm = new SimpleDateFormat(format);
return dateFm.format(date);
}
/**
* 获得今天日期
*
* @return
*/
public static String getTodayDate() {
Date date = new Date();
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
return dateFm.format(date);
}
/**
* 获得昨天日期
*
* @return
*/
public static String getYesterday() {
/* Date date = new Date();
date = new Date(date.getTime() - 1000 * 60 * 60 * 24);
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
return dateFm.format(date);*/
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -1);
Date date = cal.getTime();
return dateFm.format(date);
}
public static String getTomorrow() {
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, 1);
Date date = cal.getTime();
return dateFm.format(date);
}
/****
* 时间加一天
* @param d1
* @return
*/
public static String getToCondtionDay(Date d1) {
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(d1);
cal.add(Calendar.DATE, 1);
Date date = cal.getTime();
return dateFm.format(date);
}
/**
* 获得本周一的日期
*
* @return
*/
public static String getMondayOfThisWeek() {
Calendar c = Calendar.getInstance();
int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (dayofweek == 0) {
dayofweek = 7;
}
c.add(Calendar.DATE, -dayofweek + 1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(c.getTime());
}
/**
* 获取本周星期天的日期
*
* @return
*/
public static String getCurrentWeekday() {
// int mondayPlus = getMondayPlus();
// GregorianCalendar currentDate = new GregorianCalendar();
// currentDate.add(GregorianCalendar.DATE, mondayPlus+6);
// Date monday = currentDate.getTime();
// DateFormat df = DateFormat.getDateInstance();
// String preMonday = df.format(monday);
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal.add(Calendar.WEEK_OF_YEAR, 1);
String preMonday = df.format(cal.getTime());
return preMonday;
}
/****
* 获取下周一日期
* @return
*/
public static String getXiaWeekday() {
// int mondayPlus = getMondayPlus();
// GregorianCalendar currentDate = new GregorianCalendar();
// currentDate.add(GregorianCalendar.DATE, mondayPlus+6);
// Date monday = currentDate.getTime();
// DateFormat df = DateFormat.getDateInstance();
// String preMonday = df.format(monday);
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal.add(Calendar.WEEK_OF_YEAR, 1);
cal.add(Calendar.DATE, 1);
String preMonday = df.format(cal.getTime());
return preMonday;
}
private static int getMondayPlus() {
Calendar cd = Calendar.getInstance();
// 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1; // 因为按中国礼拜一作为第一天所以这里减1
if (dayOfWeek == 1) {
return 0;
} else {
return 1 - dayOfWeek;
}
}
/**
* 根据原来的时间(Date)获得相对偏移 N 月的时间(Date)
*
* @param protoDate 原来的时间(java.util.Date)
* @param monthOffset (向前移正数,向后移负数)
* @return 时间(java.util.Date)
*/
public static Date getOffsetMonthDate(Date protoDate, int monthOffset) {
Calendar cal = Calendar.getInstance();
cal.setTime(protoDate);
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - monthOffset);
return cal.getTime();
}
/**
* 根据原来的时间(Date)获得相对偏移 N 天的时间(Date)
*
* @param protoDate 原来的时间(java.util.Date)
* @param dateOffset (向前移正数,向后移负数)
* @return 时间(java.util.Date)
*/
public static Date getOffsetDayDate(Date protoDate, int dateOffset) {
Calendar cal = Calendar.getInstance();
cal.setTime(protoDate);
cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH)
- dateOffset);
return cal.getTime();
}
/**
* 得到上个月的最后一天
*/
public static String getLastMonthLastDay() {
//上个月最后一天
Calendar calendar = Calendar.getInstance();
//calendar.add(Calendar.MONTH, 1); //加一个月
calendar.set(Calendar.DATE, 1); //设置为该月第一天
calendar.add(Calendar.DATE, -1); //再减一天即为上个月最后一天
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(calendar.getTime());
}
/**
* 得到上个月的第一天
*/
public static String getLastMonthFirstDay() {
//上个月第一天
GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance();
gcLast.setTime(new Date());
gcLast.add(Calendar.MONTH, -1);
gcLast.set(Calendar.DAY_OF_MONTH, 1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(gcLast.getTime());
}
/**
* 获取上周一的日期
*
* @param date
* @return
*/
public static Date getLastWeekMonday(Date date) {
Date a = org.apache.commons.lang.time.DateUtils.addDays(date, -1);
Calendar cal = Calendar.getInstance();
cal.setTime(a);
cal.add(Calendar.WEEK_OF_YEAR, -1);// 一周
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return cal.getTime();
}
/**
* 获取上周日的日期
*
* @param date
* @return
*/
public static Date getLastWeekSunday(Date date) {
Date a = org.apache.commons.lang.time.DateUtils.addDays(date, -1);
Calendar cal = Calendar.getInstance();
cal.setTime(a);
cal.set(Calendar.DAY_OF_WEEK, 1);
return cal.getTime();
}
/***
* 时间转为字符串
* @param str 秒
* @return
*/
public static String conver(int str) {
if (str > 0) {
int s = str;
int N = s / 3600;
s = s % 3600;
int K = s / 60;
s = s % 60;
int M = s;
return N + "小时" + K + "分";
} else {
return "0";
}
}
/***
* 得到本月的第一天
* @return
*/
public static String getMonthFirstDay() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(calendar.getTime());
}
/***
* 上月第一天
* @return
*/
public static String getPreviousMonthFirst() {
String str = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar lastDate = Calendar.getInstance();
lastDate.set(5, 1);
lastDate.add(2, -1);
str = sdf.format(lastDate.getTime());
return str;
}
/***
* 上月最后一天
* @return
*/
public static String getPreviousMonthEnd() {
String str = "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar lastDate = Calendar.getInstance();
lastDate.add(2, -1);
lastDate.set(5, 1);
lastDate.roll(5, -1);
str = sdf.format(lastDate.getTime());
return str;
}
/**
* 获取本月最后一天的日期
*
* @return
*/
public static String getEndDateOfThisMonth() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cal.set(Calendar.DATE, 1);
cal.roll(Calendar.DATE, -1);
Date endTime = cal.getTime();
return sdf.format(endTime);
}
/**
* 获取某月的最后一天
*
* @throws
* @Title:getLastDayOfMonth
* @Description:
* @param:@param year
* @param:@param month
* @param:@return
* @return:String
*/
public static String getLastDayOfMonth(int year, int month) {
Calendar cal = Calendar.getInstance();
//设置年份
cal.set(Calendar.YEAR, year);
//设置月份
cal.set(Calendar.MONTH, month - 1);
//获取某月最大天数
int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
//设置日历中月份的最大天数
cal.set(Calendar.DAY_OF_MONTH, lastDay);
//格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String lastDayOfMonth = sdf.format(cal.getTime());
return lastDayOfMonth;
}
/**
* 格式化传的时间为 X天X小时X分X秒
*
* @param durationTime
* @return
*/
public static String formatTimeInSec(long durationTime) {
if (durationTime > 0) {
int s = (int) durationTime;
int day = s / (3600 * 24);
s = s % (3600 * 24);
int hour = s / 3600;
s = s % 3600;
int min = s / 60;
s = s % 60;
int sec = s;
return day + "天" + hour + "小时" + min + "分" + sec + "秒";
} else {
return "0";
}
}
/**
* 格式化传的时间为 X天X小时X分
*
* @param durationTime
* @return
*/
public static String formatTimeInSec1(long durationTime) {
if (durationTime > 0) {
int s = (int) durationTime;
int day = s / (3600 * 24);
s = s % (3600 * 24);
int hour = s / 3600;
s = s % 3600;
return day + "天" + hour + "小时";
} else {
return "0";
}
}
/**
* 格式化传的时间为 X天X小时X分
*
* @param durationTime
* @return
*/
public static String formatTimeInSec2(long durationTime) {
if (durationTime > 0) {
int s = (int) durationTime;
int day = s / (3600 * 24);
s = s % (3600 * 24);
int hour = s / 3600;
s = s % 3600;
int min = s / 60;
s = s % 60;
int sec = s;
return day + "天" + hour + "小时" + min + "分";
} else {
return "0";
}
}
/**
* 格式化 xx小时xx分钟
*
* @param time
* @return
*/
public static String formatTimeInSec3(long time) {
if (time > 0 && time <= 60) {
return "1分钟";
} else if (time % 3600 == 0) {
return time / 3600 + "小时";
} else if (time > 60 && time < 3600) {
return time / 60 + "分钟";
} else if (time > 3600) {
int s = (int) time;
int hour = s / 3600;
s = s % 3600;
int min = s / 60;
s = s % 60;
int sec = s;
if (s > 0) {
min = min + 1;
}
if (min == 60) {
return hour + 1 + "小时";
}
return hour + "小时" + min + "分钟";
} else {
return "0";
}
}
/**
* 将时间后退8小时 北京时间转格林威治时间
*
* @param inputDate HH:mm:ss
* @return
*/
public static String getFallBack8Hour(String inputDate) {
String recDate = "";
SimpleDateFormat inputFormat = new SimpleDateFormat("HH:mm:ss");
Date date = null;
try {
date = inputFormat.parse(inputDate);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date.getTime());
// System.out.println("北京时间:" + cal.getTime().toString().substring(11, 19));
cal.add(Calendar.HOUR, -8);
recDate = cal.getTime().toString().substring(11, 19);
} catch (ParseException e) {
e.printStackTrace();
}
return recDate;
}
/**
* 将时间前进8小时 格林威治时间转北京时间
*
* @param inputDate HH:mm:ss
* @return
*/
public static String getGoAhead8Hour(String inputDate) {
String recDate = "";
SimpleDateFormat inputFormat = new SimpleDateFormat("HH:mm:ss");
Date date = null;
try {
date = inputFormat.parse(inputDate);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date.getTime());
cal.add(Calendar.HOUR, +8);
recDate = cal.getTime().toString().substring(11, 19);
} catch (ParseException e) {
e.printStackTrace();
}
return recDate;
}
/**
* 作者:sanri <br/>
* 时间:2017-4-28下午1:35:59<br/>
* 功能:date1 时间大于(晚于)date2 返回 true ,其余返回 false <br/>
* 入参: <br/>
*/
public static boolean compareDate(String date1, String date2) {
DateFormat df = new SimpleDateFormat(YMDHMS);
try {
Date dt1 = df.parse(date1);
Date dt2 = df.parse(date2);
if (dt1.getTime() > dt2.getTime()) {
return true;
} else if (dt1.getTime() < dt2.getTime()) {
return false;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 将时间前进N分钟
*
* @param date
* @param minute 前进的分钟数
* @return
*/
public static Date getMinuteBefore(Date date, int minute) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MINUTE, minute);//要前进的分钟数
return cal.getTime();
}
public static boolean compareDate(Date date1, Date date2) {
if (date1.getTime() > date2.getTime()) {
return true;
} else if (date1.getTime() < date2.getTime()) {
return false;
} else {
return false;
}
}
/**
* 将字符串转为unix时间戳
*
* @param dateString 2016-04-12 13:46:03
* @return
*/
public static String dateToTimeStamp(String dateString) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long stamp = 0;
try {
Date date = df.parse(dateString);
stamp = date.getTime() / 1000;
} catch (ParseException e) {
e.printStackTrace();
}
return stamp + "";
}
/**
* unix时间戳转换为字符串
*
* @param timeString 1454216477
* @return
*/
public static Date timestampToDate(String timeString) {
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Long timestamp = Long.parseLong(timeString) * 1000;
// String date = sdf.format(new java.util.Date(timestamp));
return new Date(timestamp);
}
/**
* unix时间戳转换为dateFormat
*
* @param timestampString
* @return
*/
public static String timestampToDateString(String timestampString) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Long timestamp = Long.parseLong(timestampString) * 1000;
String date = sdf.format(new Date(timestamp));
return date;
}
/**
* 两个时间相差距离多少天多少小时多少分多少秒
*
* @param one 时间1
* @param two 时间2
* @return long[] 返回值为:{天, 时, 分, 秒}
*/
public static long[] getDistanceTimes(Date one, Date two) {
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
long day = diff / (24 * 60 * 60 * 1000);
long hour = (diff / (60 * 60 * 1000) - day * 24);
long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
long sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
return new long[]{day, hour, min, sec};
}
/**
* 两个时间相差距离多少天多少小时多少分多少秒
*
* @param str1 时间参数 1 格式:1990-01-01 12:00:00
* @param str2 时间参数 2 格式:2009-01-01 12:00:00
* @return String 返回值为:xx天xx小时xx分xx秒
*/
public static String getDistanceTime(String str1, String str2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date one;
Date two;
try {
one = df.parse(str1);
two = df.parse(str2);
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
long day = diff / (24 * 60 * 60 * 1000);
long hour = (diff / (60 * 60 * 1000) - day * 24);
long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
long sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
return day + "天" + hour + "小时" + min + "分" + sec + "秒";
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
/**
* 比较两个日期时间差
*
* @param startDate
* @param endDate
* @param timeUnitType
* @return
*/
public static long getDifferenceBetweenTwoTime(Date startDate, Date endDate, TimeUnitType timeUnitType) {
long duration = endDate.getTime() - startDate.getTime();
if (timeUnitType != null) {
if (TimeUnitType.SECOND.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toSeconds(duration);
} else if (TimeUnitType.MINUTE.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toMinutes(duration);
} else if (TimeUnitType.HOUR.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toHours(duration);
} else if (TimeUnitType.DAY.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toDays(duration);
}
}
return duration;
}
public static long getDistanceDay(String str1, String str2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date one;
Date two;
try {
one = df.parse(str1);
two = df.parse(str2);
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
long day = diff / (24 * 60 * 60 * 1000);
return day;
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
/**
* 获取几天前的时间
*
* @return
*/
public static String getReductionDay(int dayNum) {
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -dayNum);
Date date = cal.getTime();
return dateFm.format(date);
}
/**
* 校验时间格式
*
* @param yyyyMM
*/
public static boolean checkyyyyMM(String yyyyMM) {
if (null == parseDate(yyyyMM, "yyyyMM") || yyyyMM.length() > 6 || yyyyMM.length() < 5) {
return false;
}
int year = Integer.parseInt(yyyyMM.substring(0, 4));
int month = Integer.parseInt(yyyyMM.substring(4));
Calendar cal = Calendar.getInstance();
if (year <= 0 || year > cal.get(Calendar.YEAR) || month <= 0 || month > 12) {
return false;
}
return true;
}
/**
* 时间往前或者往后推移N天
*
* @param days
* @param date
* @return
*/
public static Date getDayBefore(int days, Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, -days);//把日期往后增加一天.整数往后推,负数往前移动
return cal.getTime();
}
public static String getDayBeforeStr(int days, String dateStr) {
DateFormat df = new SimpleDateFormat(YMDHMS);
try {
Date date = df.parse(dateStr);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, -days);//把日期往后增加一天.整数往后推,负数往前移动
date = cal.getTime();
return df.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
// public static void main(String[] args) throws ParseException {
// DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// long difference = getDifferenceBetweenTwoTime(new Date(), df.parse("2016-05-31 15:20:30"), TimeUnitType.MINUTE);
// System.out.println(difference);
// }
public static long naturalIntervalDay(long millis1, long millis2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(millis1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(millis2);
return naturalIntervalDay(calendar1, calendar2);
}
/**
* 作者:sanri <br/>
* 时间:2017-9-15下午12:41:04<br/>
* 功能:计算两个日期间的自然日期间隔 从后一天开始计算,只算天数<br/>
* 注:此方法没有包含当天
*
* @param cal1
* @param cal2
* @return
*/
public static long naturalIntervalDay(Calendar cal1, Calendar cal2) {
int day1 = cal1.get(Calendar.DAY_OF_YEAR);
int day2 = cal2.get(Calendar.DAY_OF_YEAR);
//add by sanri at 2017/11/21 解决不同年,算出来的天数不一致的问题
int year1 = cal1.get(Calendar.YEAR);
int year2 = cal2.get(Calendar.YEAR);
if (year1 == year2) {
//如果是同年,则直接可以时间相减
return Math.abs(day2 - day1);
}
int yearSwap = year1;
if (year1 > year2) {
//交换两个年
year1 = year2;
year2 = yearSwap;
}
int timeDistance = 0;
for (int i = year1; i < year2; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { //闰年
timeDistance += 366;
} else {
timeDistance += 365;
}
}
return Math.abs(timeDistance + (day2 - day1));
}
/**
* 作者:sanri <br/>
* 时间:2017-9-15上午10:17:05<br/>
* 功能:计算两个日期的间隔,使用时间戳间隔然后取整 <br/>
*
* @param date1 日期 1
* @param date2 日期 2
* @param timeUnit
* @return 两个日期的时间间隔
*/
public static long interval(Date date1, Date date2, TimeUnit timeUnit) {
return interval(date1.getTime(), date2.getTime(), timeUnit);
}
public static long interval(Calendar cal1, Calendar cal2, TimeUnit timeUnit) {
return interval(cal1.getTimeInMillis(), cal2.getTimeInMillis(), timeUnit);
}
public static long interval(long millis1, long millis2, TimeUnit timeUnit) {
long duration = Math.abs(millis2 - millis1);
return interval(duration, timeUnit);
}
public static long interval(long duration, TimeUnit timeUnit) {
return timeUnit.convert(duration, TimeUnit.MILLISECONDS);
}
public static long naturalIntervalDay(Date date1, Date date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(date2);
return naturalIntervalDay(calendar1, calendar2);
}
/**
* 计算当前时间与指定时间的时间差
*
* @param time
* @return
* @author lidh
*/
@SuppressWarnings("null")
public static long getTimeDifference(String time) {
Date parseDate = DateUtils.parseDate(time, pattern);
return System.currentTimeMillis() - parseDate.getTime();
}
/**
* 获取开始时间和结束时间的具体天数
*
* @param dBegin
* @param dEnd
* @return
*/
public static List<Date> findDates(Date dBegin, Date dEnd) {
List<Date> lDate = new ArrayList<Date>();
lDate.add(dBegin);
Calendar calBegin = Calendar.getInstance();
// 使用给定的 Date 设置此 Calendar 的时间
calBegin.setTime(dBegin);
Calendar calEnd = Calendar.getInstance();
// 使用给定的 Date 设置此 Calendar 的时间
calEnd.setTime(dEnd);
// 测试此日期是否在指定日期之后
while (dEnd.after(calBegin.getTime())) {
// 根据日历的规则,为给定的日历字段添加或减去指定的时间量
calBegin.add(Calendar.DAY_OF_MONTH, 1);
lDate.add(calBegin.getTime());
}
return lDate;
}
public static int getMaxDayOfNow(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.DATE);
}
public static int getMaxDayOfCurrentMonth() {
Calendar cal = Calendar.getInstance();
int maxNum = cal.getMaximum(Calendar.DAY_OF_MONTH);
return maxNum;
}
public static String getYearAndMonthYesterday() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
String yesterday = new SimpleDateFormat("yyyy-MM").format(cal.getTime());
return yesterday;
}
public static String getYearOfNow() {
Calendar cal = Calendar.getInstance();
return String.valueOf(cal.get(Calendar.YEAR));
}
/**
* 根据年 月 获取对应的月份 天数
*/
public static int getDaysByYearMonth(int year, int month) {
Calendar a = Calendar.getInstance();
a.set(Calendar.YEAR, year);
a.set(Calendar.MONTH, month - 1);
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
int maxDate = a.get(Calendar.DATE);
return maxDate;
}
public static void main(String[] args) {
// System.out.println(formatDate(getStartDateOfCurrentDay(new Date())));
System.out.println(getMaxDayOfCurrentMonth());
System.out.println(formatDateChineseYmdh(new Date()));
System.out.println(getYearAndMonthYesterday());
System.out.println(getYearOfNow());
System.out.println(getDaysByYearMonth(2021, 5));
}
}
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!