use of com.monitor.model.productmaterials.PanoramicProductMaterials in project new-cloud by xie-summer.
the class PanoramicRealTimeConsumptionGatherServiceImpl method queryStatisticsForDay.
private PanoramicRealTimeConsumptionGatherDto queryStatisticsForDay(String date, String code) {
PanoramicRealTimeConsumptionGatherDto gather = new PanoramicRealTimeConsumptionGatherDto();
gather.setCode(code);
gather.setValue(0.0);
gather.setRecordValues(0.0);
gather.setCtime(DateUtil.parseTimestamp(date, "yyyy-MM-dd"));
gather.setGatherTime(date);
gather.setName(StringUtils.equalsIgnoreCase(code, HG_01_XY_7505) ? "磷钙" : "普钙");
gather.setDeleteFlag(1);
gather.setDtime(null);
gather.setfId("2");
gather.setId(null);
Condition condition = new Condition(PanoramicProductMaterials.class, false);
condition.createCriteria().andCondition("code ='" + code + "' and in_or_out =1 and delete_flag =1 " + " AND date_format(utime,'%Y%m%d') = date_format('" + date + "','%Y%m%d')");
List<PanoramicProductMaterials> productMaterials = productMaterialsService.findByCondition(condition);
if (null != productMaterials && productMaterials.size() > 0) {
productMaterials.forEach(e -> {
gather.setValue(Double.parseDouble(e.getValue()) + gather.getValue());
gather.setDeleteFlag(e.getDeleteFlag());
gather.setfId(e.getfId());
gather.setId(null);
gather.setName(e.getName());
gather.setOperator(e.getOperator());
gather.setUnit(e.getUnit());
gather.setDtime(null);
gather.setUtime(e.getUtime());
});
}
Condition cond = new Condition(PanoramicInventoryEntry.class, false);
cond.createCriteria().andCondition(" code ='" + code + "' and in_or_out =1 and delete_flag =1 " + " AND date_format(utime,'%Y%m%d') = date_format('" + date + "','%Y%m%d')");
List<PanoramicInventoryEntry> inventoryEntries = inventoryEntryService.findByCondition(cond);
if (null != inventoryEntries && inventoryEntries.size() > 0) {
inventoryEntries.forEach(e -> {
gather.setRecordValues(Double.parseDouble(e.getValue()) + gather.getRecordValues());
});
}
return gather;
}
use of com.monitor.model.productmaterials.PanoramicProductMaterials in project new-cloud by xie-summer.
the class PanoramicDailyInventorySummaryServiceImpl method saveOrUpdateRecord.
private void saveOrUpdateRecord(String date, List<PanoramicDailyInventorySummary> records, List<PanoramicDailyInventorySummary> curRecords, List<PanoramicDailyInventorySummary> summaryList) {
if (null != records && records.size() > 0) {
records.forEach(e -> {
setRecordValue(date, e);
e.setId(null);
curRecords.add(e);
});
} else {
List<PanoramicRawMaterials> rawMaterialsList = rawMaterialsService.listSummaryCategory();
if (null != rawMaterialsList && rawMaterialsList.size() > 0) {
rawMaterialsList.forEach((PanoramicRawMaterials e) -> {
Double value = rawMaterialsService.summaryByCodeAndDate(e.getCode(), date);
value = value < 0 ? 0 : value;
PanoramicDailyInventorySummary record = getPanoramicDailyInventorySummary(value, 1);
record.setCode(e.getCode());
record.setName(e.getName());
curRecords.add(record);
});
}
List<PanoramicProductMaterials> categoryList = productMaterialsService.listRealTimeProductSummaryCategoryTask();
if (null != categoryList && categoryList.size() > 0) {
categoryList.forEach((PanoramicProductMaterials e) -> {
Double value = productMaterialsService.summaryByCodeAndDate(e.getCode(), date);
value = value < 0 ? 0 : value;
PanoramicDailyInventorySummary record = getPanoramicDailyInventorySummary(value, 2);
record.setCode(e.getCode());
record.setName(e.getName());
curRecords.add(record);
});
}
}
if (null == summaryList || summaryList.size() == 0) {
dailyInventorySummaryMapper.insertList(curRecords);
} else {
dailyInventorySummaryMapper.updateBatch(curRecords);
}
}
use of com.monitor.model.productmaterials.PanoramicProductMaterials in project new-cloud by xie-summer.
the class PanoramicProductMaterialsServiceImpl method productSummaryTask.
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void productSummaryTask(String name, String code, String date) {
// 先查出来,再去更新
Condition condition = new Condition(PanoramicProductMaterials.class, false);
condition.createCriteria().andCondition(" substring(code, 1, 12) = '" + code + "' AND f_id=2 AND delete_flag=1 " + " AND date_format(utime,'%Y%m%d%H') = date_format('" + date + "','%Y%m%d%H')");
List<PanoramicProductMaterials> consumptionList = productMaterialsMapper.selectByCondition(condition);
PanoramicProductMaterials record = new PanoramicProductMaterials();
record.setCode(code);
record.setName(name);
record.setValue("0");
record.setCtime(DateUtil.getCurFullTimestamp());
record.setId(null);
record.setOperator("auto_task");
record.setfId("2");
record.setUnit("吨");
record.setDeleteFlag(1);
final double[] sumValue = { 0.0 };
if (null != consumptionList && consumptionList.size() > 0) {
consumptionList.forEach(e -> {
try {
sumValue[0] += Double.parseDouble(e.getValue());
} catch (NumberFormatException e1) {
sumValue[0] = 0;
}
record.setUtime(e.getUtime());
record.setDtime(null);
record.setUnit(e.getUnit());
record.setOperator(e.getOperator());
record.setfId(e.getfId());
record.setName(e.getName());
record.setDeleteFlag(e.getDeleteFlag());
record.setCtime(e.getCtime());
record.setId(null);
});
}
PanoramicRealTimeConsumptionGather selectOne = realTimeConsumptionGatherMapper.selectByGatherTime(code, date);
Optional<PanoramicRealTimeConsumptionGather> one = Optional.ofNullable(selectOne);
if (one.isPresent()) {
selectOne.setValue(sumValue[0]);
selectOne.setUtime(DateUtil.getCurFullTimestamp());
selectOne.setCtime(selectOne.getUtime());
selectOne.setOperator("auto_task_update");
selectOne.setGatherTime(date);
realTimeConsumptionGatherMapper.updateByPrimaryKeySelective(selectOne);
} else {
PanoramicRealTimeConsumptionGather gather = new PanoramicRealTimeConsumptionGather();
gather.setCode(code);
gather.setName(name);
gather.setDeleteFlag(record.getDeleteFlag());
gather.setfId(record.getfId());
gather.setGatherTime(date);
gather.setId(null);
gather.setCtime(DateUtil.getCurFullTimestamp());
gather.setName(record.getName());
gather.setOperator(record.getOperator());
gather.setUnit(record.getUnit());
gather.setDtime(record.getDtime());
gather.setUtime(gather.getCtime());
gather.setValue(sumValue[0]);
realTimeConsumptionGatherMapper.insert(gather);
}
}
Aggregations