273 lines
11 KiB
Java
273 lines
11 KiB
Java
|
|
package com.klp.controller;
|
|||
|
|
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
import java.util.Arrays;
|
|||
|
|
|
|||
|
|
import lombok.RequiredArgsConstructor;
|
|||
|
|
import javax.servlet.http.HttpServletResponse;
|
|||
|
|
import javax.validation.constraints.*;
|
|||
|
|
import org.springframework.web.bind.annotation.*;
|
|||
|
|
import org.springframework.validation.annotation.Validated;
|
|||
|
|
import com.klp.common.annotation.RepeatSubmit;
|
|||
|
|
import com.klp.common.annotation.Log;
|
|||
|
|
import com.klp.common.core.controller.BaseController;
|
|||
|
|
import com.klp.common.core.domain.PageQuery;
|
|||
|
|
import com.klp.common.core.domain.R;
|
|||
|
|
import com.klp.common.core.validate.AddGroup;
|
|||
|
|
import com.klp.common.core.validate.EditGroup;
|
|||
|
|
import com.klp.common.enums.BusinessType;
|
|||
|
|
import com.klp.common.utils.poi.ExcelUtil;
|
|||
|
|
import com.klp.domain.vo.CostCoilDailyVo;
|
|||
|
|
import com.klp.domain.bo.CostCoilDailyBo;
|
|||
|
|
import com.klp.service.ICostCoilDailyService;
|
|||
|
|
import com.klp.common.core.page.TableDataInfo;
|
|||
|
|
|
|||
|
|
import java.time.LocalDate;
|
|||
|
|
import java.time.LocalDateTime;
|
|||
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 钢卷日成本记录表
|
|||
|
|
*
|
|||
|
|
* @author klp
|
|||
|
|
* @date 2025-11-25
|
|||
|
|
*/
|
|||
|
|
@Validated
|
|||
|
|
@RequiredArgsConstructor
|
|||
|
|
@RestController
|
|||
|
|
@RequestMapping("/wms/cost/coil")
|
|||
|
|
public class CostCoilDailyController extends BaseController {
|
|||
|
|
|
|||
|
|
private final ICostCoilDailyService iCostCoilDailyService;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查询钢卷日成本记录表列表
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/list")
|
|||
|
|
public TableDataInfo<CostCoilDailyVo> list(CostCoilDailyBo bo, PageQuery pageQuery) {
|
|||
|
|
return iCostCoilDailyService.queryPageList(bo, pageQuery);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 导出钢卷日成本记录表列表
|
|||
|
|
*/
|
|||
|
|
@Log(title = "钢卷日成本记录表", businessType = BusinessType.EXPORT)
|
|||
|
|
@PostMapping("/export")
|
|||
|
|
public void export(CostCoilDailyBo bo, HttpServletResponse response) {
|
|||
|
|
List<CostCoilDailyVo> list = iCostCoilDailyService.queryList(bo);
|
|||
|
|
ExcelUtil.exportExcel(list, "钢卷日成本记录表", CostCoilDailyVo.class, response);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取钢卷日成本记录表详细信息
|
|||
|
|
*
|
|||
|
|
* @param costId 主键
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/{costId}")
|
|||
|
|
public R<CostCoilDailyVo> getInfo(@NotNull(message = "主键不能为空")
|
|||
|
|
@PathVariable Long costId) {
|
|||
|
|
return R.ok(iCostCoilDailyService.queryById(costId));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 新增钢卷日成本记录表
|
|||
|
|
*/
|
|||
|
|
@Log(title = "钢卷日成本记录表", businessType = BusinessType.INSERT)
|
|||
|
|
@RepeatSubmit()
|
|||
|
|
@PostMapping()
|
|||
|
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody CostCoilDailyBo bo) {
|
|||
|
|
return toAjax(iCostCoilDailyService.insertByBo(bo));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 修改钢卷日成本记录表
|
|||
|
|
*/
|
|||
|
|
@Log(title = "钢卷日成本记录表", businessType = BusinessType.UPDATE)
|
|||
|
|
@RepeatSubmit()
|
|||
|
|
@PutMapping()
|
|||
|
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody CostCoilDailyBo bo) {
|
|||
|
|
return toAjax(iCostCoilDailyService.updateByBo(bo));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 删除钢卷日成本记录表
|
|||
|
|
*
|
|||
|
|
* @param costIds 主键串
|
|||
|
|
*/
|
|||
|
|
@Log(title = "钢卷日成本记录表", businessType = BusinessType.DELETE)
|
|||
|
|
@DeleteMapping("/{costIds}")
|
|||
|
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
|||
|
|
@PathVariable Long[] costIds) {
|
|||
|
|
return toAjax(iCostCoilDailyService.deleteWithValidByIds(Arrays.asList(costIds), true));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 实时计算指定钢卷的成本
|
|||
|
|
*
|
|||
|
|
* @param coilId 钢卷ID(可选)
|
|||
|
|
* @param calcTime 计算时间点(可选,默认当前时间)
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/calculate")
|
|||
|
|
public R<Map<String, Object>> calculateCost(@RequestParam(required = false) Long coilId,
|
|||
|
|
@RequestParam(required = false) LocalDateTime calcTime) {
|
|||
|
|
Map<String, Object> result = iCostCoilDailyService.calculateCost(coilId, calcTime);
|
|||
|
|
if (result.containsKey("error")) {
|
|||
|
|
return R.fail(result.get("error").toString());
|
|||
|
|
}
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 批量计算多个钢卷的成本
|
|||
|
|
*
|
|||
|
|
* @param coilIds 钢卷ID列表(支持逗号分隔的字符串或数组)
|
|||
|
|
* @param calcTime 计算时间点(可选,默认当前时间)
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/batchCalculateCost")
|
|||
|
|
public R<List<Map<String, Object>>> batchCalculateCost(@RequestParam String coilIds,
|
|||
|
|
@RequestParam(required = false) LocalDateTime calcTime) {
|
|||
|
|
// 解析coilIds字符串为Long列表
|
|||
|
|
List<Long> coilIdList = new java.util.ArrayList<>();
|
|||
|
|
if (coilIds != null && !coilIds.trim().isEmpty()) {
|
|||
|
|
String[] ids = coilIds.split(",");
|
|||
|
|
for (String id : ids) {
|
|||
|
|
try {
|
|||
|
|
Long coilId = Long.parseLong(id.trim());
|
|||
|
|
coilIdList.add(coilId);
|
|||
|
|
} catch (NumberFormatException e) {
|
|||
|
|
// 忽略无效的ID
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
List<Map<String, Object>> results = iCostCoilDailyService.batchCalculateCost(coilIdList, calcTime);
|
|||
|
|
return R.ok(results);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 批量计算钢卷成本(定时任务使用)
|
|||
|
|
*
|
|||
|
|
* @param calcDate 计算日期(可选,默认前一日)
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/batchCalculate")
|
|||
|
|
@Log(title = "批量计算钢卷成本", businessType = BusinessType.OTHER)
|
|||
|
|
public R<Integer> batchCalculate(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate calcDate) {
|
|||
|
|
if (calcDate == null) {
|
|||
|
|
calcDate = LocalDate.now().minusDays(1);
|
|||
|
|
}
|
|||
|
|
int count = iCostCoilDailyService.calculateDailyCost(calcDate);
|
|||
|
|
return R.ok(count);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查询成本统计报表
|
|||
|
|
*
|
|||
|
|
* @param startDate 开始日期
|
|||
|
|
* @param endDate 结束日期
|
|||
|
|
* @param groupBy 分组维度(warehouse/itemType/materialType)
|
|||
|
|
* @param warehouseId 库区ID(可选)
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/report/summary")
|
|||
|
|
public R<Map<String, Object>> queryCostSummary(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
|
|||
|
|
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
|
|||
|
|
@RequestParam(required = false) String groupBy,
|
|||
|
|
@RequestParam(required = false) Long warehouseId) {
|
|||
|
|
Map<String, Object> result = iCostCoilDailyService.queryCostSummary(startDate, endDate, groupBy, warehouseId);
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查询成本趋势分析
|
|||
|
|
*
|
|||
|
|
* @param startDate 开始日期
|
|||
|
|
* @param endDate 结束日期
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/report/trend")
|
|||
|
|
public R<List<Map<String, Object>>> queryCostTrend(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
|
|||
|
|
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
|
|||
|
|
List<Map<String, Object>> result = iCostCoilDailyService.queryCostTrend(startDate, endDate);
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 按入场钢卷号维度计算成本
|
|||
|
|
*
|
|||
|
|
* @param enterCoilNo 入场钢卷号
|
|||
|
|
* @param calcDate 计算日期(可选,默认当前日期)
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/calculateByEnterCoilNo")
|
|||
|
|
public R<Map<String, Object>> calculateCostByEnterCoilNo(@RequestParam String enterCoilNo,
|
|||
|
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate calcDate) {
|
|||
|
|
Map<String, Object> result = iCostCoilDailyService.calculateCostByEnterCoilNo(enterCoilNo, calcDate);
|
|||
|
|
if (result.containsKey("error")) {
|
|||
|
|
return R.fail(result.get("error").toString());
|
|||
|
|
}
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 现算成本检索(基于 wms_material_coil)
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/search/material")
|
|||
|
|
public R<Map<String, Object>> searchMaterialCost(@RequestParam(required = false) String enterCoilNo,
|
|||
|
|
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate calcDate,
|
|||
|
|
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
|
|||
|
|
@RequestParam(required = false, defaultValue = "20") Integer pageSize) {
|
|||
|
|
Map<String, Object> result = iCostCoilDailyService.searchMaterialCost(enterCoilNo, calcDate, pageNum, pageSize);
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 批量按入场钢卷号维度计算成本(定时任务使用)
|
|||
|
|
*
|
|||
|
|
* @param calcDate 计算日期(可选,默认前一日)
|
|||
|
|
*/
|
|||
|
|
@PostMapping("/batchCalculateByEnterCoilNo")
|
|||
|
|
@Log(title = "批量按入场钢卷号计算成本", businessType = BusinessType.OTHER)
|
|||
|
|
public R<Integer> batchCalculateByEnterCoilNo(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate calcDate) {
|
|||
|
|
if (calcDate == null) {
|
|||
|
|
calcDate = LocalDate.now().minusDays(1);
|
|||
|
|
}
|
|||
|
|
int count = iCostCoilDailyService.calculateDailyCostByEnterCoilNo(calcDate);
|
|||
|
|
return R.ok(count);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查询按入场钢卷号统计的成本报表
|
|||
|
|
*
|
|||
|
|
* @param startDate 开始日期
|
|||
|
|
* @param endDate 结束日期
|
|||
|
|
* @param enterCoilNo 入场钢卷号(可选)
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/report/byEnterCoilNo")
|
|||
|
|
public R<List<Map<String, Object>>> queryCostByEnterCoilNo(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
|
|||
|
|
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
|
|||
|
|
@RequestParam(required = false) String enterCoilNo) {
|
|||
|
|
List<Map<String, Object>> result = iCostCoilDailyService.queryCostByEnterCoilNo(startDate, endDate, enterCoilNo);
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 囤积成本页数据(分页 + 汇总)
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/stockpile")
|
|||
|
|
public R<Map<String, Object>> queryStockpile(@RequestParam(required = false) String enterCoilNo,
|
|||
|
|
@RequestParam(required = false) String currentCoilNo,
|
|||
|
|
PageQuery pageQuery) {
|
|||
|
|
Map<String, Object> result = iCostCoilDailyService.queryStockpileCostList(enterCoilNo, currentCoilNo, pageQuery);
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 成本模块首页概览
|
|||
|
|
* 统计当前「现存且未发货」钢卷的总成本、总净重、总毛重以及平均在库天数
|
|||
|
|
*/
|
|||
|
|
@GetMapping("/overview")
|
|||
|
|
public R<Map<String, Object>> overview() {
|
|||
|
|
Map<String, Object> result = iCostCoilDailyService.queryOverview();
|
|||
|
|
return R.ok(result);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|