|
@@ -0,0 +1,197 @@
|
|
|
+package org.dromara.bulk.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.bulk.domain.DevelopmentOrder;
|
|
|
+import org.dromara.bulk.domain.bo.DevelopmentOrderBo;
|
|
|
+import org.dromara.bulk.domain.vo.DevelopmentOrderTableDataInfo;
|
|
|
+import org.dromara.bulk.domain.vo.DevelopmentOrderVo;
|
|
|
+import org.dromara.bulk.mapper.DevelopmentOrderMapper;
|
|
|
+import org.dromara.bulk.service.DevelopmentOrderService;
|
|
|
+import org.dromara.common.core.constant.DevelopmentOrderConstants;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 开发订单Service业务层处理
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class DevelopmentOrderServiceImpl implements DevelopmentOrderService {
|
|
|
+
|
|
|
+ private final DevelopmentOrderMapper developmentOrderMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建所有状态的常量Set集合
|
|
|
+ */
|
|
|
+ private static final Set<Long> STATUS_CODES = Set.of(
|
|
|
+ DevelopmentOrderConstants.PENDING_PROCESSING,
|
|
|
+ DevelopmentOrderConstants.IN_THE_DRAWING,
|
|
|
+ DevelopmentOrderConstants.CONFIRMING_IN_PROGRESS,
|
|
|
+ DevelopmentOrderConstants.UNDER_MODIFICATION,
|
|
|
+ DevelopmentOrderConstants.IN_COLOR_ADJUSTMENT,
|
|
|
+ DevelopmentOrderConstants.IN_TYPESETTING,
|
|
|
+ DevelopmentOrderConstants.PRINTING_IN_PROGRESS,
|
|
|
+ DevelopmentOrderConstants.COMPLETED,
|
|
|
+ DevelopmentOrderConstants.CANCELLED
|
|
|
+ );
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DevelopmentOrderTableDataInfo<DevelopmentOrderVo> getList(DevelopmentOrderBo bo, PageQuery pageQuery) {
|
|
|
+ // 构建动态查询条件
|
|
|
+ LambdaQueryWrapper<DevelopmentOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ addDynamicConditions(queryWrapper, bo);
|
|
|
+
|
|
|
+ Page<DevelopmentOrderVo> page = developmentOrderMapper.selectVoPage(pageQuery.build(), queryWrapper);
|
|
|
+
|
|
|
+ Map<Long, Integer> statusCount = developmentOrderMapper.countStatusBatch(STATUS_CODES);
|
|
|
+
|
|
|
+ // 组装数据返回
|
|
|
+ return DevelopmentOrderTableDataInfo.build(page,
|
|
|
+ statusCount.get(DevelopmentOrderConstants.PENDING_PROCESSING),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.IN_THE_DRAWING),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.CONFIRMING_IN_PROGRESS),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.UNDER_MODIFICATION),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.IN_COLOR_ADJUSTMENT),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.IN_TYPESETTING),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.PRINTING_IN_PROGRESS),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.COMPLETED),
|
|
|
+ statusCount.get(DevelopmentOrderConstants.CANCELLED));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addDynamicConditions(LambdaQueryWrapper<DevelopmentOrder> queryWrapper, DevelopmentOrderBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ // 字符串字段处理
|
|
|
+ if (StringUtils.isNotBlank(bo.getCustomerName())) {
|
|
|
+ queryWrapper.like(DevelopmentOrder::getCustomerName, bo.getCustomerName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(bo.getFabric())) {
|
|
|
+ queryWrapper.like(DevelopmentOrder::getFabric, bo.getFabric());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 时间范围处理
|
|
|
+ LocalDate startDate = parseDate((String) params.get("beginTime"));
|
|
|
+ LocalDate endDate = parseDate((String) params.get("endTime"));
|
|
|
+ if (startDate != null && endDate != null) {
|
|
|
+ queryWrapper.between(DevelopmentOrder::getCreateTime, startDate, endDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private LocalDate parseDate(String dateStr) {
|
|
|
+ if (dateStr == null) return null;
|
|
|
+ try {
|
|
|
+ return LocalDate.parse(dateStr, DateTimeFormatter.ISO_LOCAL_DATE);
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
+ throw new ServiceException("日期格式错误: " + dateStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insert(DevelopmentOrderBo developmentOrder) {
|
|
|
+ return developmentOrderMapper.insert(MapstructUtils.convert(developmentOrder, DevelopmentOrder.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int update(DevelopmentOrderBo developmentOrderBo) {
|
|
|
+ checkStatus(developmentOrderBo);
|
|
|
+ return developmentOrderMapper.updateById(MapstructUtils.convert(developmentOrderBo, DevelopmentOrder.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void editRemark(DevelopmentOrderBo developmentOrderBo) {
|
|
|
+ if (!developmentOrderBo.getRemark().isEmpty()) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int delete(Long[] id) {
|
|
|
+ return developmentOrderMapper.deleteByIds(Arrays.asList(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DevelopmentOrderVo selectById(Long id) {
|
|
|
+ return MapstructUtils.convert(developmentOrderMapper.selectById(id), DevelopmentOrderVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void checkStatus(DevelopmentOrderBo developmentOrderBo) {
|
|
|
+// 状态为画图中
|
|
|
+ if (developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.IN_THE_DRAWING)) {
|
|
|
+ assertNotLongBlank(developmentOrderBo.getDesignUserId(), "设计师不能为空");
|
|
|
+ assertNotBlank(developmentOrderBo.getDesignFile(), "设计文件不能为空");
|
|
|
+ assertNotBlank(developmentOrderBo.getDesignImage(), "设计图片不能为空");
|
|
|
+ assertNotBlank(developmentOrderBo.getDesignMaterial(), "素材图片不能为空");
|
|
|
+// 设置画图开始时间
|
|
|
+ developmentOrderBo.setStartingTimeForDrawing(new Date());
|
|
|
+ }
|
|
|
+// 状态为确认中
|
|
|
+ if (developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.CONFIRMING_IN_PROGRESS)) {
|
|
|
+ assertNotLongBlank(developmentOrderBo.getConfirmUserId(), "确认人不能为空");
|
|
|
+ assertNotBlank(developmentOrderBo.getPaperDesignFile(), "纸样文件不能为空");
|
|
|
+// 设置画图结束时间
|
|
|
+ developmentOrderBo.setEndTimeOfDrawing(new Date());
|
|
|
+// 设置确认开始时间
|
|
|
+ developmentOrderBo.setConfirmStartTime(new Date());
|
|
|
+ }
|
|
|
+// 状态为调色中
|
|
|
+ if (developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.IN_COLOR_ADJUSTMENT)) {
|
|
|
+ assertNotLongBlank(developmentOrderBo.getColorUserId(), "调色人不能为空");
|
|
|
+ assertNotBlank(developmentOrderBo.getColorFile(), "调色文件不能为空");
|
|
|
+// 设置确认结束时间
|
|
|
+ developmentOrderBo.setConfirmEndTime(new Date());
|
|
|
+// 设置调色开始时间
|
|
|
+ developmentOrderBo.setColorMixingStartTime(new Date());
|
|
|
+ }
|
|
|
+// 状态为排版中
|
|
|
+ if (developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.IN_TYPESETTING)) {
|
|
|
+ assertNotLongBlank(developmentOrderBo.getLayoutUserId(), "排版人不能为空");
|
|
|
+ assertNotBlank(developmentOrderBo.getLayoutFile(), "排版文件不能为空");
|
|
|
+// 设置调色结束时间
|
|
|
+ developmentOrderBo.setEndTimeOfColorAdjustment(new Date());
|
|
|
+// 设置排版开始时间
|
|
|
+ developmentOrderBo.setLayoutStartTime(new Date());
|
|
|
+ }
|
|
|
+// 状态为打版中
|
|
|
+ if (developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.PRINTING_IN_PROGRESS)) {
|
|
|
+ assertNotLongBlank(developmentOrderBo.getPatternUserid(), "打版人不能为空");
|
|
|
+ assertNotBlank(developmentOrderBo.getPatternFile(), "打版文件不能为空");
|
|
|
+// 设置排版结束时间
|
|
|
+ developmentOrderBo.setLayoutEndTime(new Date());
|
|
|
+// 设置打版开始时间
|
|
|
+ developmentOrderBo.setPrintingStartTime(new Date());
|
|
|
+ }
|
|
|
+// 状态为已完成
|
|
|
+ if (developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.COMPLETED)) {
|
|
|
+
|
|
|
+ }
|
|
|
+// 状态为取消
|
|
|
+ if (developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.CANCELLED)) {
|
|
|
+ if (!developmentOrderBo.getStatus().equals(DevelopmentOrderConstants.CONFIRMING_IN_PROGRESS)) {
|
|
|
+ throw new ServiceException("状态为确认中才可以取消");
|
|
|
+ }
|
|
|
+ developmentOrderBo.setCancelTime(new Date());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void assertNotLongBlank(Long longId, String errorMessage) {
|
|
|
+ if (longId == null || longId == 0) {
|
|
|
+ throw new ServiceException(errorMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void assertNotBlank(String str, String errorMessage) {
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
+ throw new ServiceException(errorMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|