Commit ea4f8190 authored by jiaorz's avatar jiaorz

Merge branch 'master-vehicle-bg' into base-modify

parents 1dc5004d edfa7ebd
......@@ -12,4 +12,8 @@ public class BranchCompanyVehicleCountDTO extends PageParam {
private String endTime;
private String companyName;
//统计类型,日月年, 1、日,2、月,3、年
private Integer type;
//需要除去的天数
private Integer dayNum;
}
......@@ -11,30 +11,21 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Iterator;
import java.util.List;
import java.util.Calendar;
@Service
@Slf4j
public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCountMapper, BranchCompanyVehicleCount> {
@Autowired
VehicleInformationDownloadBiz vehicleInformationDownloadBiz;
public ObjectRestResponse add(List<BranchCompanyVehicleCount> branchCompanyVehicleCounts) {
if (branchCompanyVehicleCounts == null) {
public ObjectRestResponse add(BranchCompanyVehicleCount branchCompanyVehicleCount) {
if (branchCompanyVehicleCount == null) {
return ObjectRestResponse.paramIsEmpty();
}
Iterator<BranchCompanyVehicleCount> iterator = branchCompanyVehicleCounts.iterator();
while (iterator.hasNext()) {
BranchCompanyVehicleCount newValue = iterator.next();
if(newValue != null) {
BranchCompanyVehicleCount oldValue = selectOne(newValue);
if (oldValue != null) {
iterator.remove();
}
}
}
if(branchCompanyVehicleCounts != null && branchCompanyVehicleCounts.size() > 0) {
insertMultiSelective(branchCompanyVehicleCounts);
BranchCompanyVehicleCount oldValue = selectOne(branchCompanyVehicleCount);
if (oldValue == null) {
insertSelectiveRe(branchCompanyVehicleCount);
}
return ObjectRestResponse.succ();
}
......@@ -45,10 +36,24 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo
Integer pageSize = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit();
branchCompanyVehicleCountDTO.setPage(pageNo);
branchCompanyVehicleCountDTO.setLimit(pageSize);
if (branchCompanyVehicleCountDTO.getType() == 1) {
branchCompanyVehicleCountDTO.setDayNum(1);
} else if (branchCompanyVehicleCountDTO.getType() == 2) {
branchCompanyVehicleCountDTO.setDayNum(7);
} else if (branchCompanyVehicleCountDTO.getType() == 3) {
branchCompanyVehicleCountDTO.setDayNum(getCurrentMonthLastDay());
}
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<BranchCompanyVehicleCount> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.getAllByParam(query.getSuper()));
return ObjectRestResponse.succ(pageDataVO);
}
public int getCurrentMonthLastDay() {
Calendar a = Calendar.getInstance();
a.set(Calendar.DATE, 1);//把日期设置为当月第一天
a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天
int maxDate = a.get(Calendar.DATE);
return maxDate;
}
}
......@@ -109,7 +109,6 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
@Scheduled(cron = "0 0 */2 * * *")
public void add() {
ArrayList<BranchCompanyVehicleCount> arrayList = Lists.newArrayList();
List<BranchCompanyVehicleCountVo> branchCompanyVehicleCountVos = vehicleBiz.getAllVehicleInfo();
branchCompanyVehicleCountVos.parallelStream().forEach(result->{
try {
......@@ -119,12 +118,11 @@ public class VehicleInformationDownloadBiz extends BaseBiz<VehicleMapper, Vehicl
DateTime dateTime = DateTime.now();
String dateStr = dateTime.toString(DATE_TIME_FORMATTER);
branchCompanyVehicleCount.setCountDate(DateTime.parse(dateStr).toDate());
arrayList.add(branchCompanyVehicleCount);
branchCompanyVehicleCountBiz.add(branchCompanyVehicleCount);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
branchCompanyVehicleCountBiz.add(arrayList);
}
}
......@@ -13,7 +13,18 @@
</resultMap>
<select id="getAllByParam" parameterType="Map" resultType="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount">
select * from branch_company_vehicle_count
select *, CEILING(
(
CASE
WHEN #{type} = 1 THEN
vehicle_num / #{dayNum},
WHEN #{type} = 2 THEN
vehicle_num / #{dayNum},
WHEN #{type} = 3 THEN
vehicle_num / #{dayNum}
END
)
) AS count from branch_company_vehicle_count
<where>
<if test="companyName != null and companyName != ''">
and company_name like concat('%', #{companyName}, '%')
......@@ -21,6 +32,7 @@
<if test="startTime != null and startTime != ''">
and count_date &gt; #{startTime} and count_date &lt; #{endTime}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
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