|
|
|
|
@ -24,20 +24,20 @@ |
|
|
|
|
* Author: Chill Zhuang (bladejava@qq.com) |
|
|
|
|
*/ |
|
|
|
|
package org.springblade.desk.dashboard.service.impl; |
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.desk.dashboard.constant.BatchConstant; |
|
|
|
|
import org.springblade.desk.dashboard.pojo.dto.DsBatchPreservePlanDTO; |
|
|
|
|
import org.springblade.desk.dashboard.pojo.entity.BsWorkCenterEntity; |
|
|
|
|
import org.springblade.desk.dashboard.pojo.entity.DsBatchPreservePlanEntity; |
|
|
|
|
import org.springblade.desk.dashboard.pojo.entity.DsBatchPreserveTaskEntity; |
|
|
|
|
import org.springblade.desk.dashboard.pojo.entity.*; |
|
|
|
|
import org.springblade.desk.dashboard.pojo.vo.DsBatchPreservePlanVO; |
|
|
|
|
import org.springblade.desk.dashboard.excel.DsBatchPreservePlanExcel; |
|
|
|
|
import org.springblade.desk.dashboard.mapper.DsBatchPreservePlanMapper; |
|
|
|
|
import org.springblade.desk.dashboard.service.IBsWorkCenterService; |
|
|
|
|
import org.springblade.desk.dashboard.service.IDsBatchPreservePlanService; |
|
|
|
|
import org.springblade.desk.dashboard.service.IDsBatchPreserveTaskService; |
|
|
|
|
import org.springblade.desk.dashboard.service.IDsMainSaltAddQuantityService; |
|
|
|
|
import org.springblade.desk.dashboard.utils.DateUtils; |
|
|
|
|
import org.springblade.desk.device.pojo.entity.EquipmentEntity; |
|
|
|
|
import org.springblade.desk.device.service.IEquipmentService; |
|
|
|
|
@ -50,8 +50,12 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.ZoneId; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -60,6 +64,7 @@ import java.util.*; |
|
|
|
|
* @author BladeX |
|
|
|
|
* @since 2025-11-22 |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
|
public class DsBatchPreservePlanServiceImpl extends BaseServiceImpl<DsBatchPreservePlanMapper, DsBatchPreservePlanEntity> implements IDsBatchPreservePlanService { |
|
|
|
|
|
|
|
|
|
@ -82,6 +87,9 @@ public class DsBatchPreservePlanServiceImpl extends BaseServiceImpl<DsBatchPrese |
|
|
|
|
@Autowired |
|
|
|
|
IEpLineElectricService epLineElectricService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
IDsMainSaltAddQuantityService mainSaltAddQuantityService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IPage<DsBatchPreservePlanVO> selectDsBatchPreservePlanPage(IPage<DsBatchPreservePlanVO> page, DsBatchPreservePlanVO dsBatchPreservePlan) { |
|
|
|
|
|
|
|
|
|
@ -122,6 +130,8 @@ public class DsBatchPreservePlanServiceImpl extends BaseServiceImpl<DsBatchPrese |
|
|
|
|
batchPreservePlan.setApprovalStatus(BatchConstant.STATUS_NEW); |
|
|
|
|
} |
|
|
|
|
batchPreservePlan.setLastTaskTime(new Date()); |
|
|
|
|
batchPreservePlan.setAccumulatedStatus("1"); |
|
|
|
|
batchPreservePlan.setPreservePlanStatus("1"); |
|
|
|
|
save(batchPreservePlan); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -202,6 +212,9 @@ public class DsBatchPreservePlanServiceImpl extends BaseServiceImpl<DsBatchPrese |
|
|
|
|
DsBatchPreserveTaskEntity dsBatchPreserveTask = null; |
|
|
|
|
if(!CollectionUtils.isEmpty(batchPreservePlanList)){ |
|
|
|
|
for (DsBatchPreservePlanEntity batchPreservePlan : batchPreservePlanList) { |
|
|
|
|
if("2".equals(batchPreservePlan.getPreservePlanStatus())){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
this.createTask(batchPreservePlan, dsBatchPreserveTask); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -234,39 +247,418 @@ public class DsBatchPreservePlanServiceImpl extends BaseServiceImpl<DsBatchPrese |
|
|
|
|
*/ |
|
|
|
|
private void createTask(DsBatchPreservePlanEntity batchPreservePlan, DsBatchPreserveTaskEntity dsBatchPreserveTask) { |
|
|
|
|
|
|
|
|
|
//电量差 (1)电量差:当前值为1天的电量(自动取数)≥累计触发值,触发任务需添加量
|
|
|
|
|
dsBatchPreserveTask = new DsBatchPreserveTaskEntity(); |
|
|
|
|
//电量差 (1)电量差: 今天总电量 - 昨天总电量 > 触发值 生成任务
|
|
|
|
|
if(BatchConstant.ELECTRICITY_DIFFERENCE.equals(batchPreservePlan.getRuleType())){ |
|
|
|
|
Date yesterdayStartDate = DateUtils.getYesterdayStartDate(); |
|
|
|
|
Date yesterdayEndDate = DateUtils.getYesterdayEndDate(); |
|
|
|
|
System.out.println(yesterdayStartDate); |
|
|
|
|
System.out.println(yesterdayEndDate); |
|
|
|
|
//设备编码
|
|
|
|
|
String deviceCode = equipmentService.getById(batchPreservePlan.getDevice()).getDeviceCode(); |
|
|
|
|
//槽号
|
|
|
|
|
String batchNo = batchPreservePlan.getBatchNo(); |
|
|
|
|
//查询
|
|
|
|
|
DsBatchPreservePlanEntity dsBatchPreservePlanEntity = epLineElectricService.getDataBySlot(batchNo,deviceCode,yesterdayStartDate,yesterdayEndDate); |
|
|
|
|
|
|
|
|
|
//昨天
|
|
|
|
|
EpLineElectricEntity yesterdayDsBatchPreservePlanEntity = getPreviousDayMaxElectricData(batchPreservePlan, 1); |
|
|
|
|
//前天
|
|
|
|
|
EpLineElectricEntity frontdayDsBatchPreservePlanEntity = getPreviousDayMaxElectricData(batchPreservePlan, 2); |
|
|
|
|
|
|
|
|
|
if(null != yesterdayDsBatchPreservePlanEntity && null != frontdayDsBatchPreservePlanEntity){ |
|
|
|
|
double yesterdayElectric = Double.parseDouble(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
double frontdayElectric = Double.parseDouble(frontdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
Integer cumulativeTriggerValue = batchPreservePlan.getCumulativeTriggerValue(); |
|
|
|
|
// 计算差值并比较
|
|
|
|
|
boolean isExceedThreshold = yesterdayElectric - frontdayElectric >= cumulativeTriggerValue;; |
|
|
|
|
if(isExceedThreshold){ |
|
|
|
|
//修改计划
|
|
|
|
|
batchPreservePlan.setCumulativeInitialValue(String.valueOf(yesterdayElectric - frontdayElectric)); |
|
|
|
|
batchPreservePlan.setCurrentValue(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
batchPreservePlan.setPreservePlanStatus("2"); |
|
|
|
|
batchPreservePlan.setAccumulatedStatus("2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成任务
|
|
|
|
|
String addQuantityType = batchPreservePlan.getAddQuantityType(); |
|
|
|
|
BigDecimal actualValue = null; |
|
|
|
|
if("1".equals(addQuantityType)){ |
|
|
|
|
BigDecimal electricBigDecimal = BigDecimal.valueOf(yesterdayElectric); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
batchPreservePlan.setAddQuantity(electricBigDecimal); |
|
|
|
|
}else { |
|
|
|
|
BigDecimal electricBigDecimal = batchPreservePlan.getAddQuantity(); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
//累计电量类 (2)累计电量:(当前日期的用电量-累计初始日期对应的用电量)≥累计触发值,触发任务需添加量
|
|
|
|
|
} |
|
|
|
|
dsBatchPreserveTask.setActualValue(actualValue); |
|
|
|
|
updateById(batchPreservePlan); |
|
|
|
|
}else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
//累计电量类 (2)累计电量:如果累计初始日期>当前日期,不计算
|
|
|
|
|
//累计初始日期<=当前日期,(当前日期用电总量-累计初始值日期用电总量)>=触发值,触发任务
|
|
|
|
|
}else if(BatchConstant.CUMULATIVE_ELECTRICITY.equals(batchPreservePlan.getRuleType())){ |
|
|
|
|
|
|
|
|
|
//累计生产日期 (3)累计生产日期:当前日期-累计初始日期=累计触发值,触发任务需添加量
|
|
|
|
|
String cumulativeInitialValue = batchPreservePlan.getCumulativeInitialValue(); |
|
|
|
|
|
|
|
|
|
boolean isDate = false; |
|
|
|
|
|
|
|
|
|
Date targetDateObj = null; |
|
|
|
|
|
|
|
|
|
if (cumulativeInitialValue == null || cumulativeInitialValue.trim().isEmpty()) { |
|
|
|
|
return ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
targetDateObj = isDateAfterOrEqualNow(cumulativeInitialValue); |
|
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, -1); |
|
|
|
|
Date now = calendar.getTime(); |
|
|
|
|
isDate = !targetDateObj.before(now); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("日期格式无法解析: " + cumulativeInitialValue, e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isDate) { |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
String currentTime = sdf.format(new Date()); |
|
|
|
|
log.info("累计初始日期>当前日期,不计算 当前时间为: {}",currentTime); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EpLineElectricEntity yesterdayDsBatchPreservePlanEntity = getPreviousDayMaxElectricData(batchPreservePlan, 1); |
|
|
|
|
|
|
|
|
|
EpLineElectricEntity electricDataByTargetDate = getElectricDataByTargetDate(targetDateObj, batchPreservePlan); |
|
|
|
|
|
|
|
|
|
//(当前日期用电总量-累计初始值日期用电总量)>=触发值,触发任务
|
|
|
|
|
if(null != yesterdayDsBatchPreservePlanEntity && null != electricDataByTargetDate){ |
|
|
|
|
double electric1 = Double.parseDouble(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
double electric2 = Double.parseDouble(electricDataByTargetDate.getElectric()); |
|
|
|
|
|
|
|
|
|
Integer cumulativeTriggerValue = batchPreservePlan.getCumulativeTriggerValue(); |
|
|
|
|
|
|
|
|
|
double difference = electric1 - electric2; |
|
|
|
|
log.debug("电量差值计算 - 昨天电量: {}, 初始日期电量: {}, 差值: {}, 触发值: {}", |
|
|
|
|
electric1, electric2, difference, cumulativeTriggerValue); |
|
|
|
|
boolean shouldTrigger = difference >= cumulativeTriggerValue; |
|
|
|
|
|
|
|
|
|
if(shouldTrigger){ |
|
|
|
|
//修改计划
|
|
|
|
|
batchPreservePlan.setCurrentValue(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
batchPreservePlan.setPreservePlanStatus("2"); |
|
|
|
|
|
|
|
|
|
//生成任务
|
|
|
|
|
String addQuantityType = batchPreservePlan.getAddQuantityType(); |
|
|
|
|
BigDecimal actualValue = null; |
|
|
|
|
if("1".equals(addQuantityType)){ |
|
|
|
|
BigDecimal electricBigDecimal = BigDecimal.valueOf(electric1); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
batchPreservePlan.setAddQuantity(electricBigDecimal); |
|
|
|
|
}else { |
|
|
|
|
BigDecimal electricBigDecimal = batchPreservePlan.getAddQuantity(); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dsBatchPreserveTask.setActualValue(actualValue); |
|
|
|
|
updateById(batchPreservePlan); |
|
|
|
|
}else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//(3)累计生产日期:当前日期-累计初始日期=累计触发值,触发任务需添加量
|
|
|
|
|
}else if(BatchConstant.CUMULATIVE_PRODUCTION_DAYS.equals(batchPreservePlan.getRuleType())){ |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, -1); |
|
|
|
|
Date yesterday = calendar.getTime(); |
|
|
|
|
|
|
|
|
|
String cumulativeInitialValue = batchPreservePlan.getCumulativeInitialValue(); |
|
|
|
|
Date initialDate = isDateAfterOrEqualNow(cumulativeInitialValue); |
|
|
|
|
|
|
|
|
|
Integer cumulativeTriggerValue = batchPreservePlan.getCumulativeTriggerValue(); |
|
|
|
|
|
|
|
|
|
long daysDiff = calculateDaysDifference(initialDate, yesterday); |
|
|
|
|
|
|
|
|
|
boolean isExceedThreshold = daysDiff >= cumulativeTriggerValue; |
|
|
|
|
|
|
|
|
|
EpLineElectricEntity yesterdayDsBatchPreservePlanEntity = getPreviousDayMaxElectricData(batchPreservePlan, 1); |
|
|
|
|
double electric = Double.parseDouble(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
|
|
|
|
|
//主盐添加量类 (4)累计生产面积:当前值为"累计初始值日期~当前日期"对应作业槽【浸保护剂】工序生产总面积≥累计触发值,触发任务需添加量
|
|
|
|
|
if(isExceedThreshold){ |
|
|
|
|
|
|
|
|
|
//修改计划
|
|
|
|
|
batchPreservePlan.setCurrentValue(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
batchPreservePlan.setPreservePlanStatus("2"); |
|
|
|
|
|
|
|
|
|
//生成任务
|
|
|
|
|
String addQuantityType = batchPreservePlan.getAddQuantityType(); |
|
|
|
|
BigDecimal actualValue = null; |
|
|
|
|
if("1".equals(addQuantityType)){ |
|
|
|
|
BigDecimal electricBigDecimal = BigDecimal.valueOf(electric); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
batchPreservePlan.setAddQuantity(electricBigDecimal); |
|
|
|
|
}else { |
|
|
|
|
BigDecimal electricBigDecimal = batchPreservePlan.getAddQuantity(); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
dsBatchPreserveTask.setActualValue(actualValue); |
|
|
|
|
updateById(batchPreservePlan); |
|
|
|
|
}else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
//主盐添加量类 主盐添加量:当前值为1天内【添加量填报】页面填报的作业槽添加量≥累计触发值,触发任务需添加量
|
|
|
|
|
}else if(BatchConstant.MAIN_SALT_ADDITION.equals(batchPreservePlan.getRuleType())){ |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, -1); |
|
|
|
|
Date yesterday = calendar.getTime(); |
|
|
|
|
Long wcId = batchPreservePlan.getWcId(); |
|
|
|
|
String batchNo = batchPreservePlan.getBatchNo(); |
|
|
|
|
|
|
|
|
|
Date startDate = DateUtils.getStartTime(yesterday); |
|
|
|
|
Date endDate = DateUtils.getEndTime(yesterday); |
|
|
|
|
|
|
|
|
|
List<DsMainSaltAddQuantityEntity> mainSaltAddQuantityList = mainSaltAddQuantityService.getAddQuantity(startDate,endDate,wcId,batchNo); |
|
|
|
|
if(CollectionUtils.isEmpty(mainSaltAddQuantityList)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
BigDecimal total = mainSaltAddQuantityList.stream() |
|
|
|
|
.map(DsMainSaltAddQuantityEntity::getAddValue) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
|
|
|
|
|
Integer cumulativeTriggerValue = batchPreservePlan.getCumulativeTriggerValue(); |
|
|
|
|
|
|
|
|
|
BigDecimal triggerValueDecimal = new BigDecimal(cumulativeTriggerValue); |
|
|
|
|
|
|
|
|
|
boolean shouldTrigger = total.compareTo(triggerValueDecimal) >= 0; |
|
|
|
|
|
|
|
|
|
EpLineElectricEntity yesterdayDsBatchPreservePlanEntity = getPreviousDayMaxElectricData(batchPreservePlan, 1); |
|
|
|
|
double electric = Double.parseDouble(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
|
|
|
|
|
if(shouldTrigger){ |
|
|
|
|
//修改计划
|
|
|
|
|
batchPreservePlan.setCurrentValue(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
batchPreservePlan.setPreservePlanStatus("2"); |
|
|
|
|
|
|
|
|
|
//生成任务
|
|
|
|
|
String addQuantityType = batchPreservePlan.getAddQuantityType(); |
|
|
|
|
BigDecimal actualValue = null; |
|
|
|
|
if("1".equals(addQuantityType)){ |
|
|
|
|
BigDecimal electricBigDecimal = BigDecimal.valueOf(electric); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
batchPreservePlan.setAddQuantity(electricBigDecimal); |
|
|
|
|
}else { |
|
|
|
|
BigDecimal electricBigDecimal = batchPreservePlan.getAddQuantity(); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dsBatchPreserveTask.setActualValue(actualValue); |
|
|
|
|
updateById(batchPreservePlan); |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//累计生产面积 (5)主盐添加量:当前值为1天内【添加量填报】页面填报的作业槽添加量≥累计触发值,触发任务需添加量
|
|
|
|
|
}else if(BatchConstant.CUMULATIVE_PRODUCTION_AREA.equals(batchPreservePlan.getRuleType())){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//累计主盐添加量 (6)累计主盐添加量:当前值≥累计触发值(添加量),当前值为累计初始值日期开始在【添加量录入】页面填报的作业槽添加量总和
|
|
|
|
|
}else if(BatchConstant.CUMULATIVE_MAIN_SALT_ADDITION.equals(batchPreservePlan.getRuleType())){ |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, -1); |
|
|
|
|
Date yesterday = calendar.getTime(); |
|
|
|
|
|
|
|
|
|
String cumulativeInitialValue = batchPreservePlan.getCumulativeInitialValue(); |
|
|
|
|
Date dateAfterOrEqualNow = isDateAfterOrEqualNow(cumulativeInitialValue); |
|
|
|
|
|
|
|
|
|
Date startDate = DateUtils.getStartTime(dateAfterOrEqualNow); |
|
|
|
|
Date endDate = DateUtils.getEndTime(yesterday); |
|
|
|
|
Long wcId = batchPreservePlan.getWcId(); |
|
|
|
|
String batchNo = batchPreservePlan.getBatchNo(); |
|
|
|
|
|
|
|
|
|
List<DsMainSaltAddQuantityEntity> mainSaltAddQuantityList = mainSaltAddQuantityService.getAddQuantity(startDate,endDate,wcId,batchNo); |
|
|
|
|
BigDecimal total = mainSaltAddQuantityList.stream() |
|
|
|
|
.map(DsMainSaltAddQuantityEntity::getAddValue) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
|
|
|
|
|
Integer cumulativeTriggerValue = batchPreservePlan.getCumulativeTriggerValue(); |
|
|
|
|
|
|
|
|
|
BigDecimal triggerValueDecimal = new BigDecimal(cumulativeTriggerValue); |
|
|
|
|
|
|
|
|
|
boolean shouldTrigger = total.compareTo(triggerValueDecimal) >= 0; |
|
|
|
|
|
|
|
|
|
EpLineElectricEntity yesterdayDsBatchPreservePlanEntity = getPreviousDayMaxElectricData(batchPreservePlan, 1); |
|
|
|
|
double electric = Double.parseDouble(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
|
|
|
|
|
if(shouldTrigger){ |
|
|
|
|
//修改计划
|
|
|
|
|
batchPreservePlan.setCurrentValue(yesterdayDsBatchPreservePlanEntity.getElectric()); |
|
|
|
|
batchPreservePlan.setPreservePlanStatus("2"); |
|
|
|
|
|
|
|
|
|
//生成任务
|
|
|
|
|
String addQuantityType = batchPreservePlan.getAddQuantityType(); |
|
|
|
|
BigDecimal actualValue = null; |
|
|
|
|
if("1".equals(addQuantityType)){ |
|
|
|
|
BigDecimal electricBigDecimal = BigDecimal.valueOf(electric); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
batchPreservePlan.setAddQuantity(electricBigDecimal); |
|
|
|
|
}else { |
|
|
|
|
BigDecimal electricBigDecimal = batchPreservePlan.getAddQuantity(); |
|
|
|
|
BigDecimal multipleBigDecimal = BigDecimal.valueOf(batchPreservePlan.getAddQuantityMultiple()); |
|
|
|
|
actualValue = electricBigDecimal.multiply(multipleBigDecimal); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dsBatchPreserveTask.setActualValue(actualValue); |
|
|
|
|
updateById(batchPreservePlan); |
|
|
|
|
}else{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dsBatchPreserveTask.setBppId(batchPreservePlan.getId()); |
|
|
|
|
dsBatchPreserveTask.setTaskStatus(BatchConstant.TO_BE_MAINTAINED.longValue()); |
|
|
|
|
batchPreserveTaskService.save(dsBatchPreserveTask); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EpLineElectricEntity getPreviousDayMaxElectricData(DsBatchPreservePlanEntity batchPreservePlan, int daysAgo) { |
|
|
|
|
if (batchPreservePlan == null || daysAgo <= 0) { |
|
|
|
|
log.warn("参数无效,批次计划: {}, daysAgo: {}"+ batchPreservePlan, daysAgo); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// 获取指定天数的开始和结束时间
|
|
|
|
|
Date targetStartDate = DateUtils.getPreviousDayStartDate(daysAgo); |
|
|
|
|
Date targetEndDate = DateUtils.getPreviousDayEndDate(daysAgo); |
|
|
|
|
|
|
|
|
|
// 获取设备编码
|
|
|
|
|
EquipmentEntity equipment = equipmentService.getById(batchPreservePlan.getDevice()); |
|
|
|
|
if (equipment == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String deviceCode = equipment.getDeviceCode(); |
|
|
|
|
String batchNo = batchPreservePlan.getBatchNo(); |
|
|
|
|
|
|
|
|
|
// 查询数据
|
|
|
|
|
return epLineElectricService.getDataBySlot(batchNo, deviceCode, targetStartDate, targetEndDate); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("查询{}天前的电量数据异常", daysAgo, e); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EpLineElectricEntity getElectricDataByTargetDate(Date targetDate, DsBatchPreservePlanEntity batchPreservePlan) { |
|
|
|
|
// 参数校验
|
|
|
|
|
if (targetDate == null) { |
|
|
|
|
log.warn("目标日期不能为空"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (batchPreservePlan == null) { |
|
|
|
|
log.warn("批次计划不能为空"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (batchPreservePlan.getDevice() == null) { |
|
|
|
|
log.warn("设备ID不能为空"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(batchPreservePlan.getBatchNo())) { |
|
|
|
|
log.warn("批次号不能为空"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// 获取目标日期的开始和结束时间
|
|
|
|
|
Date startTime = DateUtils.getStartTime(targetDate); |
|
|
|
|
Date endTime = DateUtils.getEndTime(targetDate); |
|
|
|
|
|
|
|
|
|
// 获取设备信息
|
|
|
|
|
EquipmentEntity equipment = equipmentService.getById(batchPreservePlan.getDevice()); |
|
|
|
|
|
|
|
|
|
if (equipment == null) { |
|
|
|
|
log.warn("设备不存在,设备ID: {}", batchPreservePlan.getDevice()); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String deviceCode = equipment.getDeviceCode(); |
|
|
|
|
if (StringUtils.isBlank(deviceCode)) { |
|
|
|
|
log.warn("设备编码为空,设备ID: {}", batchPreservePlan.getDevice()); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取批次号
|
|
|
|
|
String batchNo = batchPreservePlan.getBatchNo(); |
|
|
|
|
|
|
|
|
|
// 查询电量数据
|
|
|
|
|
EpLineElectricEntity dataBySlot = epLineElectricService.getDataBySlot( |
|
|
|
|
batchNo, deviceCode, startTime, endTime); |
|
|
|
|
|
|
|
|
|
// 记录查询日志
|
|
|
|
|
if (dataBySlot == null) { |
|
|
|
|
log.debug("未查询到电量数据,目标日期: {}, 批次号: {}, 设备编码: {}", |
|
|
|
|
targetDate, batchNo, deviceCode); |
|
|
|
|
} else { |
|
|
|
|
log.debug("成功查询到电量数据,目标日期: {}, 批次号: {}, 设备编码: {}, 电量: {}", |
|
|
|
|
targetDate, batchNo, deviceCode, dataBySlot.getElectric()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return dataBySlot; |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("根据目标日期查询电量数据异常", e); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Date isDateAfterOrEqualNow(String cumulativeInitialValue) { |
|
|
|
|
try { |
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
|
LocalDate targetDate = LocalDate.parse(cumulativeInitialValue.trim(), formatter); |
|
|
|
|
// 转换为 Date
|
|
|
|
|
return Date.from(targetDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("日期格式无法解析: " + cumulativeInitialValue, e); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算两个日期之间的天数差(忽略时间部分) |
|
|
|
|
*/ |
|
|
|
|
private long calculateDaysDifference(Date startDate, Date endDate) { |
|
|
|
|
// 将Date转换为LocalDate(忽略时间部分)
|
|
|
|
|
LocalDate start = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
|
|
LocalDate end = endDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
|
|
|
|
|
|
|
// 计算天数差
|
|
|
|
|
return ChronoUnit.DAYS.between(start, end); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|