|
|
@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
|
|
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
import cn.iocoder.yudao.module.pms.constant.PmsConstants;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotattachment.vo.IotAttachmentSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdailyreportfuel.vo.IotDailyReportFuelSaveReqVO;
|
|
|
@@ -127,7 +128,94 @@ public class IotRdDailyReportServiceImpl implements IotRdDailyReportService {
|
|
|
public Long createIotRdDailyReport(IotRdDailyReportSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
|
IotRdDailyReportDO iotRdDailyReport = BeanUtils.toBean(createReqVO, IotRdDailyReportDO.class);
|
|
|
- iotRdDailyReportMapper.insert(iotRdDailyReport);
|
|
|
+ // 如果没有传递 deptId 则默认使用当前登录人的 部门
|
|
|
+ if (ObjUtil.isEmpty(createReqVO.getDeptId())) {
|
|
|
+ Long deptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
+ if (ObjUtil.isNotEmpty(deptId)) {
|
|
|
+ createReqVO.setDeptId(deptId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 根据部门名称 当前日期 生成日报标题
|
|
|
+ if (ObjUtil.isNotEmpty(createReqVO.getDeptId())) {
|
|
|
+ DeptDO dept = deptService.getDept(createReqVO.getDeptId());
|
|
|
+ if (ObjUtil.isNotEmpty(dept)) {
|
|
|
+ String todayDateStr = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATE_PATTERN);
|
|
|
+ iotRdDailyReport.setReportName(dept.getName() + "/" + todayDateStr + "日报");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 临时新建的日报 审批状态 默认为 审批通过 status 赋值为1 填写完成
|
|
|
+ iotRdDailyReport.setAuditStatus(SupplierAuditStatusEnum.APPROVE.getStatus());
|
|
|
+ iotRdDailyReport.setStatus(1);
|
|
|
+ if (ObjUtil.isNotEmpty(createReqVO.getId())) {
|
|
|
+ // 编辑现有数据
|
|
|
+ iotRdDailyReportMapper.updateById(iotRdDailyReport);
|
|
|
+ } else {
|
|
|
+ // 新建日报记录
|
|
|
+ iotRdDailyReportMapper.insert(iotRdDailyReport);
|
|
|
+ }
|
|
|
+ // 保存生产动态明细
|
|
|
+ if (CollUtil.isNotEmpty(createReqVO.getReportDetails())) {
|
|
|
+ // 先删除明细 再新增
|
|
|
+ List<IotRdDailyReportDetailSaveReqVO> reportDetails = createReqVO.getReportDetails();
|
|
|
+ int count = iotRdDailyReportDetailMapper.deleteByMap(ImmutableMap.of(
|
|
|
+ "report_id", iotRdDailyReport.getId()
|
|
|
+ ));
|
|
|
+ // 新增生产动态明细
|
|
|
+ List<IotRdDailyReportDetailDO> reportDOs = new ArrayList<>();
|
|
|
+ reportDetails.forEach(detail -> {
|
|
|
+ String detailEndTime = detail.getEndTime();
|
|
|
+ if (StrUtil.isNotBlank(detailEndTime)) {
|
|
|
+ String[] timeAttr = detailEndTime.split(":");
|
|
|
+ if ("24".equals(timeAttr[0])) {
|
|
|
+ detail.setEndTime("23:59:59");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ IotRdDailyReportDetailDO tempDetail = BeanUtils.toBean(detail, IotRdDailyReportDetailDO.class);
|
|
|
+ tempDetail.setDeptId(createReqVO.getDeptId());
|
|
|
+ // 临时新建的日报 不关联项目 任务
|
|
|
+ // tempDetail.setTaskId(updateObj.getTaskId());
|
|
|
+ tempDetail.setReportId(iotRdDailyReport.getId());
|
|
|
+ tempDetail.setReportDate(LocalDateTime.now());
|
|
|
+ reportDOs.add(tempDetail);
|
|
|
+ });
|
|
|
+ // 插入日报明细记录
|
|
|
+ if (CollUtil.isNotEmpty(reportDOs)) {
|
|
|
+ iotRdDailyReportDetailMapper.insertBatch(reportDOs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 保存附件
|
|
|
+ if (CollUtil.isNotEmpty(createReqVO.getAttachments())) {
|
|
|
+ List<IotAttachmentSaveReqVO> attachments = createReqVO.getAttachments();
|
|
|
+ List<IotAttachmentDO> tobeAddedAttachments = new ArrayList<>();
|
|
|
+ attachments.forEach(att -> {
|
|
|
+ IotAttachmentDO attachment = new IotAttachmentDO();
|
|
|
+ attachment.setBizId(iotRdDailyReport.getId());
|
|
|
+ attachment.setCategory(AttachmentCategoryEnum.DAILY_REPORT.getCode());
|
|
|
+ attachment.setType(AttachmentTypeEnum.EXTERNAL_RENTAL.getCode());
|
|
|
+ attachment.setFilePath(att.getFilePath());
|
|
|
+ attachment.setFileSize(att.getFileSize());
|
|
|
+ attachment.setFilename(att.getFilename());
|
|
|
+ attachment.setFileType(att.getFileType());
|
|
|
+ attachment.setRemark(att.getRemark());
|
|
|
+ tobeAddedAttachments.add(attachment);
|
|
|
+ });
|
|
|
+ if (CollUtil.isNotEmpty(tobeAddedAttachments)) {
|
|
|
+ // 先删除再新增
|
|
|
+ int count = iotAttachmentMapper.deleteByMap(ImmutableMap.of(
|
|
|
+ "category", AttachmentCategoryEnum.DAILY_REPORT.getCode(),
|
|
|
+ "biz_id", iotRdDailyReport.getId(),
|
|
|
+ "type", AttachmentTypeEnum.EXTERNAL_RENTAL.getCode()
|
|
|
+ ));
|
|
|
+ iotAttachmentMapper.insertBatch(tobeAddedAttachments);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果传递的附件列表为空 则删除已有的附件 有可能编辑已有数据
|
|
|
+ int count = iotAttachmentMapper.deleteByMap(ImmutableMap.of(
|
|
|
+ "category", AttachmentCategoryEnum.DAILY_REPORT.getCode(),
|
|
|
+ "biz_id", iotRdDailyReport.getId(),
|
|
|
+ "type", AttachmentTypeEnum.EXTERNAL_RENTAL.getCode()
|
|
|
+ ));
|
|
|
+ }
|
|
|
// 返回
|
|
|
return iotRdDailyReport.getId();
|
|
|
}
|