Browse Source

库存记录报表:前端首次查询默认当天日期,后端sql优化

master
zds 5 months ago
parent
commit
ade7016114
  1. 127
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/data/service/dao/mapper/MaterialDataMapper.xml
  2. 23
      lms/nladmin-ui/src/main.js
  3. 22
      lms/nladmin-ui/src/views/wms/sch/data/index.vue

127
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/data/service/dao/mapper/MaterialDataMapper.xml

@ -8,56 +8,83 @@
<select id="queryAll" resultType="org.nl.wms.sch.data.service.dto.MaterialDataResponse"> <select id="queryAll" resultType="org.nl.wms.sch.data.service.dto.MaterialDataResponse">
SELECT SELECT
supplierCode, supplierCode,
MAX(md.supplierName) AS supplierName, MAX( md.supplierName ) AS supplierName,
productName, productName,
specification, specification,
MAX(batch) AS batch, MAX( batch ) AS batch,
MAX(barLevel) AS barLevel, MAX( barLevel ) AS barLevel,
DATE_FORMAT(md.createTime, '%Y-%m-%d') AS date, DATE_FORMAT( md.createTime, '%Y-%m-%d' ) AS date,
COALESCE(SUM(CASE WHEN md.type = 1 THEN md.length ELSE 0 END), 0) AS ll_length, COALESCE ( SUM( CASE WHEN md.type = 1 THEN md.length ELSE 0 END ), 0 ) AS ll_length,
COALESCE(SUM(CASE WHEN md.type = 1 THEN md.weight ELSE 0 END), 0) AS ll_weight, COALESCE ( SUM( CASE WHEN md.type = 1 THEN md.weight ELSE 0 END ), 0 ) AS ll_weight,
COALESCE(SUM(CASE WHEN md.type = 2 THEN md.length ELSE 0 END), 0) AS sc_length, COALESCE ( SUM( CASE WHEN md.type = 2 THEN md.length ELSE 0 END ), 0 ) AS sc_length,
COALESCE(SUM(CASE WHEN md.type = 2 THEN md.weight ELSE 0 END), 0) AS sc_weight, COALESCE ( SUM( CASE WHEN md.type = 2 THEN md.weight ELSE 0 END ), 0 ) AS sc_weight,
COALESCE( COALESCE (
(SELECT (
SUM(CASE WHEN type = 1 THEN length ELSE 0 END) - SUM(CASE WHEN type = 2 THEN length ELSE 0 END) SELECT
FROM material_data SUM( CASE WHEN type = 1 THEN length ELSE 0 END ) - SUM( CASE WHEN type = 2 THEN length ELSE 0 END )
WHERE FROM
supplierCode = md.supplierCode AND material_data
createTime <![CDATA[ < ]]> DATE_FORMAT(DATE_SUB(CONCAT(YEAR(#{query.start_time}), '-', MONTH(#{query.start_time}), '-01'), INTERVAL 1 DAY), '%Y-%m-%d') WHERE
), 0) AS sy_length, supplierCode = md.supplierCode
COALESCE( AND productName = md.productName
(SELECT AND specification = md.specification
SUM(CASE WHEN type = 1 THEN weight ELSE 0 END) - SUM(CASE WHEN type = 2 THEN weight ELSE 0 END) AND createTime like CONCAT(DATE_FORMAT(DATE_SUB( #{query.start_time}, INTERVAL 1 DAY ), '%Y-%m-%d') , '%')
FROM material_data ),
WHERE 0
supplierCode = md.supplierCode AND ) AS sy_length,
createTime <![CDATA[ < ]]> DATE_FORMAT(DATE_SUB(CONCAT(YEAR(#{query.start_time}), '-', DAY(#{query.start_time}), '-01'), INTERVAL 1 DAY), '%Y-%m-%d') COALESCE (
), 0) AS sy_weight, (
COALESCE( SELECT
(SELECT SUM( CASE WHEN type = 1 THEN weight ELSE 0 END ) - SUM( CASE WHEN type = 2 THEN weight ELSE 0 END )
SUM(CASE WHEN type = 1 THEN length ELSE 0 END) - SUM(CASE WHEN type = 2 THEN length ELSE 0 END) FROM
FROM material_data material_data
WHERE WHERE
supplierCode = md.supplierCode and productName = md.productName and specification = md.specification supplierCode = md.supplierCode
), 0) AS jc_length, AND productName = md.productName
COALESCE( AND specification = md.specification
(SELECT AND createTime like CONCAT(DATE_FORMAT(DATE_SUB( #{query.start_time}, INTERVAL 1 DAY ), '%Y-%m-%d') , '%')
SUM(CASE WHEN type = 1 THEN weight ELSE 0 END) - SUM(CASE WHEN type = 2 THEN weight ELSE 0 END) ),
FROM material_data 0
WHERE ) AS sy_weight,
supplierCode = md.supplierCode and productName =md.productName and specification = md.specification COALESCE (
), 0) AS jc_weight (
FROM SELECT
material_data md SUM( CASE WHEN type = 1 THEN length ELSE 0 END ) - SUM( CASE WHEN type = 2 THEN length ELSE 0 END )
WHERE FROM
DATE_FORMAT(md.createTime, '%Y-%m-%d') = DATE_FORMAT(#{query.start_time}, '%Y-%m-%d') material_data
GROUP BY WHERE
md.productName,md.specification,supplierCode, DATE_FORMAT(md.createTime, '%Y-%m-%d') supplierCode = md.supplierCode
ORDER BY AND productName = md.productName
md.supplierCode, md.productName AND specification = md.specification
),
0
) AS jc_length,
COALESCE (
(
SELECT
SUM( CASE WHEN type = 1 THEN weight ELSE 0 END ) - SUM( CASE WHEN type = 2 THEN weight ELSE 0 END )
FROM
material_data
WHERE
supplierCode = md.supplierCode
AND productName = md.productName
AND specification = md.specification
),
0
) AS jc_weight
FROM
material_data md
WHERE
DATE_FORMAT( md.createTime, '%Y-%m-%d' ) = DATE_FORMAT( #{query.start_time}, '%Y-%m-%d' )
GROUP BY
md.productName,
md.specification,
supplierCode,
DATE_FORMAT( md.createTime, '%Y-%m-%d' )
ORDER BY
md.supplierCode,
md.productName
</select> </select>

23
lms/nladmin-ui/src/main.js

@ -85,3 +85,26 @@ new Vue({
store, store,
render: h => h(App) render: h => h(App)
}) })
// var time1 = new Date().format("yyyy-MM-dd hh:mm:ss");
// eslint-disable-next-line no-extend-native
Date.prototype.format = function(fmt) {
var o = {
'M+': this.getMonth() + 1, // 月份
'd+': this.getDate(), // 日
'h+': this.getHours(), // 小时
'm+': this.getMinutes(), // 分
's+': this.getSeconds(), // 秒
'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
'S': this.getMilliseconds() // 毫秒
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
}
}
return fmt
}

22
lms/nladmin-ui/src/views/wms/sch/data/index.vue

@ -27,14 +27,13 @@
<!--表格渲染--> <!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;" @selection-change="crud.selectionChangeHandler"> <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" /> <el-table-column prop="supplierCode" label="客户编码" :min-width="flexWidth('supplierCode',crud.data,'客户编码')" />
<el-table-column prop="supplierCode" label="客户编码" min-width="100" /> <el-table-column prop="supplierName" label="客户名称" :min-width="flexWidth('supplierName',crud.data,'客户名称')" />
<el-table-column prop="supplierName" label="客户名称" min-width="150" /> <el-table-column prop="productName" label="物料编码" :min-width="flexWidth('productName',crud.data,'物料编码')" />
<el-table-column prop="productName" label="物料编码" in-width="150" /> <el-table-column prop="date" label="日期" :min-width="flexWidth('date',crud.data,'日期')" />
<el-table-column prop="date" label="日期" /> <el-table-column prop="specification" label="规格" :min-width="flexWidth('specification',crud.data,'规格')" />
<el-table-column prop="specification" label="规格" /> <el-table-column prop="batch" label="来料批次" :min-width="flexWidth('batch',crud.data,'来料批次')" />
<el-table-column prop="batch" label="来料批次" /> <el-table-column prop="barLevel" label="棒源等级" :min-width="flexWidth('barLevel',crud.data,'棒源等级')" />
<el-table-column prop="barLevel" label="棒源等级" />
<el-table-column label="昨日结存"> <el-table-column label="昨日结存">
<el-table-column prop="sy_length" label="实际长度(mm)" /> <el-table-column prop="sy_length" label="实际长度(mm)" />
<el-table-column prop="sy_weight" label="实际重量(KG)" /> <el-table-column prop="sy_weight" label="实际重量(KG)" />
@ -43,7 +42,7 @@
<el-table-column prop="ll_length" label="实际长度(mm)" /> <el-table-column prop="ll_length" label="实际长度(mm)" />
<el-table-column prop="ll_weight" label="实际重量(KG)" /> <el-table-column prop="ll_weight" label="实际重量(KG)" />
</el-table-column> </el-table-column>
<el-table-column prop="pickingBatch" label="领料批次" /> <el-table-column prop="pickingBatch" label="领料批次" :min-width="flexWidth('pickingBatch',crud.data,'领料批次')" />
<el-table-column label="生产领料"> <el-table-column label="生产领料">
<el-table-column prop="sc_length" label="实际长度(mm)" /> <el-table-column prop="sc_length" label="实际长度(mm)" />
<el-table-column prop="sc_weight" label="实际重量(KG)" /> <el-table-column prop="sc_weight" label="实际重量(KG)" />
@ -63,12 +62,11 @@
import CRUD, { crud, header, presenter } from '@crud/crud' import CRUD, { crud, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation' import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation' import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination' import pagination from '@crud/Pagination'
export default { export default {
name: 'Data', name: 'Data',
components: { pagination, crudOperation, rrOperation, udOperation }, components: { pagination, crudOperation, rrOperation },
mixins: [presenter(), header(), crud()], mixins: [presenter(), header(), crud()],
cruds() { cruds() {
return CRUD({ return CRUD({
@ -84,7 +82,7 @@ export default {
reset: false reset: false
}, },
query: { query: {
// start_time: new Date().format('yyyy-MM-dd') start_time: new Date().format('yyyy-MM-dd')
} }
}) })
}, },

Loading…
Cancel
Save