From 3664ff0935aeab26d23926331333a1f55caea1c1 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Mon, 19 Jan 2026 15:23:21 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
drone-service/drone-gd/src/main/java/org/sxkj/gd/orderdata/service/impl/GdSupplyDemandServiceImpl.java | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 210 insertions(+), 8 deletions(-)
diff --git a/drone-service/drone-gd/src/main/java/org/sxkj/gd/orderdata/service/impl/GdSupplyDemandServiceImpl.java b/drone-service/drone-gd/src/main/java/org/sxkj/gd/orderdata/service/impl/GdSupplyDemandServiceImpl.java
index 9cd923d..6d0635b 100644
--- a/drone-service/drone-gd/src/main/java/org/sxkj/gd/orderdata/service/impl/GdSupplyDemandServiceImpl.java
+++ b/drone-service/drone-gd/src/main/java/org/sxkj/gd/orderdata/service/impl/GdSupplyDemandServiceImpl.java
@@ -16,16 +16,30 @@
*/
package org.sxkj.gd.orderdata.service.impl;
-import org.sxkj.gd.orderdata.entity.GdSupplyDemandEntity;
-import org.sxkj.gd.orderdata.param.GdSupplyDemandPageParam;
-import org.sxkj.gd.orderdata.vo.GdSupplyDemandVO;
-import org.sxkj.gd.orderdata.excel.GdSupplyDemandExcel;
-import org.sxkj.gd.orderdata.mapper.GdSupplyDemandMapper;
-import org.sxkj.gd.orderdata.service.IGdSupplyDemandService;
-import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import lombok.AllArgsConstructor;
+import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.sxkj.gd.orderdata.dto.GdSupplyDemandDTO;
+import org.sxkj.gd.orderdata.entity.GdSupplyDemandAuditAttachmentEntity;
+import org.sxkj.gd.orderdata.entity.GdSupplyDemandAuditEntity;
+import org.sxkj.gd.orderdata.entity.GdSupplyDemandEntity;
+import org.sxkj.gd.orderdata.excel.GdSupplyDemandExcel;
+import org.sxkj.gd.orderdata.mapper.GdSupplyDemandMapper;
+import org.sxkj.gd.orderdata.param.GdSupplyDemandPageParam;
+import org.sxkj.gd.orderdata.service.IGdSupplyDemandAuditAttachmentService;
+import org.sxkj.gd.orderdata.service.IGdSupplyDemandAuditService;
+import org.sxkj.gd.orderdata.service.IGdSupplyDemandService;
+import org.sxkj.gd.orderdata.vo.GdSupplyDemandVO;
+import org.sxkj.system.cache.SysCache;
+
+import java.util.ArrayList;
import java.util.List;
/**
@@ -35,13 +49,201 @@
* @since 2026-01-16
*/
@Service
+@AllArgsConstructor
public class GdSupplyDemandServiceImpl extends BaseServiceImpl<GdSupplyDemandMapper, GdSupplyDemandEntity> implements IGdSupplyDemandService {
+
+ /**
+ * 需求状态常量:0-草稿、1-申请中、2-审核通过、3-拒绝申请
+ */
+ private static final String STATUS_DRAFT = "0";
+ private static final String STATUS_APPLY = "1";
+ private static final String STATUS_APPROVED = "2";
+ private static final String STATUS_REJECTED = "3";
+
+ /**
+ * 审核状态常量:0-待审核、1-审核通过、2-审核拒绝
+ */
+ private static final String AUDIT_PENDING = "0";
+ private static final String AUDIT_PASS = "1";
+ private static final String AUDIT_REJECT = "2";
+
+ private final IGdSupplyDemandAuditService gdSupplyDemandAuditService;
+ private final IGdSupplyDemandAuditAttachmentService gdSupplyDemandAuditAttachmentService;
@Override
public IPage<GdSupplyDemandVO> selectGdSupplyDemandPage(IPage<GdSupplyDemandVO> page, GdSupplyDemandPageParam gdSupplyDemand) {
- return page.setRecords(baseMapper.selectGdSupplyDemandPage(page, gdSupplyDemand));
+ return page.setRecords(baseMapper.selectGdSupplyDemandPage(page, gdSupplyDemand, buildDeptIdList()));
}
+ @Override
+ public IPage<GdSupplyDemandEntity> selectGdSupplyDemandList(IPage<GdSupplyDemandEntity> page, GdSupplyDemandDTO gdSupplyDemand) {
+ return page.setRecords(baseMapper.selectGdSupplyDemandList(page, gdSupplyDemand));
+ }
+
+ @Override
+ public GdSupplyDemandEntity detailSupplyDemand(GdSupplyDemandDTO gdSupplyDemand) {
+ if (Func.isEmpty(gdSupplyDemand)) {
+ throw new ServiceException("需求参数不能为空");
+ }
+ GdSupplyDemandEntity detail = baseMapper.selectGdSupplyDemandDetail(gdSupplyDemand, buildDeptIdList());
+ if (detail == null) {
+ throw new ServiceException("未查询到数据");
+ }
+ return detail;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean submitSupplyDemand(GdSupplyDemandEntity gdSupplyDemand) {
+ if (Func.isEmpty(gdSupplyDemand)) {
+ throw new ServiceException("需求参数不能为空");
+ }
+
+ // 获取前端传入的需求状态
+ String demandStatus = gdSupplyDemand.getDemandStatus();
+ if (StringUtil.isBlank(demandStatus)) {
+ throw new ServiceException("需求状态不能为空");
+ }
+
+ // 校验状态值有效性
+ if (!STATUS_DRAFT.equals(demandStatus) && !STATUS_APPLY.equals(demandStatus)) {
+ throw new ServiceException("需求状态值无效,仅支持 0(草稿) 或 1(申请中)");
+ }
+
+ boolean isInsert = Func.isEmpty(gdSupplyDemand.getId());
+ Long userId = AuthUtil.getUserId();
+ Long deptId = Long.valueOf(AuthUtil.getDeptId());
+ gdSupplyDemand.setUpdateUser(userId);
+
+ boolean saved;
+ if (isInsert) {
+ gdSupplyDemand.setCreateUser(userId);
+ gdSupplyDemand.setCreateDept(deptId);
+ saved = baseMapper.insertGdSupplyDemand(gdSupplyDemand) > 0;
+ } else {
+ saved = baseMapper.updateGdSupplyDemand(gdSupplyDemand) > 0;
+ }
+
+ if (!saved) {
+ return false;
+ }
+
+ // 仅当状态为"申请中"(1)时才创建审核记录
+ if (STATUS_APPLY.equals(demandStatus)) {
+ GdSupplyDemandEntity supplyDemand = loadSupplyDemandForAudit(gdSupplyDemand.getId());
+ GdSupplyDemandAuditEntity auditEntity = buildAuditEntity(supplyDemand, AUDIT_PENDING, null);
+ return gdSupplyDemandAuditService.saveSupplyDemandAudit(auditEntity);
+ }
+
+ // 状态为"草稿"(0)时直接返回成功
+ return true;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean approveSupplyDemand(Long demandId, String auditOpinion, List<Long> attachIds) {
+ GdSupplyDemandEntity supplyDemand = loadSupplyDemandForAudit(demandId);
+ Long userId = AuthUtil.getUserId();
+ GdSupplyDemandEntity update = new GdSupplyDemandEntity();
+ update.setId(demandId);
+ update.setDemandStatus(STATUS_APPROVED);
+ update.setUpdateUser(userId);
+ boolean updated = baseMapper.updateGdSupplyDemand(update) > 0;
+ if (!updated) {
+ return false;
+ }
+ GdSupplyDemandAuditEntity auditEntity = buildAuditEntity(supplyDemand, AUDIT_PASS, auditOpinion);
+ boolean auditSaved = gdSupplyDemandAuditService.saveSupplyDemandAudit(auditEntity);
+ if (!auditSaved) {
+ return false;
+ }
+ if (Func.isEmpty(attachIds)) {
+ return true;
+ }
+ List<GdSupplyDemandAuditAttachmentEntity> attachments = new ArrayList<>();
+ Long deptId = Long.valueOf(AuthUtil.getDeptId());
+ attachIds.forEach(attachId -> {
+ if (attachId == null) {
+ return;
+ }
+ GdSupplyDemandAuditAttachmentEntity attachment = new GdSupplyDemandAuditAttachmentEntity();
+ attachment.setDemandId(demandId);
+ attachment.setAttachId(attachId);
+ attachment.setAreaCode(supplyDemand.getAreaCode());
+ attachment.setCreateUser(userId);
+ attachment.setCreateDept(deptId);
+ attachments.add(attachment);
+ });
+ if (attachments.isEmpty()) {
+ return true;
+ }
+ return gdSupplyDemandAuditAttachmentService.saveSupplyDemandAuditAttachments(attachments);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean rejectSupplyDemand(Long demandId, String auditOpinion) {
+ if (StringUtil.isBlank(auditOpinion)) {
+ throw new ServiceException("拒绝原因不能为空");
+ }
+ GdSupplyDemandEntity supplyDemand = loadSupplyDemandForAudit(demandId);
+ Long userId = AuthUtil.getUserId();
+ GdSupplyDemandEntity update = new GdSupplyDemandEntity();
+ update.setId(demandId);
+ update.setDemandStatus(STATUS_REJECTED);
+ update.setUpdateUser(userId);
+ boolean updated = baseMapper.updateGdSupplyDemand(update) > 0;
+ if (!updated) {
+ return false;
+ }
+ GdSupplyDemandAuditEntity auditEntity = buildAuditEntity(supplyDemand, AUDIT_REJECT, auditOpinion);
+ return gdSupplyDemandAuditService.saveSupplyDemandAudit(auditEntity);
+ }
+
+ private GdSupplyDemandAuditEntity buildAuditEntity(GdSupplyDemandEntity supplyDemand, String auditStatus, String auditOpinion) {
+ if (Func.isEmpty(supplyDemand) || supplyDemand.getId() == null) {
+ throw new ServiceException("需求数据不存在");
+ }
+ Long userId = AuthUtil.getUserId();
+ Long deptId = Long.valueOf(AuthUtil.getDeptId());
+ GdSupplyDemandAuditEntity auditEntity = new GdSupplyDemandAuditEntity();
+ auditEntity.setDemandId(supplyDemand.getId());
+ auditEntity.setAuditStatus(auditStatus);
+ auditEntity.setAuditOpinion(StringUtil.isBlank(auditOpinion) ? null : auditOpinion);
+ auditEntity.setAreaCode(supplyDemand.getAreaCode());
+ auditEntity.setCreateUser(userId);
+ auditEntity.setCreateDept(deptId);
+ return auditEntity;
+ }
+
+ private GdSupplyDemandEntity loadSupplyDemandForAudit(Long demandId) {
+ if (demandId == null) {
+ throw new ServiceException("需求编号不能为空");
+ }
+ GdSupplyDemandDTO query = new GdSupplyDemandDTO();
+ query.setId(demandId);
+ GdSupplyDemandEntity detail = baseMapper.selectGdSupplyDemandDetail(query, buildDeptIdList());
+ if (detail == null) {
+ throw new ServiceException("需求数据不存在");
+ }
+ return detail;
+ }
+
+ private List<Long> buildDeptIdList() {
+ if (AuthUtil.isAdministrator()) {
+ return null;
+ }
+ Long deptId = Long.valueOf(AuthUtil.getDeptId());
+ List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
+ List<Long> result = new ArrayList<>();
+ if (Func.isNotEmpty(deptIdList)) {
+ result.addAll(deptIdList);
+ }
+ if (!result.contains(deptId)) {
+ result.add(deptId);
+ }
+ return result;
+ }
@Override
public List<GdSupplyDemandExcel> exportGdSupplyDemand(Wrapper<GdSupplyDemandEntity> queryWrapper) {
--
Gitblit v1.9.3