Commit 6a0992d8 zshaohui

出入库统计报表修改

1 个父辈 a12a00a6
......@@ -1015,6 +1015,7 @@ public class BaseDeviceHandler implements IDeviceHandler {
Storage storage = dataCache.getStorageById(storagePos.getStorageId());
InOutData inOutData = dataCache.getLastSaveInOutData(storage.getCid(), storage.getId());
inOutData.setExecuteTime(inOutData.getExecuteTime() + executeTime);
inOutData.setUpdateDate(new Date());
inOutDataManager.save(inOutData);
}
}
......
......@@ -54,7 +54,7 @@ public class InOutDataManagerImpl implements IInOutDataManager {
if (storageIdList != null && !storageIdList.isEmpty()) {
c.and("storageId").in(storageIdList);
}
Sort s = Sort.by(Sort.Direction.DESC, "createDate");
Sort s = Sort.by(Sort.Direction.ASC, "createDate");
return inOutDataDao.findByQuery(q.addCriteria(c).with(s));
}
......
package com.neotel.smfcore.core.report;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.neotel.smfcore.common.bean.BetweenData;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.inout.service.manager.IInOutDataManager;
import com.neotel.smfcore.core.inout.service.po.InOutData;
......@@ -11,6 +12,7 @@ import com.neotel.smfcore.core.report.bean.ChartItem;
import com.neotel.smfcore.core.report.rest.dto.InoutDataDto;
import com.neotel.smfcore.core.report.rest.dto.InventoryBoxDto;
import com.neotel.smfcore.core.report.rest.dto.InventoryGroupDto;
import com.neotel.smfcore.core.report.rest.query.ReportExtQuery;
import com.neotel.smfcore.core.report.rest.query.ReportQuery;
import com.neotel.smfcore.core.storage.bean.UsageItem;
import com.neotel.smfcore.core.storage.service.manager.IStorageManager;
......@@ -32,6 +34,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@RestController
......@@ -138,41 +141,57 @@ public class ReportController {
@ApiOperation("出入库统计")
@RequestMapping("/api/report/getInOutData")
@AnonymousAccess
public InOutDataDto getServenInOutData(ReportQuery query) {
public InOutDataDto getInOutData(ReportExtQuery query) {
InOutDataDto dto = new InOutDataDto();
List<String> dateStrList = new ArrayList<>();
List<Integer> inDataList = new ArrayList<>();
List<Integer> outDataList = new ArrayList<>();
int days = 7;
//1.获取当前日期
String currentDateStr = DateUtil.toDateString(new Date(), "yyyy-MM-dd");
Date currentDate = DateUtil.toDate(currentDateStr, "yyyy-MM-dd");
//判断日期是否为空
//开始时间与结束时间赋值
String currentDateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH");
Date startDate = DateUtil.parse(currentDateStr, "yyyy-MM-dd HH");
Date endDate = DateUtil.parse(currentDateStr, "yyyy-MM-dd HH");
BetweenData<Date> updateDate = query.getUpdateDate();
if (updateDate != null) {
Date from = updateDate.getFrom();
Date to = updateDate.getTo();
if (to != null) {
currentDate = to;
}
if (from != null) {
days = (int) cn.hutool.core.date.DateUtil.between(from, to, DateUnit.DAY) + 1;
startDate = from;
}
if (to != null) {
endDate = to;
}
} else {
endDate = DateUtil.parse(currentDateStr, "yyyy-MM-dd");
startDate = DateUtil.offsetDay(endDate, -7);
}
//2.开始处理 7天数据
for (int day = 1; day <= days; day++) {
Date startDate = DateUtil.addDays(currentDate, day - days);
Date endDate = DateUtil.addDays(currentDate, day - days + 1);
List<InOutData> inOutDataList = inOutDataManager.findByDate(startDate, endDate, query.getStorageIdList());
int inData = 0;
int outData = 0;
if (inOutDataList != null && !inOutDataList.isEmpty()) {
inData = inOutDataList.stream().mapToInt(InOutData::getInCount).sum();
outData = inOutDataList.stream().mapToInt(InOutData::getOutCount).sum();
//判断相差小时数,是否超过48小时
long between = DateUtil.between(startDate, endDate, DateUnit.HOUR);
List<InOutData> inOutDataList = inOutDataManager.findByDate(startDate, endDate, query.getStorageIdList());
while (startDate.getTime() < endDate.getTime()) {
DateTime nextDayTime;
if (between > 48) {
dateStrList.add(DateUtil.format(startDate, "MM/dd"));
nextDayTime = DateUtil.offsetDay(startDate, 1);
} else {
dateStrList.add(DateUtil.format(startDate, "MM/dd HH"));
nextDayTime = DateUtil.offsetHour(startDate, 1);
}
int inCount = 0, outCount = 0;
for (InOutData inOutData : inOutDataList) {
if (inOutData.getCreateDate().getTime() >= startDate.getTime() && inOutData.getCreateDate().getTime() < nextDayTime.getTime()) {
inCount = inCount + inOutData.getInCount();
outCount = outCount + inOutData.getOutCount();
}
}
inDataList.add(inCount);
outDataList.add(outCount);
if (between > 48) {
startDate = DateUtil.offsetDay(startDate, 1);
} else {
startDate = DateUtil.offsetHour(startDate, 1);
}
dateStrList.add(DateUtil.toDateString(startDate, "MM/dd"));
inDataList.add(inData);
outDataList.add(outData);
}
dto.setDateStrList(dateStrList);
dto.setInDataList(inDataList);
......
package com.neotel.smfcore.core.report.rest.query;
import com.neotel.smfcore.common.bean.BetweenData;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class ReportExtQuery extends ReportQuery{
@DateTimeFormat(pattern = "yyyy-MM-dd HH")
private BetweenData<Date> updateDate;
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!