|
@@ -1,15 +1,41 @@
|
|
package cn.iocoder.yudao.module.pms.service.iotrhdailyreport;
|
|
package cn.iocoder.yudao.module.pms.service.iotrhdailyreport;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicecategorytemplateattrs.vo.IotDeviceProperty;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotprojecttask.vo.IotProjectTaskPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportSaveReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotprojecttask.IotProjectTaskDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotrhdailyreport.IotRhDailyReportDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotrhdailyreport.IotRhDailyReportDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotprojecttask.IotProjectTaskMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotrhdailyreport.IotRhDailyReportMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotrhdailyreport.IotRhDailyReportMapper;
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
|
|
|
|
+import cn.iocoder.yudao.module.system.service.dict.DictDataService;
|
|
|
|
+import cn.iocoder.yudao.module.system.service.dict.DictTypeService;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.lang.reflect.Type;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_RH_DAILY_REPORT_NOT_EXISTS;
|
|
import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_RH_DAILY_REPORT_NOT_EXISTS;
|
|
@@ -25,12 +51,131 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private IotRhDailyReportMapper iotRhDailyReportMapper;
|
|
private IotRhDailyReportMapper iotRhDailyReportMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotProjectTaskMapper iotProjectTaskMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotDeviceMapper iotDeviceMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private DictDataService dictDataService;
|
|
|
|
+ @Resource
|
|
|
|
+ private DictTypeService dictTypeService;
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
public Long createIotRhDailyReport(IotRhDailyReportSaveReqVO createReqVO) {
|
|
public Long createIotRhDailyReport(IotRhDailyReportSaveReqVO createReqVO) {
|
|
// 插入
|
|
// 插入
|
|
IotRhDailyReportDO iotRhDailyReport = BeanUtils.toBean(createReqVO, IotRhDailyReportDO.class);
|
|
IotRhDailyReportDO iotRhDailyReport = BeanUtils.toBean(createReqVO, IotRhDailyReportDO.class);
|
|
|
|
+ // 根据日报的 施工队伍 deptId 查询队伍所在的 项目 任务
|
|
|
|
+ // 根据日报的施工状态 更新 对应任务的 状态
|
|
|
|
+ if (ObjUtil.isNotEmpty(createReqVO.getDeptId())) {
|
|
|
|
+ Set<Long> deviceIds = new HashSet<>();
|
|
|
|
+ IotProjectTaskPageReqVO reqVO = new IotProjectTaskPageReqVO();
|
|
|
|
+ reqVO.setDeptId(createReqVO.getDeptId());
|
|
|
|
+ // 查询包含当前日报施工队伍的任务
|
|
|
|
+ List<IotProjectTaskDO> tasks = iotProjectTaskMapper.selectList(reqVO);
|
|
|
|
+ if (CollUtil.isNotEmpty(tasks)) {
|
|
|
|
+ IotProjectTaskDO task = tasks.get(0);
|
|
|
|
+ // 暂时只考虑1个施工队伍只属于1个任务
|
|
|
|
+ iotRhDailyReport.setProjectId(task.getProjectId());
|
|
|
|
+ iotRhDailyReport.setTaskId(task.getId());
|
|
|
|
+ // 根据日报状态 查新 日报所属任务的状态
|
|
|
|
+ if (ObjUtil.isNotEmpty(createReqVO.getConstructionStatus())) {
|
|
|
|
+ task.setStatus(createReqVO.getConstructionStatus());
|
|
|
|
+ // 更新任务状态
|
|
|
|
+ iotProjectTaskMapper.updateById(task);
|
|
|
|
+ }
|
|
|
|
+ // 查询任务的设备列表
|
|
|
|
+ deviceIds = task.getDeviceIds();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 找到当前小队下的 电驱增压机 分类下设备的产能 计算 运行时效
|
|
|
|
+ DictTypeDO dictType = dictTypeService.getDictType("rq_iot_charger_device_category");
|
|
|
|
+ AtomicReference<BigDecimal> capacity = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
|
+ if (ObjUtil.isNotEmpty(dictType)) {
|
|
|
|
+ if (StrUtil.isNotBlank(dictType.getRemark())) {
|
|
|
|
+ IotDevicePageReqVO capacityReqVO = new IotDevicePageReqVO();
|
|
|
|
+ capacityReqVO.setDeptId(createReqVO.getDeptId());
|
|
|
|
+ capacityReqVO.setAssetClass(Long.valueOf(dictType.getRemark()));
|
|
|
|
+ List<IotDeviceDO> capacityDevices = iotDeviceMapper.selectList(capacityReqVO);
|
|
|
|
+ if (CollUtil.isNotEmpty(capacityDevices)) {
|
|
|
|
+ // 解析每个设备的 扩展属性 找出 已经设置 了产能的设备并提取值
|
|
|
|
+ capacityDevices.forEach(device -> {
|
|
|
|
+ if (StrUtil.isNotBlank(device.getTemplateJson())) {
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
+ Type listType = new TypeToken<List<IotDeviceProperty>>(){}.getType();
|
|
|
|
+ List<IotDeviceProperty> deviceProperties = gson.fromJson(device.getTemplateJson(), listType);
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceProperties)) {
|
|
|
|
+ deviceProperties.forEach(property -> {
|
|
|
|
+ if ("产能".equals(property.getName()) && StrUtil.isNotBlank(property.getValue())) {
|
|
|
|
+ // 当前扩展属性已经维护了 产能 值
|
|
|
|
+ capacity.set(new BigDecimal(property.getValue()));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 计算运行时效 当日注气量/产能
|
|
|
|
+ if (ObjUtil.isNotEmpty(createReqVO.getDailyGasInjection()) && (capacity.get().compareTo(BigDecimal.ZERO)>0)) {
|
|
|
|
+ iotRhDailyReport.setTransitTime(createReqVO.getDailyGasInjection().divide(capacity.get(), 2, RoundingMode.HALF_UP));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 查询当前日报所属任务关联的设备
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceIds)) {
|
|
|
|
+ // 查询当前小队下所有设备
|
|
|
|
+ IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
|
|
|
|
+ // deviceReqVO.setDeptId(createReqVO.getDeptId());
|
|
|
|
+ deviceReqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
|
|
+ List<IotDeviceDO> devices = iotDeviceMapper.selectList(deviceReqVO);
|
|
|
|
+ if (CollUtil.isNotEmpty(devices)) {
|
|
|
|
+ AtomicReference<String> deviceNewStatus = new AtomicReference<>(StrUtil.EMPTY);
|
|
|
|
+ // 日报状态 与 设备状态 对应关系
|
|
|
|
+ // 动迁 施工 现场待命/驻地待命(待命) pms_device_status
|
|
|
|
+ List<DictDataDO> dictDatas = dictDataService.getDictDataListByDictType("rq_iot_project_work_progress");
|
|
|
|
+ AtomicReference<String> dailyDictLabel = new AtomicReference<>(StrUtil.EMPTY);
|
|
|
|
+ List<DictDataDO> deviceDictDatas = dictDataService.getDictDataListByDictType("pms_device_status");
|
|
|
|
+ if (CollUtil.isNotEmpty(dictDatas)) {
|
|
|
|
+ dictDatas.forEach(data -> {
|
|
|
|
+ if (createReqVO.getConstructionStatus().equals(Integer.valueOf(data.getValue()))) {
|
|
|
|
+ dailyDictLabel.set(data.getLabel());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceDictDatas)) {
|
|
|
|
+ deviceDictDatas.forEach(data -> {
|
|
|
|
+ if (dailyDictLabel.equals(data.getLabel())) {
|
|
|
|
+ // 动迁 施工
|
|
|
|
+ deviceNewStatus.set(data.getValue());
|
|
|
|
+ }
|
|
|
|
+ if (data.getLabel().contains(dailyDictLabel.get())) {
|
|
|
|
+ // 现场待命/驻地待命(待命)
|
|
|
|
+ deviceNewStatus.set(data.getValue());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 批量更新设备状态
|
|
|
|
+ devices.forEach(device -> {
|
|
|
|
+ device.setDeviceStatus(deviceNewStatus.get());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 设置任务时间范围 昨天下午4点到今天下午4点
|
|
|
|
+ // 设置任务时间范围 昨天下午4点到今天下午4点
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ // 今天下午4点
|
|
|
|
+ LocalDateTime today4pm = now.withHour(16).withMinute(0).withSecond(0).withNano(0);
|
|
|
|
+ // 昨天下午4点
|
|
|
|
+ LocalDateTime yesterday4pm = today4pm.minusDays(1);
|
|
|
|
+ iotRhDailyReport.setConstructionStartDate(yesterday4pm);
|
|
|
|
+ iotRhDailyReport.setConstructionEndDate(today4pm);
|
|
iotRhDailyReportMapper.insert(iotRhDailyReport);
|
|
iotRhDailyReportMapper.insert(iotRhDailyReport);
|
|
|
|
+ // 当天如果已经有此小队的记录 新增
|
|
|
|
+ // 当天如果没有此小队的日报记录 修改
|
|
|
|
+
|
|
// 返回
|
|
// 返回
|
|
return iotRhDailyReport.getId();
|
|
return iotRhDailyReport.getId();
|
|
}
|
|
}
|