Commit 91842fdc authored by jiaorz's avatar jiaorz

车辆服务次数统计

parent db29f1ce
package com.xxfc.platform.order.Utils; package com.xxfc.platform.order.Utils;
import org.joda.time.DateTime;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
...@@ -108,4 +112,51 @@ public class OrderDateUtils { ...@@ -108,4 +112,51 @@ public class OrderDateUtils {
cal.setTimeInMillis(System.currentTimeMillis()); cal.setTimeInMillis(System.currentTimeMillis());
return cal.get(Calendar.YEAR); return cal.get(Calendar.YEAR);
} }
public static LocalDate dateToLocalDate(Date date) {
return LocalDate.from(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
}
public static Date localDateToDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
/**
* 获取当天的开始时间
* @return
*/
public static long getStartOfDay() {
return getStartOfDay(new Date());
}
/**
* 获取某天的开始时间
* @param date
* @return
*/
public static long getStartOfDay(Date date) {
DateTime dateTime = new DateTime(date);
DateTime startOfDay = dateTime.withTimeAtStartOfDay();
return startOfDay.getMillis();
}
/**
* 获取当天的结束时间
* @return
*/
public static long getEndOfDay() {
return getEndOfDay(new Date());
}
/**
* 获取某天的结束时间
* @param date
* @return
*/
public static long getEndOfDay(Date date) {
DateTime dateTime = new DateTime(date);
DateTime endOfDay = dateTime.millisOfDay().withMaximumValue();
return endOfDay.getMillis();
}
} }
package com.xxfc.platform.order.entity; package com.xxfc.platform.order.entity;
import lombok.Data;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import java.util.Date; import java.util.Date;
@Table(name = "order_vehicle_service_statistics") @Table(name = "order_vehicle_service_statistics")
@Data
public class OrderVehicleServiceStatistics { public class OrderVehicleServiceStatistics {
@Id @Id
private Integer id; private Integer id;
...@@ -26,158 +29,20 @@ public class OrderVehicleServiceStatistics { ...@@ -26,158 +29,20 @@ public class OrderVehicleServiceStatistics {
private Integer arrivalNum; private Integer arrivalNum;
@Column(name = "count_year") @Column(name = "count_year")
private Integer countYear; private String countYear;
@Column(name = "count_month") @Column(name = "count_month")
private Integer countMonth; private String countMonth;
@Column(name = "count_date") @Column(name = "count_date")
private Date countDate; private Date countDate;
@Column(name = "count_week") @Column(name = "count_week")
private Integer countWeek; private String countWeek;
/** /**
* 租车使用天数 * 租车使用天数
*/ */
@Column(name = "rent_num") @Column(name = "rent_num")
private Integer rentNum; private Integer rentNum;
/**
* @return id
*/
public Integer getId() {
return id;
}
/**
* @param id
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @return company_id
*/
public Integer getCompanyId() {
return companyId;
}
/**
* @param companyId
*/
public void setCompanyId(Integer companyId) {
this.companyId = companyId;
}
/**
* 获取出车服务次数
*
* @return departure_num - 出车服务次数
*/
public Integer getDepartureNum() {
return departureNum;
}
/**
* 设置出车服务次数
*
* @param departureNum 出车服务次数
*/
public void setDepartureNum(Integer departureNum) {
this.departureNum = departureNum;
}
/**
* 获取收车服务次数
*
* @return arrival_num - 收车服务次数
*/
public Integer getArrivalNum() {
return arrivalNum;
}
/**
* 设置收车服务次数
*
* @param arrivalNum 收车服务次数
*/
public void setArrivalNum(Integer arrivalNum) {
this.arrivalNum = arrivalNum;
}
/**
* @return count_year
*/
public Integer getCountYear() {
return countYear;
}
/**
* @param countYear
*/
public void setCountYear(Integer countYear) {
this.countYear = countYear;
}
/**
* @return count_month
*/
public Integer getCountMonth() {
return countMonth;
}
/**
* @param countMonth
*/
public void setCountMonth(Integer countMonth) {
this.countMonth = countMonth;
}
/**
* @return count_date
*/
public Date getCountDate() {
return countDate;
}
/**
* @param countDate
*/
public void setCountDate(Date countDate) {
this.countDate = countDate;
}
/**
* @return count_week
*/
public Integer getCountWeek() {
return countWeek;
}
/**
* @param countWeek
*/
public void setCountWeek(Integer countWeek) {
this.countWeek = countWeek;
}
/**
* 获取租车使用天数
*
* @return rent_num - 租车使用天数
*/
public Integer getRentNum() {
return rentNum;
}
/**
* 设置租车使用天数
*
* @param rentNum 租车使用天数
*/
public void setRentNum(Integer rentNum) {
this.rentNum = rentNum;
}
} }
\ No newline at end of file
...@@ -12,6 +12,8 @@ public class CountVehicleServiceNumVo { ...@@ -12,6 +12,8 @@ public class CountVehicleServiceNumVo {
private String countMonth; private String countMonth;
//年周 //年周
private String countWeek; private String countWeek;
//天
private String countDay;
//日期 //日期
private Date countDate; private Date countDate;
//公司ID //公司ID
......
package com.xxfc.platform.order.biz; package com.xxfc.platform.order.biz;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.order.Utils.OrderDateUtils;
import com.xxfc.platform.order.entity.OrderVehicleServiceStatistics; import com.xxfc.platform.order.entity.OrderVehicleServiceStatistics;
import com.xxfc.platform.order.mapper.OrderVehicleServiceStatisticsMapper; import com.xxfc.platform.order.mapper.OrderVehicleServiceStatisticsMapper;
import com.xxfc.platform.order.pojo.CountVehicleServiceNumVo; import com.xxfc.platform.order.pojo.CountVehicleServiceNumVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -19,15 +24,52 @@ public class OrderVehicleServiceStatisticsBiz extends BaseBiz<OrderVehicleServic ...@@ -19,15 +24,52 @@ public class OrderVehicleServiceStatisticsBiz extends BaseBiz<OrderVehicleServic
@Autowired @Autowired
BaseOrderBiz baseOrderBiz; BaseOrderBiz baseOrderBiz;
//获取订单,解析租车天数
//
public void getAllOrder() { public void getAllOrder() {
} }
public void countVehicleServiceNum() { public void countVehicleServiceNum(DateTime dateTime) {
Date nowTime = DateTime.now().minusDays(1).toDate();
if (dateTime != null) {
nowTime = dateTime.minusDays(1).toDate();
}
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("startTime", OrderDateUtils.getStartOfDay(nowTime));
map.put("endTime", OrderDateUtils.getEndOfDay(nowTime));
List<CountVehicleServiceNumVo> list = mapper.countVehicleServiceNum(map); List<CountVehicleServiceNumVo> list = mapper.countVehicleServiceNum(map);
if (list != null && list.size() > 0) {
list.parallelStream().forEach(result -> {
OrderVehicleServiceStatistics orderVehicleServiceStatistics = new OrderVehicleServiceStatistics();
log.info(result.toString());
BeanUtil.copyProperties(result, orderVehicleServiceStatistics, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
String dateStr = result.getCountYear() +"-"+ result.getCountMonth() +"-"+ result.getCountDay();
DateTime date = DateTime.parse(dateStr);
orderVehicleServiceStatistics.setCountDate(date.toDate());
orderVehicleServiceStatistics.setCountMonth(result.getCountYear() + result.getCountMonth());
orderVehicleServiceStatistics.setCountWeek(result.getCountYear() + result.getCountWeek());
add(orderVehicleServiceStatistics);
});
}
} }
public void add(OrderVehicleServiceStatistics orderVehicleServiceStatistics) {
if(orderVehicleServiceStatistics != null) {
OrderVehicleServiceStatistics oldValue = mapper.selectOne(orderVehicleServiceStatistics);
if (oldValue == null) {
insertSelectiveRe(orderVehicleServiceStatistics);
}
}
}
//添加记录
public void addAll() {
DateTime dateTime = DateTime.parse("2019-08-01");
for(DateTime curDate = dateTime.plusDays(1); curDate.compareTo(DateTime.now()) < 0; curDate = curDate.plusDays(1)) {
countVehicleServiceNum(curDate);
}
}
} }
package com.xxfc.platform.order.rest.background;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.order.biz.OrderVehicleServiceStatisticsBiz;
import com.xxfc.platform.order.entity.OrderVehicleServiceStatistics;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/vehicle/serviceNum")
public class VehicleServiceNumController extends BaseController<OrderVehicleServiceStatisticsBiz, OrderVehicleServiceStatistics> {
@GetMapping(value = "/app/unauth/addAll")
public void addAll() {
baseBiz.addAll();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment