feat: 增加工时报表导出并调整质量菜单
This commit is contained in:
@@ -25,7 +25,7 @@ BEGIN
|
||||
(
|
||||
SELECT
|
||||
src.[账号代码],
|
||||
COALESCE(prodParent.[id], src.[pid]) AS [pid],
|
||||
qualityParent.[id] AS [pid],
|
||||
src.[icon],
|
||||
src.[AddData],
|
||||
src.[DeleteData],
|
||||
@@ -37,13 +37,15 @@ BEGIN
|
||||
SELECT TOP (1) rp.[id]
|
||||
FROM [dbo].[登录基础数据_二级菜单] AS rp
|
||||
WHERE rp.[账号代码] = src.[账号代码]
|
||||
AND rp.[pid] = 0
|
||||
AND rp.[是否启用] = 1
|
||||
AND rp.[title] = N'生产管理'
|
||||
AND (rp.[title] = N'质量管理' OR rp.[path] = '/QualityManagement' OR rp.[name] = 'QualityManagement')
|
||||
ORDER BY rp.[id]
|
||||
) AS prodParent
|
||||
) AS qualityParent
|
||||
WHERE src.[是否启用] = 1
|
||||
AND (@TargetRole IS NULL OR src.[账号代码] = @TargetRole)
|
||||
AND (src.[path] = @SourcePath OR src.[componet] = @SourceComponent OR src.[title] = N'生产计划跟踪')
|
||||
AND qualityParent.[id] IS NOT NULL
|
||||
AND NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
@@ -77,7 +79,7 @@ BEGIN
|
||||
SELECT
|
||||
ROW_NUMBER() OVER (ORDER BY src.[账号代码], src.[id]) AS rn,
|
||||
src.[账号代码],
|
||||
COALESCE(prodParent.[id], src.[pid]) AS [pid],
|
||||
qualityParent.[id] AS [pid],
|
||||
src.[icon],
|
||||
src.[AddData],
|
||||
src.[DeleteData],
|
||||
@@ -89,13 +91,15 @@ BEGIN
|
||||
SELECT TOP (1) rp.[id]
|
||||
FROM [dbo].[登录基础数据_二级菜单] AS rp
|
||||
WHERE rp.[账号代码] = src.[账号代码]
|
||||
AND rp.[pid] = 0
|
||||
AND rp.[是否启用] = 1
|
||||
AND rp.[title] = N'生产管理'
|
||||
AND (rp.[title] = N'质量管理' OR rp.[path] = '/QualityManagement' OR rp.[name] = 'QualityManagement')
|
||||
ORDER BY rp.[id]
|
||||
) AS prodParent
|
||||
) AS qualityParent
|
||||
WHERE src.[是否启用] = 1
|
||||
AND (@TargetRole IS NULL OR src.[账号代码] = @TargetRole)
|
||||
AND (src.[path] = @SourcePath OR src.[componet] = @SourceComponent OR src.[title] = N'生产计划跟踪')
|
||||
AND qualityParent.[id] IS NOT NULL
|
||||
AND NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
@@ -132,6 +136,24 @@ END;
|
||||
|
||||
UPDATE [dbo].[登录基础数据_二级菜单]
|
||||
SET
|
||||
[pid] = COALESCE
|
||||
(
|
||||
(
|
||||
SELECT TOP (1) qualityParent.[id]
|
||||
FROM [dbo].[登录基础数据_二级菜单] AS qualityParent
|
||||
WHERE qualityParent.[账号代码] = [dbo].[登录基础数据_二级菜单].[账号代码]
|
||||
AND qualityParent.[pid] = 0
|
||||
AND qualityParent.[是否启用] = 1
|
||||
AND
|
||||
(
|
||||
qualityParent.[title] = N'质量管理'
|
||||
OR qualityParent.[path] = '/QualityManagement'
|
||||
OR qualityParent.[name] = 'QualityManagement'
|
||||
)
|
||||
ORDER BY qualityParent.[id]
|
||||
),
|
||||
[pid]
|
||||
),
|
||||
[path] = @Path,
|
||||
[componet] = @Component,
|
||||
[name] = @Name,
|
||||
@@ -144,4 +166,3 @@ SELECT [id], [pid], [path], [componet], [name], [title], [icon], [账号代码],
|
||||
FROM [dbo].[登录基础数据_二级菜单]
|
||||
WHERE [path] = @Path OR [componet] = @Component OR [title] = @Title
|
||||
ORDER BY [账号代码], [id];
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
USE [YL_MESDB];
|
||||
GO
|
||||
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
DECLARE @QualityMenuId int = 4;
|
||||
|
||||
DECLARE @TargetAccounts TABLE
|
||||
(
|
||||
[账号代码] int PRIMARY KEY
|
||||
);
|
||||
|
||||
INSERT INTO @TargetAccounts ([账号代码])
|
||||
SELECT DISTINCT [账号代码]
|
||||
FROM [dbo].[登录基础数据_二级菜单]
|
||||
WHERE [path] = 'ProductPassRateWorkstation/index'
|
||||
OR [componet] = '/ProductionManagement/ProductPassRateWorkstation/index'
|
||||
OR [name] = 'ProductPassRateWorkstation'
|
||||
OR [title] IN (N'产品合格率工位', N'产品合格率(工位)');
|
||||
|
||||
IF NOT EXISTS (SELECT 1 FROM @TargetAccounts)
|
||||
BEGIN
|
||||
THROW 50001, N'未找到产品合格率工位菜单,未执行迁移。', 1;
|
||||
END;
|
||||
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
IF EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM @TargetAccounts AS target
|
||||
INNER JOIN [dbo].[登录基础数据_二级菜单] AS menu WITH (UPDLOCK, HOLDLOCK)
|
||||
ON menu.[账号代码] = target.[账号代码]
|
||||
AND menu.[id] = @QualityMenuId
|
||||
WHERE menu.[pid] <> 0
|
||||
OR menu.[path] <> '/QualityManagement'
|
||||
OR menu.[name] <> 'QualityManagement'
|
||||
OR menu.[title] <> N'质量管理'
|
||||
)
|
||||
BEGIN
|
||||
THROW 50002, N'目标账号的菜单 ID 4 已被其他菜单占用,未执行迁移。', 1;
|
||||
END;
|
||||
|
||||
INSERT INTO [dbo].[登录基础数据_二级菜单]
|
||||
([id], [pid], [path], [componet], [redirect], [name], [title], [icon], [账号代码], [模块代码], [操作时间], [是否启用])
|
||||
SELECT
|
||||
@QualityMenuId,
|
||||
0,
|
||||
'/QualityManagement',
|
||||
'/layout/Layout',
|
||||
NULL,
|
||||
'QualityManagement',
|
||||
N'质量管理',
|
||||
'KKIMaintenance',
|
||||
target.[账号代码],
|
||||
@QualityMenuId,
|
||||
GETDATE(),
|
||||
1
|
||||
FROM @TargetAccounts AS target
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM [dbo].[登录基础数据_二级菜单] AS existing WITH (UPDLOCK, HOLDLOCK)
|
||||
WHERE existing.[账号代码] = target.[账号代码]
|
||||
AND existing.[id] = @QualityMenuId
|
||||
);
|
||||
|
||||
UPDATE qualityMenu
|
||||
SET
|
||||
qualityMenu.[pid] = 0,
|
||||
qualityMenu.[path] = '/QualityManagement',
|
||||
qualityMenu.[componet] = '/layout/Layout',
|
||||
qualityMenu.[redirect] = NULL,
|
||||
qualityMenu.[name] = 'QualityManagement',
|
||||
qualityMenu.[title] = N'质量管理',
|
||||
qualityMenu.[icon] = 'KKIMaintenance',
|
||||
qualityMenu.[模块代码] = @QualityMenuId,
|
||||
qualityMenu.[是否启用] = 1,
|
||||
qualityMenu.[操作时间] = GETDATE()
|
||||
FROM [dbo].[登录基础数据_二级菜单] AS qualityMenu
|
||||
INNER JOIN @TargetAccounts AS target
|
||||
ON target.[账号代码] = qualityMenu.[账号代码]
|
||||
WHERE qualityMenu.[id] = @QualityMenuId;
|
||||
|
||||
UPDATE targetMenu
|
||||
SET
|
||||
targetMenu.[pid] = @QualityMenuId,
|
||||
targetMenu.[path] = 'ProductPassRateWorkstation/index',
|
||||
targetMenu.[componet] = '/ProductionManagement/ProductPassRateWorkstation/index',
|
||||
targetMenu.[redirect] = NULL,
|
||||
targetMenu.[name] = 'ProductPassRateWorkstation',
|
||||
targetMenu.[title] = N'产品合格率(工位)',
|
||||
targetMenu.[模块代码] = targetMenu.[id],
|
||||
targetMenu.[是否启用] = 1,
|
||||
targetMenu.[操作时间] = GETDATE()
|
||||
FROM [dbo].[登录基础数据_二级菜单] AS targetMenu
|
||||
INNER JOIN @TargetAccounts AS target
|
||||
ON target.[账号代码] = targetMenu.[账号代码]
|
||||
WHERE targetMenu.[path] = 'ProductPassRateWorkstation/index'
|
||||
OR targetMenu.[componet] = '/ProductionManagement/ProductPassRateWorkstation/index'
|
||||
OR targetMenu.[name] = 'ProductPassRateWorkstation'
|
||||
OR targetMenu.[title] IN (N'产品合格率工位', N'产品合格率(工位)');
|
||||
|
||||
COMMIT TRANSACTION;
|
||||
|
||||
SELECT
|
||||
menu.[id],
|
||||
menu.[pid],
|
||||
menu.[path],
|
||||
menu.[componet],
|
||||
menu.[name],
|
||||
menu.[title],
|
||||
menu.[账号代码],
|
||||
menu.[模块代码],
|
||||
menu.[是否启用]
|
||||
FROM [dbo].[登录基础数据_二级菜单] AS menu
|
||||
INNER JOIN @TargetAccounts AS target
|
||||
ON target.[账号代码] = menu.[账号代码]
|
||||
WHERE menu.[id] = @QualityMenuId
|
||||
OR menu.[path] = 'ProductPassRateWorkstation/index'
|
||||
OR menu.[componet] = '/ProductionManagement/ProductPassRateWorkstation/index'
|
||||
ORDER BY menu.[账号代码], menu.[pid], menu.[id];
|
||||
GO
|
||||
@@ -63,6 +63,15 @@
|
||||
<span class="show-text">任务ID:</span>
|
||||
<el-input v-model="searchForm.did" clearable size="small" style="width: 90px; margin-right: 8px" />
|
||||
<el-button :loading="loading" icon="el-icon-search" plain size="small" type="primary" @click="searchTable">查询</el-button>
|
||||
<el-button
|
||||
:disabled="loading || tableData.length === 0"
|
||||
:loading="exporting"
|
||||
icon="el-icon-download"
|
||||
plain
|
||||
size="small"
|
||||
type="success"
|
||||
@click="exportToExcel"
|
||||
>导出</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
@@ -110,11 +119,14 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as XLSX from 'xlsx'
|
||||
|
||||
export default {
|
||||
name: 'DesignReportHoursReport',
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
exporting: false,
|
||||
tableData: [],
|
||||
projectOptions: [],
|
||||
materialOptions: [],
|
||||
@@ -176,6 +188,86 @@ export default {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
exportToExcel() {
|
||||
if (this.tableData.length === 0) {
|
||||
this.$message.warning('没有数据可导出')
|
||||
return
|
||||
}
|
||||
|
||||
this.exporting = true
|
||||
try {
|
||||
const rows = this.flattenTree(this.tableData)
|
||||
const exportData = rows.map(row => ({
|
||||
层级: row.Level === 1 ? '操作人汇总' : (row.Level === 2 ? '日期汇总' : '任务明细'),
|
||||
'操作人 / 日期 / 任务': `${' '.repeat(Math.max((row.Level || 1) - 1, 0))}${this.getTreeTitle(row)}`,
|
||||
工作日期: this.getExportValue(row.工作日期),
|
||||
RID: this.getExportValue(row.RID),
|
||||
DID: this.getExportValue(row.DID),
|
||||
项目号: this.getExportValue(row.项目号),
|
||||
物料编码: this.getExportValue(row.物料编码),
|
||||
物料名称: this.getExportValue(row.物料名称),
|
||||
图号: this.getExportValue(row.图号),
|
||||
类别: this.getExportValue(row.类别),
|
||||
报工次数: this.getExportValue(row.报工次数),
|
||||
'工时(h)': this.formatHours(row.工时小时),
|
||||
开始时间: this.getExportValue(row.开始时间),
|
||||
结束时间: this.getExportValue(row.结束时间),
|
||||
校验状态: this.getExportValue(row.校验状态),
|
||||
进度说明: this.getExportValue(row.进度说明),
|
||||
备注: this.getExportValue(row.备注)
|
||||
}))
|
||||
const workbook = XLSX.utils.book_new()
|
||||
const worksheet = XLSX.utils.json_to_sheet(exportData)
|
||||
worksheet['!cols'] = [
|
||||
{ wch: 12 },
|
||||
{ wch: 32 },
|
||||
{ wch: 14 },
|
||||
{ wch: 10 },
|
||||
{ wch: 10 },
|
||||
{ wch: 16 },
|
||||
{ wch: 22 },
|
||||
{ wch: 24 },
|
||||
{ wch: 16 },
|
||||
{ wch: 16 },
|
||||
{ wch: 12 },
|
||||
{ wch: 12 },
|
||||
{ wch: 20 },
|
||||
{ wch: 20 },
|
||||
{ wch: 14 },
|
||||
{ wch: 30 },
|
||||
{ wch: 30 }
|
||||
]
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, '设计工时报表')
|
||||
XLSX.writeFile(workbook, `设计工时报表_${this.formatDateForFileName(new Date())}.xlsx`)
|
||||
this.$message.success('导出成功')
|
||||
} catch (error) {
|
||||
console.error('设计工时报表导出失败:', error)
|
||||
this.$message.error('导出失败')
|
||||
} finally {
|
||||
this.exporting = false
|
||||
}
|
||||
},
|
||||
flattenTree(rows) {
|
||||
return rows.reduce((result, row) => {
|
||||
result.push(row)
|
||||
if (row.children && row.children.length > 0) {
|
||||
result.push(...this.flattenTree(row.children))
|
||||
}
|
||||
return result
|
||||
}, [])
|
||||
},
|
||||
getExportValue(value) {
|
||||
return value === null || value === undefined ? '' : value
|
||||
},
|
||||
formatDateForFileName(date) {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||
return `${year}${month}${day}_${hours}${minutes}${seconds}`
|
||||
},
|
||||
async queryProjects(query) {
|
||||
const data = this.CreateData('11', '设计报工_项目查询', [['过滤', query || '']])
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user