|
|
@@ -7,9 +7,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
import com.alibaba.excel.util.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
@@ -18,41 +16,52 @@ import org.springblade.core.mp.support.Query;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.factory.common.FactoryUitls;
|
|
|
+import org.springblade.factory.entity.PcBladeSalesForecastMain;
|
|
|
import org.springblade.factory.entity.PcBladeSalesForecastSummary;
|
|
|
import org.springblade.factory.mapper.PcBladeSalesForecastSummaryMapper;
|
|
|
+import org.springblade.factory.service.PcBladeSalesForecastMainService;
|
|
|
import org.springblade.factory.service.PcBladeSalesForecastSummaryService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.time.temporal.TemporalAdjusters;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
-import java.time.DateTimeException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
@Service
|
|
|
-@AllArgsConstructor
|
|
|
@Slf4j
|
|
|
public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBladeSalesForecastSummaryMapper, PcBladeSalesForecastSummary> implements PcBladeSalesForecastSummaryService {
|
|
|
|
|
|
- private PcBladeSalesForecastSummaryMapper forecastMapper;
|
|
|
+ // 使用Setter注入+Lazy解决循环依赖
|
|
|
+ private PcBladeSalesForecastMainService salesForecastMainService;
|
|
|
+ private FactoryUitls factoryUitls;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ public void setSalesForecastMainService(PcBladeSalesForecastMainService salesForecastMainService) {
|
|
|
+ this.salesForecastMainService = salesForecastMainService;
|
|
|
+ }
|
|
|
|
|
|
+ @Autowired
|
|
|
+ public void setFactoryUitls(FactoryUitls factoryUitls) {
|
|
|
+ this.factoryUitls = factoryUitls;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public List<PcBladeSalesForecastSummary> selectPcBladeSalesForecastSummaryList(PcBladeSalesForecastSummary pcBladeSalesForecastSummary) {
|
|
|
- QueryWrapper<PcBladeSalesForecastSummary> queryWrapper = new QueryWrapper<>();
|
|
|
+ QueryWrapper<PcBladeSalesForecastSummary> queryWrapper = new QueryWrapper<>(pcBladeSalesForecastSummary);
|
|
|
return this.list(queryWrapper);
|
|
|
}
|
|
|
|
|
|
@@ -71,17 +80,12 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return this.updateById(pcBladeSalesForecastSummary);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 批量保存销售预测明细表数据
|
|
|
- *
|
|
|
- * @param pcBladeSalesForecastSummaryList 销售预测明细表数据列表
|
|
|
- * @return 是否保存成功
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean saveBatch(List<PcBladeSalesForecastSummary> pcBladeSalesForecastSummaryList) {
|
|
|
- // 1. 验证参数
|
|
|
if (CollectionUtils.isEmpty(pcBladeSalesForecastSummaryList)) {
|
|
|
log.warn("批量保存失败:明细表数据列表为空");
|
|
|
return false;
|
|
|
@@ -91,7 +95,6 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
int total = pcBladeSalesForecastSummaryList.size();
|
|
|
log.info("开始批量保存销售预测明细表数据,共{}条记录", total);
|
|
|
|
|
|
- // 2. 不限制批次,直接保存全部数据
|
|
|
boolean success = super.saveBatch(pcBladeSalesForecastSummaryList);
|
|
|
|
|
|
if (success) {
|
|
|
@@ -104,21 +107,16 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("批量保存销售预测明细表数据时发生异常", e);
|
|
|
- // 事务会自动回滚
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量更新销售预测明细表数据
|
|
|
- *
|
|
|
- * @param pcBladeSalesForecastSummaryList 销售预测明细表数据列表
|
|
|
- * @return 是否更新成功
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean updateById(List<PcBladeSalesForecastSummary> pcBladeSalesForecastSummaryList) {
|
|
|
- // 1. 验证参数
|
|
|
if (CollectionUtils.isEmpty(pcBladeSalesForecastSummaryList)) {
|
|
|
log.warn("批量更新失败:明细表数据列表为空");
|
|
|
return false;
|
|
|
@@ -129,15 +127,12 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
int successCount = 0;
|
|
|
log.info("开始批量更新销售预测明细表数据,共{}条记录", total);
|
|
|
|
|
|
- // 2. 遍历列表,逐条更新
|
|
|
for (PcBladeSalesForecastSummary summary : pcBladeSalesForecastSummaryList) {
|
|
|
- // 验证ID是否存在
|
|
|
if (summary.getId() == null) {
|
|
|
log.warn("跳过无ID的明细表数据,无法更新");
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // 执行更新操作
|
|
|
boolean updated = super.updateById(summary);
|
|
|
if (updated) {
|
|
|
successCount++;
|
|
|
@@ -146,36 +141,20 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 3. 检查更新结果
|
|
|
if (successCount == 0) {
|
|
|
log.error("批量更新失败,所有数据未成功更新");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
log.info("销售预测明细表数据批量更新完成,共{}条记录,成功更新{}条", total, successCount);
|
|
|
- // 如果有部分更新成功,这里根据业务需求决定返回true还是false
|
|
|
- // 这里返回true表示至少有一条更新成功
|
|
|
return true;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("批量更新销售预测明细表数据时发生异常", e);
|
|
|
- // 事务会自动回滚
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /* ========== 业务接口 ========== */
|
|
|
-
|
|
|
-
|
|
|
- private FactoryUitls factoryUitls;
|
|
|
-
|
|
|
/**
|
|
|
* 检查是否可以提报(当月21日为截止日期)
|
|
|
*/
|
|
|
@@ -183,13 +162,11 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
public boolean checkCanSubmit() {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
int currentDay = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
- // 直接判断当前日期是否超过21日
|
|
|
return currentDay <= 21;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 检查当前经销商是否已提报该月份的预测
|
|
|
- * 按经销商、年份、月份、品牌、物料维度检查
|
|
|
*/
|
|
|
@Override
|
|
|
public List<PcBladeSalesForecastSummary> checkAlreadySubmitted(PcBladeSalesForecastSummary forecast) {
|
|
|
@@ -198,12 +175,10 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
.eq("year", forecast.getYear())
|
|
|
.eq("month", forecast.getMonth());
|
|
|
|
|
|
- // 如果有品牌ID,增加品牌维度检查
|
|
|
if (forecast.getBrandId() != null) {
|
|
|
queryWrapper.eq("BRAND_ID", forecast.getBrandId());
|
|
|
}
|
|
|
|
|
|
- // 如果有物料ID,增加物料维度检查
|
|
|
if (forecast.getItemId() != null) {
|
|
|
queryWrapper.eq("ITEM_ID", forecast.getItemId());
|
|
|
}
|
|
|
@@ -217,7 +192,6 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R<String> saveOrUpdateForecast(PcBladeSalesForecastSummary forecast) {
|
|
|
- // 1. 检查日期是否超过21日
|
|
|
if (!checkCanSubmit()) {
|
|
|
return R.fail("本月21日后不能再提报预测");
|
|
|
}
|
|
|
@@ -227,39 +201,30 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return R.fail("经销商ID不能为空");
|
|
|
}
|
|
|
|
|
|
- // 2. 验证当前操作的经销商是否为登录用户,防止冒充填报
|
|
|
Long loginUserId = AuthUtil.getUserId();
|
|
|
if (!customerId.equals(loginUserId)) {
|
|
|
return R.fail("无权操作其他经销商的预测数据");
|
|
|
}
|
|
|
|
|
|
- // 3. 检查是否已提报
|
|
|
List<PcBladeSalesForecastSummary> existingForecasts = checkAlreadySubmitted(forecast);
|
|
|
boolean isUpdate = !existingForecasts.isEmpty();
|
|
|
|
|
|
- // 4. 设置公共字段
|
|
|
- if (existingForecasts != null && existingForecasts.size() > 0) {
|
|
|
- // 更新操作,获取已有记录的ID
|
|
|
+ if (isUpdate) {
|
|
|
forecast.setId(existingForecasts.get(0).getId());
|
|
|
forecast.setUpdateTime(new Date());
|
|
|
forecast.setUpdateUser(loginUserId);
|
|
|
- // 重置审批状态为未审批
|
|
|
forecast.setApprovalStatus(0);
|
|
|
forecast.setApprovedBy(null);
|
|
|
forecast.setApprovedName(null);
|
|
|
forecast.setApprovedTime(null);
|
|
|
} else {
|
|
|
- // 新增操作,生成ID
|
|
|
-// forecast.setId(IdWorker.getId()); // MyBatis-Plus自带的雪花算法ID生成
|
|
|
forecast.setCreateTime(new Date());
|
|
|
forecast.setCreateUser(loginUserId);
|
|
|
forecast.setUpdateTime(new Date());
|
|
|
forecast.setUpdateUser(loginUserId);
|
|
|
- // 初始审批状态为未审批
|
|
|
forecast.setApprovalStatus(0);
|
|
|
}
|
|
|
|
|
|
- // 5. 保存信息
|
|
|
boolean success = this.saveOrUpdate(forecast);
|
|
|
if (!success) {
|
|
|
return R.fail(isUpdate ? "更新预测失败" : "新增预测失败");
|
|
|
@@ -278,7 +243,6 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return R.fail("没有需要保存的数据");
|
|
|
}
|
|
|
|
|
|
- // 1. 检查日期是否超过21日
|
|
|
if (!checkCanSubmit()) {
|
|
|
return R.fail("本月21日后不能再提报预测");
|
|
|
}
|
|
|
@@ -291,17 +255,14 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return R.fail("经销商ID不能为空");
|
|
|
}
|
|
|
|
|
|
- // 2. 验证权限,防止冒充填报
|
|
|
if (!customerId.equals(loginUserId)) {
|
|
|
return R.fail("无权操作其他经销商的预测数据");
|
|
|
}
|
|
|
|
|
|
- // 3. 检查是否已提报
|
|
|
List<PcBladeSalesForecastSummary> existingForecasts = checkAlreadySubmitted(forecast);
|
|
|
boolean isUpdate = !existingForecasts.isEmpty();
|
|
|
|
|
|
- // 4. 设置公共字段
|
|
|
- if (existingForecasts != null && existingForecasts.size() > 0) {
|
|
|
+ if (isUpdate) {
|
|
|
forecast.setId(existingForecasts.get(0).getId());
|
|
|
forecast.setUpdateTime(new Date());
|
|
|
forecast.setUpdateUser(loginUserId);
|
|
|
@@ -310,7 +271,6 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
forecast.setApprovedName(null);
|
|
|
forecast.setApprovedTime(null);
|
|
|
} else {
|
|
|
-// forecast.setId(IdWorker.getId()); // MyBatis-Plus自带的雪花算法ID生成
|
|
|
forecast.setCreateTime(new Date());
|
|
|
forecast.setCreateUser(loginUserId);
|
|
|
forecast.setUpdateTime(new Date());
|
|
|
@@ -319,7 +279,6 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 5. 批量保存
|
|
|
boolean success = this.saveOrUpdateBatch(forecasts);
|
|
|
return success ? R.success("批量操作成功") : R.fail("批量操作失败");
|
|
|
}
|
|
|
@@ -330,13 +289,11 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // 获取当前年月
|
|
|
LocalDate now = LocalDate.now();
|
|
|
int currentYear = now.getYear();
|
|
|
int currentMonth = now.getMonthValue();
|
|
|
|
|
|
QueryWrapper<PcBladeSalesForecastSummary> queryWrapper = new QueryWrapper<>();
|
|
|
- // 将customerId改为CUSTOMER_ID,与数据库实际列名保持一致
|
|
|
queryWrapper.eq("CUSTOMER_ID", customerId)
|
|
|
.eq("year", currentYear)
|
|
|
.eq("month", currentMonth)
|
|
|
@@ -350,23 +307,17 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
*/
|
|
|
@Override
|
|
|
public void exportExcelTemplate(HttpServletResponse response) throws IOException {
|
|
|
- // 创建Excel工作簿
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
- // 创建工作表
|
|
|
Sheet sheet = workbook.createSheet("销售预测模板");
|
|
|
|
|
|
- // 创建表头行
|
|
|
Row headerRow = sheet.createRow(0);
|
|
|
|
|
|
- // 定义表头内容(与实体类字段对应)
|
|
|
String[] headers = {
|
|
|
"年份", "月份", "经销商ID", "经销商编码", "经销商名称",
|
|
|
"品牌ID", "品牌编码", "品牌名称", "物料ID", "物料编码",
|
|
|
"物料名称", "规格", "花纹", "预测数量"
|
|
|
};
|
|
|
|
|
|
- // 创建单元格样式
|
|
|
-
|
|
|
CellStyle headerStyle = workbook.createCellStyle();
|
|
|
Font font = workbook.createFont();
|
|
|
font.setBold(true);
|
|
|
@@ -377,16 +328,13 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
|
- // 设置表头
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
Cell cell = headerRow.createCell(i);
|
|
|
cell.setCellValue(headers[i]);
|
|
|
cell.setCellStyle(headerStyle);
|
|
|
- // 自动调整列宽
|
|
|
sheet.autoSizeColumn(i);
|
|
|
}
|
|
|
|
|
|
- // 添加一行示例数据(可选)
|
|
|
Row exampleRow = sheet.createRow(1);
|
|
|
exampleRow.createCell(0).setCellValue(2023);
|
|
|
exampleRow.createCell(1).setCellValue(10);
|
|
|
@@ -400,12 +348,10 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
exampleRow.createCell(12).setCellValue("花纹示例");
|
|
|
exampleRow.createCell(13).setCellValue(100);
|
|
|
|
|
|
- // 设置响应头
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
String fileName = URLEncoder.encode("销售预测模板.xlsx", StandardCharsets.UTF_8.name());
|
|
|
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + fileName);
|
|
|
|
|
|
- // 写入响应输出流
|
|
|
try (OutputStream os = response.getOutputStream()) {
|
|
|
workbook.write(os);
|
|
|
} finally {
|
|
|
@@ -419,17 +365,14 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R<String> importExcelData(MultipartFile file) throws IOException {
|
|
|
- // 检查是否可以提报
|
|
|
if (!checkCanSubmit()) {
|
|
|
return R.fail("本月21日后不能再提报预测");
|
|
|
}
|
|
|
|
|
|
- // 检查文件是否为空
|
|
|
if (file.isEmpty()) {
|
|
|
return R.fail("导入文件不能为空");
|
|
|
}
|
|
|
|
|
|
- // 检查文件格式
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
if (fileName == null || (!fileName.endsWith(".xlsx") && !fileName.endsWith(".xls"))) {
|
|
|
return R.fail("请上传Excel格式的文件");
|
|
|
@@ -440,37 +383,28 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return R.fail("用户未登录");
|
|
|
}
|
|
|
|
|
|
- // 使用EasyExcel读取Excel文件
|
|
|
List<PcBladeSalesForecastSummary> forecasts = EasyExcel.read(file.getInputStream())
|
|
|
.head(PcBladeSalesForecastSummary.class)
|
|
|
.registerReadListener(new AnalysisEventListener<PcBladeSalesForecastSummary>() {
|
|
|
- // 可以在这里添加逐行验证逻辑
|
|
|
@Override
|
|
|
- public void invoke(PcBladeSalesForecastSummary data, AnalysisContext context) {
|
|
|
-
|
|
|
- }
|
|
|
+ public void invoke(PcBladeSalesForecastSummary data, AnalysisContext context) {}
|
|
|
|
|
|
@Override
|
|
|
- public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
- // 所有数据解析完成后执行
|
|
|
- }
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext context) {}
|
|
|
})
|
|
|
.sheet()
|
|
|
.doReadSync();
|
|
|
|
|
|
- // 验证导入的数据
|
|
|
if (forecasts.isEmpty()) {
|
|
|
return R.fail("导入数据为空");
|
|
|
}
|
|
|
|
|
|
- // 数据验证和处理
|
|
|
List<String> errorMessages = new ArrayList<>();
|
|
|
|
|
|
for (int i = 0; i < forecasts.size(); i++) {
|
|
|
PcBladeSalesForecastSummary forecast = forecasts.get(i);
|
|
|
- int rowNum = i + 2; // 行号从2开始(表头+1)
|
|
|
+ int rowNum = i + 2;
|
|
|
|
|
|
- // 基本数据验证
|
|
|
if (forecast.getYear() == null) {
|
|
|
errorMessages.add("第" + rowNum + "行:年份不能为空");
|
|
|
}
|
|
|
@@ -487,27 +421,22 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
errorMessages.add("第" + rowNum + "行:预测数量必须大于0");
|
|
|
}
|
|
|
|
|
|
- // 设置系统字段,覆盖可能手动填写的值
|
|
|
- forecast.setCustomerId(loginUserId); // 强制设置为当前登录用户ID
|
|
|
- forecast.setId(null); // 清除ID,由系统生成
|
|
|
- forecast.setApprovalStatus(0); // 初始化为未审批状态
|
|
|
+ forecast.setCustomerId(loginUserId);
|
|
|
+ forecast.setId(null);
|
|
|
+ forecast.setApprovalStatus(0);
|
|
|
forecast.setCreateTime(new Date());
|
|
|
forecast.setCreateUser(AuthUtil.getUserId());
|
|
|
forecast.setUpdateTime(new Date());
|
|
|
forecast.setUpdateUser(AuthUtil.getUserId());
|
|
|
-
|
|
|
- // 清除审批相关字段,避免导入时携带
|
|
|
forecast.setApprovedBy(null);
|
|
|
forecast.setApprovedName(null);
|
|
|
forecast.setApprovedTime(null);
|
|
|
}
|
|
|
|
|
|
- // 如果有验证错误,返回错误信息
|
|
|
if (!errorMessages.isEmpty()) {
|
|
|
return R.fail("导入数据验证失败:\n" + String.join("\n", errorMessages));
|
|
|
}
|
|
|
|
|
|
- // 调用批量保存方法
|
|
|
return batchSaveOrUpdateForecastsFun(forecasts);
|
|
|
}
|
|
|
|
|
|
@@ -516,15 +445,13 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
*/
|
|
|
private R<String> batchSaveOrUpdateForecastsFun(List<PcBladeSalesForecastSummary> forecasts) {
|
|
|
try {
|
|
|
- // 先删除当前用户已有的同月份数据,避免重复
|
|
|
PcBladeSalesForecastSummary example = new PcBladeSalesForecastSummary();
|
|
|
example.setCustomerId(forecasts.get(0).getCustomerId());
|
|
|
example.setYear(forecasts.get(0).getYear());
|
|
|
example.setMonth(forecasts.get(0).getMonth());
|
|
|
- forecastMapper.deleteByExample(example);
|
|
|
+ baseMapper.delete(new QueryWrapper<>(example));
|
|
|
|
|
|
- // 批量插入新数据
|
|
|
- forecastMapper.batchInsert(forecasts);
|
|
|
+ this.saveBatch(forecasts);
|
|
|
return R.success("导入成功,共导入" + forecasts.size() + "条数据");
|
|
|
} catch (Exception e) {
|
|
|
log.error("批量保存预测数据失败", e);
|
|
|
@@ -551,7 +478,6 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return R.fail("预测数据不存在");
|
|
|
}
|
|
|
|
|
|
- // 设置审批信息
|
|
|
forecast.setApprovalStatus(approvalStatus);
|
|
|
forecast.setApprovedBy(AuthUtil.getUserId());
|
|
|
forecast.setApprovedName(AuthUtil.getUserName());
|
|
|
@@ -563,32 +489,64 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
return success ? R.success("审核成功") : R.fail("审核失败");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 工厂端审核预测数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R<String> approveFactoryForecast(Long id, Long forecastMainId, Integer approvalStatus, String approvalRemark) {
|
|
|
+ if (forecastMainId == null) {
|
|
|
+ return R.fail("预测销售主数据ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ PcBladeSalesForecastMain pcBladeSalesForecastMain = salesForecastMainService.selectPcBladeSalesForecastMainById(forecastMainId);
|
|
|
+ if (pcBladeSalesForecastMain == null) {
|
|
|
+ return R.fail("预测销售主数据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (id == null) {
|
|
|
+ return R.fail("预测ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (approvalStatus == null || (approvalStatus != 1 && approvalStatus != 2)) {
|
|
|
+ return R.fail("审批状态不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ PcBladeSalesForecastSummary forecast = this.getById(id);
|
|
|
+ if (forecast == null) {
|
|
|
+ return R.fail("预测数据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ forecast.setApprovalStatus(approvalStatus);
|
|
|
+ forecast.setApprovedBy(AuthUtil.getUserId());
|
|
|
+ forecast.setApprovedName(AuthUtil.getUserName());
|
|
|
+ forecast.setApprovedTime(LocalDateTime.now());
|
|
|
+ forecast.setUpdateTime(new Date());
|
|
|
+ forecast.setUpdateUser(AuthUtil.getUserId());
|
|
|
+
|
|
|
+ boolean success = this.updateById(forecast);
|
|
|
+ return success ? R.success("审核成功") : R.fail("审核失败");
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 根据用户ID和日期条件查询销售预测列表(分页)
|
|
|
*/
|
|
|
@Override
|
|
|
public IPage<PcBladeSalesForecastSummary> getForecastPageByUserId(Long customerId, LocalDate startDate, LocalDate endDate, Query query) {
|
|
|
- // 创建分页对象
|
|
|
IPage<PcBladeSalesForecastSummary> page = new Page<>(query.getCurrent(), query.getSize());
|
|
|
-
|
|
|
- // 构建查询条件
|
|
|
QueryWrapper<PcBladeSalesForecastSummary> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("CUSTOMER_ID", customerId);
|
|
|
|
|
|
- // 处理日期区间查询
|
|
|
if (startDate != null && endDate != null) {
|
|
|
queryWrapper.ge("year", startDate.getYear())
|
|
|
.le("year", endDate.getYear());
|
|
|
|
|
|
- // 如果是同一年,添加月份条件
|
|
|
if (startDate.getYear() == endDate.getYear()) {
|
|
|
queryWrapper.and(w -> w
|
|
|
.ge("month", startDate.getMonthValue())
|
|
|
.le("month", endDate.getMonthValue())
|
|
|
);
|
|
|
} else if (startDate.getYear() < endDate.getYear()) {
|
|
|
- // 跨年度查询
|
|
|
queryWrapper.and(w -> w
|
|
|
.or(qw -> qw.eq("year", startDate.getYear()).ge("month", startDate.getMonthValue()))
|
|
|
.or(qw -> qw.eq("year", endDate.getYear()).le("month", endDate.getMonthValue()))
|
|
|
@@ -596,23 +554,18 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
);
|
|
|
}
|
|
|
} else if (startDate != null) {
|
|
|
- // 只有开始日期
|
|
|
queryWrapper.ge("year", startDate.getYear());
|
|
|
- if (queryWrapper.getEntity().getYear().equals(startDate.getYear())) {
|
|
|
+ if (queryWrapper.getEntity().getYear() != null && queryWrapper.getEntity().getYear().equals(startDate.getYear())) {
|
|
|
queryWrapper.ge("month", startDate.getMonthValue());
|
|
|
}
|
|
|
} else if (endDate != null) {
|
|
|
- // 只有结束日期
|
|
|
queryWrapper.le("year", endDate.getYear());
|
|
|
- if (queryWrapper.getEntity().getYear().equals(endDate.getYear())) {
|
|
|
+ if (queryWrapper.getEntity().getYear() != null && queryWrapper.getEntity().getYear().equals(endDate.getYear())) {
|
|
|
queryWrapper.le("month", endDate.getMonthValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 按年份和月份降序排列
|
|
|
queryWrapper.orderByDesc("year", "month", "create_time");
|
|
|
-
|
|
|
- // 执行分页查询
|
|
|
return this.page(page, queryWrapper);
|
|
|
}
|
|
|
|
|
|
@@ -621,11 +574,9 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
*/
|
|
|
@Override
|
|
|
public List<PcBladeSalesForecastSummary> getForecastListByUserId(Long customerId, LocalDate startDate, LocalDate endDate) {
|
|
|
- // 复用分页查询的条件构建逻辑
|
|
|
QueryWrapper<PcBladeSalesForecastSummary> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("CUSTOMER_ID", customerId);
|
|
|
|
|
|
- // 处理日期区间查询(与分页方法相同)
|
|
|
if (startDate != null && endDate != null) {
|
|
|
queryWrapper.ge("year", startDate.getYear())
|
|
|
.le("year", endDate.getYear());
|
|
|
@@ -644,19 +595,17 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
}
|
|
|
} else if (startDate != null) {
|
|
|
queryWrapper.ge("year", startDate.getYear());
|
|
|
- if (queryWrapper.getEntity().getYear().equals(startDate.getYear())) {
|
|
|
+ if (queryWrapper.getEntity().getYear() != null && queryWrapper.getEntity().getYear().equals(startDate.getYear())) {
|
|
|
queryWrapper.ge("month", startDate.getMonthValue());
|
|
|
}
|
|
|
} else if (endDate != null) {
|
|
|
queryWrapper.le("year", endDate.getYear());
|
|
|
- if (queryWrapper.getEntity().getYear().equals(endDate.getYear())) {
|
|
|
+ if (queryWrapper.getEntity().getYear() != null && queryWrapper.getEntity().getYear().equals(endDate.getYear())) {
|
|
|
queryWrapper.le("month", endDate.getMonthValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
queryWrapper.orderByDesc("year", "month", "create_time");
|
|
|
-
|
|
|
- // 执行列表查询
|
|
|
return this.list(queryWrapper);
|
|
|
}
|
|
|
|
|
|
@@ -673,8 +622,4 @@ public class PcBladeSalesForecastSummaryServiceImpl extends BaseServiceImpl<PcBl
|
|
|
|
|
|
return this.list(queryWrapper);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|