成本模块
This commit is contained in:
@@ -249,4 +249,101 @@ public class SampleService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 6、成本日计算任务
|
||||
* 每天凌晨 2 点由调度中心触发,负责调用业务系统接口,计算前一日成本日报数据。
|
||||
*
|
||||
* 调度中心建议配置:
|
||||
* - JobHandler:costDailyCalculateJob
|
||||
* - Cron:0 0 2 * * ?
|
||||
* - 执行参数(可选):baseUrl=http://127.0.0.1:8080
|
||||
*/
|
||||
@XxlJob("costDailyCalculateJob")
|
||||
public void costDailyCalculateJob() throws Exception {
|
||||
// 1. 计算前一日日期
|
||||
java.time.LocalDate calcDate = java.time.LocalDate.now().minusDays(1);
|
||||
String dateStr = calcDate.toString(); // yyyy-MM-dd
|
||||
|
||||
// 2. 解析调度参数,获取业务系统基础地址
|
||||
String param = XxlJobHelper.getJobParam();
|
||||
String baseUrl = "http://127.0.0.1:8080"; // 默认本机
|
||||
if (param != null && !param.trim().isEmpty()) {
|
||||
// 简单解析形式:baseUrl=http://host:port
|
||||
for (String line : param.split("\n")) {
|
||||
line = line.trim();
|
||||
if (line.startsWith("baseUrl=")) {
|
||||
baseUrl = line.substring("baseUrl=".length()).trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 构造两个调用地址
|
||||
String urlDaily = baseUrl + "/wms/cost/coil/batchCalculate?calcDate=" + dateStr;
|
||||
String urlByEnterCoilNo = baseUrl + "/wms/cost/coil/batchCalculateByEnterCoilNo?calcDate=" + dateStr;
|
||||
|
||||
XxlJobHelper.log("开始成本日计算,calcDate={}, baseUrl={}", dateStr, baseUrl);
|
||||
|
||||
// 4. 依次调用两个接口
|
||||
try {
|
||||
doPost(urlDaily);
|
||||
XxlJobHelper.log("调用 batchCalculate 成功: {}", urlDaily);
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.log(e);
|
||||
XxlJobHelper.handleFail("调用 batchCalculate 失败: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
doPost(urlByEnterCoilNo);
|
||||
XxlJobHelper.log("调用 batchCalculateByEnterCoilNo 成功: {}", urlByEnterCoilNo);
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.log(e);
|
||||
XxlJobHelper.handleFail("调用 batchCalculateByEnterCoilNo 失败: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// 默认成功
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单的 POST 请求工具,复用 JDK HttpURLConnection。
|
||||
*/
|
||||
private void doPost(String url) throws Exception {
|
||||
HttpURLConnection connection = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
URL realUrl = new URL(url);
|
||||
connection = (HttpURLConnection) realUrl.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.setUseCaches(false);
|
||||
connection.setReadTimeout(30 * 1000);
|
||||
connection.setConnectTimeout(10 * 1000);
|
||||
connection.setRequestProperty("connection", "Keep-Alive");
|
||||
|
||||
connection.connect();
|
||||
|
||||
int statusCode = connection.getResponseCode();
|
||||
if (statusCode != 200) {
|
||||
throw new RuntimeException("HTTP " + url + " StatusCode(" + statusCode + ") Invalid.");
|
||||
}
|
||||
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
XxlJobHelper.log("调用 {} 返回: {}", url, result.toString());
|
||||
} finally {
|
||||
if (bufferedReader != null) {
|
||||
bufferedReader.close();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
388
klp-ui/src/views/wms/cost/dashboard/index.vue
Normal file
388
klp-ui/src/views/wms/cost/dashboard/index.vue
Normal file
@@ -0,0 +1,388 @@
|
||||
<template>
|
||||
<div class="app-container cost-dashboard">
|
||||
<!-- 成本概览 -->
|
||||
<div class="overview-section">
|
||||
<div class="overview-item">
|
||||
<div class="overview-label">今日总成本</div>
|
||||
<div class="overview-value primary">{{ formatMoney(todayCost) }}</div>
|
||||
<div class="overview-desc">元</div>
|
||||
</div>
|
||||
<div class="overview-item">
|
||||
<div class="overview-label">在库钢卷数</div>
|
||||
<div class="overview-value warning">{{ totalCoils }}</div>
|
||||
<div class="overview-desc">个</div>
|
||||
</div>
|
||||
<div class="overview-item">
|
||||
<div class="overview-label">总净重</div>
|
||||
<div class="overview-value success">{{ formatWeight(totalNetWeight) }}</div>
|
||||
<div class="overview-desc">吨</div>
|
||||
</div>
|
||||
<div class="overview-item">
|
||||
<div class="overview-label">当前成本标准</div>
|
||||
<div class="overview-value info">{{ formatMoney(currentUnitCost) }}</div>
|
||||
<div class="overview-desc">元/吨/天</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 快速入口 -->
|
||||
<div class="action-section">
|
||||
<div class="section-header">
|
||||
<span>快速入口</span>
|
||||
<el-tooltip content="批量日计算改为后端定时任务,这里仅提供配置与明细入口" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div class="action-buttons">
|
||||
<el-button type="warning" icon="el-icon-setting" @click="goToStandardConfig">
|
||||
成本标准配置
|
||||
</el-button>
|
||||
<el-button type="info" icon="el-icon-view" @click="goToDetail">
|
||||
查看成本明细
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 成本趋势图表 -->
|
||||
<div class="chart-section">
|
||||
<div class="section-header">
|
||||
<span>成本趋势(近30天)</span>
|
||||
<el-date-picker
|
||||
v-model="trendDateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
size="small"
|
||||
style="width: 300px;"
|
||||
value-format="yyyy-MM-dd"
|
||||
@change="loadTrendData"
|
||||
/>
|
||||
</div>
|
||||
<div id="costTrendChart" style="height: 300px;"></div>
|
||||
</div>
|
||||
|
||||
<!-- 成本分布统计 -->
|
||||
<div class="stat-section">
|
||||
<div class="stat-item">
|
||||
<div class="section-header">
|
||||
<span>按库区统计</span>
|
||||
</div>
|
||||
<el-table :data="warehouseStats" stripe style="width: 100%">
|
||||
<el-table-column prop="warehouseName" label="库区名称" />
|
||||
<el-table-column prop="coilCount" label="钢卷数" align="right" />
|
||||
<el-table-column prop="totalCost" label="总成本" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatMoney(scope.row.totalCost) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="section-header">
|
||||
<span>按物品类型统计</span>
|
||||
</div>
|
||||
<el-table :data="itemTypeStats" stripe style="width: 100%">
|
||||
<el-table-column prop="itemType" label="物品类型">
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.itemType === 'raw_material' ? '原料' : '成品' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="coilCount" label="钢卷数" align="right" />
|
||||
<el-table-column prop="totalCost" label="总成本" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatMoney(scope.row.totalCost) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
queryCostSummary,
|
||||
queryCostTrend,
|
||||
getCurrentCostStandard,
|
||||
getCostOverview
|
||||
} from '@/api/wms/cost'
|
||||
import * as echarts from 'echarts'
|
||||
|
||||
export default {
|
||||
name: 'CostDashboard',
|
||||
data() {
|
||||
return {
|
||||
todayCost: 0,
|
||||
totalCoils: 0,
|
||||
totalNetWeight: 0,
|
||||
totalGrossWeight: 0,
|
||||
avgStorageDays: 0,
|
||||
currentUnitCost: 10000,
|
||||
trendDateRange: [],
|
||||
trendChart: null,
|
||||
warehouseStats: [],
|
||||
itemTypeStats: []
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.initTrendDateRange()
|
||||
this.loadOverviewData()
|
||||
this.loadTrendData()
|
||||
this.loadStatsData()
|
||||
this.loadCurrentStandard()
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.trendChart) {
|
||||
this.trendChart.dispose()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
initTrendDateRange() {
|
||||
const end = new Date()
|
||||
const start = new Date()
|
||||
start.setTime(start.getTime() - 30 * 24 * 60 * 60 * 1000)
|
||||
this.trendDateRange = [
|
||||
start.toISOString().split('T')[0],
|
||||
end.toISOString().split('T')[0]
|
||||
]
|
||||
},
|
||||
async loadOverviewData() {
|
||||
try {
|
||||
const res = await getCostOverview()
|
||||
if (res.code === 200 && res.data) {
|
||||
this.todayCost = res.data.totalCost || 0
|
||||
this.totalCoils = res.data.totalCoils || 0
|
||||
this.totalNetWeight = res.data.totalNetWeight || 0
|
||||
this.totalGrossWeight = res.data.totalGrossWeight || 0
|
||||
this.avgStorageDays = res.data.avgStorageDays || 0
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载概览数据失败:', error)
|
||||
}
|
||||
},
|
||||
async loadTrendData() {
|
||||
if (!this.trendDateRange || this.trendDateRange.length !== 2) return
|
||||
try {
|
||||
const startDate = this.trendDateRange[0] instanceof Date
|
||||
? this.trendDateRange[0].toISOString().split('T')[0]
|
||||
: this.trendDateRange[0]
|
||||
const endDate = this.trendDateRange[1] instanceof Date
|
||||
? this.trendDateRange[1].toISOString().split('T')[0]
|
||||
: this.trendDateRange[1]
|
||||
const res = await queryCostTrend(startDate, endDate)
|
||||
if (res.code === 200 && res.data) {
|
||||
this.renderTrendChart(res.data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载趋势数据失败:', error)
|
||||
}
|
||||
},
|
||||
renderTrendChart(data) {
|
||||
this.$nextTick(() => {
|
||||
if (!this.trendChart) {
|
||||
this.trendChart = echarts.init(document.getElementById('costTrendChart'))
|
||||
}
|
||||
const dates = data.map(item => item.date)
|
||||
const costs = data.map(item => item.totalCost)
|
||||
const option = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
formatter: (params) => {
|
||||
return `${params[0].name}<br/>成本: ${this.formatMoney(params[0].value)}元`
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '4%',
|
||||
bottom: '3%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: dates,
|
||||
axisLine: { lineStyle: { color: '#C0C4CC' } }
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
axisLine: { lineStyle: { color: '#C0C4CC' } },
|
||||
axisLabel: {
|
||||
formatter: (value) => {
|
||||
if (value >= 10000) {
|
||||
return (value / 10000).toFixed(1) + '万'
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
},
|
||||
series: [{
|
||||
data: costs,
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
itemStyle: { color: '#409EFF' },
|
||||
areaStyle: {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0,
|
||||
y: 0,
|
||||
x2: 0,
|
||||
y2: 1,
|
||||
colorStops: [
|
||||
{ offset: 0, color: 'rgba(64, 158, 255, 0.3)' },
|
||||
{ offset: 1, color: 'rgba(64, 158, 255, 0.1)' }
|
||||
]
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
this.trendChart.setOption(option)
|
||||
})
|
||||
},
|
||||
async loadStatsData() {
|
||||
try {
|
||||
const today = new Date().toISOString().split('T')[0]
|
||||
const res = await queryCostSummary(today, today, 'warehouse', null)
|
||||
if (res.code === 200) {
|
||||
this.warehouseStats = res.data.details || []
|
||||
const itemTypeRes = await queryCostSummary(today, today, 'itemType', null)
|
||||
if (itemTypeRes.code === 200) {
|
||||
this.itemTypeStats = itemTypeRes.data.details || []
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败:', error)
|
||||
}
|
||||
},
|
||||
async loadCurrentStandard() {
|
||||
try {
|
||||
const res = await getCurrentCostStandard()
|
||||
if (res.code === 200 && res.data) {
|
||||
this.currentUnitCost = res.data.unitCost || 10000
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载成本标准失败:', error)
|
||||
}
|
||||
},
|
||||
goToStandardConfig() {
|
||||
this.$router.push('/wms/cost/standard')
|
||||
},
|
||||
goToDetail() {
|
||||
this.$router.push('/wms/cost/detail')
|
||||
},
|
||||
formatMoney(value) {
|
||||
if (!value) return '0.00'
|
||||
return Number(value).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
},
|
||||
formatWeight(value) {
|
||||
if (!value) return '0.000'
|
||||
return Number(value).toFixed(3)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.cost-dashboard {
|
||||
padding: 20px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.overview-section {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ebeef5;
|
||||
|
||||
.overview-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
|
||||
.overview-label {
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.overview-value {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
|
||||
&.primary {
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
&.success {
|
||||
color: #67c23a;
|
||||
}
|
||||
|
||||
&.info {
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
.overview-desc {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-section {
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ebeef5;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 500;
|
||||
margin-bottom: 15px;
|
||||
font-size: 16px;
|
||||
color: #303133;
|
||||
|
||||
.el-icon-question {
|
||||
color: #909399;
|
||||
cursor: help;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.chart-section {
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ebeef5;
|
||||
}
|
||||
|
||||
.stat-section {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ebeef5;
|
||||
}
|
||||
</style>
|
||||
|
||||
568
klp-ui/src/views/wms/cost/detail/index.vue
Normal file
568
klp-ui/src/views/wms/cost/detail/index.vue
Normal file
@@ -0,0 +1,568 @@
|
||||
<template>
|
||||
<div class="cost-search-page">
|
||||
<div class="hero">
|
||||
<div class="hero-content">
|
||||
<h1>成本检索中心</h1>
|
||||
<p>基于 wms_material_coil 实时计算,输入入场钢卷号即可查看成本</p>
|
||||
<div class="search-bar">
|
||||
<el-input
|
||||
v-model.trim="searchForm.enterCoilNo"
|
||||
placeholder="请输入入场钢卷号(支持前缀)"
|
||||
clearable
|
||||
class="search-input"
|
||||
@input="handleInputChange"
|
||||
@keyup.enter.native="handleSearchClick"
|
||||
/>
|
||||
<el-date-picker
|
||||
v-model="searchForm.calcDate"
|
||||
type="date"
|
||||
placeholder="可选:指定计算日期"
|
||||
value-format="yyyy-MM-dd"
|
||||
class="search-date"
|
||||
:picker-options="datePickerOptions"
|
||||
@change="handleCalcDateChange"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-search"
|
||||
:loading="loading"
|
||||
@click="handleSearchClick"
|
||||
>
|
||||
检索成本
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="hero-meta">
|
||||
<span>未发货:计算到选择日期(默认今日)</span>
|
||||
<span>已发货:计算到发货前一天</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="result-wrapper">
|
||||
<div class="result-actions">
|
||||
<el-button type="text" icon="el-icon-setting" @click="goToStandardConfig">成本标准配置</el-button>
|
||||
<el-divider direction="vertical"></el-divider>
|
||||
<el-button type="text" icon="el-icon-tickets" @click="goToDetail">查看历史明细</el-button>
|
||||
</div>
|
||||
|
||||
<el-empty
|
||||
v-if="!searchExecuted && !loading"
|
||||
description="请输入入场钢卷号后开始检索"
|
||||
/>
|
||||
|
||||
<div v-else>
|
||||
<el-card v-loading="loading" shadow="never" class="summary-card">
|
||||
<div class="summary-header">
|
||||
<div>
|
||||
<div class="summary-label">入场钢卷号</div>
|
||||
<div class="summary-value">{{ summary.enterCoilNo || '-' }}</div>
|
||||
</div>
|
||||
<el-tag type="info" effect="plain">
|
||||
统计日期:{{ summary.calcDate || '-' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="summary-grid">
|
||||
<div class="grid-item">
|
||||
<div class="grid-label">总子钢卷数</div>
|
||||
<div class="grid-value primary">{{ summary.totalCoils }}</div>
|
||||
<div class="grid-desc">
|
||||
<span>在库 {{ summary.unshippedCount }}</span>
|
||||
<span>已发货 {{ summary.shippedCount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid-item">
|
||||
<div class="grid-label">总毛重</div>
|
||||
<div class="grid-value">{{ formatWeight(summary.totalGrossWeight) }} 吨</div>
|
||||
<div class="grid-desc">毛重优先,缺失时用净重</div>
|
||||
</div>
|
||||
<div class="grid-item">
|
||||
<div class="grid-label">总净重</div>
|
||||
<div class="grid-value">{{ formatWeight(summary.totalNetWeight) }} 吨</div>
|
||||
<div class="grid-desc">实时换算为吨</div>
|
||||
</div>
|
||||
<div class="grid-item">
|
||||
<div class="grid-label">累计成本</div>
|
||||
<div class="grid-value accent">{{ formatMoney(summary.totalCost) }} 元</div>
|
||||
<div class="grid-desc">所有子钢卷累计值</div>
|
||||
</div>
|
||||
<div class="grid-item">
|
||||
<div class="grid-label">平均在库天数</div>
|
||||
<div class="grid-value">{{ formatNumber(summary.avgStorageDays, 2) }} 天</div>
|
||||
<div class="grid-desc">含在库与已发货</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<div v-if="cards.length" class="card-section">
|
||||
<div class="card-grid">
|
||||
<div class="coil-card" v-for="card in cards" :key="card.coilId">
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<div class="coil-no">{{ card.currentCoilNo }}</div>
|
||||
<div class="coil-meta">入库:{{ formatDate(card.startDate) }}</div>
|
||||
</div>
|
||||
<el-tag
|
||||
size="mini"
|
||||
:type="card.isShipped ? 'info' : 'success'"
|
||||
effect="plain"
|
||||
>
|
||||
{{ card.isShipped ? '已发货' : '在库' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">毛重(吨)</span>
|
||||
<span class="metric-value">{{ formatWeight(card.grossWeightTon) }}</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">净重(吨)</span>
|
||||
<span class="metric-value">{{ formatWeight(card.netWeightTon) }}</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">计费基准</span>
|
||||
<span class="metric-value">
|
||||
<el-tag size="mini" :type="card.weightBasis === 'gross' ? 'success' : 'info'" effect="plain">
|
||||
{{ card.weightBasis === 'gross' ? '毛重' : '净重' }}
|
||||
</el-tag>
|
||||
</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">在库天数</span>
|
||||
<span :class="['metric-value', getStorageDaysClass(card.storageDays)]">
|
||||
{{ card.storageDays || '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">单位成本</span>
|
||||
<span class="metric-value">{{ formatMoney(card.unitCost) }} 元/吨/天</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">累计成本</span>
|
||||
<span class="metric-value accent">{{ formatMoney(card.totalCost) }} 元</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">计费截至</span>
|
||||
<span class="metric-value">{{ formatDate(card.endDate) }}</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">所在库区</span>
|
||||
<span class="metric-value">{{ card.warehouseName || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pagination" v-if="pagination.total > pagination.pageSize">
|
||||
<el-pagination
|
||||
background
|
||||
layout="prev, pager, next"
|
||||
:page-size="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:current-page.sync="pagination.pageNum"
|
||||
@current-change="handlePageChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-empty
|
||||
v-else-if="!loading"
|
||||
description="暂无匹配钢卷"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { searchMaterialCost } from '@/api/wms/cost'
|
||||
|
||||
export default {
|
||||
name: 'CostSearchDashboard',
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
searchExecuted: false,
|
||||
searchForm: {
|
||||
enterCoilNo: '',
|
||||
calcDate: null
|
||||
},
|
||||
pagination: {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
total: 0
|
||||
},
|
||||
summary: {
|
||||
enterCoilNo: '',
|
||||
calcDate: '',
|
||||
totalCoils: 0,
|
||||
shippedCount: 0,
|
||||
unshippedCount: 0,
|
||||
totalGrossWeight: 0,
|
||||
totalNetWeight: 0,
|
||||
totalCost: 0,
|
||||
avgStorageDays: 0
|
||||
},
|
||||
cards: [],
|
||||
debounceTimer: null,
|
||||
datePickerOptions: {
|
||||
disabledDate(time) {
|
||||
return time.getTime() > Date.now()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.debounceTimer) {
|
||||
clearTimeout(this.debounceTimer)
|
||||
this.debounceTimer = null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleInputChange() {
|
||||
this.pagination.pageNum = 1
|
||||
if (this.debounceTimer) {
|
||||
clearTimeout(this.debounceTimer)
|
||||
}
|
||||
this.debounceTimer = setTimeout(() => {
|
||||
this.fetchResults()
|
||||
}, 400)
|
||||
},
|
||||
handleCalcDateChange() {
|
||||
if (!this.searchForm.enterCoilNo) return
|
||||
this.pagination.pageNum = 1
|
||||
this.fetchResults()
|
||||
},
|
||||
handleSearchClick() {
|
||||
this.pagination.pageNum = 1
|
||||
this.fetchResults()
|
||||
},
|
||||
async fetchResults() {
|
||||
if (!this.searchForm.enterCoilNo) {
|
||||
this.resetResults(false)
|
||||
return
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
const params = {
|
||||
enterCoilNo: this.searchForm.enterCoilNo.trim(),
|
||||
calcDate: this.searchForm.calcDate,
|
||||
pageNum: this.pagination.pageNum,
|
||||
pageSize: this.pagination.pageSize
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await searchMaterialCost(params)
|
||||
this.searchExecuted = true
|
||||
if (res.code === 200 && res.data) {
|
||||
const data = res.data
|
||||
const summaryData = data.summary || {}
|
||||
this.summary = {
|
||||
enterCoilNo: summaryData.enterCoilNo || params.enterCoilNo,
|
||||
calcDate: summaryData.calcDate || params.calcDate || this.formatDate(new Date()),
|
||||
totalCoils: summaryData.totalCoils || 0,
|
||||
shippedCount: summaryData.shippedCount || 0,
|
||||
unshippedCount: summaryData.unshippedCount || 0,
|
||||
totalGrossWeight: summaryData.totalGrossWeight || 0,
|
||||
totalNetWeight: summaryData.totalNetWeight || 0,
|
||||
totalCost: summaryData.totalCost || 0,
|
||||
avgStorageDays: summaryData.avgStorageDays || 0
|
||||
}
|
||||
this.cards = (data.records || []).map(item => ({
|
||||
...item,
|
||||
isShipped: item.isShipped === 1 || item.isShipped === true
|
||||
}))
|
||||
this.pagination.total = data.total || 0
|
||||
this.pagination.pageNum = data.pageNum || params.pageNum
|
||||
} else {
|
||||
this.resetResults(true)
|
||||
this.$message.warning(res.msg || '未查询到成本数据')
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error('检索失败,请稍后再试')
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
handlePageChange(page) {
|
||||
this.pagination.pageNum = page
|
||||
this.fetchResults()
|
||||
},
|
||||
resetResults(keepExecuted) {
|
||||
if (!keepExecuted) {
|
||||
this.searchExecuted = false
|
||||
}
|
||||
this.cards = []
|
||||
this.pagination.total = 0
|
||||
this.summary = {
|
||||
enterCoilNo: this.searchForm.enterCoilNo || '',
|
||||
calcDate: this.searchForm.calcDate || '',
|
||||
totalCoils: 0,
|
||||
shippedCount: 0,
|
||||
unshippedCount: 0,
|
||||
totalGrossWeight: 0,
|
||||
totalNetWeight: 0,
|
||||
totalCost: 0,
|
||||
avgStorageDays: 0
|
||||
}
|
||||
},
|
||||
goToStandardConfig() {
|
||||
this.$router.push('/wms/cost/standard')
|
||||
},
|
||||
goToDetail() {
|
||||
this.$router.push('/wms/cost/detail')
|
||||
},
|
||||
formatMoney(value) {
|
||||
if (!value) return '0.00'
|
||||
return Number(value).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2
|
||||
})
|
||||
},
|
||||
formatWeight(value) {
|
||||
if (!value) return '0.000'
|
||||
return Number(value).toFixed(3)
|
||||
},
|
||||
formatNumber(value, fraction = 2) {
|
||||
if (!value) return Number(0).toFixed(fraction)
|
||||
return Number(value).toFixed(fraction)
|
||||
},
|
||||
formatDate(value) {
|
||||
if (!value) return '-'
|
||||
if (value instanceof Date) {
|
||||
const yyyy = value.getFullYear()
|
||||
const mm = `${value.getMonth() + 1}`.padStart(2, '0')
|
||||
const dd = `${value.getDate()}`.padStart(2, '0')
|
||||
return `${yyyy}-${mm}-${dd}`
|
||||
}
|
||||
return value
|
||||
},
|
||||
getStorageDaysClass(days) {
|
||||
if (!days) return ''
|
||||
if (days >= 60) return 'storage-days-high'
|
||||
if (days >= 30) return 'storage-days-medium'
|
||||
return 'storage-days-normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.cost-search-page {
|
||||
min-height: 100%;
|
||||
background: #eef1f4;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
.hero {
|
||||
background: linear-gradient(120deg, #f7f8fa 0%, #e2e5ec 100%);
|
||||
border-bottom: 1px solid #d5d9e0;
|
||||
padding: 48px 20px 36px;
|
||||
color: #2f3135;
|
||||
}
|
||||
|
||||
.hero-content {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
|
||||
h1 {
|
||||
font-size: 34px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-bottom: 24px;
|
||||
color: #5f646e;
|
||||
}
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.search-input {
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
.search-date {
|
||||
width: 220px;
|
||||
}
|
||||
}
|
||||
|
||||
.hero-meta {
|
||||
margin-top: 14px;
|
||||
font-size: 13px;
|
||||
color: #757a85;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.result-wrapper {
|
||||
max-width: 1100px;
|
||||
margin: -25px auto 0;
|
||||
padding: 0 20px 40px;
|
||||
}
|
||||
|
||||
.result-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 14px;
|
||||
|
||||
::v-deep .el-button--text {
|
||||
color: #5f6470;
|
||||
}
|
||||
}
|
||||
|
||||
.summary-card {
|
||||
border: 1px solid #d7dbe2;
|
||||
border-radius: 10px;
|
||||
background: #fefefe;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.summary-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.summary-label {
|
||||
font-size: 13px;
|
||||
color: #80848f;
|
||||
}
|
||||
|
||||
.summary-value {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: #2f3135;
|
||||
}
|
||||
}
|
||||
|
||||
.summary-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 14px;
|
||||
|
||||
.grid-item {
|
||||
padding: 14px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e2e5ea;
|
||||
background: linear-gradient(180deg, #f9fafc 0%, #f0f2f5 100%);
|
||||
|
||||
.grid-label {
|
||||
font-size: 13px;
|
||||
color: #7b808a;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.grid-value {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
color: #2f3135;
|
||||
|
||||
&.primary {
|
||||
color: #435d7a;
|
||||
}
|
||||
|
||||
&.accent {
|
||||
color: #aa7728;
|
||||
}
|
||||
}
|
||||
|
||||
.grid-desc {
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
color: #9a9fac;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.card-section {
|
||||
border: 1px solid #d7dbe2;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
background: #fdfdfd;
|
||||
}
|
||||
|
||||
.card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.coil-card {
|
||||
border: 1px solid #d0d4dc;
|
||||
border-radius: 10px;
|
||||
padding: 16px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 6px 18px rgba(32, 41, 58, 0.08);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
|
||||
.coil-no {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #2e3240;
|
||||
}
|
||||
|
||||
.coil-meta {
|
||||
font-size: 12px;
|
||||
color: #8a8f99;
|
||||
}
|
||||
}
|
||||
|
||||
.card-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.metric-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 13px;
|
||||
color: #5a5f6b;
|
||||
|
||||
.metric-value {
|
||||
font-weight: 600;
|
||||
color: #30343c;
|
||||
}
|
||||
|
||||
.metric-value.accent {
|
||||
color: #b4792b;
|
||||
}
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin-top: 20px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.storage-days-normal {
|
||||
color: #4c805c;
|
||||
}
|
||||
|
||||
.storage-days-medium {
|
||||
color: #b78b38;
|
||||
}
|
||||
|
||||
.storage-days-high {
|
||||
color: #b3473f;
|
||||
}
|
||||
</style>
|
||||
|
||||
363
klp-ui/src/views/wms/cost/standard/index.vue
Normal file
363
klp-ui/src/views/wms/cost/standard/index.vue
Normal file
@@ -0,0 +1,363 @@
|
||||
<template>
|
||||
<div class="app-container cost-standard">
|
||||
<!-- 当前有效标准提示 -->
|
||||
<div class="alert-section" v-if="currentStandard">
|
||||
<div class="alert-content">
|
||||
<i class="el-icon-info"></i>
|
||||
<span>当前有效标准:<strong>{{ formatMoney(currentStandard.unitCost) }}</strong> 元/吨/天(生效日期:{{ currentStandard.effectiveDate }})</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 查询条件 -->
|
||||
<div class="query-section">
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px">
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增成本标准</el-button>
|
||||
<el-button type="success" icon="el-icon-refresh" @click="loadCurrentStandard">刷新当前标准</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<!-- 成本标准列表 -->
|
||||
<div class="table-section">
|
||||
<div class="section-header">
|
||||
<span>成本标准配置列表</span>
|
||||
<el-tooltip content="成本标准按生效日期自动应用,历史标准不会影响已计算的成本记录" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="standardList"
|
||||
stripe
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column prop="unitCost" label="单位成本" align="right">
|
||||
<template slot-scope="scope">
|
||||
<span class="cost-value">{{ formatMoney(scope.row.unitCost) }}</span> 元/吨/天
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="effectiveDate" label="生效日期" />
|
||||
<el-table-column prop="expireDate" label="失效日期">
|
||||
<template slot-scope="scope">
|
||||
{{ scope.row.expireDate || '当前有效' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态">
|
||||
<template slot-scope="scope">
|
||||
<el-tag :type="scope.row.status === 1 ? 'success' : 'info'">
|
||||
{{ scope.row.status === 1 ? '有效' : '失效' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" />
|
||||
<el-table-column prop="createBy" label="创建人" />
|
||||
<el-table-column prop="createTime" label="创建时间" />
|
||||
<el-table-column label="操作" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" size="small" @click="handleUpdate(scope.row)">修改</el-button>
|
||||
<el-button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleDelete(scope.row)"
|
||||
:disabled="scope.row.status === 1"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total > 0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 新增/修改对话框 -->
|
||||
<el-dialog
|
||||
:title="dialogTitle"
|
||||
:visible.sync="dialogVisible"
|
||||
width="600px"
|
||||
>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="单位成本" prop="unitCost">
|
||||
<el-input-number
|
||||
v-model="form.unitCost"
|
||||
:precision="2"
|
||||
:step="1000"
|
||||
:min="0"
|
||||
style="width: 100%;"
|
||||
/>
|
||||
<div style="color: #909399; font-size: 12px; margin-top: 5px;">
|
||||
单位:元/吨/天
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="生效日期" prop="effectiveDate">
|
||||
<el-date-picker
|
||||
v-model="form.effectiveDate"
|
||||
type="date"
|
||||
placeholder="选择生效日期"
|
||||
style="width: 100%;"
|
||||
value-format="yyyy-MM-dd"
|
||||
:picker-options="{
|
||||
disabledDate(time) {
|
||||
return time.getTime() < Date.now() - 8.64e7
|
||||
}
|
||||
}"
|
||||
/>
|
||||
<div style="color: #909399; font-size: 12px; margin-top: 5px;">
|
||||
生效日期不能早于今天
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input
|
||||
v-model="form.remark"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入备注说明"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer">
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm" :loading="submitting">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
listCostStandardConfig,
|
||||
getCostStandardConfig,
|
||||
addCostStandardConfig,
|
||||
updateCostStandardConfig,
|
||||
delCostStandardConfig,
|
||||
getCurrentCostStandard
|
||||
} from '@/api/wms/cost'
|
||||
|
||||
export default {
|
||||
name: 'CostStandard',
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
submitting: false,
|
||||
total: 0,
|
||||
standardList: [],
|
||||
currentStandard: null,
|
||||
dialogVisible: false,
|
||||
dialogTitle: '新增成本标准',
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 20
|
||||
},
|
||||
form: {
|
||||
configId: null,
|
||||
unitCost: 10000,
|
||||
effectiveDate: null,
|
||||
remark: null
|
||||
},
|
||||
rules: {
|
||||
unitCost: [
|
||||
{ required: true, message: '请输入单位成本', trigger: 'blur' },
|
||||
{ type: 'number', min: 0, message: '单位成本必须大于0', trigger: 'blur' }
|
||||
],
|
||||
effectiveDate: [
|
||||
{ required: true, message: '请选择生效日期', trigger: 'change' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
this.loadCurrentStandard()
|
||||
},
|
||||
methods: {
|
||||
async getList() {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await listCostStandardConfig(this.queryParams)
|
||||
if (res.code === 200) {
|
||||
this.standardList = res.rows || []
|
||||
this.total = res.total || 0
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error('加载成本标准列表失败')
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
async loadCurrentStandard() {
|
||||
try {
|
||||
const res = await getCurrentCostStandard()
|
||||
if (res.code === 200) {
|
||||
this.currentStandard = res.data
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载当前标准失败:', error)
|
||||
}
|
||||
},
|
||||
handleAdd() {
|
||||
this.dialogTitle = '新增成本标准'
|
||||
this.form = {
|
||||
configId: null,
|
||||
unitCost: 10000,
|
||||
effectiveDate: null,
|
||||
remark: null
|
||||
}
|
||||
this.dialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.form && this.$refs.form.clearValidate()
|
||||
})
|
||||
},
|
||||
async handleUpdate(row) {
|
||||
this.dialogTitle = '修改成本标准'
|
||||
try {
|
||||
const res = await getCostStandardConfig(row.configId)
|
||||
if (res.code === 200) {
|
||||
this.form = {
|
||||
configId: res.data.configId,
|
||||
unitCost: res.data.unitCost,
|
||||
effectiveDate: res.data.effectiveDate,
|
||||
remark: res.data.remark
|
||||
}
|
||||
this.dialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.form && this.$refs.form.clearValidate()
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error('加载成本标准详情失败')
|
||||
}
|
||||
},
|
||||
async handleDelete(row) {
|
||||
this.$confirm('确定要删除该成本标准吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
try {
|
||||
const res = await delCostStandardConfig([row.configId])
|
||||
if (res.code === 200) {
|
||||
this.$message.success('删除成功')
|
||||
this.getList()
|
||||
this.loadCurrentStandard()
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error('删除失败')
|
||||
}
|
||||
})
|
||||
},
|
||||
submitForm() {
|
||||
this.$refs.form.validate(async (valid) => {
|
||||
if (valid) {
|
||||
this.submitting = true
|
||||
try {
|
||||
if (this.form.configId) {
|
||||
// 修改
|
||||
const res = await updateCostStandardConfig(this.form)
|
||||
if (res.code === 200) {
|
||||
this.$message.success('修改成功')
|
||||
this.dialogVisible = false
|
||||
this.getList()
|
||||
this.loadCurrentStandard()
|
||||
}
|
||||
} else {
|
||||
// 新增
|
||||
const res = await addCostStandardConfig(this.form)
|
||||
if (res.code === 200) {
|
||||
this.$message.success('新增成功')
|
||||
this.dialogVisible = false
|
||||
this.getList()
|
||||
this.loadCurrentStandard()
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error(this.form.configId ? '修改失败' : '新增失败')
|
||||
} finally {
|
||||
this.submitting = false
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
formatMoney(value) {
|
||||
if (!value) return '0.00'
|
||||
return Number(value).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.cost-standard {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.alert-section {
|
||||
margin-bottom: 20px;
|
||||
padding: 15px 20px;
|
||||
background: #ECF5FF;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #B3D8FF;
|
||||
|
||||
.alert-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: #409EFF;
|
||||
font-size: 14px;
|
||||
|
||||
i {
|
||||
margin-right: 8px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
strong {
|
||||
font-size: 16px;
|
||||
margin: 0 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.query-section {
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background: #FAFAFA;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #EBEEF5;
|
||||
}
|
||||
|
||||
.table-section {
|
||||
padding: 20px;
|
||||
background: #FAFAFA;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #EBEEF5;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 500;
|
||||
margin-bottom: 15px;
|
||||
font-size: 16px;
|
||||
color: #303133;
|
||||
|
||||
.el-icon-question {
|
||||
color: #909399;
|
||||
cursor: help;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.cost-value {
|
||||
color: #409EFF;
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,5 +1,422 @@
|
||||
<template>
|
||||
<div>
|
||||
囤积成本页面
|
||||
<div class="app-container cost-stockpile">
|
||||
<!-- 查询条件 -->
|
||||
<div class="query-section">
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="120px">
|
||||
<el-form-item label="入场钢卷号">
|
||||
<el-input
|
||||
v-model="queryParams.enterCoilNo"
|
||||
placeholder="请输入入场钢卷号"
|
||||
clearable
|
||||
style="width: 200px;"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="当前钢卷号">
|
||||
<el-input
|
||||
v-model="queryParams.currentCoilNo"
|
||||
placeholder="请输入当前钢卷号"
|
||||
clearable
|
||||
style="width: 200px;"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
|
||||
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
|
||||
<el-button type="success" icon="el-icon-refresh-left" @click="refreshCosts" :loading="refreshing">
|
||||
刷新成本
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<!-- 汇总信息 -->
|
||||
<div class="summary-section">
|
||||
<div class="summary-item">
|
||||
<div class="summary-label">在库钢卷数</div>
|
||||
<div class="summary-value warning">{{ total }}</div>
|
||||
<div class="summary-desc">个</div>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<div class="summary-label">总净重</div>
|
||||
<div class="summary-value success">{{ formatWeight(totalNetWeight) }}</div>
|
||||
<div class="summary-desc">吨</div>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<div class="summary-label">总毛重</div>
|
||||
<div class="summary-value success">{{ formatWeight(totalGrossWeight) }}</div>
|
||||
<div class="summary-desc">吨</div>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<div class="summary-label">总囤积成本</div>
|
||||
<div class="summary-value primary">{{ formatMoney(totalCost) }}</div>
|
||||
<div class="summary-desc">元</div>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<div class="summary-label">平均在库天数</div>
|
||||
<div class="summary-value info">{{ avgStorageDays }}</div>
|
||||
<div class="summary-desc">天</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 钢卷列表 -->
|
||||
<div class="table-section">
|
||||
<div class="section-header">
|
||||
<span>囤积成本明细</span>
|
||||
<el-tooltip content="按入场钢卷号聚类展示囤积成本,点击查看详情可查看该入场卷下每个子钢卷的成本" placement="top">
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="coilList"
|
||||
stripe
|
||||
style="width: 100%"
|
||||
@sort-change="handleSortChange"
|
||||
>
|
||||
<el-table-column prop="enterCoilNo" label="入场钢卷号" />
|
||||
<el-table-column prop="coilCount" label="子钢卷数" align="right" />
|
||||
<el-table-column prop="totalGrossWeight" label="总毛重(吨)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatWeight(scope.row.totalGrossWeight) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="totalNetWeight" label="总净重(吨)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatWeight(scope.row.totalNetWeight) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="avgStorageDays" label="平均在库天数" align="right" sortable="custom">
|
||||
<template slot-scope="scope">
|
||||
<span :class="getStorageDaysClass(scope.row.avgStorageDays)">
|
||||
{{ scope.row.avgStorageDays || '-' }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="maxStorageDays" label="最大在库天数" align="right" sortable="custom">
|
||||
<template slot-scope="scope">
|
||||
<span :class="getStorageDaysClass(scope.row.maxStorageDays)">
|
||||
{{ scope.row.maxStorageDays || '-' }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="totalCost" label="累计成本(元)" align="right" sortable="custom">
|
||||
<template slot-scope="scope">
|
||||
<span class="cost-total">{{ formatMoney(scope.row.totalCost) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" size="small" @click="viewCoilDetail(scope.row)">查看子钢卷成本</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total > 0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 入场钢卷号下子钢卷详情对话框 -->
|
||||
<el-dialog
|
||||
title="入场钢卷号下子钢卷成本详情"
|
||||
:visible.sync="showDetailDialog"
|
||||
width="900px"
|
||||
>
|
||||
<div v-if="detailEnterCoilNo" style="margin-bottom: 10px;">
|
||||
入场钢卷号:<strong>{{ detailEnterCoilNo }}</strong>
|
||||
</div>
|
||||
<el-table :data="detailList" stripe style="width: 100%">
|
||||
<el-table-column prop="currentCoilNo" label="当前钢卷号" />
|
||||
<el-table-column prop="grossWeightTon" label="毛重(吨)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatWeight(scope.row.grossWeightTon) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="netWeightTon" label="净重(吨)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatWeight(scope.row.netWeightTon) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="storageDays" label="在库天数" align="right">
|
||||
<template slot-scope="scope">
|
||||
<span :class="getStorageDaysClass(scope.row.storageDays)">
|
||||
{{ scope.row.storageDays || '-' }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="unitCost" label="单位成本(元/吨/天)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatMoney(scope.row.unitCost) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="dailyCost" label="日成本(元)" align="right">
|
||||
<template slot-scope="scope">
|
||||
{{ formatMoney(scope.row.dailyCost) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="totalCost" label="累计成本(元)" align="right">
|
||||
<template slot-scope="scope">
|
||||
<span class="cost-total">{{ formatMoney(scope.row.totalCost) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { calculateCostByEnterCoilNo, getStockpileCostList } from '@/api/wms/cost'
|
||||
|
||||
export default {
|
||||
name: 'CostStockpile',
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
refreshing: false,
|
||||
total: 0,
|
||||
totalNetWeight: 0,
|
||||
totalGrossWeight: 0,
|
||||
totalCost: 0,
|
||||
avgStorageDays: 0,
|
||||
coilList: [],
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 50,
|
||||
enterCoilNo: null,
|
||||
currentCoilNo: null
|
||||
},
|
||||
showDetailDialog: false,
|
||||
detailEnterCoilNo: null,
|
||||
detailList: []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
},
|
||||
methods: {
|
||||
async getList() {
|
||||
this.loading = true
|
||||
try {
|
||||
const params = {
|
||||
enterCoilNo: this.queryParams.enterCoilNo,
|
||||
currentCoilNo: this.queryParams.currentCoilNo,
|
||||
pageNum: this.queryParams.pageNum,
|
||||
pageSize: this.queryParams.pageSize
|
||||
}
|
||||
const res = await getStockpileCostList(params)
|
||||
if (res.code === 200 && res.data) {
|
||||
this.coilList = res.data.rows || []
|
||||
this.total = res.data.total || 0
|
||||
const summary = res.data.summary || {}
|
||||
this.totalNetWeight = summary.totalNetWeight || 0
|
||||
this.totalGrossWeight = summary.totalGrossWeight || 0
|
||||
this.totalCost = summary.totalCost || 0
|
||||
this.avgStorageDays = summary.avgStorageDays || 0
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error('加载钢卷列表失败')
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
async refreshCosts() {
|
||||
this.refreshing = true
|
||||
try {
|
||||
await this.getList()
|
||||
this.$message.success('已重新计算并刷新列表')
|
||||
} catch (error) {
|
||||
this.$message.error('刷新成本失败')
|
||||
} finally {
|
||||
this.refreshing = false
|
||||
}
|
||||
},
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1
|
||||
this.getList()
|
||||
},
|
||||
resetQuery() {
|
||||
this.queryParams = {
|
||||
pageNum: 1,
|
||||
pageSize: 50,
|
||||
enterCoilNo: null,
|
||||
currentCoilNo: null
|
||||
}
|
||||
this.getList()
|
||||
},
|
||||
handleSortChange({ prop, order }) {
|
||||
if (order === 'ascending') {
|
||||
this.coilList.sort((a, b) => {
|
||||
const valA = a[prop] || 0
|
||||
const valB = b[prop] || 0
|
||||
return valA - valB
|
||||
})
|
||||
} else if (order === 'descending') {
|
||||
this.coilList.sort((a, b) => {
|
||||
const valA = a[prop] || 0
|
||||
const valB = b[prop] || 0
|
||||
return valB - valA
|
||||
})
|
||||
}
|
||||
},
|
||||
async viewCoilDetail(row) {
|
||||
try {
|
||||
const res = await calculateCostByEnterCoilNo(row.enterCoilNo, null)
|
||||
if (res.code === 200 && res.data && !res.data.error) {
|
||||
this.detailEnterCoilNo = row.enterCoilNo
|
||||
this.detailList = res.data.coilDetails || []
|
||||
this.showDetailDialog = true
|
||||
} else {
|
||||
this.$message.error(res.data?.error || '加载详情失败')
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error('加载详情失败')
|
||||
}
|
||||
},
|
||||
getStorageDaysClass(days) {
|
||||
if (!days) return ''
|
||||
if (days >= 30) return 'storage-days-high'
|
||||
if (days >= 15) return 'storage-days-medium'
|
||||
return 'storage-days-normal'
|
||||
},
|
||||
formatMoney(value) {
|
||||
if (!value) return '0.00'
|
||||
return Number(value).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
},
|
||||
formatWeight(value) {
|
||||
if (!value) return '0.000'
|
||||
// 如果值大于1000,可能是kg单位,需要转换
|
||||
const weight = Number(value) > 1000 ? Number(value) / 1000 : Number(value)
|
||||
return weight.toFixed(3)
|
||||
},
|
||||
formatDateTime(value) {
|
||||
if (!value) return '-'
|
||||
const date = new Date(value)
|
||||
return date.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.cost-stockpile {
|
||||
padding: 20px;
|
||||
background: #FFFFFF;
|
||||
}
|
||||
|
||||
.query-section {
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background: #FAFAFA;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #EBEEF5;
|
||||
}
|
||||
|
||||
.summary-section {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
padding: 20px;
|
||||
background: #FAFAFA;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #EBEEF5;
|
||||
|
||||
.summary-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
|
||||
.summary-label {
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.summary-value {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
|
||||
&.primary {
|
||||
color: #409EFF;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
color: #E6A23C;
|
||||
}
|
||||
|
||||
&.success {
|
||||
color: #67C23A;
|
||||
}
|
||||
|
||||
&.info {
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
.summary-desc {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.table-section {
|
||||
padding: 20px;
|
||||
background: #FAFAFA;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #EBEEF5;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 500;
|
||||
margin-bottom: 15px;
|
||||
font-size: 16px;
|
||||
color: #303133;
|
||||
|
||||
.el-icon-question {
|
||||
color: #909399;
|
||||
cursor: help;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.cost-value {
|
||||
color: #409EFF;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.cost-total {
|
||||
color: #E6A23C;
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.storage-days-normal {
|
||||
color: #67C23A;
|
||||
}
|
||||
|
||||
.storage-days-medium {
|
||||
color: #E6A23C;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.storage-days-high {
|
||||
color: #F56C6C;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.klp.controller;
|
||||
|
||||
import java.util.List;
|
||||
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.CostStandardConfigVo;
|
||||
import com.klp.domain.bo.CostStandardConfigBo;
|
||||
import com.klp.service.ICostStandardConfigService;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 成本标准配置表
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/wms/cost/standard")
|
||||
public class CostStandardConfigController extends BaseController {
|
||||
|
||||
private final ICostStandardConfigService iCostStandardConfigService;
|
||||
|
||||
/**
|
||||
* 查询成本标准配置表列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<CostStandardConfigVo> list(CostStandardConfigBo bo, PageQuery pageQuery) {
|
||||
return iCostStandardConfigService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出成本标准配置表列表
|
||||
*/
|
||||
@Log(title = "成本标准配置表", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(CostStandardConfigBo bo, HttpServletResponse response) {
|
||||
List<CostStandardConfigVo> list = iCostStandardConfigService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "成本标准配置表", CostStandardConfigVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取成本标准配置表详细信息
|
||||
*
|
||||
* @param configId 主键
|
||||
*/
|
||||
@GetMapping("/{configId}")
|
||||
public R<CostStandardConfigVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long configId) {
|
||||
return R.ok(iCostStandardConfigService.queryById(configId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前有效的成本标准
|
||||
*/
|
||||
@GetMapping("/current")
|
||||
public R<CostStandardConfigVo> getCurrent() {
|
||||
return R.ok(iCostStandardConfigService.queryCurrentEffective());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增成本标准配置表
|
||||
*/
|
||||
@Log(title = "成本标准配置表", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody CostStandardConfigBo bo) {
|
||||
return toAjax(iCostStandardConfigService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改成本标准配置表
|
||||
*/
|
||||
@Log(title = "成本标准配置表", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody CostStandardConfigBo bo) {
|
||||
return toAjax(iCostStandardConfigService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除成本标准配置表
|
||||
*
|
||||
* @param configIds 主键串
|
||||
*/
|
||||
@Log(title = "成本标准配置表", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{configIds}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] configIds) {
|
||||
return toAjax(iCostStandardConfigService.deleteWithValidByIds(Arrays.asList(configIds), true));
|
||||
}
|
||||
}
|
||||
|
||||
85
klp-wms/src/main/java/com/klp/domain/CostCoilDaily.java
Normal file
85
klp-wms/src/main/java/com/klp/domain/CostCoilDaily.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.klp.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 钢卷日成本记录表对象 cost_coil_daily
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("cost_coil_daily")
|
||||
public class CostCoilDaily extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "cost_id")
|
||||
private Long costId;
|
||||
|
||||
/**
|
||||
* 钢卷ID(关联wms_material_coil.coil_id)
|
||||
*/
|
||||
private Long coilId;
|
||||
|
||||
/**
|
||||
* 当前钢卷号
|
||||
*/
|
||||
private String currentCoilNo;
|
||||
|
||||
/**
|
||||
* 计算日期
|
||||
*/
|
||||
private LocalDate calcDate;
|
||||
|
||||
/**
|
||||
* 净重(吨)
|
||||
*/
|
||||
private BigDecimal netWeight;
|
||||
|
||||
/**
|
||||
* 单位成本(元/吨/天)
|
||||
*/
|
||||
private BigDecimal unitCost;
|
||||
|
||||
/**
|
||||
* 日成本(元)
|
||||
*/
|
||||
private BigDecimal dailyCost;
|
||||
|
||||
/**
|
||||
* 累计在库天数
|
||||
*/
|
||||
private Integer storageDays;
|
||||
|
||||
/**
|
||||
* 累计成本(元)
|
||||
*/
|
||||
private BigDecimal totalCost;
|
||||
|
||||
/**
|
||||
* 所在库区ID
|
||||
*/
|
||||
private Long warehouseId;
|
||||
|
||||
/**
|
||||
* 物品类型(raw_material/product)
|
||||
*/
|
||||
private String itemType;
|
||||
|
||||
/**
|
||||
* 材料类型
|
||||
*/
|
||||
private String materialType;
|
||||
}
|
||||
|
||||
61
klp-wms/src/main/java/com/klp/domain/CostStandardConfig.java
Normal file
61
klp-wms/src/main/java/com/klp/domain/CostStandardConfig.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package com.klp.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 成本标准配置表对象 cost_standard_config
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("cost_standard_config")
|
||||
public class CostStandardConfig extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "config_id")
|
||||
private Long configId;
|
||||
|
||||
/**
|
||||
* 单位成本(元/吨/天)
|
||||
*/
|
||||
private BigDecimal unitCost;
|
||||
|
||||
/**
|
||||
* 生效日期
|
||||
*/
|
||||
private LocalDate effectiveDate;
|
||||
|
||||
/**
|
||||
* 失效日期(NULL表示当前有效)
|
||||
*/
|
||||
private LocalDate expireDate;
|
||||
|
||||
/**
|
||||
* 状态(0=失效,1=有效)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 删除标志(0=正常,1=已删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 备注说明
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
|
||||
90
klp-wms/src/main/java/com/klp/domain/bo/CostCoilDailyBo.java
Normal file
90
klp-wms/src/main/java/com/klp/domain/bo/CostCoilDailyBo.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package com.klp.domain.bo;
|
||||
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 钢卷日成本记录表业务对象 cost_coil_daily
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CostCoilDailyBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private Long costId;
|
||||
|
||||
/**
|
||||
* 钢卷ID(关联wms_material_coil.coil_id)
|
||||
*/
|
||||
private Long coilId;
|
||||
|
||||
/**
|
||||
* 当前钢卷号
|
||||
*/
|
||||
private String currentCoilNo;
|
||||
|
||||
/**
|
||||
* 计算日期
|
||||
*/
|
||||
private LocalDate calcDate;
|
||||
|
||||
/**
|
||||
* 净重(吨)
|
||||
*/
|
||||
private BigDecimal netWeight;
|
||||
|
||||
/**
|
||||
* 单位成本(元/吨/天)
|
||||
*/
|
||||
private BigDecimal unitCost;
|
||||
|
||||
/**
|
||||
* 日成本(元)
|
||||
*/
|
||||
private BigDecimal dailyCost;
|
||||
|
||||
/**
|
||||
* 累计在库天数
|
||||
*/
|
||||
private Integer storageDays;
|
||||
|
||||
/**
|
||||
* 累计成本(元)
|
||||
*/
|
||||
private BigDecimal totalCost;
|
||||
|
||||
/**
|
||||
* 所在库区ID
|
||||
*/
|
||||
private Long warehouseId;
|
||||
|
||||
/**
|
||||
* 物品类型(raw_material/product)
|
||||
*/
|
||||
private String itemType;
|
||||
|
||||
/**
|
||||
* 材料类型
|
||||
*/
|
||||
private String materialType;
|
||||
|
||||
/**
|
||||
* 开始日期(用于查询)
|
||||
*/
|
||||
private LocalDate startDate;
|
||||
|
||||
/**
|
||||
* 结束日期(用于查询)
|
||||
*/
|
||||
private LocalDate endDate;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.klp.domain.bo;
|
||||
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 成本标准配置表业务对象 cost_standard_config
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CostStandardConfigBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private Long configId;
|
||||
|
||||
/**
|
||||
* 单位成本(元/吨/天)
|
||||
*/
|
||||
private BigDecimal unitCost;
|
||||
|
||||
/**
|
||||
* 生效日期
|
||||
*/
|
||||
private LocalDate effectiveDate;
|
||||
|
||||
/**
|
||||
* 失效日期(NULL表示当前有效)
|
||||
*/
|
||||
private LocalDate expireDate;
|
||||
|
||||
/**
|
||||
* 状态(0=失效,1=有效)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注说明
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
|
||||
98
klp-wms/src/main/java/com/klp/domain/vo/CostCoilDailyVo.java
Normal file
98
klp-wms/src/main/java/com/klp/domain/vo/CostCoilDailyVo.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package com.klp.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 钢卷日成本记录表视图对象 cost_coil_daily
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CostCoilDailyVo {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@ExcelProperty(value = "成本记录ID")
|
||||
private Long costId;
|
||||
|
||||
/**
|
||||
* 钢卷ID(关联wms_material_coil.coil_id)
|
||||
*/
|
||||
@ExcelProperty(value = "钢卷ID")
|
||||
private Long coilId;
|
||||
|
||||
/**
|
||||
* 当前钢卷号
|
||||
*/
|
||||
@ExcelProperty(value = "钢卷号")
|
||||
private String currentCoilNo;
|
||||
|
||||
/**
|
||||
* 计算日期
|
||||
*/
|
||||
@ExcelProperty(value = "计算日期")
|
||||
private LocalDate calcDate;
|
||||
|
||||
/**
|
||||
* 净重(吨)
|
||||
*/
|
||||
@ExcelProperty(value = "净重(吨)")
|
||||
private BigDecimal netWeight;
|
||||
|
||||
/**
|
||||
* 单位成本(元/吨/天)
|
||||
*/
|
||||
@ExcelProperty(value = "单位成本(元/吨/天)")
|
||||
private BigDecimal unitCost;
|
||||
|
||||
/**
|
||||
* 日成本(元)
|
||||
*/
|
||||
@ExcelProperty(value = "日成本(元)")
|
||||
private BigDecimal dailyCost;
|
||||
|
||||
/**
|
||||
* 累计在库天数
|
||||
*/
|
||||
@ExcelProperty(value = "累计在库天数")
|
||||
private Integer storageDays;
|
||||
|
||||
/**
|
||||
* 累计成本(元)
|
||||
*/
|
||||
@ExcelProperty(value = "累计成本(元)")
|
||||
private BigDecimal totalCost;
|
||||
|
||||
/**
|
||||
* 所在库区ID
|
||||
*/
|
||||
@ExcelProperty(value = "库区ID")
|
||||
private Long warehouseId;
|
||||
|
||||
/**
|
||||
* 库区名称
|
||||
*/
|
||||
@ExcelProperty(value = "库区名称")
|
||||
private String warehouseName;
|
||||
|
||||
/**
|
||||
* 物品类型(raw_material/product)
|
||||
*/
|
||||
@ExcelProperty(value = "物品类型")
|
||||
private String itemType;
|
||||
|
||||
/**
|
||||
* 材料类型
|
||||
*/
|
||||
@ExcelProperty(value = "材料类型")
|
||||
private String materialType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.klp.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 成本标准配置表视图对象 cost_standard_config
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CostStandardConfigVo {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@ExcelProperty(value = "配置ID")
|
||||
private Long configId;
|
||||
|
||||
/**
|
||||
* 单位成本(元/吨/天)
|
||||
*/
|
||||
@ExcelProperty(value = "单位成本(元/吨/天)")
|
||||
private BigDecimal unitCost;
|
||||
|
||||
/**
|
||||
* 生效日期
|
||||
*/
|
||||
@ExcelProperty(value = "生效日期")
|
||||
private LocalDate effectiveDate;
|
||||
|
||||
/**
|
||||
* 失效日期(NULL表示当前有效)
|
||||
*/
|
||||
@ExcelProperty(value = "失效日期")
|
||||
private LocalDate expireDate;
|
||||
|
||||
/**
|
||||
* 状态(0=失效,1=有效)
|
||||
*/
|
||||
@ExcelProperty(value = "状态")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 备注说明
|
||||
*/
|
||||
@ExcelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@ExcelProperty(value = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ExcelProperty(value = "创建时间")
|
||||
private java.util.Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@ExcelProperty(value = "更新人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@ExcelProperty(value = "更新时间")
|
||||
private java.util.Date updateTime;
|
||||
}
|
||||
|
||||
150
klp-wms/src/main/java/com/klp/mapper/CostCoilDailyMapper.java
Normal file
150
klp-wms/src/main/java/com/klp/mapper/CostCoilDailyMapper.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package com.klp.mapper;
|
||||
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
import com.klp.domain.CostCoilDaily;
|
||||
import com.klp.domain.vo.CostCoilDailyVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 钢卷日成本记录表Mapper接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
public interface CostCoilDailyMapper extends BaseMapperPlus<CostCoilDailyMapper, CostCoilDaily, CostCoilDailyVo> {
|
||||
|
||||
/**
|
||||
* 查询成本统计汇总
|
||||
*
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @param warehouseId 库区ID(可选)
|
||||
* @param itemType 物品类型(可选)
|
||||
* @param materialType 材料类型(可选)
|
||||
* @return 统计结果
|
||||
*/
|
||||
Map<String, Object> selectCostSummary(@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("warehouseId") Long warehouseId,
|
||||
@Param("itemType") String itemType,
|
||||
@Param("materialType") String materialType);
|
||||
|
||||
/**
|
||||
* 按库区统计成本
|
||||
*
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @return 统计结果列表
|
||||
*/
|
||||
List<Map<String, Object>> selectCostByWarehouse(@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate);
|
||||
|
||||
/**
|
||||
* 按物品类型统计成本
|
||||
*
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @return 统计结果列表
|
||||
*/
|
||||
List<Map<String, Object>> selectCostByItemType(@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate);
|
||||
|
||||
/**
|
||||
* 检查指定日期和钢卷的成本记录是否存在
|
||||
*
|
||||
* @param coilId 钢卷ID
|
||||
* @param calcDate 计算日期
|
||||
* @return 记录数量
|
||||
*/
|
||||
int countByCoilIdAndDate(@Param("coilId") Long coilId, @Param("calcDate") LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 按入场钢卷号统计成本
|
||||
*
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @param enterCoilNo 入场钢卷号(可选)
|
||||
* @return 统计结果列表
|
||||
*/
|
||||
List<Map<String, Object>> selectCostByEnterCoilNo(@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("enterCoilNo") String enterCoilNo);
|
||||
|
||||
/**
|
||||
* 删除指定日期的成本记录
|
||||
*
|
||||
* @param calcDate 计算日期
|
||||
* @return 删除数量
|
||||
*/
|
||||
int deleteByCalcDate(@Param("calcDate") LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 囤积成本(按入场钢卷号聚合)列表查询
|
||||
*
|
||||
* @param calcDate 计算日期
|
||||
* @param enterCoilNo 入场钢卷号(可选,支持精确匹配或前缀匹配,可在 SQL 中自行处理)
|
||||
* @param offset 分页偏移量
|
||||
* @param pageSize 分页大小
|
||||
* @return 聚合后的列表
|
||||
*/
|
||||
List<Map<String, Object>> selectStockpileByEnterCoilNo(@Param("calcDate") LocalDate calcDate,
|
||||
@Param("enterCoilNo") String enterCoilNo,
|
||||
@Param("offset") int offset,
|
||||
@Param("pageSize") int pageSize);
|
||||
|
||||
/**
|
||||
* 囤积成本(按入场钢卷号聚合)列表总数
|
||||
*
|
||||
* @param calcDate 计算日期
|
||||
* @param enterCoilNo 入场钢卷号(可选)
|
||||
* @return 入场钢卷号分组条数
|
||||
*/
|
||||
long countStockpileByEnterCoilNo(@Param("calcDate") LocalDate calcDate,
|
||||
@Param("enterCoilNo") String enterCoilNo);
|
||||
|
||||
/**
|
||||
* 囤积成本(按入场钢卷号聚合)汇总
|
||||
*
|
||||
* @param calcDate 计算日期
|
||||
* @param enterCoilNo 入场钢卷号(可选)
|
||||
* @return 汇总数据
|
||||
*/
|
||||
Map<String, Object> selectStockpileSummaryByEnterCoilNo(@Param("calcDate") LocalDate calcDate,
|
||||
@Param("enterCoilNo") String enterCoilNo);
|
||||
|
||||
/**
|
||||
* 首页概览:直接基于 wms_material_coil 现算当日成本
|
||||
*/
|
||||
Map<String, Object> selectOverviewFromMaterialCoil();
|
||||
|
||||
/**
|
||||
* 成本趋势(按日汇总)
|
||||
*/
|
||||
List<Map<String, Object>> selectCostTrend(@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate);
|
||||
|
||||
/**
|
||||
* 成本检索(基于 wms_material_coil 实时计算)- 列表
|
||||
*/
|
||||
List<Map<String, Object>> selectMaterialCostCards(@Param("enterCoilNo") String enterCoilNo,
|
||||
@Param("calcDate") LocalDate calcDate,
|
||||
@Param("offset") int offset,
|
||||
@Param("pageSize") int pageSize);
|
||||
|
||||
/**
|
||||
* 成本检索(基于 wms_material_coil 实时计算)- 总数
|
||||
*/
|
||||
long countMaterialCostCards(@Param("enterCoilNo") String enterCoilNo,
|
||||
@Param("calcDate") LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 成本检索(基于 wms_material_coil 实时计算)- 汇总
|
||||
*/
|
||||
Map<String, Object> selectMaterialCostSummary(@Param("enterCoilNo") String enterCoilNo,
|
||||
@Param("calcDate") LocalDate calcDate);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.klp.mapper;
|
||||
|
||||
import com.klp.domain.CostStandardConfig;
|
||||
import com.klp.domain.vo.CostStandardConfigVo;
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 成本标准配置表Mapper接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
public interface CostStandardConfigMapper extends BaseMapperPlus<CostStandardConfigMapper, CostStandardConfig, CostStandardConfigVo> {
|
||||
|
||||
/**
|
||||
* 查询指定日期的有效成本标准
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 成本标准配置
|
||||
*/
|
||||
CostStandardConfigVo selectEffectiveByDate(@Param("date") LocalDate date);
|
||||
|
||||
/**
|
||||
* 查询当前有效的成本标准
|
||||
*
|
||||
* @return 成本标准配置
|
||||
*/
|
||||
CostStandardConfigVo selectCurrentEffective();
|
||||
}
|
||||
|
||||
156
klp-wms/src/main/java/com/klp/service/ICostCoilDailyService.java
Normal file
156
klp-wms/src/main/java/com/klp/service/ICostCoilDailyService.java
Normal file
@@ -0,0 +1,156 @@
|
||||
package com.klp.service;
|
||||
|
||||
import com.klp.domain.vo.CostCoilDailyVo;
|
||||
import com.klp.domain.bo.CostCoilDailyBo;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 钢卷日成本记录表Service接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
public interface ICostCoilDailyService {
|
||||
|
||||
/**
|
||||
* 查询钢卷日成本记录表
|
||||
*/
|
||||
CostCoilDailyVo queryById(Long costId);
|
||||
|
||||
/**
|
||||
* 查询钢卷日成本记录表列表
|
||||
*/
|
||||
TableDataInfo<CostCoilDailyVo> queryPageList(CostCoilDailyBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询钢卷日成本记录表列表
|
||||
*/
|
||||
List<CostCoilDailyVo> queryList(CostCoilDailyBo bo);
|
||||
|
||||
/**
|
||||
* 新增钢卷日成本记录表
|
||||
*/
|
||||
Boolean insertByBo(CostCoilDailyBo bo);
|
||||
|
||||
/**
|
||||
* 修改钢卷日成本记录表
|
||||
*/
|
||||
Boolean updateByBo(CostCoilDailyBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除钢卷日成本记录表信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 实时计算指定钢卷的成本
|
||||
*
|
||||
* @param coilId 钢卷ID(可选,不传则计算所有现存钢卷)
|
||||
* @param calcTime 计算时间点(可选,默认当前时间)
|
||||
* @return 成本计算结果
|
||||
*/
|
||||
Map<String, Object> calculateCost(Long coilId, java.time.LocalDateTime calcTime);
|
||||
|
||||
/**
|
||||
* 批量计算多个钢卷的成本
|
||||
*
|
||||
* @param coilIds 钢卷ID列表
|
||||
* @param calcTime 计算时间点(可选,默认当前时间)
|
||||
* @return 成本计算结果列表,每个元素包含一个钢卷的成本信息
|
||||
*/
|
||||
List<Map<String, Object>> batchCalculateCost(List<Long> coilIds, java.time.LocalDateTime calcTime);
|
||||
|
||||
/**
|
||||
* 批量计算钢卷成本(定时任务使用)
|
||||
*
|
||||
* @param calcDate 计算日期(前一日)
|
||||
* @return 计算成功的数量
|
||||
*/
|
||||
int calculateDailyCost(LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 查询成本统计报表
|
||||
*
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @param groupBy 分组维度(warehouse/itemType/materialType)
|
||||
* @param warehouseId 库区ID(可选)
|
||||
* @return 统计结果
|
||||
*/
|
||||
Map<String, Object> queryCostSummary(LocalDate startDate, LocalDate endDate, String groupBy, Long warehouseId);
|
||||
|
||||
/**
|
||||
* 查询成本趋势分析
|
||||
*
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @return 趋势数据
|
||||
*/
|
||||
List<Map<String, Object>> queryCostTrend(LocalDate startDate, LocalDate endDate);
|
||||
|
||||
/**
|
||||
* 按入场钢卷号维度计算成本
|
||||
* 同一个入场钢卷号可能被分卷成多个钢卷,需要汇总计算
|
||||
* 未发货的:计算到当日;已发货的:计算到发货前一天
|
||||
*
|
||||
* @param enterCoilNo 入场钢卷号
|
||||
* @param calcDate 计算日期(可选,默认当前日期)
|
||||
* @return 成本计算结果(包含各子卷明细和汇总)
|
||||
*/
|
||||
Map<String, Object> calculateCostByEnterCoilNo(String enterCoilNo, LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 批量按入场钢卷号维度计算成本(定时任务使用)
|
||||
* 按入场钢卷号分组,计算每个入场钢卷号的总成本
|
||||
*
|
||||
* @param calcDate 计算日期(可选,默认前一日)
|
||||
* @return 计算成功的入场钢卷号数量
|
||||
*/
|
||||
int calculateDailyCostByEnterCoilNo(LocalDate calcDate);
|
||||
|
||||
/**
|
||||
* 现算成本检索(基于 wms_material_coil)
|
||||
*
|
||||
* @param enterCoilNo 入场钢卷号(支持前缀匹配)
|
||||
* @param calcDate 计算日期(可选,默认当前日期)
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @return 汇总与分页明细
|
||||
*/
|
||||
Map<String, Object> searchMaterialCost(String enterCoilNo, LocalDate calcDate, int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* 查询按入场钢卷号统计的成本报表
|
||||
*
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @param enterCoilNo 入场钢卷号(可选,用于精确查询)
|
||||
* @return 统计结果列表
|
||||
*/
|
||||
List<Map<String, Object>> queryCostByEnterCoilNo(LocalDate startDate, LocalDate endDate, String enterCoilNo);
|
||||
|
||||
/**
|
||||
* 成本模块首页概览数据
|
||||
* 统计当前「现存且未发货」钢卷的总成本、总净重、总毛重以及平均在库天数
|
||||
*
|
||||
* @return 概览数据:totalCost、totalNetWeight、totalGrossWeight、avgStorageDays、totalCoils
|
||||
*/
|
||||
Map<String, Object> queryOverview();
|
||||
|
||||
/**
|
||||
* 囤积成本页数据(后台统一计算)
|
||||
*
|
||||
* @param enterCoilNo 入场钢卷号(可选)
|
||||
* @param currentCoilNo 当前钢卷号(可选)
|
||||
* @param pageQuery 分页参数
|
||||
* @return rows+total+summary 结果
|
||||
*/
|
||||
Map<String, Object> queryStockpileCostList(String enterCoilNo, String currentCoilNo, PageQuery pageQuery);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.klp.service;
|
||||
|
||||
import com.klp.domain.vo.CostStandardConfigVo;
|
||||
import com.klp.domain.bo.CostStandardConfigBo;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 成本标准配置表Service接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
public interface ICostStandardConfigService {
|
||||
|
||||
/**
|
||||
* 查询成本标准配置表
|
||||
*/
|
||||
CostStandardConfigVo queryById(Long configId);
|
||||
|
||||
/**
|
||||
* 查询成本标准配置表列表
|
||||
*/
|
||||
TableDataInfo<CostStandardConfigVo> queryPageList(CostStandardConfigBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询成本标准配置表列表
|
||||
*/
|
||||
List<CostStandardConfigVo> queryList(CostStandardConfigBo bo);
|
||||
|
||||
/**
|
||||
* 新增成本标准配置表
|
||||
*/
|
||||
Boolean insertByBo(CostStandardConfigBo bo);
|
||||
|
||||
/**
|
||||
* 修改成本标准配置表
|
||||
*/
|
||||
Boolean updateByBo(CostStandardConfigBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除成本标准配置表信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 查询当前有效的成本标准
|
||||
*
|
||||
* @return 成本标准配置
|
||||
*/
|
||||
CostStandardConfigVo queryCurrentEffective();
|
||||
|
||||
/**
|
||||
* 查询指定日期的有效成本标准
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 成本标准配置
|
||||
*/
|
||||
CostStandardConfigVo queryEffectiveByDate(LocalDate date);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,946 @@
|
||||
package com.klp.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.klp.domain.bo.CostCoilDailyBo;
|
||||
import com.klp.domain.vo.CostCoilDailyVo;
|
||||
import com.klp.domain.CostCoilDaily;
|
||||
import com.klp.domain.WmsMaterialCoil;
|
||||
import com.klp.domain.vo.CostStandardConfigVo;
|
||||
import com.klp.mapper.CostCoilDailyMapper;
|
||||
import com.klp.mapper.WmsMaterialCoilMapper;
|
||||
import com.klp.service.ICostCoilDailyService;
|
||||
import com.klp.service.ICostStandardConfigService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 钢卷日成本记录表Service业务层处理
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class CostCoilDailyServiceImpl implements ICostCoilDailyService {
|
||||
|
||||
private final CostCoilDailyMapper baseMapper;
|
||||
private final WmsMaterialCoilMapper coilMapper;
|
||||
private final ICostStandardConfigService costStandardConfigService;
|
||||
|
||||
/**
|
||||
* 查询钢卷日成本记录表
|
||||
*/
|
||||
@Override
|
||||
public CostCoilDailyVo queryById(Long costId) {
|
||||
return baseMapper.selectVoById(costId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询钢卷日成本记录表列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<CostCoilDailyVo> queryPageList(CostCoilDailyBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<CostCoilDaily> lqw = buildQueryWrapper(bo);
|
||||
Page<CostCoilDailyVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询钢卷日成本记录表列表
|
||||
*/
|
||||
@Override
|
||||
public List<CostCoilDailyVo> queryList(CostCoilDailyBo bo) {
|
||||
LambdaQueryWrapper<CostCoilDaily> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<CostCoilDaily> buildQueryWrapper(CostCoilDailyBo bo) {
|
||||
LambdaQueryWrapper<CostCoilDaily> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getCostId() != null, CostCoilDaily::getCostId, bo.getCostId());
|
||||
lqw.eq(bo.getCoilId() != null, CostCoilDaily::getCoilId, bo.getCoilId());
|
||||
lqw.like(bo.getCurrentCoilNo() != null, CostCoilDaily::getCurrentCoilNo, bo.getCurrentCoilNo());
|
||||
lqw.eq(bo.getCalcDate() != null, CostCoilDaily::getCalcDate, bo.getCalcDate());
|
||||
lqw.eq(bo.getWarehouseId() != null, CostCoilDaily::getWarehouseId, bo.getWarehouseId());
|
||||
lqw.eq(bo.getItemType() != null, CostCoilDaily::getItemType, bo.getItemType());
|
||||
lqw.eq(bo.getMaterialType() != null, CostCoilDaily::getMaterialType, bo.getMaterialType());
|
||||
if (bo.getStartDate() != null) {
|
||||
lqw.ge(CostCoilDaily::getCalcDate, bo.getStartDate());
|
||||
}
|
||||
if (bo.getEndDate() != null) {
|
||||
lqw.le(CostCoilDaily::getCalcDate, bo.getEndDate());
|
||||
}
|
||||
lqw.orderByDesc(CostCoilDaily::getCalcDate);
|
||||
lqw.orderByDesc(CostCoilDaily::getCostId);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增钢卷日成本记录表
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(CostCoilDailyBo bo) {
|
||||
CostCoilDaily add = BeanUtil.toBean(bo, CostCoilDaily.class);
|
||||
validEntityBeforeSave(add);
|
||||
return baseMapper.insert(add) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改钢卷日成本记录表
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(CostCoilDailyBo bo) {
|
||||
CostCoilDaily update = BeanUtil.toBean(bo, CostCoilDaily.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(CostCoilDaily entity) {
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除钢卷日成本记录表信息
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
// TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时计算指定钢卷的成本
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> calculateCost(Long coilId, LocalDateTime calcTime) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 1. 查询钢卷信息
|
||||
WmsMaterialCoil coil = coilMapper.selectById(coilId);
|
||||
if (coil == null) {
|
||||
result.put("error", "钢卷不存在");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 2. 验证是否为计算对象(data_type=1, export_time IS NULL)
|
||||
if (coil.getDataType() == null || coil.getDataType() != 1) {
|
||||
result.put("error", "该钢卷不是现存数据,不在计算范围内");
|
||||
return result;
|
||||
}
|
||||
|
||||
if (coil.getExportTime() != null) {
|
||||
result.put("error", "该钢卷已发货,不在计算范围内");
|
||||
return result;
|
||||
}
|
||||
|
||||
WeightContext weightContext = resolveWeightContext(coil);
|
||||
if (!weightContext.isValid()) {
|
||||
result.put("error", "钢卷毛重与净重均为空或为0,无法计算成本");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 3. 计算在库天数
|
||||
LocalDate startDate = coil.getCreateTime() != null
|
||||
? coil.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()
|
||||
: LocalDate.now();
|
||||
LocalDate endDate = calcTime != null ? calcTime.toLocalDate() : LocalDate.now();
|
||||
|
||||
long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
||||
if (days < 1) {
|
||||
days = 1; // 不足一天按一天计算
|
||||
}
|
||||
|
||||
// 4. 获取成本标准(使用入库日期的成本标准)
|
||||
CostStandardConfigVo costStandard = costStandardConfigService.queryEffectiveByDate(startDate);
|
||||
if (costStandard == null) {
|
||||
// 如果没有找到对应日期的标准,使用当前有效的标准
|
||||
costStandard = costStandardConfigService.queryCurrentEffective();
|
||||
}
|
||||
|
||||
if (costStandard == null || costStandard.getUnitCost() == null) {
|
||||
result.put("error", "未找到有效的成本标准配置");
|
||||
return result;
|
||||
}
|
||||
|
||||
BigDecimal unitCost = costStandard.getUnitCost();
|
||||
|
||||
// 5. 计算成本(按毛重优先)
|
||||
BigDecimal dailyCost = weightContext.getCostTon().multiply(unitCost).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal totalCost = dailyCost.multiply(BigDecimal.valueOf(days)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
// 6. 返回结果
|
||||
result.put("coilId", coil.getCoilId());
|
||||
result.put("coilNo", coil.getCurrentCoilNo());
|
||||
result.put("netWeight", weightContext.getNetTon()); // 吨
|
||||
result.put("netWeightKg", weightContext.getNetKg()); // 千克
|
||||
result.put("grossWeightKg", weightContext.getGrossKg());
|
||||
result.put("grossWeightTon", weightContext.getGrossTon());
|
||||
result.put("costWeightTon", weightContext.getCostTon());
|
||||
result.put("weightBasis", weightContext.useGross() ? "gross" : "net");
|
||||
result.put("storageDays", days);
|
||||
result.put("unitCost", unitCost);
|
||||
result.put("dailyCost", dailyCost);
|
||||
result.put("totalCost", totalCost);
|
||||
result.put("warehouseId", coil.getWarehouseId());
|
||||
result.put("itemType", coil.getItemType());
|
||||
result.put("materialType", coil.getMaterialType());
|
||||
result.put("createTime", coil.getCreateTime());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量计算多个钢卷的成本
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> batchCalculateCost(List<Long> coilIds, LocalDateTime calcTime) {
|
||||
List<Map<String, Object>> results = new ArrayList<>();
|
||||
|
||||
if (coilIds == null || coilIds.isEmpty()) {
|
||||
return results;
|
||||
}
|
||||
|
||||
// 批量查询钢卷信息
|
||||
QueryWrapper<WmsMaterialCoil> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("coil_id", coilIds);
|
||||
List<WmsMaterialCoil> coils = coilMapper.selectList(queryWrapper);
|
||||
|
||||
if (coils == null || coils.isEmpty()) {
|
||||
return results;
|
||||
}
|
||||
|
||||
// 获取成本标准(统一使用当前有效的标准,因为批量计算时可能跨多个日期)
|
||||
LocalDate calcDate = calcTime != null ? calcTime.toLocalDate() : LocalDate.now();
|
||||
CostStandardConfigVo costStandard = costStandardConfigService.queryEffectiveByDate(calcDate);
|
||||
if (costStandard == null) {
|
||||
costStandard = costStandardConfigService.queryCurrentEffective();
|
||||
}
|
||||
|
||||
BigDecimal unitCost = null;
|
||||
if (costStandard != null && costStandard.getUnitCost() != null) {
|
||||
unitCost = costStandard.getUnitCost();
|
||||
}
|
||||
|
||||
// 遍历计算每个钢卷的成本
|
||||
for (WmsMaterialCoil coil : coils) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 验证是否为计算对象(data_type=1, export_time IS NULL)
|
||||
if (coil.getDataType() == null || coil.getDataType() != 1) {
|
||||
result.put("coilId", coil.getCoilId());
|
||||
result.put("coilNo", coil.getCurrentCoilNo());
|
||||
result.put("error", "该钢卷不是现存数据,不在计算范围内");
|
||||
results.add(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (coil.getExportTime() != null) {
|
||||
result.put("coilId", coil.getCoilId());
|
||||
result.put("coilNo", coil.getCurrentCoilNo());
|
||||
result.put("error", "该钢卷已发货,不在计算范围内");
|
||||
results.add(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
WeightContext weightContext = resolveWeightContext(coil);
|
||||
if (!weightContext.isValid()) {
|
||||
result.put("coilId", coil.getCoilId());
|
||||
result.put("coilNo", coil.getCurrentCoilNo());
|
||||
result.put("error", "钢卷毛重与净重均为空或为0,无法计算成本");
|
||||
results.add(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 计算在库天数
|
||||
LocalDate startDate = coil.getCreateTime() != null
|
||||
? coil.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()
|
||||
: LocalDate.now();
|
||||
LocalDate endDate = calcTime != null ? calcTime.toLocalDate() : LocalDate.now();
|
||||
|
||||
long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
||||
if (days < 1) {
|
||||
days = 1; // 不足一天按一天计算
|
||||
}
|
||||
|
||||
// 如果统一标准为空,尝试使用入库日期的标准
|
||||
BigDecimal finalUnitCost = unitCost;
|
||||
if (finalUnitCost == null) {
|
||||
CostStandardConfigVo startDateStandard = costStandardConfigService.queryEffectiveByDate(startDate);
|
||||
if (startDateStandard != null && startDateStandard.getUnitCost() != null) {
|
||||
finalUnitCost = startDateStandard.getUnitCost();
|
||||
} else {
|
||||
CostStandardConfigVo currentStandard = costStandardConfigService.queryCurrentEffective();
|
||||
if (currentStandard != null && currentStandard.getUnitCost() != null) {
|
||||
finalUnitCost = currentStandard.getUnitCost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (finalUnitCost == null) {
|
||||
result.put("coilId", coil.getCoilId());
|
||||
result.put("coilNo", coil.getCurrentCoilNo());
|
||||
result.put("error", "未找到有效的成本标准配置");
|
||||
results.add(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 计算成本(毛重优先)
|
||||
BigDecimal dailyCost = weightContext.getCostTon().multiply(finalUnitCost).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal totalCost = dailyCost.multiply(BigDecimal.valueOf(days)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
// 返回结果
|
||||
result.put("coilId", coil.getCoilId());
|
||||
result.put("coilNo", coil.getCurrentCoilNo());
|
||||
result.put("netWeight", weightContext.getNetTon()); // 吨
|
||||
result.put("netWeightKg", weightContext.getNetKg()); // 千克
|
||||
result.put("grossWeightKg", weightContext.getGrossKg());
|
||||
result.put("grossWeightTon", weightContext.getGrossTon());
|
||||
result.put("costWeightTon", weightContext.getCostTon());
|
||||
result.put("weightBasis", weightContext.useGross() ? "gross" : "net");
|
||||
result.put("storageDays", days);
|
||||
result.put("unitCost", finalUnitCost);
|
||||
result.put("dailyCost", dailyCost);
|
||||
result.put("totalCost", totalCost);
|
||||
result.put("warehouseId", coil.getWarehouseId());
|
||||
result.put("itemType", coil.getItemType());
|
||||
result.put("materialType", coil.getMaterialType());
|
||||
result.put("createTime", coil.getCreateTime());
|
||||
|
||||
results.add(result);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量计算钢卷成本(定时任务使用)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int calculateDailyCost(LocalDate calcDate) {
|
||||
log.info("开始计算日期 {} 的钢卷成本", calcDate);
|
||||
|
||||
// 0. 防止重复记录,先清理当日历史
|
||||
int deleted = baseMapper.deleteByCalcDate(calcDate);
|
||||
log.info("已删除日期 {} 的历史成本记录 {} 条", calcDate, deleted);
|
||||
|
||||
// 1. 查询所有现存且未发货的钢卷
|
||||
QueryWrapper<WmsMaterialCoil> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("data_type", 1) // 现存数据
|
||||
.isNull("export_time") // 未发货(export_time IS NULL)
|
||||
.eq("del_flag", 0); // 未删除
|
||||
|
||||
List<WmsMaterialCoil> coils = coilMapper.selectList(queryWrapper);
|
||||
log.info("找到 {} 个需要计算成本的钢卷", coils.size());
|
||||
|
||||
// 2. 获取成本标准
|
||||
CostStandardConfigVo costStandard = costStandardConfigService.queryEffectiveByDate(calcDate);
|
||||
if (costStandard == null) {
|
||||
costStandard = costStandardConfigService.queryCurrentEffective();
|
||||
}
|
||||
|
||||
if (costStandard == null || costStandard.getUnitCost() == null) {
|
||||
log.error("未找到日期 {} 的有效成本标准配置", calcDate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BigDecimal unitCost = costStandard.getUnitCost();
|
||||
int successCount = 0;
|
||||
|
||||
// 3. 遍历计算每个钢卷的成本
|
||||
for (WmsMaterialCoil coil : coils) {
|
||||
try {
|
||||
// 计算在库天数(从入库到计算日期)
|
||||
LocalDate createDate = coil.getCreateTime() != null
|
||||
? coil.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()
|
||||
: LocalDate.now();
|
||||
long days = ChronoUnit.DAYS.between(createDate, calcDate) + 1;
|
||||
if (days < 1) {
|
||||
days = 1;
|
||||
}
|
||||
|
||||
// 计算成本(毛重优先)
|
||||
WeightContext weightContext = resolveWeightContext(coil);
|
||||
if (!weightContext.isValid()) {
|
||||
log.warn("钢卷 {} 缺少有效重量,跳过", coil.getCurrentCoilNo());
|
||||
continue;
|
||||
}
|
||||
BigDecimal dailyCost = weightContext.getCostTon().multiply(unitCost).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal totalCost = dailyCost.multiply(BigDecimal.valueOf(days)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
// 4. 保存成本记录
|
||||
CostCoilDaily costRecord = new CostCoilDaily();
|
||||
costRecord.setCoilId(coil.getCoilId());
|
||||
costRecord.setCurrentCoilNo(coil.getCurrentCoilNo());
|
||||
costRecord.setCalcDate(calcDate);
|
||||
costRecord.setNetWeight(weightContext.getCostTon());
|
||||
costRecord.setUnitCost(unitCost);
|
||||
costRecord.setDailyCost(dailyCost);
|
||||
costRecord.setStorageDays((int) days);
|
||||
costRecord.setTotalCost(totalCost);
|
||||
costRecord.setWarehouseId(coil.getWarehouseId());
|
||||
costRecord.setItemType(coil.getItemType());
|
||||
costRecord.setMaterialType(coil.getMaterialType());
|
||||
|
||||
baseMapper.insert(costRecord);
|
||||
successCount++;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("计算钢卷 {} 的成本时发生错误: {}", coil.getCurrentCoilNo(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("完成计算日期 {} 的钢卷成本,成功计算 {} 条记录", calcDate, successCount);
|
||||
return successCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询成本统计报表
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryCostSummary(LocalDate startDate, LocalDate endDate, String groupBy, Long warehouseId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 查询汇总数据
|
||||
Map<String, Object> summary = baseMapper.selectCostSummary(startDate, endDate, warehouseId, null, null);
|
||||
result.put("summary", summary);
|
||||
|
||||
// 根据分组维度查询明细
|
||||
List<Map<String, Object>> details = new ArrayList<>();
|
||||
if ("warehouse".equals(groupBy)) {
|
||||
details = baseMapper.selectCostByWarehouse(startDate, endDate);
|
||||
} else if ("itemType".equals(groupBy)) {
|
||||
details = baseMapper.selectCostByItemType(startDate, endDate);
|
||||
}
|
||||
result.put("details", details);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询成本趋势分析
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> queryCostTrend(LocalDate startDate, LocalDate endDate) {
|
||||
LocalDate effectiveStart = startDate != null ? startDate : LocalDate.now().minusDays(30);
|
||||
LocalDate effectiveEnd = endDate != null ? endDate : LocalDate.now();
|
||||
return baseMapper.selectCostTrend(effectiveStart, effectiveEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按入场钢卷号维度计算成本
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> calculateCostByEnterCoilNo(String enterCoilNo, LocalDate calcDate) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("enterCoilNo", enterCoilNo);
|
||||
|
||||
if (calcDate == null) {
|
||||
calcDate = LocalDate.now();
|
||||
}
|
||||
|
||||
// 1. 查询该入场钢卷号下的所有钢卷(包括已发货和未发货的)
|
||||
QueryWrapper<WmsMaterialCoil> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("enter_coil_no", enterCoilNo)
|
||||
.eq("data_type", 1) // 现存数据
|
||||
.eq("del_flag", 0); // 未删除
|
||||
|
||||
List<WmsMaterialCoil> coils = coilMapper.selectList(queryWrapper);
|
||||
if (coils.isEmpty()) {
|
||||
result.put("error", "未找到入场钢卷号 " + enterCoilNo + " 的相关钢卷");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Map<String, Object>> coilDetails = new ArrayList<>();
|
||||
BigDecimal totalCost = BigDecimal.ZERO;
|
||||
BigDecimal totalNetWeight = BigDecimal.ZERO;
|
||||
BigDecimal totalGrossWeight = BigDecimal.ZERO;
|
||||
int unshippedCount = 0;
|
||||
int shippedCount = 0;
|
||||
|
||||
// 2. 遍历每个钢卷计算成本
|
||||
for (WmsMaterialCoil coil : coils) {
|
||||
Map<String, Object> coilDetail = new HashMap<>();
|
||||
coilDetail.put("coilId", coil.getCoilId());
|
||||
coilDetail.put("currentCoilNo", coil.getCurrentCoilNo());
|
||||
coilDetail.put("isShipped", coil.getExportTime() != null);
|
||||
|
||||
// 计算在库天数
|
||||
LocalDate startDate = coil.getCreateTime() != null
|
||||
? coil.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()
|
||||
: LocalDate.now();
|
||||
|
||||
// 确定结束日期:已发货的计算到发货前一天,未发货的计算到当日
|
||||
LocalDate endDate;
|
||||
if (coil.getExportTime() != null) {
|
||||
// 已发货:计算到发货前一天
|
||||
endDate = coil.getExportTime().toInstant()
|
||||
.atZone(java.time.ZoneId.systemDefault())
|
||||
.toLocalDate()
|
||||
.minusDays(1);
|
||||
shippedCount++;
|
||||
} else {
|
||||
// 未发货:计算到当日
|
||||
endDate = calcDate;
|
||||
unshippedCount++;
|
||||
}
|
||||
|
||||
// 确保结束日期不早于开始日期
|
||||
if (endDate.isBefore(startDate)) {
|
||||
endDate = startDate;
|
||||
}
|
||||
|
||||
long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
||||
if (days < 1) {
|
||||
days = 1;
|
||||
}
|
||||
|
||||
// 获取成本标准
|
||||
CostStandardConfigVo costStandard = costStandardConfigService.queryEffectiveByDate(startDate);
|
||||
if (costStandard == null) {
|
||||
costStandard = costStandardConfigService.queryCurrentEffective();
|
||||
}
|
||||
|
||||
if (costStandard == null || costStandard.getUnitCost() == null) {
|
||||
coilDetail.put("error", "未找到有效的成本标准配置");
|
||||
coilDetails.add(coilDetail);
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal unitCost = costStandard.getUnitCost();
|
||||
|
||||
// 计算成本(毛重优先)
|
||||
WeightContext weightContext = resolveWeightContext(coil);
|
||||
if (!weightContext.isValid()) {
|
||||
coilDetail.put("error", "钢卷缺少有效重量,无法计算");
|
||||
coilDetails.add(coilDetail);
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal dailyCost = weightContext.getCostTon().multiply(unitCost).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal coilTotalCost = dailyCost.multiply(BigDecimal.valueOf(days)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
coilDetail.put("netWeightTon", weightContext.getNetTon());
|
||||
coilDetail.put("grossWeightTon", weightContext.getGrossTon());
|
||||
coilDetail.put("weightBasis", weightContext.useGross() ? "gross" : "net");
|
||||
coilDetail.put("storageDays", days);
|
||||
coilDetail.put("unitCost", unitCost);
|
||||
coilDetail.put("dailyCost", dailyCost);
|
||||
coilDetail.put("totalCost", coilTotalCost);
|
||||
coilDetail.put("startDate", startDate);
|
||||
coilDetail.put("endDate", endDate);
|
||||
coilDetail.put("exportTime", coil.getExportTime());
|
||||
|
||||
coilDetails.add(coilDetail);
|
||||
|
||||
// 累计总成本和总净重
|
||||
totalCost = totalCost.add(coilTotalCost);
|
||||
totalNetWeight = totalNetWeight.add(weightContext.getNetTon());
|
||||
totalGrossWeight = totalGrossWeight.add(weightContext.getGrossTon());
|
||||
}
|
||||
|
||||
// 3. 汇总结果
|
||||
result.put("coilDetails", coilDetails);
|
||||
result.put("totalCoils", coils.size());
|
||||
result.put("shippedCount", shippedCount);
|
||||
result.put("unshippedCount", unshippedCount);
|
||||
result.put("totalNetWeight", totalNetWeight.setScale(3, RoundingMode.HALF_UP));
|
||||
result.put("totalGrossWeight", totalGrossWeight.setScale(3, RoundingMode.HALF_UP));
|
||||
result.put("totalCost", totalCost.setScale(2, RoundingMode.HALF_UP));
|
||||
result.put("calcDate", calcDate);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量按入场钢卷号维度计算成本(定时任务使用)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int calculateDailyCostByEnterCoilNo(LocalDate calcDate) {
|
||||
if (calcDate == null) {
|
||||
calcDate = LocalDate.now().minusDays(1);
|
||||
}
|
||||
|
||||
log.info("开始按入场钢卷号维度计算日期 {} 的成本", calcDate);
|
||||
|
||||
// 清理当日历史记录,防止重复计算
|
||||
int deleted = baseMapper.deleteByCalcDate(calcDate);
|
||||
log.info("已删除日期 {} 的历史成本记录 {} 条(按入场卷号维度重算)", calcDate, deleted);
|
||||
|
||||
// 1. 查询所有需要计算的入场钢卷号(去重)
|
||||
QueryWrapper<WmsMaterialCoil> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("DISTINCT enter_coil_no")
|
||||
.eq("data_type", 1)
|
||||
.eq("del_flag", 0)
|
||||
.isNotNull("enter_coil_no");
|
||||
|
||||
List<WmsMaterialCoil> distinctCoils = coilMapper.selectList(queryWrapper);
|
||||
log.info("找到 {} 个需要计算成本的入场钢卷号", distinctCoils.size());
|
||||
|
||||
int successCount = 0;
|
||||
|
||||
// 2. 遍历每个入场钢卷号计算成本
|
||||
for (WmsMaterialCoil distinctCoil : distinctCoils) {
|
||||
try {
|
||||
String enterCoilNo = distinctCoil.getEnterCoilNo();
|
||||
if (enterCoilNo == null || enterCoilNo.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 计算该入场钢卷号的成本
|
||||
Map<String, Object> costResult = calculateCostByEnterCoilNo(enterCoilNo, calcDate);
|
||||
|
||||
if (costResult.containsKey("error")) {
|
||||
log.warn("计算入场钢卷号 {} 的成本时发生错误: {}", enterCoilNo, costResult.get("error"));
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取该入场钢卷号下的所有钢卷
|
||||
QueryWrapper<WmsMaterialCoil> coilQueryWrapper = new QueryWrapper<>();
|
||||
coilQueryWrapper.eq("enter_coil_no", enterCoilNo)
|
||||
.eq("data_type", 1)
|
||||
.eq("del_flag", 0);
|
||||
|
||||
List<WmsMaterialCoil> coils = coilMapper.selectList(coilQueryWrapper);
|
||||
|
||||
// 为每个钢卷生成成本记录
|
||||
for (WmsMaterialCoil coil : coils) {
|
||||
// 确定计算结束日期
|
||||
LocalDate startDate = coil.getCreateTime() != null
|
||||
? coil.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate()
|
||||
: LocalDate.now();
|
||||
|
||||
LocalDate endDate;
|
||||
if (coil.getExportTime() != null) {
|
||||
// 已发货:计算到发货前一天
|
||||
endDate = coil.getExportTime().toInstant()
|
||||
.atZone(java.time.ZoneId.systemDefault())
|
||||
.toLocalDate()
|
||||
.minusDays(1);
|
||||
} else {
|
||||
// 未发货:计算到计算日期
|
||||
endDate = calcDate;
|
||||
}
|
||||
|
||||
// 对于已发货的钢卷,只计算到发货前一天,如果计算日期在发货日期之后,跳过
|
||||
if (coil.getExportTime() != null) {
|
||||
LocalDate exportDate = coil.getExportTime().toInstant()
|
||||
.atZone(java.time.ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
// 如果计算日期在发货日期之后,不需要计算
|
||||
if (calcDate.isAfter(exportDate)) {
|
||||
continue;
|
||||
}
|
||||
// 如果计算日期等于发货日期,计算到前一天
|
||||
if (calcDate.isEqual(exportDate)) {
|
||||
endDate = exportDate.minusDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 确保结束日期不早于开始日期
|
||||
if (endDate.isBefore(startDate)) {
|
||||
endDate = startDate;
|
||||
}
|
||||
|
||||
// 计算在库天数(到结束日期)
|
||||
long days = ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
||||
if (days < 1) {
|
||||
days = 1;
|
||||
}
|
||||
|
||||
// 获取成本标准
|
||||
CostStandardConfigVo costStandard = costStandardConfigService.queryEffectiveByDate(startDate);
|
||||
if (costStandard == null) {
|
||||
costStandard = costStandardConfigService.queryCurrentEffective();
|
||||
}
|
||||
|
||||
if (costStandard == null || costStandard.getUnitCost() == null) {
|
||||
log.warn("未找到入场钢卷号 {} 钢卷 {} 的有效成本标准", enterCoilNo, coil.getCurrentCoilNo());
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal unitCost = costStandard.getUnitCost();
|
||||
|
||||
// 计算成本
|
||||
WeightContext weightContext = resolveWeightContext(coil);
|
||||
if (!weightContext.isValid()) {
|
||||
log.warn("入场卷号 {} 下的钢卷 {} 缺少有效重量,跳过", enterCoilNo, coil.getCurrentCoilNo());
|
||||
continue;
|
||||
}
|
||||
BigDecimal dailyCost = weightContext.getCostTon().multiply(unitCost).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal totalCost = dailyCost.multiply(BigDecimal.valueOf(days)).setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
// 保存成本记录
|
||||
CostCoilDaily costRecord = new CostCoilDaily();
|
||||
costRecord.setCoilId(coil.getCoilId());
|
||||
costRecord.setCurrentCoilNo(coil.getCurrentCoilNo());
|
||||
costRecord.setCalcDate(calcDate);
|
||||
costRecord.setNetWeight(weightContext.getCostTon());
|
||||
costRecord.setUnitCost(unitCost);
|
||||
costRecord.setDailyCost(dailyCost);
|
||||
costRecord.setStorageDays((int) days);
|
||||
costRecord.setTotalCost(totalCost);
|
||||
costRecord.setWarehouseId(coil.getWarehouseId());
|
||||
costRecord.setItemType(coil.getItemType());
|
||||
costRecord.setMaterialType(coil.getMaterialType());
|
||||
|
||||
baseMapper.insert(costRecord);
|
||||
}
|
||||
|
||||
successCount++;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("按入场钢卷号维度计算成本时发生错误: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("完成按入场钢卷号维度计算日期 {} 的成本,成功计算 {} 个入场钢卷号", calcDate, successCount);
|
||||
return successCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> searchMaterialCost(String enterCoilNo, LocalDate calcDate, int pageNum, int pageSize) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
int safePageNum = pageNum > 0 ? pageNum : 1;
|
||||
int safePageSize = pageSize > 0 ? Math.min(pageSize, 100) : 20;
|
||||
LocalDate effectiveCalcDate = calcDate != null ? calcDate : LocalDate.now();
|
||||
String trimmedEnterCoilNo = StringUtils.isNotBlank(enterCoilNo) ? enterCoilNo.trim() : null;
|
||||
|
||||
result.put("enterCoilNo", trimmedEnterCoilNo);
|
||||
result.put("calcDate", effectiveCalcDate);
|
||||
result.put("pageNum", safePageNum);
|
||||
result.put("pageSize", safePageSize);
|
||||
result.put("records", Collections.emptyList());
|
||||
result.put("total", 0L);
|
||||
|
||||
Map<String, Object> summary = buildEmptySearchSummary(trimmedEnterCoilNo, effectiveCalcDate);
|
||||
if (trimmedEnterCoilNo == null) {
|
||||
result.put("summary", summary);
|
||||
return result;
|
||||
}
|
||||
|
||||
long total = baseMapper.countMaterialCostCards(trimmedEnterCoilNo, effectiveCalcDate);
|
||||
if (total > 0) {
|
||||
Map<String, Object> dbSummary = baseMapper.selectMaterialCostSummary(trimmedEnterCoilNo, effectiveCalcDate);
|
||||
summary = normalizeMaterialCostSummary(dbSummary, trimmedEnterCoilNo, effectiveCalcDate);
|
||||
|
||||
int offset = (safePageNum - 1) * safePageSize;
|
||||
List<Map<String, Object>> cards = baseMapper.selectMaterialCostCards(trimmedEnterCoilNo, effectiveCalcDate, offset, safePageSize);
|
||||
result.put("records", cards);
|
||||
result.put("total", total);
|
||||
} else {
|
||||
result.put("total", 0L);
|
||||
}
|
||||
|
||||
result.put("summary", summary);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询按入场钢卷号统计的成本报表
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> queryCostByEnterCoilNo(LocalDate startDate, LocalDate endDate, String enterCoilNo) {
|
||||
return baseMapper.selectCostByEnterCoilNo(startDate, endDate, enterCoilNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 囤积成本页数据(后台统一计算)
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryStockpileCostList(String enterCoilNo, String currentCoilNo, PageQuery pageQuery) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 使用 SQL 直接按入场钢卷号聚合,避免在 Service 层做大循环
|
||||
LocalDate calcDate = LocalDate.now();
|
||||
int pageNum = pageQuery.getPageNum() != null ? pageQuery.getPageNum() : 1;
|
||||
int pageSize = pageQuery.getPageSize() != null ? pageQuery.getPageSize() : 50;
|
||||
int offset = (pageNum - 1) * pageSize;
|
||||
|
||||
String trimmedEnterCoilNo = StringUtils.isNotBlank(enterCoilNo) ? enterCoilNo.trim() : null;
|
||||
|
||||
List<Map<String, Object>> rows = baseMapper.selectStockpileByEnterCoilNo(calcDate, trimmedEnterCoilNo, offset, pageSize);
|
||||
long total = baseMapper.countStockpileByEnterCoilNo(calcDate, trimmedEnterCoilNo);
|
||||
Map<String, Object> summary = baseMapper.selectStockpileSummaryByEnterCoilNo(calcDate, trimmedEnterCoilNo);
|
||||
|
||||
if (summary == null) {
|
||||
summary = new HashMap<>();
|
||||
summary.put("totalNetWeight", BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP));
|
||||
summary.put("totalGrossWeight", BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP));
|
||||
summary.put("totalCost", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
|
||||
summary.put("avgStorageDays", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
|
||||
// 兼容前端字段命名
|
||||
summary.putIfAbsent("totalCoils", total);
|
||||
|
||||
result.put("rows", rows);
|
||||
result.put("total", total);
|
||||
result.put("summary", summary);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 成本模块首页概览数据
|
||||
* 统计当前「现存且未发货」钢卷的总成本、总净重、总毛重以及平均在库天数
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> queryOverview() {
|
||||
Map<String, Object> db = baseMapper.selectOverviewFromMaterialCoil();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (db == null || db.isEmpty()) {
|
||||
result.put("totalCost", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
|
||||
result.put("totalNetWeight", BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP));
|
||||
result.put("totalGrossWeight", BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP));
|
||||
result.put("avgStorageDays", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
|
||||
result.put("totalCoils", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
BigDecimal totalCost = toBigDecimal(db.get("totalCost"), 2);
|
||||
BigDecimal totalNetWeight = toBigDecimal(db.get("totalNetWeight"), 3);
|
||||
BigDecimal totalGrossWeight = toBigDecimal(db.get("totalGrossWeight"), 3);
|
||||
BigDecimal avgStorageDays = toBigDecimal(db.get("avgStorageDays"), 2);
|
||||
Number totalCoils = db.get("totalCoils") instanceof Number ? (Number) db.get("totalCoils") : 0;
|
||||
|
||||
result.put("totalCost", totalCost);
|
||||
result.put("totalNetWeight", totalNetWeight);
|
||||
result.put("totalGrossWeight", totalGrossWeight);
|
||||
result.put("avgStorageDays", avgStorageDays);
|
||||
result.put("totalCoils", totalCoils.intValue());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private BigDecimal toBigDecimal(Object value, int scale) {
|
||||
if (value == null) {
|
||||
return BigDecimal.ZERO.setScale(scale, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (value instanceof BigDecimal) {
|
||||
return ((BigDecimal) value).setScale(scale, RoundingMode.HALF_UP);
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return BigDecimal.valueOf(((Number) value).doubleValue()).setScale(scale, RoundingMode.HALF_UP);
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(value.toString()).setScale(scale, RoundingMode.HALF_UP);
|
||||
} catch (Exception e) {
|
||||
return BigDecimal.ZERO.setScale(scale, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> buildEmptySearchSummary(String enterCoilNo, LocalDate calcDate) {
|
||||
Map<String, Object> summary = new HashMap<>();
|
||||
summary.put("enterCoilNo", enterCoilNo);
|
||||
summary.put("calcDate", calcDate);
|
||||
summary.put("totalCoils", 0);
|
||||
summary.put("shippedCount", 0);
|
||||
summary.put("unshippedCount", 0);
|
||||
summary.put("totalCost", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
|
||||
summary.put("totalNetWeight", BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP));
|
||||
summary.put("totalGrossWeight", BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP));
|
||||
summary.put("avgStorageDays", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
|
||||
return summary;
|
||||
}
|
||||
|
||||
private Map<String, Object> normalizeMaterialCostSummary(Map<String, Object> db, String enterCoilNo, LocalDate calcDate) {
|
||||
Map<String, Object> summary = buildEmptySearchSummary(enterCoilNo, calcDate);
|
||||
if (db == null || db.isEmpty()) {
|
||||
return summary;
|
||||
}
|
||||
summary.put("totalCoils", toBigDecimal(db.get("totalCoils"), 0).intValue());
|
||||
summary.put("shippedCount", toBigDecimal(db.get("shippedCount"), 0).intValue());
|
||||
summary.put("unshippedCount", toBigDecimal(db.get("unshippedCount"), 0).intValue());
|
||||
summary.put("totalCost", toBigDecimal(db.get("totalCost"), 2));
|
||||
summary.put("totalNetWeight", toBigDecimal(db.get("totalNetWeight"), 3));
|
||||
summary.put("totalGrossWeight", toBigDecimal(db.get("totalGrossWeight"), 3));
|
||||
summary.put("avgStorageDays", toBigDecimal(db.get("avgStorageDays"), 2));
|
||||
return summary;
|
||||
}
|
||||
|
||||
private WeightContext resolveWeightContext(WmsMaterialCoil coil) {
|
||||
BigDecimal netWeightKg = coil.getNetWeight() == null ? BigDecimal.ZERO : coil.getNetWeight();
|
||||
BigDecimal grossWeightKg = coil.getGrossWeight() == null ? BigDecimal.ZERO : coil.getGrossWeight();
|
||||
BigDecimal costWeightKg = grossWeightKg.compareTo(BigDecimal.ZERO) > 0 ? grossWeightKg : netWeightKg;
|
||||
return new WeightContext(netWeightKg, grossWeightKg, costWeightKg);
|
||||
}
|
||||
|
||||
|
||||
private static class WeightContext {
|
||||
private static final BigDecimal THOUSAND = BigDecimal.valueOf(1000);
|
||||
private final BigDecimal netKg;
|
||||
private final BigDecimal grossKg;
|
||||
private final BigDecimal costKg;
|
||||
private final BigDecimal netTon;
|
||||
private final BigDecimal grossTon;
|
||||
private final BigDecimal costTon;
|
||||
|
||||
WeightContext(BigDecimal netKg, BigDecimal grossKg, BigDecimal costKg) {
|
||||
this.netKg = netKg;
|
||||
this.grossKg = grossKg;
|
||||
this.costKg = costKg;
|
||||
this.netTon = convertToTon(netKg);
|
||||
this.grossTon = convertToTon(grossKg);
|
||||
this.costTon = convertToTon(costKg);
|
||||
}
|
||||
|
||||
private BigDecimal convertToTon(BigDecimal kg) {
|
||||
if (kg == null || kg.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return kg.divide(THOUSAND, 3, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
boolean isValid() {
|
||||
return costKg != null && costKg.compareTo(BigDecimal.ZERO) > 0;
|
||||
}
|
||||
|
||||
boolean useGross() {
|
||||
return grossKg != null && grossKg.compareTo(BigDecimal.ZERO) > 0;
|
||||
}
|
||||
|
||||
BigDecimal getNetKg() {
|
||||
return netKg;
|
||||
}
|
||||
|
||||
BigDecimal getGrossKg() {
|
||||
return grossKg;
|
||||
}
|
||||
|
||||
BigDecimal getNetTon() {
|
||||
return netTon;
|
||||
}
|
||||
|
||||
BigDecimal getGrossTon() {
|
||||
return grossTon;
|
||||
}
|
||||
|
||||
BigDecimal getCostTon() {
|
||||
return costTon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.klp.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.klp.domain.bo.CostStandardConfigBo;
|
||||
import com.klp.domain.vo.CostStandardConfigVo;
|
||||
import com.klp.domain.CostStandardConfig;
|
||||
import com.klp.mapper.CostStandardConfigMapper;
|
||||
import com.klp.service.ICostStandardConfigService;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 成本标准配置表Service业务层处理
|
||||
*
|
||||
* @author klp
|
||||
* @date 2025-11-25
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class CostStandardConfigServiceImpl implements ICostStandardConfigService {
|
||||
|
||||
private final CostStandardConfigMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询成本标准配置表
|
||||
*/
|
||||
@Override
|
||||
public CostStandardConfigVo queryById(Long configId) {
|
||||
return baseMapper.selectVoById(configId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询成本标准配置表列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<CostStandardConfigVo> queryPageList(CostStandardConfigBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<CostStandardConfig> lqw = buildQueryWrapper(bo);
|
||||
Page<CostStandardConfigVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询成本标准配置表列表
|
||||
*/
|
||||
@Override
|
||||
public List<CostStandardConfigVo> queryList(CostStandardConfigBo bo) {
|
||||
LambdaQueryWrapper<CostStandardConfig> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<CostStandardConfig> buildQueryWrapper(CostStandardConfigBo bo) {
|
||||
LambdaQueryWrapper<CostStandardConfig> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getConfigId() != null, CostStandardConfig::getConfigId, bo.getConfigId());
|
||||
lqw.eq(bo.getUnitCost() != null, CostStandardConfig::getUnitCost, bo.getUnitCost());
|
||||
lqw.eq(bo.getEffectiveDate() != null, CostStandardConfig::getEffectiveDate, bo.getEffectiveDate());
|
||||
lqw.eq(bo.getStatus() != null, CostStandardConfig::getStatus, bo.getStatus());
|
||||
lqw.orderByDesc(CostStandardConfig::getEffectiveDate);
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增成本标准配置表
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean insertByBo(CostStandardConfigBo bo) {
|
||||
// 如果新标准立即生效,需要将当前有效的标准标记为失效
|
||||
if (bo.getEffectiveDate() != null && !bo.getEffectiveDate().isAfter(LocalDate.now())) {
|
||||
// 将当前有效的标准标记为失效
|
||||
CostStandardConfigVo current = queryCurrentEffective();
|
||||
if (current != null) {
|
||||
CostStandardConfig update = new CostStandardConfig();
|
||||
update.setConfigId(current.getConfigId());
|
||||
update.setExpireDate(LocalDate.now().minusDays(1));
|
||||
update.setStatus(0);
|
||||
baseMapper.updateById(update);
|
||||
}
|
||||
}
|
||||
|
||||
CostStandardConfig add = BeanUtil.toBean(bo, CostStandardConfig.class);
|
||||
if (add.getStatus() == null) {
|
||||
add.setStatus(1); // 默认有效
|
||||
}
|
||||
validEntityBeforeSave(add);
|
||||
return baseMapper.insert(add) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改成本标准配置表
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(CostStandardConfigBo bo) {
|
||||
CostStandardConfig update = BeanUtil.toBean(bo, CostStandardConfig.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(CostStandardConfig entity) {
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除成本标准配置表信息
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
// TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前有效的成本标准
|
||||
*/
|
||||
@Override
|
||||
public CostStandardConfigVo queryCurrentEffective() {
|
||||
return baseMapper.selectCurrentEffective();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定日期的有效成本标准
|
||||
*/
|
||||
@Override
|
||||
public CostStandardConfigVo queryEffectiveByDate(LocalDate date) {
|
||||
return baseMapper.selectEffectiveByDate(date);
|
||||
}
|
||||
}
|
||||
|
||||
54
klp-wms/src/main/java/com/klp/task/CostCoilDailyTask.java
Normal file
54
klp-wms/src/main/java/com/klp/task/CostCoilDailyTask.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.klp.task;
|
||||
|
||||
import com.klp.service.ICostCoilDailyService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 成本日统计定时任务
|
||||
*
|
||||
* 每天凌晨 2 点执行:
|
||||
* 1. 按钢卷维度生成前一日的日成本记录;
|
||||
* 2. 按入场钢卷号维度生成前一日的日成本记录。
|
||||
*
|
||||
* 说明:
|
||||
* - 具体的计算逻辑在 {@link ICostCoilDailyService#calculateDailyCost(LocalDate)} 和
|
||||
* {@link ICostCoilDailyService#calculateDailyCostByEnterCoilNo(LocalDate)} 中实现。
|
||||
* - 当前任务只负责在固定时间触发这两个方法。
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
public class CostCoilDailyTask {
|
||||
|
||||
private final ICostCoilDailyService costCoilDailyService;
|
||||
|
||||
/**
|
||||
* 每天凌晨 2:00 计算前一日钢卷日成本(按钢卷维度)
|
||||
*/
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
public void calculateDailyCostByCoil() {
|
||||
LocalDate calcDate = LocalDate.now().minusDays(1);
|
||||
log.info("[成本定时任务] 开始按钢卷维度计算日期 {} 的成本", calcDate);
|
||||
int count = costCoilDailyService.calculateDailyCost(calcDate);
|
||||
log.info("[成本定时任务] 按钢卷维度计算日期 {} 的成本完成,成功 {} 条", calcDate, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每天凌晨 2:10 计算前一日钢卷日成本(按入场钢卷号维度)
|
||||
* 与上一个任务错开几分钟,避免同时占用资源。
|
||||
*/
|
||||
@Scheduled(cron = "0 10 2 * * ?")
|
||||
public void calculateDailyCostByEnterCoilNo() {
|
||||
LocalDate calcDate = LocalDate.now().minusDays(1);
|
||||
log.info("[成本定时任务] 开始按入场钢卷号维度计算日期 {} 的成本", calcDate);
|
||||
int count = costCoilDailyService.calculateDailyCostByEnterCoilNo(calcDate);
|
||||
log.info("[成本定时任务] 按入场钢卷号维度计算日期 {} 的成本完成,成功 {} 个入场钢卷号", calcDate, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
523
klp-wms/src/main/resources/mapper/klp/CostCoilDailyMapper.xml
Normal file
523
klp-wms/src/main/resources/mapper/klp/CostCoilDailyMapper.xml
Normal file
@@ -0,0 +1,523 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.mapper.CostCoilDailyMapper">
|
||||
|
||||
<resultMap type="com.klp.domain.CostCoilDaily" id="CostCoilDailyResult">
|
||||
<result property="costId" column="cost_id"/>
|
||||
<result property="coilId" column="coil_id"/>
|
||||
<result property="currentCoilNo" column="current_coil_no"/>
|
||||
<result property="calcDate" column="calc_date"/>
|
||||
<result property="netWeight" column="net_weight"/>
|
||||
<result property="unitCost" column="unit_cost"/>
|
||||
<result property="dailyCost" column="daily_cost"/>
|
||||
<result property="storageDays" column="storage_days"/>
|
||||
<result property="totalCost" column="total_cost"/>
|
||||
<result property="warehouseId" column="warehouse_id"/>
|
||||
<result property="itemType" column="item_type"/>
|
||||
<result property="materialType" column="material_type"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.klp.domain.vo.CostCoilDailyVo" id="CostCoilDailyVoResult">
|
||||
<result property="costId" column="cost_id"/>
|
||||
<result property="coilId" column="coil_id"/>
|
||||
<result property="currentCoilNo" column="current_coil_no"/>
|
||||
<result property="calcDate" column="calc_date"/>
|
||||
<result property="netWeight" column="net_weight"/>
|
||||
<result property="unitCost" column="unit_cost"/>
|
||||
<result property="dailyCost" column="daily_cost"/>
|
||||
<result property="storageDays" column="storage_days"/>
|
||||
<result property="totalCost" column="total_cost"/>
|
||||
<result property="warehouseId" column="warehouse_id"/>
|
||||
<result property="warehouseName" column="warehouse_name"/>
|
||||
<result property="itemType" column="item_type"/>
|
||||
<result property="materialType" column="material_type"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 自定义查询,关联库区名称 -->
|
||||
<select id="selectVoPage" resultType="com.klp.domain.vo.CostCoilDailyVo">
|
||||
SELECT
|
||||
ccd.cost_id,
|
||||
ccd.coil_id,
|
||||
ccd.current_coil_no,
|
||||
ccd.calc_date,
|
||||
ccd.net_weight,
|
||||
ccd.unit_cost,
|
||||
ccd.daily_cost,
|
||||
ccd.storage_days,
|
||||
ccd.total_cost,
|
||||
ccd.warehouse_id,
|
||||
w.warehouse_name,
|
||||
ccd.item_type,
|
||||
ccd.material_type
|
||||
FROM cost_coil_daily ccd
|
||||
LEFT JOIN wms_warehouse w ON ccd.warehouse_id = w.warehouse_id AND w.del_flag = 0
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectVoList" resultType="com.klp.domain.vo.CostCoilDailyVo">
|
||||
SELECT
|
||||
ccd.cost_id,
|
||||
ccd.coil_id,
|
||||
ccd.current_coil_no,
|
||||
ccd.calc_date,
|
||||
ccd.net_weight,
|
||||
ccd.unit_cost,
|
||||
ccd.daily_cost,
|
||||
ccd.storage_days,
|
||||
ccd.total_cost,
|
||||
ccd.warehouse_id,
|
||||
w.warehouse_name,
|
||||
ccd.item_type,
|
||||
ccd.material_type
|
||||
FROM cost_coil_daily ccd
|
||||
LEFT JOIN wms_warehouse w ON ccd.warehouse_id = w.warehouse_id AND w.del_flag = 0
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectVoById" resultType="com.klp.domain.vo.CostCoilDailyVo">
|
||||
SELECT
|
||||
ccd.cost_id,
|
||||
ccd.coil_id,
|
||||
ccd.current_coil_no,
|
||||
ccd.calc_date,
|
||||
ccd.net_weight,
|
||||
ccd.unit_cost,
|
||||
ccd.daily_cost,
|
||||
ccd.storage_days,
|
||||
ccd.total_cost,
|
||||
ccd.warehouse_id,
|
||||
w.warehouse_name,
|
||||
ccd.item_type,
|
||||
ccd.material_type
|
||||
FROM cost_coil_daily ccd
|
||||
LEFT JOIN wms_warehouse w ON ccd.warehouse_id = w.warehouse_id AND w.del_flag = 0
|
||||
WHERE ccd.cost_id = #{costId}
|
||||
</select>
|
||||
|
||||
<!-- 查询成本统计汇总(基于当前 wms_material_coil 快照) -->
|
||||
<select id="selectCostSummary" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
COUNT(*) AS totalCoils,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.total_cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
SUM(t.daily_cost_amount) AS totalDailyCost
|
||||
FROM (
|
||||
SELECT
|
||||
m.coil_id,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost
|
||||
END AS daily_cost_amount,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS total_cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
<if test="warehouseId != null">
|
||||
AND m.warehouse_id = #{warehouseId}
|
||||
</if>
|
||||
<if test="itemType != null and itemType != ''">
|
||||
AND m.item_type = #{itemType}
|
||||
</if>
|
||||
<if test="materialType != null and materialType != ''">
|
||||
AND m.material_type = #{materialType}
|
||||
</if>
|
||||
) t
|
||||
</select>
|
||||
|
||||
<!-- 按库区统计成本(基于当前 wms_material_coil 快照) -->
|
||||
<select id="selectCostByWarehouse" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
t.warehouse_id AS warehouseId,
|
||||
COALESCE(w.warehouse_name, '-') AS warehouseName,
|
||||
COUNT(*) AS coilCount,
|
||||
SUM(t.total_cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight
|
||||
FROM (
|
||||
SELECT
|
||||
m.coil_id,
|
||||
m.warehouse_id,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS total_cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
) t
|
||||
LEFT JOIN wms_warehouse w ON t.warehouse_id = w.warehouse_id
|
||||
GROUP BY t.warehouse_id, w.warehouse_name
|
||||
ORDER BY totalCost DESC
|
||||
</select>
|
||||
|
||||
<!-- 按物品类型统计成本(基于当前 wms_material_coil 快照) -->
|
||||
<select id="selectCostByItemType" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
t.item_type AS itemType,
|
||||
COUNT(*) AS coilCount,
|
||||
SUM(t.total_cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight
|
||||
FROM (
|
||||
SELECT
|
||||
m.coil_id,
|
||||
m.item_type,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS total_cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
) t
|
||||
GROUP BY t.item_type
|
||||
ORDER BY totalCost DESC
|
||||
</select>
|
||||
|
||||
<!-- 检查指定日期和钢卷的成本记录是否存在 -->
|
||||
<select id="countByCoilIdAndDate" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM cost_coil_daily
|
||||
WHERE coil_id = #{coilId}
|
||||
AND calc_date = #{calcDate}
|
||||
</select>
|
||||
|
||||
<!-- 按入场钢卷号统计成本 -->
|
||||
<select id="selectCostByEnterCoilNo" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
mc.enter_coil_no AS enterCoilNo,
|
||||
COUNT(DISTINCT mc.coil_id) AS coilCount,
|
||||
COUNT(DISTINCT CASE WHEN mc.export_time IS NULL THEN mc.coil_id END) AS unshippedCount,
|
||||
COUNT(DISTINCT CASE WHEN mc.export_time IS NOT NULL THEN mc.coil_id END) AS shippedCount,
|
||||
SUM(ccd.total_cost) AS totalCost,
|
||||
SUM(ccd.net_weight) AS totalNetWeight,
|
||||
AVG(ccd.storage_days) AS avgStorageDays,
|
||||
MAX(ccd.calc_date) AS lastCalcDate
|
||||
FROM cost_coil_daily ccd
|
||||
INNER JOIN wms_material_coil mc ON ccd.coil_id = mc.coil_id
|
||||
WHERE ccd.calc_date BETWEEN #{startDate} AND #{endDate}
|
||||
AND mc.data_type = 1
|
||||
AND mc.del_flag = 0
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND mc.enter_coil_no = #{enterCoilNo}
|
||||
</if>
|
||||
GROUP BY mc.enter_coil_no
|
||||
ORDER BY totalCost DESC
|
||||
</select>
|
||||
|
||||
<select id="selectStockpileByEnterCoilNo" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
t.enter_coil_no AS enterCoilNo,
|
||||
COUNT(*) AS coilCount,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight,
|
||||
SUM(t.cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
MAX(t.storage_days) AS maxStorageDays
|
||||
FROM (
|
||||
SELECT
|
||||
m.enter_coil_no,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS cost_amount,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND m.enter_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
</if>
|
||||
) t
|
||||
GROUP BY t.enter_coil_no
|
||||
ORDER BY t.enter_coil_no DESC
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
|
||||
<!-- 囤积成本(按入场钢卷号聚合)列表总数 -->
|
||||
<select id="countStockpileByEnterCoilNo" resultType="long">
|
||||
SELECT
|
||||
COUNT(*) AS cnt
|
||||
FROM (
|
||||
SELECT m.enter_coil_no
|
||||
FROM wms_material_coil m
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND m.enter_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
</if>
|
||||
GROUP BY m.enter_coil_no
|
||||
) t
|
||||
</select>
|
||||
|
||||
<!-- 囤积成本(按入场钢卷号聚合)汇总 -->
|
||||
<select id="selectStockpileSummaryByEnterCoilNo" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight,
|
||||
SUM(t.cost_amount) AS totalCost,
|
||||
AVG(t.storage_days) AS avgStorageDays
|
||||
FROM (
|
||||
SELECT
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS cost_amount,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND m.enter_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
</if>
|
||||
) t
|
||||
</select>
|
||||
|
||||
<select id="selectOverviewFromMaterialCoil" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
COUNT(*) AS totalCoils,
|
||||
SUM(t.net_weight_ton) AS totalNetWeight,
|
||||
SUM(t.gross_weight_ton) AS totalGrossWeight,
|
||||
AVG(t.storage_days) AS avgStorageDays,
|
||||
SUM(t.cost_amount) AS totalCost
|
||||
FROM (
|
||||
SELECT
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
(DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1) AS storage_days,
|
||||
CASE
|
||||
WHEN cs.unit_cost IS NULL THEN 0
|
||||
ELSE (
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN m.gross_weight
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END
|
||||
) / 1000 * cs.unit_cost * (DATEDIFF(CURDATE(), IFNULL(m.create_time, CURDATE())) + 1)
|
||||
END AS cost_amount
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.export_time IS NULL
|
||||
) t
|
||||
</select>
|
||||
|
||||
<!-- 成本趋势(按日统计 cost_coil_daily) -->
|
||||
<select id="selectCostTrend" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
ccd.calc_date AS date,
|
||||
SUM(ccd.total_cost) AS totalCost,
|
||||
SUM(ccd.net_weight) AS totalNetWeight,
|
||||
SUM(ccd.daily_cost) AS totalDailyCost
|
||||
FROM cost_coil_daily ccd
|
||||
WHERE 1 = 1
|
||||
<if test="startDate != null">
|
||||
AND ccd.calc_date >= #{startDate}
|
||||
</if>
|
||||
<if test="endDate != null">
|
||||
AND ccd.calc_date <= #{endDate}
|
||||
</if>
|
||||
GROUP BY ccd.calc_date
|
||||
ORDER BY ccd.calc_date
|
||||
</select>
|
||||
|
||||
<!-- ==================== 成本检索(实时计算) ==================== -->
|
||||
<sql id="MaterialCoilCostBase">
|
||||
SELECT
|
||||
m.enter_coil_no,
|
||||
m.coil_id,
|
||||
m.current_coil_no,
|
||||
IFNULL(m.net_weight, 0) / 1000 AS net_weight_ton,
|
||||
IFNULL(m.gross_weight, 0) / 1000 AS gross_weight_ton,
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN 'gross'
|
||||
ELSE 'net'
|
||||
END AS weight_basis,
|
||||
CASE
|
||||
WHEN IFNULL(m.gross_weight, 0) > 0 THEN IFNULL(m.gross_weight, 0)
|
||||
ELSE IFNULL(m.net_weight, 0)
|
||||
END / 1000 AS charge_weight_ton,
|
||||
DATE(m.create_time) AS start_date,
|
||||
CASE
|
||||
WHEN m.export_time IS NOT NULL THEN DATE_SUB(DATE(m.export_time), INTERVAL 1 DAY)
|
||||
WHEN #{calcDate} IS NOT NULL THEN #{calcDate}
|
||||
ELSE CURDATE()
|
||||
END AS raw_end_date,
|
||||
CASE
|
||||
WHEN m.export_time IS NULL THEN 0
|
||||
ELSE 1
|
||||
END AS is_shipped,
|
||||
IFNULL(cs.unit_cost, 0) AS unit_cost,
|
||||
m.warehouse_id,
|
||||
COALESCE(w.warehouse_name, '-') AS warehouse_name
|
||||
FROM wms_material_coil m
|
||||
LEFT JOIN cost_standard_config cs
|
||||
ON cs.status = 1
|
||||
AND DATE(m.create_time) >= cs.effective_date
|
||||
AND (cs.expire_date IS NULL OR DATE(m.create_time) <= cs.expire_date)
|
||||
LEFT JOIN wms_warehouse w ON w.warehouse_id = m.warehouse_id AND w.del_flag = 0
|
||||
WHERE m.data_type = 1
|
||||
AND m.del_flag = 0
|
||||
AND m.enter_coil_no IS NOT NULL
|
||||
<if test="enterCoilNo != null and enterCoilNo != ''">
|
||||
AND m.enter_coil_no LIKE CONCAT(#{enterCoilNo}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<sql id="MaterialCoilCostCalc">
|
||||
SELECT
|
||||
base.*,
|
||||
CASE
|
||||
WHEN base.raw_end_date < base.start_date THEN base.start_date
|
||||
ELSE base.raw_end_date
|
||||
END AS end_date,
|
||||
CASE
|
||||
WHEN DATEDIFF(
|
||||
CASE
|
||||
WHEN base.raw_end_date < base.start_date THEN base.start_date
|
||||
ELSE base.raw_end_date
|
||||
END,
|
||||
base.start_date
|
||||
) < 0 THEN 1
|
||||
ELSE DATEDIFF(
|
||||
CASE
|
||||
WHEN base.raw_end_date < base.start_date THEN base.start_date
|
||||
ELSE base.raw_end_date
|
||||
END,
|
||||
base.start_date
|
||||
) + 1
|
||||
END AS storage_days
|
||||
FROM (
|
||||
<include refid="MaterialCoilCostBase"/>
|
||||
) base
|
||||
</sql>
|
||||
|
||||
<select id="selectMaterialCostSummary" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
COUNT(*) AS totalCoils,
|
||||
IFNULL(SUM(calc_data.net_weight_ton), 0) AS totalNetWeight,
|
||||
IFNULL(SUM(calc_data.gross_weight_ton), 0) AS totalGrossWeight,
|
||||
IFNULL(SUM(calc_data.charge_weight_ton * calc_data.unit_cost * calc_data.storage_days), 0) AS totalCost,
|
||||
IFNULL(AVG(calc_data.storage_days), 0) AS avgStorageDays,
|
||||
IFNULL(SUM(CASE WHEN calc_data.is_shipped = 1 THEN 1 ELSE 0 END), 0) AS shippedCount,
|
||||
IFNULL(SUM(CASE WHEN calc_data.is_shipped = 0 THEN 1 ELSE 0 END), 0) AS unshippedCount
|
||||
FROM (
|
||||
<include refid="MaterialCoilCostCalc"/>
|
||||
) calc_data
|
||||
</select>
|
||||
|
||||
<select id="countMaterialCostCards" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM (
|
||||
<include refid="MaterialCoilCostCalc"/>
|
||||
) calc_data
|
||||
</select>
|
||||
|
||||
<select id="selectMaterialCostCards" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
calc_data.enter_coil_no AS enterCoilNo,
|
||||
calc_data.coil_id AS coilId,
|
||||
calc_data.current_coil_no AS currentCoilNo,
|
||||
calc_data.net_weight_ton AS netWeightTon,
|
||||
calc_data.gross_weight_ton AS grossWeightTon,
|
||||
calc_data.weight_basis AS weightBasis,
|
||||
calc_data.storage_days AS storageDays,
|
||||
ROUND(calc_data.unit_cost, 2) AS unitCost,
|
||||
ROUND(calc_data.charge_weight_ton * calc_data.unit_cost, 2) AS dailyCost,
|
||||
ROUND(calc_data.charge_weight_ton * calc_data.unit_cost * calc_data.storage_days, 2) AS totalCost,
|
||||
calc_data.is_shipped AS isShipped,
|
||||
calc_data.start_date AS startDate,
|
||||
calc_data.end_date AS endDate,
|
||||
calc_data.warehouse_id AS warehouseId,
|
||||
calc_data.warehouse_name AS warehouseName
|
||||
FROM (
|
||||
<include refid="MaterialCoilCostCalc"/>
|
||||
) calc_data
|
||||
ORDER BY calc_data.start_date DESC, calc_data.current_coil_no DESC
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
|
||||
<!-- 删除指定日期的成本记录 -->
|
||||
<delete id="deleteByCalcDate">
|
||||
DELETE FROM cost_coil_daily
|
||||
WHERE calc_date = #{calcDate}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.mapper.CostStandardConfigMapper">
|
||||
|
||||
<resultMap type="com.klp.domain.CostStandardConfig" id="CostStandardConfigResult">
|
||||
<result property="configId" column="config_id"/>
|
||||
<result property="unitCost" column="unit_cost"/>
|
||||
<result property="effectiveDate" column="effective_date"/>
|
||||
<result property="expireDate" column="expire_date"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="delFlag" column="del_flag"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.klp.domain.vo.CostStandardConfigVo" id="CostStandardConfigVoResult">
|
||||
<result property="configId" column="config_id"/>
|
||||
<result property="unitCost" column="unit_cost"/>
|
||||
<result property="effectiveDate" column="effective_date"/>
|
||||
<result property="expireDate" column="expire_date"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 查询指定日期的有效成本标准 -->
|
||||
<select id="selectEffectiveByDate" resultMap="CostStandardConfigVoResult">
|
||||
SELECT *
|
||||
FROM cost_standard_config
|
||||
WHERE del_flag = 0
|
||||
AND status = 1
|
||||
AND effective_date <= #{date}
|
||||
AND (expire_date IS NULL OR expire_date >= #{date})
|
||||
ORDER BY effective_date DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 查询当前有效的成本标准 -->
|
||||
<select id="selectCurrentEffective" resultMap="CostStandardConfigVoResult">
|
||||
SELECT *
|
||||
FROM cost_standard_config
|
||||
WHERE del_flag = 0
|
||||
AND status = 1
|
||||
AND effective_date <= CURDATE()
|
||||
AND (expire_date IS NULL OR expire_date >= CURDATE())
|
||||
ORDER BY effective_date DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user