Commit 63526ab48d0ef093a9323beb1086c4dfcfb3eb59
1 parent
0d910d68
fix: 门店目标归属统一存组织ID,并修复日报汇总与转卡品项统计
门店目标保存/同步上月时归一化事业部等归属字段为组织ID,列表不再把ID转成名称;日报事业部与四大天王兼容历史名称关联;转卡品项按开单日期兜底 yjsj;补充相关 SQL 与前端编辑防呆。 Co-authored-by: Cursor <cursoragent@cursor.com>
Showing
13 changed files
with
696 additions
and
156 deletions
antis-ncc-admin/src/views/lqYcsdMdmbsd/components/edit-dialog.vue
| @@ -443,16 +443,15 @@ export default { | @@ -443,16 +443,15 @@ export default { | ||
| 443 | methods: { | 443 | methods: { |
| 444 | // 获取事业部选项 | 444 | // 获取事业部选项 |
| 445 | getBusinessUnitOptions() { | 445 | getBusinessUnitOptions() { |
| 446 | - lqmdtargetApi.previewDataInterface('734724946332222725').then(res => { | 446 | + return lqmdtargetApi.previewDataInterface('734724946332222725').then(res => { |
| 447 | this.businessUnitOptions = res.data.list || [] | 447 | this.businessUnitOptions = res.data.list || [] |
| 448 | }).catch(() => { | 448 | }).catch(() => { |
| 449 | this.businessUnitOptions = [] | 449 | this.businessUnitOptions = [] |
| 450 | }) | 450 | }) |
| 451 | - | ||
| 452 | }, | 451 | }, |
| 453 | // 获取科技部选项 | 452 | // 获取科技部选项 |
| 454 | getTechDepartmentOptions() { | 453 | getTechDepartmentOptions() { |
| 455 | - lqmdtargetApi.previewDataInterface('734725044101448965').then(res => { | 454 | + return lqmdtargetApi.previewDataInterface('734725044101448965').then(res => { |
| 456 | this.techDepartmentOptions = res.data.list || [] | 455 | this.techDepartmentOptions = res.data.list || [] |
| 457 | }).catch(() => { | 456 | }).catch(() => { |
| 458 | this.techDepartmentOptions = [] | 457 | this.techDepartmentOptions = [] |
| @@ -460,7 +459,7 @@ export default { | @@ -460,7 +459,7 @@ export default { | ||
| 460 | }, | 459 | }, |
| 461 | // 获取教育部选项 | 460 | // 获取教育部选项 |
| 462 | getEducationDepartmentOptions() { | 461 | getEducationDepartmentOptions() { |
| 463 | - lqmdtargetApi.previewDataInterface('734725010941281541').then(res => { | 462 | + return lqmdtargetApi.previewDataInterface('734725010941281541').then(res => { |
| 464 | this.educationDepartmentOptions = res.data.list || [] | 463 | this.educationDepartmentOptions = res.data.list || [] |
| 465 | }).catch(() => { | 464 | }).catch(() => { |
| 466 | this.educationDepartmentOptions = [] | 465 | this.educationDepartmentOptions = [] |
| @@ -468,7 +467,7 @@ export default { | @@ -468,7 +467,7 @@ export default { | ||
| 468 | }, | 467 | }, |
| 469 | // 获取大项目部选项 | 468 | // 获取大项目部选项 |
| 470 | getMajorProjectDepartmentOptions() { | 469 | getMajorProjectDepartmentOptions() { |
| 471 | - lqmdtargetApi.previewDataInterface('734725079920805125').then(res => { | 470 | + return lqmdtargetApi.previewDataInterface('734725079920805125').then(res => { |
| 472 | this.majorProjectDepartmentOptions = res.data.list || [] | 471 | this.majorProjectDepartmentOptions = res.data.list || [] |
| 473 | }).catch(() => { | 472 | }).catch(() => { |
| 474 | this.majorProjectDepartmentOptions = [] | 473 | this.majorProjectDepartmentOptions = [] |
| @@ -484,36 +483,71 @@ export default { | @@ -484,36 +483,71 @@ export default { | ||
| 484 | this.managerList = [] | 483 | this.managerList = [] |
| 485 | } | 484 | } |
| 486 | }, | 485 | }, |
| 486 | + // 将历史名称或异常值归一化为组织ID(下拉选项 value 均为 id) | ||
| 487 | + coerceOrganizeFields() { | ||
| 488 | + const fieldMap = [ | ||
| 489 | + ['businessUnit', this.businessUnitOptions], | ||
| 490 | + ['techDepartment', this.techDepartmentOptions], | ||
| 491 | + ['educationDepartment', this.educationDepartmentOptions], | ||
| 492 | + ['majorProjectDepartment', this.majorProjectDepartmentOptions] | ||
| 493 | + ] | ||
| 494 | + fieldMap.forEach(([field, options]) => { | ||
| 495 | + const val = this.localFormData[field] | ||
| 496 | + if (!val || !options || options.length === 0) return | ||
| 497 | + if (/^\d{15,}$/.test(String(val))) return | ||
| 498 | + const option = options.find(item => | ||
| 499 | + item.fullName === val || item.FullName === val || item.id === val || item.Id === val | ||
| 500 | + ) | ||
| 501 | + if (option) { | ||
| 502 | + this.localFormData[field] = option.id || option.Id | ||
| 503 | + } | ||
| 504 | + }) | ||
| 505 | + }, | ||
| 487 | // 初始化表单数据 | 506 | // 初始化表单数据 |
| 488 | - initFormData() { | ||
| 489 | - this.getBusinessUnitOptions() | ||
| 490 | - this.getTechDepartmentOptions() | ||
| 491 | - this.getEducationDepartmentOptions() | ||
| 492 | - this.getMajorProjectDepartmentOptions() | ||
| 493 | - this.getManagerList() | 507 | + async initFormData() { |
| 508 | + await Promise.all([ | ||
| 509 | + this.getBusinessUnitOptions(), | ||
| 510 | + this.getTechDepartmentOptions(), | ||
| 511 | + this.getEducationDepartmentOptions(), | ||
| 512 | + this.getMajorProjectDepartmentOptions(), | ||
| 513 | + this.getManagerList() | ||
| 514 | + ]) | ||
| 494 | if (this.isEdit && this.formData) { | 515 | if (this.isEdit && this.formData) { |
| 495 | - // 编辑模式,填充现有数据 | 516 | + let row = this.formData |
| 517 | + const id = this.formData.id || this.formData.Id | ||
| 518 | + if (id) { | ||
| 519 | + try { | ||
| 520 | + const res = await lqmdtargetApi.getById(id) | ||
| 521 | + if (res && res.data) { | ||
| 522 | + row = res.data | ||
| 523 | + } | ||
| 524 | + } catch (error) { | ||
| 525 | + console.error('获取门店目标详情失败:', error) | ||
| 526 | + } | ||
| 527 | + } | ||
| 528 | + // 编辑模式,填充现有数据(详情接口返回组织ID,避免列表展示名称被误保存) | ||
| 496 | this.localFormData = { | 529 | this.localFormData = { |
| 497 | - storeId: this.formData.storeId || this.formData.StoreId || '', | ||
| 498 | - month: this.formData.month || this.formData.Month || '', | ||
| 499 | - businessUnit: this.formData.businessUnit || this.formData.BusinessUnit || '', | ||
| 500 | - techDepartment: this.formData.techDepartment || this.formData.TechDepartment || '', | ||
| 501 | - educationDepartment: this.formData.educationDepartment || this.formData.EducationDepartment || '', | ||
| 502 | - majorProjectDepartment: this.formData.majorProjectDepartment || this.formData.MajorProjectDepartment || '', | ||
| 503 | - businessUnitTarget: this.formData.businessUnitTarget !== undefined ? Number(this.formData.businessUnitTarget) : 0, | ||
| 504 | - techDepartmentTarget: this.formData.techDepartmentTarget !== undefined ? Number(this.formData.techDepartmentTarget) : 0, | ||
| 505 | - educationDepartmentTarget: this.formData.educationDepartmentTarget !== undefined ? Number(this.formData.educationDepartmentTarget) : 0, | ||
| 506 | - majorProjectDepartmentTarget: this.formData.majorProjectDepartmentTarget !== undefined ? Number(this.formData.majorProjectDepartmentTarget) : 0, | ||
| 507 | - businessUnitGeneralManager: this.formData.businessUnitGeneralManager || this.formData.BusinessUnitGeneralManager || '', | ||
| 508 | - businessUnitManager: this.formData.businessUnitManager || this.formData.BusinessUnitManager || '', | ||
| 509 | - storeTarget: this.formData.storeTarget !== undefined ? Number(this.formData.storeTarget) : 0, | ||
| 510 | - storeLifeline: this.formData.storeLifeline !== undefined ? Number(this.formData.storeLifeline) : 0, | ||
| 511 | - storeConsumeTarget: this.formData.storeConsumeTarget !== undefined ? Number(this.formData.storeConsumeTarget) : 0, | ||
| 512 | - storeProjectTarget: this.formData.storeProjectTarget !== undefined ? Number(this.formData.storeProjectTarget) : 0, | ||
| 513 | - storeHeadcountTarget: this.formData.storeHeadcountTarget !== undefined ? Number(this.formData.storeHeadcountTarget) : 0, | ||
| 514 | - assistantHeadcountTargetStage1: this.formData.assistantHeadcountTargetStage1 !== undefined ? Number(this.formData.assistantHeadcountTargetStage1) : 0, | ||
| 515 | - assistantHeadcountTargetStage2: this.formData.assistantHeadcountTargetStage2 !== undefined ? Number(this.formData.assistantHeadcountTargetStage2) : 0 | 530 | + storeId: row.storeId || row.StoreId || '', |
| 531 | + month: row.month || row.Month || '', | ||
| 532 | + businessUnit: row.businessUnit || row.BusinessUnit || '', | ||
| 533 | + techDepartment: row.techDepartment || row.TechDepartment || '', | ||
| 534 | + educationDepartment: row.educationDepartment || row.EducationDepartment || '', | ||
| 535 | + majorProjectDepartment: row.majorProjectDepartment || row.MajorProjectDepartment || '', | ||
| 536 | + businessUnitTarget: row.businessUnitTarget !== undefined ? Number(row.businessUnitTarget) : 0, | ||
| 537 | + techDepartmentTarget: row.techDepartmentTarget !== undefined ? Number(row.techDepartmentTarget) : 0, | ||
| 538 | + educationDepartmentTarget: row.educationDepartmentTarget !== undefined ? Number(row.educationDepartmentTarget) : 0, | ||
| 539 | + majorProjectDepartmentTarget: row.majorProjectDepartmentTarget !== undefined ? Number(row.majorProjectDepartmentTarget) : 0, | ||
| 540 | + businessUnitGeneralManager: row.businessUnitGeneralManager || row.BusinessUnitGeneralManager || '', | ||
| 541 | + businessUnitManager: row.businessUnitManager || row.BusinessUnitManager || '', | ||
| 542 | + storeTarget: row.storeTarget !== undefined ? Number(row.storeTarget) : 0, | ||
| 543 | + storeLifeline: row.storeLifeline !== undefined ? Number(row.storeLifeline) : 0, | ||
| 544 | + storeConsumeTarget: row.storeConsumeTarget !== undefined ? Number(row.storeConsumeTarget) : 0, | ||
| 545 | + storeProjectTarget: row.storeProjectTarget !== undefined ? Number(row.storeProjectTarget) : 0, | ||
| 546 | + storeHeadcountTarget: row.storeHeadcountTarget !== undefined ? Number(row.storeHeadcountTarget) : 0, | ||
| 547 | + assistantHeadcountTargetStage1: row.assistantHeadcountTargetStage1 !== undefined ? Number(row.assistantHeadcountTargetStage1) : 0, | ||
| 548 | + assistantHeadcountTargetStage2: row.assistantHeadcountTargetStage2 !== undefined ? Number(row.assistantHeadcountTargetStage2) : 0 | ||
| 516 | } | 549 | } |
| 550 | + this.coerceOrganizeFields() | ||
| 517 | } else { | 551 | } else { |
| 518 | // 新增模式,重置表单 | 552 | // 新增模式,重置表单 |
| 519 | this.localFormData = { | 553 | this.localFormData = { |
antis-ncc-admin/src/views/lqYcsdMdmbsd/index.vue
| @@ -397,11 +397,14 @@ export default { | @@ -397,11 +397,14 @@ export default { | ||
| 397 | }) | 397 | }) |
| 398 | }, | 398 | }, |
| 399 | 399 | ||
| 400 | - // 获取部门名称 | ||
| 401 | - getDepartmentName(id, options) { | ||
| 402 | - if (!id || !options || options.length === 0) return '' | ||
| 403 | - const option = options.find(item => item.id === id || item.Id === id) | ||
| 404 | - return option ? (option.fullName || option.FullName) : '' | 400 | + // 获取部门名称:优先按组织ID匹配选项;后端已解析为名称或库内仅存名称时直接展示 |
| 401 | + getDepartmentName(value, options) { | ||
| 402 | + if (!value) return '' | ||
| 403 | + if (options && options.length > 0) { | ||
| 404 | + const option = options.find(item => item.id === value || item.Id === value) | ||
| 405 | + if (option) return option.fullName || option.FullName || value | ||
| 406 | + } | ||
| 407 | + return value | ||
| 405 | }, | 408 | }, |
| 406 | 409 | ||
| 407 | // 获取列表数据 | 410 | // 获取列表数据 |
antis-ncc-admin/src/views/statisticsList/form1.vue
| @@ -844,6 +844,7 @@ export default { | @@ -844,6 +844,7 @@ export default { | ||
| 844 | 844 | ||
| 845 | // 构建表头 | 845 | // 构建表头 |
| 846 | const headers = [ | 846 | const headers = [ |
| 847 | + '开单ID', | ||
| 847 | '开单日期', | 848 | '开单日期', |
| 848 | '客户姓名', | 849 | '客户姓名', |
| 849 | '客户电话', | 850 | '客户电话', |
| @@ -875,6 +876,7 @@ export default { | @@ -875,6 +876,7 @@ export default { | ||
| 875 | this.records.forEach(row => { | 876 | this.records.forEach(row => { |
| 876 | // 获取基础数据 | 877 | // 获取基础数据 |
| 877 | const baseData = { | 878 | const baseData = { |
| 879 | + billingId: row.id || '无', | ||
| 878 | date: this.formatDate(row.date) || '无', | 880 | date: this.formatDate(row.date) || '无', |
| 879 | customerName: row.customerName || '无', | 881 | customerName: row.customerName || '无', |
| 880 | customerPhone: row.customerPhone || '无', | 882 | customerPhone: row.customerPhone || '无', |
| @@ -916,6 +918,7 @@ export default { | @@ -916,6 +918,7 @@ export default { | ||
| 916 | // 如果没有健康师,创建一行空数据 | 918 | // 如果没有健康师,创建一行空数据 |
| 917 | if (healthTeachers.length === 0) { | 919 | if (healthTeachers.length === 0) { |
| 918 | const rowData = [ | 920 | const rowData = [ |
| 921 | + baseData.billingId, | ||
| 919 | baseData.date, | 922 | baseData.date, |
| 920 | baseData.customerName, | 923 | baseData.customerName, |
| 921 | baseData.customerPhone, | 924 | baseData.customerPhone, |
| @@ -973,6 +976,7 @@ export default { | @@ -973,6 +976,7 @@ export default { | ||
| 973 | 976 | ||
| 974 | // 构建行数据(所有行都显示完整数据,补全空白部分) | 977 | // 构建行数据(所有行都显示完整数据,补全空白部分) |
| 975 | const rowData = [ | 978 | const rowData = [ |
| 979 | + baseData.billingId, // 开单ID | ||
| 976 | baseData.date, // 开单日期 | 980 | baseData.date, // 开单日期 |
| 977 | baseData.customerName, // 客户姓名 | 981 | baseData.customerName, // 客户姓名 |
| 978 | baseData.customerPhone, // 客户电话 | 982 | baseData.customerPhone, // 客户电话 |
| @@ -1010,6 +1014,7 @@ export default { | @@ -1010,6 +1014,7 @@ export default { | ||
| 1010 | 1014 | ||
| 1011 | // 设置列宽 | 1015 | // 设置列宽 |
| 1012 | ws['!cols'] = [ | 1016 | ws['!cols'] = [ |
| 1017 | + { wch: 22 }, // 开单ID | ||
| 1013 | { wch: 12 }, // 开单日期 | 1018 | { wch: 12 }, // 开单日期 |
| 1014 | { wch: 12 }, // 客户姓名 | 1019 | { wch: 12 }, // 客户姓名 |
| 1015 | { wch: 15 }, // 客户电话 | 1020 | { wch: 15 }, // 客户电话 |
antis-ncc-admin/src/views/statisticsList/form7.vue
| @@ -241,7 +241,21 @@ | @@ -241,7 +241,21 @@ | ||
| 241 | :data="list" | 241 | :data="list" |
| 242 | has-c | 242 | has-c |
| 243 | > | 243 | > |
| 244 | - <el-table-column prop="employeeName" label="员工姓名" /> | 244 | + <el-table-column prop="employeeName" label="员工姓名" min-width="120"> |
| 245 | + <template slot-scope="scope"> | ||
| 246 | + <div class="table-cell-with-icon"> | ||
| 247 | + <i class="el-icon-user cell-icon primary"></i> | ||
| 248 | + <span class="cell-text">{{ scope.row.employeeName || '无' }}</span> | ||
| 249 | + <el-tag | ||
| 250 | + v-if="scope.row.isOnJob === 0" | ||
| 251 | + type="info" | ||
| 252 | + size="mini" | ||
| 253 | + disable-transitions | ||
| 254 | + class="employee-status-tag" | ||
| 255 | + >已离职</el-tag> | ||
| 256 | + </div> | ||
| 257 | + </template> | ||
| 258 | + </el-table-column> | ||
| 245 | <el-table-column prop="storeName" label="门店名称" /> | 259 | <el-table-column prop="storeName" label="门店名称" /> |
| 246 | <el-table-column prop="departmentName" label="部门名称" /> | 260 | <el-table-column prop="departmentName" label="部门名称" /> |
| 247 | <el-table-column prop="goldTriangleName" label="金三角名称" > | 261 | <el-table-column prop="goldTriangleName" label="金三角名称" > |
| @@ -965,6 +979,7 @@ export default { | @@ -965,6 +979,7 @@ export default { | ||
| 965 | sheetName: '门店综合统计', | 979 | sheetName: '门店综合统计', |
| 966 | columns: [ | 980 | columns: [ |
| 967 | { label: '员工姓名', prop: 'employeeName' }, | 981 | { label: '员工姓名', prop: 'employeeName' }, |
| 982 | + { label: '在职状态', formatter: row => (row.isOnJob === 0 ? '已离职' : '在职') }, | ||
| 968 | { label: '门店名称', prop: 'storeName' }, | 983 | { label: '门店名称', prop: 'storeName' }, |
| 969 | { label: '部门名称', prop: 'departmentName' }, | 984 | { label: '部门名称', prop: 'departmentName' }, |
| 970 | { label: '金三角名称', prop: 'goldTriangleName' }, | 985 | { label: '金三角名称', prop: 'goldTriangleName' }, |
| @@ -1137,6 +1152,10 @@ export default { | @@ -1137,6 +1152,10 @@ export default { | ||
| 1137 | } | 1152 | } |
| 1138 | } | 1153 | } |
| 1139 | 1154 | ||
| 1155 | +.employee-status-tag { | ||
| 1156 | + margin-left: 6px; | ||
| 1157 | +} | ||
| 1158 | + | ||
| 1140 | // 搜索框区域样式 | 1159 | // 搜索框区域样式 |
| 1141 | .NCC-common-search-box { | 1160 | .NCC-common-search-box { |
| 1142 | .el-form-item { | 1161 | .el-form-item { |
netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdKdjlb/BillingRecordSummaryExportOutput.cs
| @@ -8,6 +8,11 @@ namespace NCC.Extend.Entitys.Dto.LqKdKdjlb | @@ -8,6 +8,11 @@ namespace NCC.Extend.Entitys.Dto.LqKdKdjlb | ||
| 8 | public class BillingRecordSummaryExportOutput | 8 | public class BillingRecordSummaryExportOutput |
| 9 | { | 9 | { |
| 10 | /// <summary> | 10 | /// <summary> |
| 11 | + /// 开单ID | ||
| 12 | + /// </summary> | ||
| 13 | + public string BillingId { get; set; } | ||
| 14 | + | ||
| 15 | + /// <summary> | ||
| 11 | /// 开单日期 | 16 | /// 开单日期 |
| 12 | /// </summary> | 17 | /// </summary> |
| 13 | public string BillingDate { get; set; } | 18 | public string BillingDate { get; set; } |
netcore/src/Modularity/Extend/NCC.Extend.Entitys/Dto/LqKdKdjlb/HealthCoachStatisticsOutput.cs
| @@ -119,5 +119,10 @@ namespace NCC.Extend.Entitys.Dto.LqKdKdjlb | @@ -119,5 +119,10 @@ namespace NCC.Extend.Entitys.Dto.LqKdKdjlb | ||
| 119 | /// 队伍业绩占比 - 该健康师所在金三角的业绩占门店总业绩的比例(百分比,0-100) | 119 | /// 队伍业绩占比 - 该健康师所在金三角的业绩占门店总业绩的比例(百分比,0-100) |
| 120 | /// </summary> | 120 | /// </summary> |
| 121 | public decimal teamPerformanceRatio { get; set; } | 121 | public decimal teamPerformanceRatio { get; set; } |
| 122 | + | ||
| 123 | + /// <summary> | ||
| 124 | + /// 是否在职(BASE_USER.F_IsOnJob,0=离职,null 视为在职) | ||
| 125 | + /// </summary> | ||
| 126 | + public int? isOnJob { get; set; } | ||
| 122 | } | 127 | } |
| 123 | } | 128 | } |
netcore/src/Modularity/Extend/NCC.Extend/LqDailyReportService.cs
| @@ -378,7 +378,7 @@ namespace NCC.Extend | @@ -378,7 +378,7 @@ namespace NCC.Extend | ||
| 378 | COALESCE(SUM(target.F_BusinessUnitTarget), 0) as TargetPerformance, | 378 | COALESCE(SUM(target.F_BusinessUnitTarget), 0) as TargetPerformance, |
| 379 | COUNT(DISTINCT target.F_StoreId) as StoreCount | 379 | COUNT(DISTINCT target.F_StoreId) as StoreCount |
| 380 | FROM base_organize o | 380 | FROM base_organize o |
| 381 | - LEFT JOIN lq_md_target target ON target.F_BusinessUnit = o.F_Id AND target.F_Month = '{month}' | 381 | + LEFT JOIN lq_md_target target ON (target.F_BusinessUnit = o.F_Id OR target.F_BusinessUnit = o.F_FullName) AND target.F_Month = '{month}' |
| 382 | WHERE o.F_Category = 'department' | 382 | WHERE o.F_Category = 'department' |
| 383 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | 383 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) |
| 384 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') | 384 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') |
| @@ -418,20 +418,21 @@ namespace NCC.Extend | @@ -418,20 +418,21 @@ namespace NCC.Extend | ||
| 418 | 418 | ||
| 419 | var billingPerformanceSql = $@" | 419 | var billingPerformanceSql = $@" |
| 420 | SELECT | 420 | SELECT |
| 421 | - target.F_BusinessUnit as BusinessUnitId, | 421 | + o.F_Id as BusinessUnitId, |
| 422 | COALESCE(SUM(billing.sfyj), 0) as BillingPerformance | 422 | COALESCE(SUM(billing.sfyj), 0) as BillingPerformance |
| 423 | FROM lq_kd_kdjlb billing | 423 | FROM lq_kd_kdjlb billing |
| 424 | INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId AND target.F_Month = '{month}' | 424 | INNER JOIN lq_md_target target ON billing.djmd = target.F_StoreId AND target.F_Month = '{month}' |
| 425 | - INNER JOIN base_organize o ON target.F_BusinessUnit = o.F_Id | 425 | + INNER JOIN base_organize o ON (target.F_BusinessUnit = o.F_Id OR target.F_BusinessUnit = o.F_FullName) |
| 426 | WHERE billing.F_IsEffective = 1 | 426 | WHERE billing.F_IsEffective = 1 |
| 427 | AND target.F_BusinessUnit IS NOT NULL | 427 | AND target.F_BusinessUnit IS NOT NULL |
| 428 | + AND target.F_BusinessUnit != '' | ||
| 428 | AND o.F_Category = 'department' | 429 | AND o.F_Category = 'department' |
| 429 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | 430 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) |
| 430 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') | 431 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') |
| 431 | AND DATE(billing.kdrq) >= '{startDate:yyyy-MM-dd}' | 432 | AND DATE(billing.kdrq) >= '{startDate:yyyy-MM-dd}' |
| 432 | AND DATE(billing.kdrq) <= '{endDate:yyyy-MM-dd}' | 433 | AND DATE(billing.kdrq) <= '{endDate:yyyy-MM-dd}' |
| 433 | - AND target.F_BusinessUnit IN ('{unitIdsStr}') | ||
| 434 | - GROUP BY target.F_BusinessUnit"; | 434 | + AND o.F_Id IN ('{unitIdsStr}') |
| 435 | + GROUP BY o.F_Id"; | ||
| 435 | 436 | ||
| 436 | var billingPerformanceData = await _db.Ado.SqlQueryAsync<dynamic>(billingPerformanceSql); | 437 | var billingPerformanceData = await _db.Ado.SqlQueryAsync<dynamic>(billingPerformanceSql); |
| 437 | 438 | ||
| @@ -439,20 +440,21 @@ namespace NCC.Extend | @@ -439,20 +440,21 @@ namespace NCC.Extend | ||
| 439 | // 重要:门店归属事业部应该从门店目标表(lq_md_target)中获取,不同月份的归属可能不一样 | 440 | // 重要:门店归属事业部应该从门店目标表(lq_md_target)中获取,不同月份的归属可能不一样 |
| 440 | var refundPerformanceSql = $@" | 441 | var refundPerformanceSql = $@" |
| 441 | SELECT | 442 | SELECT |
| 442 | - target.F_BusinessUnit as BusinessUnitId, | 443 | + o.F_Id as BusinessUnitId, |
| 443 | COALESCE(SUM(COALESCE(refund.F_ActualRefundAmount, refund.tkje, 0)), 0) as RefundPerformance | 444 | COALESCE(SUM(COALESCE(refund.F_ActualRefundAmount, refund.tkje, 0)), 0) as RefundPerformance |
| 444 | FROM lq_hytk_hytk refund | 445 | FROM lq_hytk_hytk refund |
| 445 | INNER JOIN lq_md_target target ON refund.md = target.F_StoreId AND target.F_Month = '{month}' | 446 | INNER JOIN lq_md_target target ON refund.md = target.F_StoreId AND target.F_Month = '{month}' |
| 446 | - INNER JOIN base_organize o ON target.F_BusinessUnit = o.F_Id | 447 | + INNER JOIN base_organize o ON (target.F_BusinessUnit = o.F_Id OR target.F_BusinessUnit = o.F_FullName) |
| 447 | WHERE refund.F_IsEffective = 1 | 448 | WHERE refund.F_IsEffective = 1 |
| 448 | AND target.F_BusinessUnit IS NOT NULL | 449 | AND target.F_BusinessUnit IS NOT NULL |
| 450 | + AND target.F_BusinessUnit != '' | ||
| 449 | AND o.F_Category = 'department' | 451 | AND o.F_Category = 'department' |
| 450 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | 452 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) |
| 451 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') | 453 | AND o.F_FullName IN ('事业一部', '事业二部', '事业三部', '事业四部', '事业五部', '事业六部') |
| 452 | AND DATE(refund.tksj) >= '{startDate:yyyy-MM-dd}' | 454 | AND DATE(refund.tksj) >= '{startDate:yyyy-MM-dd}' |
| 453 | AND DATE(refund.tksj) <= '{endDate:yyyy-MM-dd}' | 455 | AND DATE(refund.tksj) <= '{endDate:yyyy-MM-dd}' |
| 454 | - AND target.F_BusinessUnit IN ('{unitIdsStr}') | ||
| 455 | - GROUP BY target.F_BusinessUnit"; | 456 | + AND o.F_Id IN ('{unitIdsStr}') |
| 457 | + GROUP BY o.F_Id"; | ||
| 456 | 458 | ||
| 457 | var refundPerformanceData = await _db.Ado.SqlQueryAsync<dynamic>(refundPerformanceSql); | 459 | var refundPerformanceData = await _db.Ado.SqlQueryAsync<dynamic>(refundPerformanceSql); |
| 458 | 460 | ||
| @@ -588,7 +590,7 @@ namespace NCC.Extend | @@ -588,7 +590,7 @@ namespace NCC.Extend | ||
| 588 | COALESCE(SUM(target.{deptType.Value.targetFieldName}), 0) as TargetPerformance, | 590 | COALESCE(SUM(target.{deptType.Value.targetFieldName}), 0) as TargetPerformance, |
| 589 | COUNT(DISTINCT target.F_StoreId) as StoreCount | 591 | COUNT(DISTINCT target.F_StoreId) as StoreCount |
| 590 | FROM base_organize o | 592 | FROM base_organize o |
| 591 | - LEFT JOIN lq_md_target target ON target.{deptType.Value.fieldName} = o.F_Id AND target.F_Month = '{month}' | 593 | + LEFT JOIN lq_md_target target ON (target.{deptType.Value.fieldName} = o.F_Id OR target.{deptType.Value.fieldName} = o.F_FullName) AND target.F_Month = '{month}' |
| 592 | WHERE o.F_Category = 'department' | 594 | WHERE o.F_Category = 'department' |
| 593 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | 595 | AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) |
| 594 | AND o.F_FullName IN ('{deptNamesStr}') | 596 | AND o.F_FullName IN ('{deptNamesStr}') |
| @@ -627,7 +629,8 @@ namespace NCC.Extend | @@ -627,7 +629,8 @@ namespace NCC.Extend | ||
| 627 | } | 629 | } |
| 628 | 630 | ||
| 629 | // 第二步:优化策略 - 先获取门店列表,只查询这些门店的数据,大幅提升性能 | 631 | // 第二步:优化策略 - 先获取门店列表,只查询这些门店的数据,大幅提升性能 |
| 630 | - var deptIdsStr = string.Join("','", departmentDict.Keys); | 632 | + var organizeAliasToIdMap = await BuildOrganizeAliasToIdMapAsync(departmentDict.Keys); |
| 633 | + var deptAliasInClause = string.Join("','", organizeAliasToIdMap.Keys.Where(x => !string.IsNullOrEmpty(x))); | ||
| 631 | 634 | ||
| 632 | // 2.1 先快速获取有目标记录的门店ID列表(使用索引,非常快,通常<100ms) | 635 | // 2.1 先快速获取有目标记录的门店ID列表(使用索引,非常快,通常<100ms) |
| 633 | var storeIdsSql = $@" | 636 | var storeIdsSql = $@" |
| @@ -635,9 +638,9 @@ namespace NCC.Extend | @@ -635,9 +638,9 @@ namespace NCC.Extend | ||
| 635 | FROM lq_md_target | 638 | FROM lq_md_target |
| 636 | WHERE F_Month = '{month}' | 639 | WHERE F_Month = '{month}' |
| 637 | AND ( | 640 | AND ( |
| 638 | - F_EducationDepartment IN ('{deptIdsStr}') | ||
| 639 | - OR F_TechDepartment IN ('{deptIdsStr}') | ||
| 640 | - OR F_MajorProjectDepartment IN ('{deptIdsStr}') | 641 | + F_EducationDepartment IN ('{deptAliasInClause}') |
| 642 | + OR F_TechDepartment IN ('{deptAliasInClause}') | ||
| 643 | + OR F_MajorProjectDepartment IN ('{deptAliasInClause}') | ||
| 641 | )"; | 644 | )"; |
| 642 | 645 | ||
| 643 | var storeIdsData = await _db.Ado.SqlQueryAsync<dynamic>(storeIdsSql); | 646 | var storeIdsData = await _db.Ado.SqlQueryAsync<dynamic>(storeIdsSql); |
| @@ -758,9 +761,13 @@ namespace NCC.Extend | @@ -758,9 +761,13 @@ namespace NCC.Extend | ||
| 758 | else if (deptField == "F_MajorProjectDepartment") | 761 | else if (deptField == "F_MajorProjectDepartment") |
| 759 | targetDeptId = target?.F_MajorProjectDepartment?.ToString(); | 762 | targetDeptId = target?.F_MajorProjectDepartment?.ToString(); |
| 760 | 763 | ||
| 761 | - if (!string.IsNullOrEmpty(targetDeptId) && departmentDict.ContainsKey(targetDeptId)) | 764 | + if (!string.IsNullOrEmpty(targetDeptId)) |
| 762 | { | 765 | { |
| 763 | - departmentDict[targetDeptId].BillingPerformance += storeAmount; | 766 | + var resolvedDeptId = ResolveOrganizeId(targetDeptId, organizeAliasToIdMap); |
| 767 | + if (!string.IsNullOrEmpty(resolvedDeptId) && departmentDict.ContainsKey(resolvedDeptId)) | ||
| 768 | + { | ||
| 769 | + departmentDict[resolvedDeptId].BillingPerformance += storeAmount; | ||
| 770 | + } | ||
| 764 | } | 771 | } |
| 765 | } | 772 | } |
| 766 | } | 773 | } |
| @@ -807,9 +814,13 @@ namespace NCC.Extend | @@ -807,9 +814,13 @@ namespace NCC.Extend | ||
| 807 | else if (deptField == "F_MajorProjectDepartment") | 814 | else if (deptField == "F_MajorProjectDepartment") |
| 808 | targetDeptId = target?.F_MajorProjectDepartment?.ToString(); | 815 | targetDeptId = target?.F_MajorProjectDepartment?.ToString(); |
| 809 | 816 | ||
| 810 | - if (!string.IsNullOrEmpty(targetDeptId) && departmentDict.ContainsKey(targetDeptId)) | 817 | + if (!string.IsNullOrEmpty(targetDeptId)) |
| 811 | { | 818 | { |
| 812 | - departmentDict[targetDeptId].RefundPerformance += storeRefundAmount; | 819 | + var resolvedDeptId = ResolveOrganizeId(targetDeptId, organizeAliasToIdMap); |
| 820 | + if (!string.IsNullOrEmpty(resolvedDeptId) && departmentDict.ContainsKey(resolvedDeptId)) | ||
| 821 | + { | ||
| 822 | + departmentDict[resolvedDeptId].RefundPerformance += storeRefundAmount; | ||
| 823 | + } | ||
| 813 | } | 824 | } |
| 814 | } | 825 | } |
| 815 | } | 826 | } |
| @@ -857,9 +868,13 @@ namespace NCC.Extend | @@ -857,9 +868,13 @@ namespace NCC.Extend | ||
| 857 | else if (deptField == "F_MajorProjectDepartment") | 868 | else if (deptField == "F_MajorProjectDepartment") |
| 858 | targetDeptId = target?.F_MajorProjectDepartment?.ToString(); | 869 | targetDeptId = target?.F_MajorProjectDepartment?.ToString(); |
| 859 | 870 | ||
| 860 | - if (!string.IsNullOrEmpty(targetDeptId) && departmentDict.ContainsKey(targetDeptId)) | 871 | + if (!string.IsNullOrEmpty(targetDeptId)) |
| 861 | { | 872 | { |
| 862 | - departmentDict[targetDeptId].DeductAmount += storeDeductAmount; | 873 | + var resolvedDeptId = ResolveOrganizeId(targetDeptId, organizeAliasToIdMap); |
| 874 | + if (!string.IsNullOrEmpty(resolvedDeptId) && departmentDict.ContainsKey(resolvedDeptId)) | ||
| 875 | + { | ||
| 876 | + departmentDict[resolvedDeptId].DeductAmount += storeDeductAmount; | ||
| 877 | + } | ||
| 863 | } | 878 | } |
| 864 | } | 879 | } |
| 865 | } | 880 | } |
| @@ -1605,7 +1620,7 @@ namespace NCC.Extend | @@ -1605,7 +1620,7 @@ namespace NCC.Extend | ||
| 1605 | (billing, target, store, org) => | 1620 | (billing, target, store, org) => |
| 1606 | billing.Djmd == target.StoreId | 1621 | billing.Djmd == target.StoreId |
| 1607 | && target.Month == month | 1622 | && target.Month == month |
| 1608 | - && target.BusinessUnit == org.Id | 1623 | + && (target.BusinessUnit == org.Id || target.BusinessUnit == org.FullName) |
| 1609 | && billing.Djmd == store.Id) | 1624 | && billing.Djmd == store.Id) |
| 1610 | .Where((billing, target, store, org) => billing.IsEffective == StatusEnum.有效.GetHashCode()) | 1625 | .Where((billing, target, store, org) => billing.IsEffective == StatusEnum.有效.GetHashCode()) |
| 1611 | .Where((billing, target, store, org) => billing.Sfyj > 0) // 只统计有金额的开单 | 1626 | .Where((billing, target, store, org) => billing.Sfyj > 0) // 只统计有金额的开单 |
| @@ -1973,6 +1988,54 @@ namespace NCC.Extend | @@ -1973,6 +1988,54 @@ namespace NCC.Extend | ||
| 1973 | } | 1988 | } |
| 1974 | #endregion | 1989 | #endregion |
| 1975 | 1990 | ||
| 1991 | + /// <summary> | ||
| 1992 | + /// 构建组织别名(ID/名称)到组织ID的映射,兼容 lq_md_target 归属字段混存 ID 与名称。 | ||
| 1993 | + /// </summary> | ||
| 1994 | + private async Task<Dictionary<string, string>> BuildOrganizeAliasToIdMapAsync(IEnumerable<string> organizeIds) | ||
| 1995 | + { | ||
| 1996 | + var ids = organizeIds? | ||
| 1997 | + .Where(x => !string.IsNullOrWhiteSpace(x)) | ||
| 1998 | + .Distinct() | ||
| 1999 | + .ToList() ?? new List<string>(); | ||
| 2000 | + | ||
| 2001 | + if (!ids.Any()) | ||
| 2002 | + { | ||
| 2003 | + return new Dictionary<string, string>(StringComparer.Ordinal); | ||
| 2004 | + } | ||
| 2005 | + | ||
| 2006 | + var orgs = await _db.Queryable<OrganizeEntity>() | ||
| 2007 | + .Where(x => ids.Contains(x.Id) && x.DeleteMark == null) | ||
| 2008 | + .Select(x => new { x.Id, x.FullName }) | ||
| 2009 | + .ToListAsync(); | ||
| 2010 | + | ||
| 2011 | + var map = new Dictionary<string, string>(StringComparer.Ordinal); | ||
| 2012 | + foreach (var org in orgs) | ||
| 2013 | + { | ||
| 2014 | + map[org.Id] = org.Id; | ||
| 2015 | + if (!string.IsNullOrWhiteSpace(org.FullName)) | ||
| 2016 | + { | ||
| 2017 | + map[org.FullName] = org.Id; | ||
| 2018 | + } | ||
| 2019 | + } | ||
| 2020 | + | ||
| 2021 | + return map; | ||
| 2022 | + } | ||
| 2023 | + | ||
| 2024 | + /// <summary> | ||
| 2025 | + /// 将 lq_md_target 中的组织归属值(ID 或名称)解析为标准组织ID。 | ||
| 2026 | + /// </summary> | ||
| 2027 | + private static string ResolveOrganizeId(string rawValue, Dictionary<string, string> aliasToIdMap) | ||
| 2028 | + { | ||
| 2029 | + if (string.IsNullOrWhiteSpace(rawValue)) | ||
| 2030 | + { | ||
| 2031 | + return null; | ||
| 2032 | + } | ||
| 2033 | + | ||
| 2034 | + return aliasToIdMap != null && aliasToIdMap.TryGetValue(rawValue, out var id) | ||
| 2035 | + ? id | ||
| 2036 | + : rawValue; | ||
| 2037 | + } | ||
| 2038 | + | ||
| 1976 | 2039 | ||
| 1977 | } | 2040 | } |
| 1978 | } | 2041 | } |
netcore/src/Modularity/Extend/NCC.Extend/LqKdKdjlbService.cs
| @@ -381,6 +381,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -381,6 +381,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 381 | { | 381 | { |
| 382 | exportData.Add(new BillingRecordSummaryExportOutput | 382 | exportData.Add(new BillingRecordSummaryExportOutput |
| 383 | { | 383 | { |
| 384 | + BillingId = billing.id ?? "无", | ||
| 384 | BillingDate = FormatDate(billing.kdrq), | 385 | BillingDate = FormatDate(billing.kdrq), |
| 385 | StoreName = billing.djmdName ?? "无", | 386 | StoreName = billing.djmdName ?? "无", |
| 386 | CustomerName = billing.kdhyc ?? "无", | 387 | CustomerName = billing.kdhyc ?? "无", |
| @@ -416,6 +417,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -416,6 +417,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 416 | { | 417 | { |
| 417 | exportData.Add(new BillingRecordSummaryExportOutput | 418 | exportData.Add(new BillingRecordSummaryExportOutput |
| 418 | { | 419 | { |
| 420 | + BillingId = billing.id ?? "无", | ||
| 419 | BillingDate = FormatDate(billing.kdrq), | 421 | BillingDate = FormatDate(billing.kdrq), |
| 420 | StoreName = billing.djmdName ?? "无", | 422 | StoreName = billing.djmdName ?? "无", |
| 421 | CustomerName = billing.kdhyc ?? "无", | 423 | CustomerName = billing.kdhyc ?? "无", |
| @@ -461,7 +463,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -461,7 +463,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 461 | 463 | ||
| 462 | // 配置Excel导出 | 464 | // 配置Excel导出 |
| 463 | List<ParamsModel> paramList = | 465 | List<ParamsModel> paramList = |
| 464 | - "[{\"value\":\"开单日期\",\"field\":\"BillingDate\"},{\"value\":\"单据门店\",\"field\":\"StoreName\"},{\"value\":\"客户姓名\",\"field\":\"CustomerName\"},{\"value\":\"客户电话\",\"field\":\"CustomerPhone\"},{\"value\":\"客户档案号\",\"field\":\"CustomerArchiveNo\"},{\"value\":\"进店渠道\",\"field\":\"CustomerChannel\"},{\"value\":\"金三角\",\"field\":\"GoldTriangle\"},{\"value\":\"客户类型\",\"field\":\"CustomerType\"},{\"value\":\"健康师\",\"field\":\"HealthCoach\"},{\"value\":\"业绩金额\",\"field\":\"PerformanceAmount\"},{\"value\":\"相关品项\",\"field\":\"RelatedItem\"},{\"value\":\"分类\",\"field\":\"Category\"},{\"value\":\"类型\",\"field\":\"Type\"},{\"value\":\"单价\",\"field\":\"UnitPrice\"},{\"value\":\"次数\",\"field\":\"ProjectNumber\"},{\"value\":\"品项金额\",\"field\":\"ItemAmount\"},{\"value\":\"已付金额\",\"field\":\"PaidAmount\"},{\"value\":\"欠款金额\",\"field\":\"DebtAmount\"},{\"value\":\"总金额\",\"field\":\"TotalAmount\"},{\"value\":\"支付方式\",\"field\":\"PaymentMethod\"},{\"value\":\"合作机构\",\"field\":\"CooperationInstitution\"},{\"value\":\"结算机构\",\"field\":\"SettlementInstitution\"},{\"value\":\"活动名称\",\"field\":\"ActivityName\"},{\"value\":\"备注\",\"field\":\"Remark\"},{\"value\":\"开单时间\",\"field\":\"CreateTime\"}]".ToList<ParamsModel>(); | 466 | + "[{\"value\":\"开单ID\",\"field\":\"BillingId\"},{\"value\":\"开单日期\",\"field\":\"BillingDate\"},{\"value\":\"单据门店\",\"field\":\"StoreName\"},{\"value\":\"客户姓名\",\"field\":\"CustomerName\"},{\"value\":\"客户电话\",\"field\":\"CustomerPhone\"},{\"value\":\"客户档案号\",\"field\":\"CustomerArchiveNo\"},{\"value\":\"进店渠道\",\"field\":\"CustomerChannel\"},{\"value\":\"金三角\",\"field\":\"GoldTriangle\"},{\"value\":\"客户类型\",\"field\":\"CustomerType\"},{\"value\":\"健康师\",\"field\":\"HealthCoach\"},{\"value\":\"业绩金额\",\"field\":\"PerformanceAmount\"},{\"value\":\"相关品项\",\"field\":\"RelatedItem\"},{\"value\":\"分类\",\"field\":\"Category\"},{\"value\":\"类型\",\"field\":\"Type\"},{\"value\":\"单价\",\"field\":\"UnitPrice\"},{\"value\":\"次数\",\"field\":\"ProjectNumber\"},{\"value\":\"品项金额\",\"field\":\"ItemAmount\"},{\"value\":\"已付金额\",\"field\":\"PaidAmount\"},{\"value\":\"欠款金额\",\"field\":\"DebtAmount\"},{\"value\":\"总金额\",\"field\":\"TotalAmount\"},{\"value\":\"支付方式\",\"field\":\"PaymentMethod\"},{\"value\":\"合作机构\",\"field\":\"CooperationInstitution\"},{\"value\":\"结算机构\",\"field\":\"SettlementInstitution\"},{\"value\":\"活动名称\",\"field\":\"ActivityName\"},{\"value\":\"备注\",\"field\":\"Remark\"},{\"value\":\"开单时间\",\"field\":\"CreateTime\"}]".ToList<ParamsModel>(); |
| 465 | 467 | ||
| 466 | ExcelConfig excelconfig = new ExcelConfig(); | 468 | ExcelConfig excelconfig = new ExcelConfig(); |
| 467 | excelconfig.FileName = "开单记录汇总_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".xls"; | 469 | excelconfig.FileName = "开单记录汇总_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".xls"; |
| @@ -3282,6 +3284,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -3282,6 +3284,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 3282 | var detailedRecords = billingRecords.Select(billing => new | 3284 | var detailedRecords = billingRecords.Select(billing => new |
| 3283 | { | 3285 | { |
| 3284 | // 基本信息 | 3286 | // 基本信息 |
| 3287 | + id = billing.id, | ||
| 3285 | date = billing.kdrq?.ToString("yyyy-MM-dd"), | 3288 | date = billing.kdrq?.ToString("yyyy-MM-dd"), |
| 3286 | customerName = billing.kdhyc, | 3289 | customerName = billing.kdhyc, |
| 3287 | customerPhone = billing.kdhysjh, | 3290 | customerPhone = billing.kdhysjh, |
| @@ -3997,6 +4000,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -3997,6 +4000,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 3997 | TotalPrice = transferAmount, | 4000 | TotalPrice = transferAmount, |
| 3998 | ActualPrice = transferAmount, | 4001 | ActualPrice = transferAmount, |
| 3999 | IsEffective = StatusEnum.有效.GetHashCode(), | 4002 | IsEffective = StatusEnum.有效.GetHashCode(), |
| 4003 | + Yjsj = transferTime, | ||
| 4000 | Remark = $"从会员 {fromMember.Khmc} 转入", | 4004 | Remark = $"从会员 {fromMember.Khmc} 转入", |
| 4001 | ItemCategory = await _db.Queryable<LqXmzlEntity>().Where(x => x.Id == refundPxmxEntity.Px).Select(x => x.Qt2).FirstAsync(), | 4005 | ItemCategory = await _db.Queryable<LqXmzlEntity>().Where(x => x.Id == refundPxmxEntity.Px).Select(x => x.Qt2).FirstAsync(), |
| 4002 | PerformanceType = await _db.Queryable<LqXmzlEntity>().Where(x => x.Id == refundPxmxEntity.Px).Select(x => x.Fl3).FirstAsync() ?? "", | 4006 | PerformanceType = await _db.Queryable<LqXmzlEntity>().Where(x => x.Id == refundPxmxEntity.Px).Select(x => x.Fl3).FirstAsync() ?? "", |
| @@ -4259,6 +4263,10 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4259,6 +4263,10 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4259 | /// - employeeName: 健康师姓名(可选) | 4263 | /// - employeeName: 健康师姓名(可选) |
| 4260 | /// - currentPage / pageSize: 分页(数据库层 LIMIT;pageSize 最大 500,避免一次拉全量健康师导致超时) | 4264 | /// - currentPage / pageSize: 分页(数据库层 LIMIT;pageSize 最大 500,避免一次拉全量健康师导致超时) |
| 4261 | /// | 4265 | /// |
| 4266 | + /// 人员范围(与 historical-on-job-inference 一致,按统计起止时间): | ||
| 4267 | + /// - 仅展示统计时段内曾在职的健康师:入职不晚于 endTime,且(无离职日或离职日≥startTime) | ||
| 4268 | + /// - 统计开始前已离职的员工不展示;时段内中途离职者仍展示其时段内业绩,isOnJob=0 时前端可标「已离职」 | ||
| 4269 | + /// | ||
| 4262 | /// 返回字段说明: | 4270 | /// 返回字段说明: |
| 4263 | /// - EmployeeId: 健康师ID | 4271 | /// - EmployeeId: 健康师ID |
| 4264 | /// - EmployeeName: 健康师姓名 | 4272 | /// - EmployeeName: 健康师姓名 |
| @@ -4310,6 +4318,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4310,6 +4318,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4310 | SELECT | 4318 | SELECT |
| 4311 | u.F_Id as EmployeeId, | 4319 | u.F_Id as EmployeeId, |
| 4312 | u.F_REALNAME as EmployeeName, | 4320 | u.F_REALNAME as EmployeeName, |
| 4321 | + u.F_IsOnJob as IsOnJob, | ||
| 4313 | u.F_MDID as StoreId, | 4322 | u.F_MDID as StoreId, |
| 4314 | md.dm as StoreName, | 4323 | md.dm as StoreName, |
| 4315 | COALESCE(target.F_BusinessUnit, md.syb) as DepartmentId, | 4324 | COALESCE(target.F_BusinessUnit, md.syb) as DepartmentId, |
| @@ -4654,6 +4663,12 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4654,6 +4663,12 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4654 | 4663 | ||
| 4655 | var filterSql = conditions.Any() ? " AND " + string.Join(" AND ", conditions) : string.Empty; | 4664 | var filterSql = conditions.Any() ? " AND " + string.Join(" AND ", conditions) : string.Empty; |
| 4656 | 4665 | ||
| 4666 | + // 统计时段内在职口径:不依赖当前 F_IsOnJob,避免历史月误杀;时段开始前已离职的不展示 | ||
| 4667 | + const string periodOnJobSql = @" | ||
| 4668 | + AND u.F_DeleteMark IS NULL | ||
| 4669 | + AND u.F_ENTRYDATE IS NOT NULL AND u.F_ENTRYDATE <= @endTime | ||
| 4670 | + AND (u.F_LeaveDate IS NULL OR u.F_LeaveDate >= @startTime)"; | ||
| 4671 | + | ||
| 4657 | var pageIndex = input.currentPage < 1 ? 1 : input.currentPage; | 4672 | var pageIndex = input.currentPage < 1 ? 1 : input.currentPage; |
| 4658 | var pageSize = input.pageSize < 1 ? 20 : Math.Min(input.pageSize, 500); | 4673 | var pageSize = input.pageSize < 1 ? 20 : Math.Min(input.pageSize, 500); |
| 4659 | var offset = (pageIndex - 1) * pageSize; | 4674 | var offset = (pageIndex - 1) * pageSize; |
| @@ -4662,7 +4677,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4662,7 +4677,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4662 | SELECT COUNT(1) | 4677 | SELECT COUNT(1) |
| 4663 | FROM BASE_USER u | 4678 | FROM BASE_USER u |
| 4664 | LEFT JOIN lq_mdxx md ON u.F_MDID = md.F_Id | 4679 | LEFT JOIN lq_mdxx md ON u.F_MDID = md.F_Id |
| 4665 | - WHERE u.F_GW = '健康师'" + filterSql; | 4680 | + WHERE u.F_GW = '健康师'" + periodOnJobSql + filterSql; |
| 4666 | 4681 | ||
| 4667 | var totalCount = await _db.Ado.GetIntAsync(countSql, baseParameters); | 4682 | var totalCount = await _db.Ado.GetIntAsync(countSql, baseParameters); |
| 4668 | 4683 | ||
| @@ -4670,7 +4685,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4670,7 +4685,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4670 | SELECT u.F_Id | 4685 | SELECT u.F_Id |
| 4671 | FROM BASE_USER u | 4686 | FROM BASE_USER u |
| 4672 | LEFT JOIN lq_mdxx md ON u.F_MDID = md.F_Id | 4687 | LEFT JOIN lq_mdxx md ON u.F_MDID = md.F_Id |
| 4673 | - WHERE u.F_GW = '健康师'" + filterSql + @" | 4688 | + WHERE u.F_GW = '健康师'" + periodOnJobSql + filterSql + @" |
| 4674 | ORDER BY u.F_REALNAME | 4689 | ORDER BY u.F_REALNAME |
| 4675 | LIMIT @hcOffset, @hcPageSize"; | 4690 | LIMIT @hcOffset, @hcPageSize"; |
| 4676 | 4691 | ||
| @@ -4800,6 +4815,68 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4800,6 +4815,68 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4800 | } | 4815 | } |
| 4801 | 4816 | ||
| 4802 | /// <summary> | 4817 | /// <summary> |
| 4818 | + /// 品项开单时间:优先品项 yjsj,转卡等历史数据兜底开单主表 kdrq。 | ||
| 4819 | + /// </summary> | ||
| 4820 | + private static DateTime? ResolveBillingItemTime(LqKdPxmxEntity pxmx, Dictionary<string, DateTime?> billingKdrqDict) | ||
| 4821 | + { | ||
| 4822 | + if (pxmx?.Yjsj != null) | ||
| 4823 | + { | ||
| 4824 | + return pxmx.Yjsj; | ||
| 4825 | + } | ||
| 4826 | + | ||
| 4827 | + if (!string.IsNullOrEmpty(pxmx?.Glkdbh) | ||
| 4828 | + && billingKdrqDict != null | ||
| 4829 | + && billingKdrqDict.TryGetValue(pxmx.Glkdbh, out var kdrq)) | ||
| 4830 | + { | ||
| 4831 | + return kdrq; | ||
| 4832 | + } | ||
| 4833 | + | ||
| 4834 | + return null; | ||
| 4835 | + } | ||
| 4836 | + | ||
| 4837 | + /// <summary> | ||
| 4838 | + /// 开单品项明细基础查询。时间筛选使用 COALESCE(pxmx.yjsj, 开单.kdrq),兼容转卡等未写 yjsj 的品项行。 | ||
| 4839 | + /// </summary> | ||
| 4840 | + private ISugarQueryable<LqKdPxmxEntity> BuildBillingItemDetailPxmxQuery( | ||
| 4841 | + BillingItemDetailListQueryInput input, | ||
| 4842 | + DateTime? startBillingTime, | ||
| 4843 | + DateTime? endBillingTime, | ||
| 4844 | + List<string> filterStoreIds) | ||
| 4845 | + { | ||
| 4846 | + DateTime? startDt = null; | ||
| 4847 | + DateTime? endDt = null; | ||
| 4848 | + if (startBillingTime.HasValue) | ||
| 4849 | + { | ||
| 4850 | + startDt = new DateTime(startBillingTime.Value.Year, startBillingTime.Value.Month, startBillingTime.Value.Day, 0, 0, 0); | ||
| 4851 | + } | ||
| 4852 | + | ||
| 4853 | + if (endBillingTime.HasValue) | ||
| 4854 | + { | ||
| 4855 | + endDt = new DateTime(endBillingTime.Value.Year, endBillingTime.Value.Month, endBillingTime.Value.Day, 23, 59, 59); | ||
| 4856 | + } | ||
| 4857 | + | ||
| 4858 | + return _db.Queryable<LqKdPxmxEntity, LqKdKdjlbEntity>((pxmx, kd) => new JoinQueryInfos( | ||
| 4859 | + JoinType.Inner, pxmx.Glkdbh == kd.Id)) | ||
| 4860 | + .Where((pxmx, kd) => pxmx.IsEffective == StatusEnum.有效.GetHashCode()) | ||
| 4861 | + .Where((pxmx, kd) => kd.IsEffective == StatusEnum.有效.GetHashCode()) | ||
| 4862 | + .WhereIF(!string.IsNullOrEmpty(input.Id), (pxmx, kd) => pxmx.Id == input.Id) | ||
| 4863 | + .WhereIF(!string.IsNullOrEmpty(input.BillingId), (pxmx, kd) => pxmx.Glkdbh == input.BillingId) | ||
| 4864 | + .WhereIF(startDt.HasValue, (pxmx, kd) => SqlFunc.IsNull(pxmx.Yjsj, kd.Kdrq) >= startDt) | ||
| 4865 | + .WhereIF(endDt.HasValue, (pxmx, kd) => SqlFunc.IsNull(pxmx.Yjsj, kd.Kdrq) <= endDt) | ||
| 4866 | + .WhereIF(!string.IsNullOrEmpty(input.ActivityId), (pxmx, kd) => pxmx.ActivityId == input.ActivityId) | ||
| 4867 | + .WhereIF(!string.IsNullOrEmpty(input.MemberId), (pxmx, kd) => pxmx.MemberId == input.MemberId) | ||
| 4868 | + .WhereIF(!string.IsNullOrEmpty(input.ItemId), (pxmx, kd) => pxmx.Px == input.ItemId) | ||
| 4869 | + .WhereIF(!string.IsNullOrEmpty(input.ItemName), (pxmx, kd) => (pxmx.Pxmc != null && pxmx.Pxmc.Contains(input.ItemName)) | ||
| 4870 | + || SqlFunc.Subqueryable<LqXmzlEntity>().Where(z => z.Id == pxmx.Px && z.Xmmc != null && z.Xmmc.Contains(input.ItemName)).Any()) | ||
| 4871 | + .WhereIF(!string.IsNullOrEmpty(input.SourceType), (pxmx, kd) => pxmx.SourceType == input.SourceType) | ||
| 4872 | + .WhereIF(!string.IsNullOrEmpty(input.ItemType), (pxmx, kd) => pxmx.ItemCategory == input.ItemType) | ||
| 4873 | + .WhereIF(!string.IsNullOrEmpty(input.MemberName), (pxmx, kd) => SqlFunc.Subqueryable<LqKhxxEntity>().Where(x => x.Id == pxmx.MemberId && x.Khmc != null && x.Khmc.Contains(input.MemberName)).Any()) | ||
| 4874 | + .WhereIF(!string.IsNullOrEmpty(input.MemberPhone), (pxmx, kd) => SqlFunc.Subqueryable<LqKhxxEntity>().Where(x => x.Id == pxmx.MemberId && x.Sjh == input.MemberPhone).Any()) | ||
| 4875 | + .WhereIF(filterStoreIds != null && filterStoreIds.Any(), (pxmx, kd) => filterStoreIds.Contains(kd.Djmd)) | ||
| 4876 | + .Select((pxmx, kd) => pxmx); | ||
| 4877 | + } | ||
| 4878 | + | ||
| 4879 | + /// <summary> | ||
| 4803 | /// 获取开单品项明细记录列表(分页) | 4880 | /// 获取开单品项明细记录列表(分页) |
| 4804 | /// </summary> | 4881 | /// </summary> |
| 4805 | /// <remarks> | 4882 | /// <remarks> |
| @@ -4932,27 +5009,10 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4932,27 +5009,10 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4932 | } | 5009 | } |
| 4933 | 5010 | ||
| 4934 | // 优化查询:先分页查询主表,再批量查询关联数据,避免子查询性能问题 | 5011 | // 优化查询:先分页查询主表,再批量查询关联数据,避免子查询性能问题 |
| 4935 | - // 1. 先构建基础查询条件 | ||
| 4936 | - var baseQuery = _db.Queryable<LqKdPxmxEntity>() | ||
| 4937 | - .Where(pxmx => pxmx.IsEffective == StatusEnum.有效.GetHashCode()) | ||
| 4938 | - .WhereIF(!string.IsNullOrEmpty(input.Id), pxmx => pxmx.Id == input.Id) | ||
| 4939 | - .WhereIF(!string.IsNullOrEmpty(input.BillingId), pxmx => pxmx.Glkdbh == input.BillingId) | ||
| 4940 | - .WhereIF(startBillingTime.HasValue, pxmx => pxmx.Yjsj >= new DateTime(startBillingTime.Value.Year, startBillingTime.Value.Month, startBillingTime.Value.Day, 0, 0, 0)) | ||
| 4941 | - .WhereIF(endBillingTime.HasValue, pxmx => pxmx.Yjsj <= new DateTime(endBillingTime.Value.Year, endBillingTime.Value.Month, endBillingTime.Value.Day, 23, 59, 59)) | ||
| 4942 | - .WhereIF(!string.IsNullOrEmpty(input.ActivityId), pxmx => pxmx.ActivityId == input.ActivityId) | ||
| 4943 | - .WhereIF(!string.IsNullOrEmpty(input.MemberId), pxmx => pxmx.MemberId == input.MemberId) | ||
| 4944 | - .WhereIF(!string.IsNullOrEmpty(input.ItemId), pxmx => pxmx.Px == input.ItemId) | ||
| 4945 | - .WhereIF(!string.IsNullOrEmpty(input.ItemName), pxmx => (pxmx.Pxmc != null && pxmx.Pxmc.Contains(input.ItemName)) | ||
| 4946 | - || SqlFunc.Subqueryable<LqXmzlEntity>().Where(z => z.Id == pxmx.Px && z.Xmmc != null && z.Xmmc.Contains(input.ItemName)).Any()) | ||
| 4947 | - .WhereIF(!string.IsNullOrEmpty(input.SourceType), pxmx => pxmx.SourceType == input.SourceType) | ||
| 4948 | - .WhereIF(!string.IsNullOrEmpty(input.ItemType), pxmx => pxmx.ItemCategory == input.ItemType); | ||
| 4949 | - | ||
| 4950 | - // 2. 通过 EXISTS 子查询筛选关联字段(在分页前筛选,确保分页准确) | ||
| 4951 | - // 处理多门店筛选:优先使用StoreIds,如果没有则使用StoreId | 5012 | + // 处理多门店筛选:优先使用StoreIds,如果没有则使用StoreId;支持逗号串或多值参数 |
| 4952 | var filterStoreIds = new List<string>(); | 5013 | var filterStoreIds = new List<string>(); |
| 4953 | if (!string.IsNullOrEmpty(input.StoreIds)) | 5014 | if (!string.IsNullOrEmpty(input.StoreIds)) |
| 4954 | { | 5015 | { |
| 4955 | - // 解析逗号分隔的门店ID字符串 | ||
| 4956 | filterStoreIds = input.StoreIds.Split(',') | 5016 | filterStoreIds = input.StoreIds.Split(',') |
| 4957 | .Where(x => !string.IsNullOrWhiteSpace(x)) | 5017 | .Where(x => !string.IsNullOrWhiteSpace(x)) |
| 4958 | .Select(x => x.Trim()) | 5018 | .Select(x => x.Trim()) |
| @@ -4963,9 +5023,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -4963,9 +5023,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 4963 | filterStoreIds = new List<string> { input.StoreId }; | 5023 | filterStoreIds = new List<string> { input.StoreId }; |
| 4964 | } | 5024 | } |
| 4965 | 5025 | ||
| 4966 | - baseQuery = baseQuery.WhereIF(!string.IsNullOrEmpty(input.MemberName), pxmx => SqlFunc.Subqueryable<LqKhxxEntity>().Where(x => x.Id == pxmx.MemberId && x.Khmc != null && x.Khmc.Contains(input.MemberName)).Any()) | ||
| 4967 | - .WhereIF(!string.IsNullOrEmpty(input.MemberPhone), pxmx => SqlFunc.Subqueryable<LqKhxxEntity>().Where(x => x.Id == pxmx.MemberId && x.Sjh == input.MemberPhone).Any()) | ||
| 4968 | - .WhereIF(filterStoreIds.Any(), pxmx => SqlFunc.Subqueryable<LqKdKdjlbEntity>().Where(x => x.Id == pxmx.Glkdbh && filterStoreIds.Contains(x.Djmd)).Any()); | 5026 | + var baseQuery = BuildBillingItemDetailPxmxQuery(input, startBillingTime, endBillingTime, filterStoreIds); |
| 4969 | 5027 | ||
| 4970 | // 3. 先分页查询主表数据(查询实体类,提高性能) | 5028 | // 3. 先分页查询主表数据(查询实体类,提高性能) |
| 4971 | var pagedData = await baseQuery.OrderBy(sidx + " " + sort).ToPagedListAsync(input.currentPage, input.pageSize); | 5029 | var pagedData = await baseQuery.OrderBy(sidx + " " + sort).ToPagedListAsync(input.currentPage, input.pageSize); |
| @@ -5018,17 +5076,19 @@ namespace NCC.Extend.LqKdKdjlb | @@ -5018,17 +5076,19 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 5018 | var billingStoreDict = new Dictionary<string, string>(); | 5076 | var billingStoreDict = new Dictionary<string, string>(); |
| 5019 | var billingExtraInfoDict = new Dictionary<string, dynamic>(); | 5077 | var billingExtraInfoDict = new Dictionary<string, dynamic>(); |
| 5020 | var billingDeductDict = new Dictionary<string, decimal>(); | 5078 | var billingDeductDict = new Dictionary<string, decimal>(); |
| 5079 | + var billingKdrqDict = new Dictionary<string, DateTime?>(); | ||
| 5021 | 5080 | ||
| 5022 | if (billingIds.Any()) | 5081 | if (billingIds.Any()) |
| 5023 | { | 5082 | { |
| 5024 | var billings = await _db.Queryable<LqKdKdjlbEntity>() | 5083 | var billings = await _db.Queryable<LqKdKdjlbEntity>() |
| 5025 | .Where(x => billingIds.Contains(x.Id)) | 5084 | .Where(x => billingIds.Contains(x.Id)) |
| 5026 | - .Select(x => new { x.Id, x.Djmd, x.Hgjg, x.Fkyy, x.Fkfs, x.DeductAmount }) | 5085 | + .Select(x => new { x.Id, x.Djmd, x.Hgjg, x.Fkyy, x.Fkfs, x.DeductAmount, x.Kdrq }) |
| 5027 | .ToListAsync(); | 5086 | .ToListAsync(); |
| 5028 | 5087 | ||
| 5029 | billingStoreDict = billings.ToDictionary(x => x.Id, x => x.Djmd ?? ""); | 5088 | billingStoreDict = billings.ToDictionary(x => x.Id, x => x.Djmd ?? ""); |
| 5030 | billingExtraInfoDict = billings.ToDictionary(x => x.Id, x => (dynamic)new { Hgjg = x.Hgjg, Fkyy = x.Fkyy, Fkfs = x.Fkfs }); | 5089 | billingExtraInfoDict = billings.ToDictionary(x => x.Id, x => (dynamic)new { Hgjg = x.Hgjg, Fkyy = x.Fkyy, Fkfs = x.Fkfs }); |
| 5031 | billingDeductDict = billings.ToDictionary(x => x.Id, x => x.DeductAmount); | 5090 | billingDeductDict = billings.ToDictionary(x => x.Id, x => x.DeductAmount); |
| 5091 | + billingKdrqDict = billings.ToDictionary(x => x.Id, x => x.Kdrq); | ||
| 5032 | } | 5092 | } |
| 5033 | 5093 | ||
| 5034 | var billingItemTotalDict = await GetBillingItemActualPriceTotalsAsync(billingIds); | 5094 | var billingItemTotalDict = await GetBillingItemActualPriceTotalsAsync(billingIds); |
| @@ -5064,7 +5124,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -5064,7 +5124,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 5064 | { | 5124 | { |
| 5065 | id = pxmx.Id, | 5125 | id = pxmx.Id, |
| 5066 | billingId = pxmx.Glkdbh, | 5126 | billingId = pxmx.Glkdbh, |
| 5067 | - billingTime = pxmx.Yjsj, | 5127 | + billingTime = ResolveBillingItemTime(pxmx, billingKdrqDict), |
| 5068 | activityName = pxmx.ActivityId != null && activityDict.ContainsKey(pxmx.ActivityId) ? activityDict[pxmx.ActivityId] : "", | 5128 | activityName = pxmx.ActivityId != null && activityDict.ContainsKey(pxmx.ActivityId) ? activityDict[pxmx.ActivityId] : "", |
| 5069 | memberName = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Name : "", | 5129 | memberName = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Name : "", |
| 5070 | memberPhone = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Phone : "", | 5130 | memberPhone = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Phone : "", |
| @@ -5139,20 +5199,6 @@ namespace NCC.Extend.LqKdKdjlb | @@ -5139,20 +5199,6 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 5139 | if (!startBillingTime.HasValue || !endBillingTime.HasValue) | 5199 | if (!startBillingTime.HasValue || !endBillingTime.HasValue) |
| 5140 | throw NCCException.Oh("请选择开始时间和结束时间"); | 5200 | throw NCCException.Oh("请选择开始时间和结束时间"); |
| 5141 | 5201 | ||
| 5142 | - var baseQuery = _db.Queryable<LqKdPxmxEntity>() | ||
| 5143 | - .Where(pxmx => pxmx.IsEffective == StatusEnum.有效.GetHashCode()) | ||
| 5144 | - .WhereIF(!string.IsNullOrEmpty(input.Id), pxmx => pxmx.Id == input.Id) | ||
| 5145 | - .WhereIF(!string.IsNullOrEmpty(input.BillingId), pxmx => pxmx.Glkdbh == input.BillingId) | ||
| 5146 | - .WhereIF(startBillingTime.HasValue, pxmx => pxmx.Yjsj >= new DateTime(startBillingTime.Value.Year, startBillingTime.Value.Month, startBillingTime.Value.Day, 0, 0, 0)) | ||
| 5147 | - .WhereIF(endBillingTime.HasValue, pxmx => pxmx.Yjsj <= new DateTime(endBillingTime.Value.Year, endBillingTime.Value.Month, endBillingTime.Value.Day, 23, 59, 59)) | ||
| 5148 | - .WhereIF(!string.IsNullOrEmpty(input.ActivityId), pxmx => pxmx.ActivityId == input.ActivityId) | ||
| 5149 | - .WhereIF(!string.IsNullOrEmpty(input.MemberId), pxmx => pxmx.MemberId == input.MemberId) | ||
| 5150 | - .WhereIF(!string.IsNullOrEmpty(input.ItemId), pxmx => pxmx.Px == input.ItemId) | ||
| 5151 | - .WhereIF(!string.IsNullOrEmpty(input.ItemName), pxmx => (pxmx.Pxmc != null && pxmx.Pxmc.Contains(input.ItemName)) | ||
| 5152 | - || SqlFunc.Subqueryable<LqXmzlEntity>().Where(z => z.Id == pxmx.Px && z.Xmmc != null && z.Xmmc.Contains(input.ItemName)).Any()) | ||
| 5153 | - .WhereIF(!string.IsNullOrEmpty(input.SourceType), pxmx => pxmx.SourceType == input.SourceType) | ||
| 5154 | - .WhereIF(!string.IsNullOrEmpty(input.ItemType), pxmx => pxmx.ItemCategory == input.ItemType); | ||
| 5155 | - | ||
| 5156 | var filterStoreIds = new List<string>(); | 5202 | var filterStoreIds = new List<string>(); |
| 5157 | if (!string.IsNullOrEmpty(input.StoreIds)) | 5203 | if (!string.IsNullOrEmpty(input.StoreIds)) |
| 5158 | { | 5204 | { |
| @@ -5166,9 +5212,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -5166,9 +5212,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 5166 | filterStoreIds = new List<string> { input.StoreId }; | 5212 | filterStoreIds = new List<string> { input.StoreId }; |
| 5167 | } | 5213 | } |
| 5168 | 5214 | ||
| 5169 | - baseQuery = baseQuery.WhereIF(!string.IsNullOrEmpty(input.MemberName), pxmx => SqlFunc.Subqueryable<LqKhxxEntity>().Where(x => x.Id == pxmx.MemberId && x.Khmc != null && x.Khmc.Contains(input.MemberName)).Any()) | ||
| 5170 | - .WhereIF(!string.IsNullOrEmpty(input.MemberPhone), pxmx => SqlFunc.Subqueryable<LqKhxxEntity>().Where(x => x.Id == pxmx.MemberId && x.Sjh == input.MemberPhone).Any()) | ||
| 5171 | - .WhereIF(filterStoreIds.Any(), pxmx => SqlFunc.Subqueryable<LqKdKdjlbEntity>().Where(x => x.Id == pxmx.Glkdbh && filterStoreIds.Contains(x.Djmd)).Any()); | 5215 | + var baseQuery = BuildBillingItemDetailPxmxQuery(input, startBillingTime, endBillingTime, filterStoreIds); |
| 5172 | 5216 | ||
| 5173 | var allData = await baseQuery.OrderBy(sidx + " " + sort).ToListAsync(); | 5217 | var allData = await baseQuery.OrderBy(sidx + " " + sort).ToListAsync(); |
| 5174 | if (allData == null || !allData.Any()) | 5218 | if (allData == null || !allData.Any()) |
| @@ -5188,15 +5232,17 @@ namespace NCC.Extend.LqKdKdjlb | @@ -5188,15 +5232,17 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 5188 | var billingStoreDict = new Dictionary<string, string>(); | 5232 | var billingStoreDict = new Dictionary<string, string>(); |
| 5189 | var billingExtraInfoDict = new Dictionary<string, (string Hgjg, string Fkyy, string Fkfs)>(); | 5233 | var billingExtraInfoDict = new Dictionary<string, (string Hgjg, string Fkyy, string Fkfs)>(); |
| 5190 | var billingDeductDict = new Dictionary<string, decimal>(); | 5234 | var billingDeductDict = new Dictionary<string, decimal>(); |
| 5235 | + var billingKdrqDict = new Dictionary<string, DateTime?>(); | ||
| 5191 | if (billingIds.Any()) | 5236 | if (billingIds.Any()) |
| 5192 | { | 5237 | { |
| 5193 | var billings = await _db.Queryable<LqKdKdjlbEntity>() | 5238 | var billings = await _db.Queryable<LqKdKdjlbEntity>() |
| 5194 | .Where(x => billingIds.Contains(x.Id)) | 5239 | .Where(x => billingIds.Contains(x.Id)) |
| 5195 | - .Select(x => new { x.Id, x.Djmd, x.Hgjg, x.Fkyy, x.Fkfs, x.DeductAmount }) | 5240 | + .Select(x => new { x.Id, x.Djmd, x.Hgjg, x.Fkyy, x.Fkfs, x.DeductAmount, x.Kdrq }) |
| 5196 | .ToListAsync(); | 5241 | .ToListAsync(); |
| 5197 | billingStoreDict = billings.ToDictionary(x => x.Id, x => x.Djmd ?? ""); | 5242 | billingStoreDict = billings.ToDictionary(x => x.Id, x => x.Djmd ?? ""); |
| 5198 | billingExtraInfoDict = billings.ToDictionary(x => x.Id, x => (x.Hgjg ?? "", x.Fkyy ?? "", x.Fkfs ?? "")); | 5243 | billingExtraInfoDict = billings.ToDictionary(x => x.Id, x => (x.Hgjg ?? "", x.Fkyy ?? "", x.Fkfs ?? "")); |
| 5199 | billingDeductDict = billings.ToDictionary(x => x.Id, x => x.DeductAmount); | 5244 | billingDeductDict = billings.ToDictionary(x => x.Id, x => x.DeductAmount); |
| 5245 | + billingKdrqDict = billings.ToDictionary(x => x.Id, x => x.Kdrq); | ||
| 5200 | } | 5246 | } |
| 5201 | 5247 | ||
| 5202 | var billingItemTotalDict = await GetBillingItemActualPriceTotalsAsync(billingIds); | 5248 | var billingItemTotalDict = await GetBillingItemActualPriceTotalsAsync(billingIds); |
| @@ -5234,7 +5280,7 @@ namespace NCC.Extend.LqKdKdjlb | @@ -5234,7 +5280,7 @@ namespace NCC.Extend.LqKdKdjlb | ||
| 5234 | { | 5280 | { |
| 5235 | id = pxmx.Id, | 5281 | id = pxmx.Id, |
| 5236 | billingId = pxmx.Glkdbh, | 5282 | billingId = pxmx.Glkdbh, |
| 5237 | - billingTime = pxmx.Yjsj, | 5283 | + billingTime = ResolveBillingItemTime(pxmx, billingKdrqDict), |
| 5238 | activityName = pxmx.ActivityId != null && activityDict.ContainsKey(pxmx.ActivityId) ? activityDict[pxmx.ActivityId] : "", | 5284 | activityName = pxmx.ActivityId != null && activityDict.ContainsKey(pxmx.ActivityId) ? activityDict[pxmx.ActivityId] : "", |
| 5239 | memberName = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Name : "", | 5285 | memberName = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Name : "", |
| 5240 | memberPhone = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Phone : "", | 5286 | memberPhone = pxmx.MemberId != null && memberDict.ContainsKey(pxmx.MemberId) ? memberDict[pxmx.MemberId].Phone : "", |
netcore/src/Modularity/Extend/NCC.Extend/LqMdTargetService.cs
| @@ -92,7 +92,7 @@ namespace NCC.Extend.LqMdTarget | @@ -92,7 +92,7 @@ namespace NCC.Extend.LqMdTarget | ||
| 92 | if (data.list != null) | 92 | if (data.list != null) |
| 93 | { | 93 | { |
| 94 | var list = data.list.ToList(); | 94 | var list = data.list.ToList(); |
| 95 | - await EnrichExportNamesAsync(list); | 95 | + await EnrichStoreDisplayAsync(list); |
| 96 | data.list = list; | 96 | data.list = list; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| @@ -228,6 +228,7 @@ namespace NCC.Extend.LqMdTarget | @@ -228,6 +228,7 @@ namespace NCC.Extend.LqMdTarget | ||
| 228 | } | 228 | } |
| 229 | var entity = input.Adapt<LqMdTargetEntity>(); | 229 | var entity = input.Adapt<LqMdTargetEntity>(); |
| 230 | entity.Id = YitIdHelper.NextId().ToString(); | 230 | entity.Id = YitIdHelper.NextId().ToString(); |
| 231 | + await NormalizeOrganizeFieldsAsync(entity); | ||
| 231 | entity.CreateTime = DateTime.Now; | 232 | entity.CreateTime = DateTime.Now; |
| 232 | entity.CreateUser = userInfo.userId; | 233 | entity.CreateUser = userInfo.userId; |
| 233 | var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync(); | 234 | var isOk = await _db.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync(); |
| @@ -359,6 +360,7 @@ namespace NCC.Extend.LqMdTarget | @@ -359,6 +360,7 @@ namespace NCC.Extend.LqMdTarget | ||
| 359 | } | 360 | } |
| 360 | var updateEntity = input.Adapt<LqMdTargetEntity>(); | 361 | var updateEntity = input.Adapt<LqMdTargetEntity>(); |
| 361 | updateEntity.Id = id; | 362 | updateEntity.Id = id; |
| 363 | + await NormalizeOrganizeFieldsAsync(updateEntity); | ||
| 362 | updateEntity.UpdateTime = DateTime.Now; | 364 | updateEntity.UpdateTime = DateTime.Now; |
| 363 | updateEntity.UpdateUser = userInfo.userId; | 365 | updateEntity.UpdateUser = userInfo.userId; |
| 364 | var isOk = await _db.Updateable(updateEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); | 366 | var isOk = await _db.Updateable(updateEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); |
| @@ -492,6 +494,12 @@ namespace NCC.Extend.LqMdTarget | @@ -492,6 +494,12 @@ namespace NCC.Extend.LqMdTarget | ||
| 492 | 494 | ||
| 493 | if (newEntities.Count > 0) | 495 | if (newEntities.Count > 0) |
| 494 | { | 496 | { |
| 497 | + var orgAliasMap = await BuildOrganizeAliasToIdMapAsync(); | ||
| 498 | + foreach (var entity in newEntities) | ||
| 499 | + { | ||
| 500 | + NormalizeOrganizeFields(entity, orgAliasMap); | ||
| 501 | + } | ||
| 502 | + | ||
| 495 | syncedCount = await _db.Insertable(newEntities).ExecuteCommandAsync(); | 503 | syncedCount = await _db.Insertable(newEntities).ExecuteCommandAsync(); |
| 496 | } | 504 | } |
| 497 | 505 | ||
| @@ -579,20 +587,27 @@ namespace NCC.Extend.LqMdTarget | @@ -579,20 +587,27 @@ namespace NCC.Extend.LqMdTarget | ||
| 579 | (t, s) => t.StoreId == s.Id) | 587 | (t, s) => t.StoreId == s.Id) |
| 580 | .Where((t, s) => t.Month == input.Month); | 588 | .Where((t, s) => t.Month == input.Month); |
| 581 | 589 | ||
| 582 | - // 根据组织类型添加部门过滤条件 | 590 | + var orgAliasMap = await BuildOrganizeAliasToIdMapAsync(); |
| 591 | + var departmentId = ResolveOrganizeId(input.DepartmentId, orgAliasMap); | ||
| 592 | + if (string.IsNullOrEmpty(departmentId)) | ||
| 593 | + { | ||
| 594 | + throw NCCException.Oh("部门ID无效"); | ||
| 595 | + } | ||
| 596 | + | ||
| 597 | + // 根据组织类型添加部门过滤条件(兼容历史名称脏数据) | ||
| 583 | switch (input.OrganizationType) | 598 | switch (input.OrganizationType) |
| 584 | { | 599 | { |
| 585 | case "事业部": | 600 | case "事业部": |
| 586 | - query = query.Where((t, s) => t.BusinessUnit == input.DepartmentId); | 601 | + query = query.Where((t, s) => t.BusinessUnit == departmentId || t.BusinessUnit == input.DepartmentId); |
| 587 | break; | 602 | break; |
| 588 | case "科技部": | 603 | case "科技部": |
| 589 | - query = query.Where((t, s) => t.TechDepartment == input.DepartmentId); | 604 | + query = query.Where((t, s) => t.TechDepartment == departmentId || t.TechDepartment == input.DepartmentId); |
| 590 | break; | 605 | break; |
| 591 | case "教育部": | 606 | case "教育部": |
| 592 | - query = query.Where((t, s) => t.EducationDepartment == input.DepartmentId); | 607 | + query = query.Where((t, s) => t.EducationDepartment == departmentId || t.EducationDepartment == input.DepartmentId); |
| 593 | break; | 608 | break; |
| 594 | case "大项目部": | 609 | case "大项目部": |
| 595 | - query = query.Where((t, s) => t.MajorProjectDepartment == input.DepartmentId); | 610 | + query = query.Where((t, s) => t.MajorProjectDepartment == departmentId || t.MajorProjectDepartment == input.DepartmentId); |
| 596 | break; | 611 | break; |
| 597 | default: | 612 | default: |
| 598 | throw NCCException.Oh($"不支持的组织类型:{input.OrganizationType},支持的类型:事业部、科技部、教育部、大项目部"); | 613 | throw NCCException.Oh($"不支持的组织类型:{input.OrganizationType},支持的类型:事业部、科技部、教育部、大项目部"); |
| @@ -667,63 +682,155 @@ namespace NCC.Extend.LqMdTarget | @@ -667,63 +682,155 @@ namespace NCC.Extend.LqMdTarget | ||
| 667 | } | 682 | } |
| 668 | 683 | ||
| 669 | /// <summary> | 684 | /// <summary> |
| 670 | - /// 解析门店与组织名称,供列表与导出展示(含已软删门店) | 685 | + /// 列表展示:仅补门店名称,归属字段保持组织ID(避免编辑保存时把名称写回库) |
| 671 | /// </summary> | 686 | /// </summary> |
| 672 | - private async Task EnrichExportNamesAsync(List<LqMdTargetListOutput> exportData) | 687 | + private async Task EnrichStoreDisplayAsync(List<LqMdTargetListOutput> rows) |
| 673 | { | 688 | { |
| 674 | - if (exportData == null || exportData.Count == 0) | 689 | + if (rows == null || rows.Count == 0) |
| 675 | return; | 690 | return; |
| 676 | 691 | ||
| 677 | - var storeIds = exportData | 692 | + var storeIds = rows |
| 678 | .Where(x => !string.IsNullOrEmpty(x.storeId)) | 693 | .Where(x => !string.IsNullOrEmpty(x.storeId)) |
| 679 | .Select(x => x.storeId) | 694 | .Select(x => x.storeId) |
| 680 | .Distinct() | 695 | .Distinct() |
| 681 | .ToList(); | 696 | .ToList(); |
| 682 | 697 | ||
| 683 | - var storeDict = storeIds.Count > 0 | ||
| 684 | - ? (await _db.Queryable<LqMdxxEntity>() | 698 | + if (storeIds.Count == 0) |
| 699 | + return; | ||
| 700 | + | ||
| 701 | + var storeDict = (await _db.Queryable<LqMdxxEntity>() | ||
| 685 | .Where(x => storeIds.Contains(x.Id)) | 702 | .Where(x => storeIds.Contains(x.Id)) |
| 686 | .Select(x => new { x.Id, x.Dm, x.Status }) | 703 | .Select(x => new { x.Id, x.Dm, x.Status }) |
| 687 | .ToListAsync()) | 704 | .ToListAsync()) |
| 688 | - .ToDictionary( | ||
| 689 | - x => x.Id, | ||
| 690 | - x => new StoreDisplayInfo | ||
| 691 | - { | ||
| 692 | - Name = x.Dm ?? string.Empty, | ||
| 693 | - Deleted = x.Status == InvalidStatus | ||
| 694 | - }) | ||
| 695 | - : new Dictionary<string, StoreDisplayInfo>(); | ||
| 696 | - | ||
| 697 | - var orgIds = exportData | 705 | + .ToDictionary( |
| 706 | + x => x.Id, | ||
| 707 | + x => new StoreDisplayInfo | ||
| 708 | + { | ||
| 709 | + Name = x.Dm ?? string.Empty, | ||
| 710 | + Deleted = x.Status == InvalidStatus | ||
| 711 | + }); | ||
| 712 | + | ||
| 713 | + foreach (var item in rows) | ||
| 714 | + { | ||
| 715 | + if (!string.IsNullOrEmpty(item.storeId) && storeDict.TryGetValue(item.storeId, out var storeInfo)) | ||
| 716 | + { | ||
| 717 | + item.storeName = storeInfo.Name; | ||
| 718 | + item.storeDeleted = storeInfo.Deleted; | ||
| 719 | + } | ||
| 720 | + } | ||
| 721 | + } | ||
| 722 | + | ||
| 723 | + /// <summary> | ||
| 724 | + /// 解析门店与组织名称,供导出展示(含已软删门店) | ||
| 725 | + /// </summary> | ||
| 726 | + private async Task EnrichExportNamesAsync(List<LqMdTargetListOutput> exportData) | ||
| 727 | + { | ||
| 728 | + if (exportData == null || exportData.Count == 0) | ||
| 729 | + return; | ||
| 730 | + | ||
| 731 | + await EnrichStoreDisplayAsync(exportData); | ||
| 732 | + | ||
| 733 | + var orgValues = exportData | ||
| 698 | .SelectMany(x => new[] { x.businessUnit, x.techDepartment, x.educationDepartment, x.majorProjectDepartment }) | 734 | .SelectMany(x => new[] { x.businessUnit, x.techDepartment, x.educationDepartment, x.majorProjectDepartment }) |
| 699 | .Where(x => !string.IsNullOrEmpty(x)) | 735 | .Where(x => !string.IsNullOrEmpty(x)) |
| 700 | .Distinct() | 736 | .Distinct() |
| 701 | .ToList(); | 737 | .ToList(); |
| 702 | 738 | ||
| 703 | - var orgDict = orgIds.Count > 0 | ||
| 704 | - ? (await _db.Queryable<OrganizeEntity>() | ||
| 705 | - .Where(x => orgIds.Contains(x.Id) && x.DeleteMark == null) | 739 | + var orgDict = new Dictionary<string, string>(); |
| 740 | + var orgNameDict = new Dictionary<string, string>(StringComparer.Ordinal); | ||
| 741 | + if (orgValues.Count > 0) | ||
| 742 | + { | ||
| 743 | + var orgs = await _db.Queryable<OrganizeEntity>() | ||
| 744 | + .Where(x => (orgValues.Contains(x.Id) || orgValues.Contains(x.FullName)) | ||
| 745 | + && x.DeleteMark == null | ||
| 746 | + && x.Category == "department") | ||
| 706 | .Select(x => new { x.Id, x.FullName }) | 747 | .Select(x => new { x.Id, x.FullName }) |
| 707 | - .ToListAsync()) | ||
| 708 | - .ToDictionary(x => x.Id, x => x.FullName ?? string.Empty) | ||
| 709 | - : new Dictionary<string, string>(); | 748 | + .ToListAsync(); |
| 710 | 749 | ||
| 711 | - foreach (var item in exportData) | ||
| 712 | - { | ||
| 713 | - if (!string.IsNullOrEmpty(item.storeId) && storeDict.TryGetValue(item.storeId, out var storeInfo)) | 750 | + orgDict = orgs.ToDictionary(x => x.Id, x => x.FullName ?? string.Empty); |
| 751 | + foreach (var org in orgs.Where(x => !string.IsNullOrEmpty(x.FullName))) | ||
| 714 | { | 752 | { |
| 715 | - item.storeName = storeInfo.Name; | ||
| 716 | - item.storeDeleted = storeInfo.Deleted; | 753 | + orgNameDict[org.FullName] = org.FullName; |
| 717 | } | 754 | } |
| 755 | + } | ||
| 718 | 756 | ||
| 719 | - item.businessUnit = ResolveOrganizeDisplayName(item.businessUnit, orgDict); | ||
| 720 | - item.techDepartment = ResolveOrganizeDisplayName(item.techDepartment, orgDict); | ||
| 721 | - item.educationDepartment = ResolveOrganizeDisplayName(item.educationDepartment, orgDict); | ||
| 722 | - item.majorProjectDepartment = ResolveOrganizeDisplayName(item.majorProjectDepartment, orgDict); | 757 | + foreach (var item in exportData) |
| 758 | + { | ||
| 759 | + item.businessUnit = ResolveOrganizeDisplayName(item.businessUnit, orgDict, orgNameDict); | ||
| 760 | + item.techDepartment = ResolveOrganizeDisplayName(item.techDepartment, orgDict, orgNameDict); | ||
| 761 | + item.educationDepartment = ResolveOrganizeDisplayName(item.educationDepartment, orgDict, orgNameDict); | ||
| 762 | + item.majorProjectDepartment = ResolveOrganizeDisplayName(item.majorProjectDepartment, orgDict, orgNameDict); | ||
| 723 | } | 763 | } |
| 724 | } | 764 | } |
| 725 | 765 | ||
| 726 | /// <summary> | 766 | /// <summary> |
| 767 | + /// 保存前将归属字段统一归一化为 base_organize.F_Id | ||
| 768 | + /// </summary> | ||
| 769 | + private async Task NormalizeOrganizeFieldsAsync(LqMdTargetEntity entity) | ||
| 770 | + { | ||
| 771 | + if (entity == null) | ||
| 772 | + return; | ||
| 773 | + | ||
| 774 | + var orgAliasMap = await BuildOrganizeAliasToIdMapAsync(); | ||
| 775 | + NormalizeOrganizeFields(entity, orgAliasMap); | ||
| 776 | + } | ||
| 777 | + | ||
| 778 | + /// <summary> | ||
| 779 | + /// 使用组织映射将归属字段归一化为组织ID | ||
| 780 | + /// </summary> | ||
| 781 | + private static void NormalizeOrganizeFields(LqMdTargetEntity entity, Dictionary<string, string> orgAliasMap) | ||
| 782 | + { | ||
| 783 | + if (entity == null) | ||
| 784 | + return; | ||
| 785 | + | ||
| 786 | + entity.BusinessUnit = ResolveOrganizeId(entity.BusinessUnit, orgAliasMap, "事业部"); | ||
| 787 | + entity.TechDepartment = ResolveOrganizeId(entity.TechDepartment, orgAliasMap, "科技部"); | ||
| 788 | + entity.EducationDepartment = ResolveOrganizeId(entity.EducationDepartment, orgAliasMap, "教育部"); | ||
| 789 | + entity.MajorProjectDepartment = ResolveOrganizeId(entity.MajorProjectDepartment, orgAliasMap, "大项目部"); | ||
| 790 | + } | ||
| 791 | + | ||
| 792 | + /// <summary> | ||
| 793 | + /// 构建组织别名(ID/名称)到组织ID的映射 | ||
| 794 | + /// </summary> | ||
| 795 | + private async Task<Dictionary<string, string>> BuildOrganizeAliasToIdMapAsync() | ||
| 796 | + { | ||
| 797 | + var orgs = await _db.Queryable<OrganizeEntity>() | ||
| 798 | + .Where(x => x.Category == "department" && x.DeleteMark == null) | ||
| 799 | + .Select(x => new { x.Id, x.FullName }) | ||
| 800 | + .ToListAsync(); | ||
| 801 | + | ||
| 802 | + var map = new Dictionary<string, string>(StringComparer.Ordinal); | ||
| 803 | + foreach (var org in orgs) | ||
| 804 | + { | ||
| 805 | + if (!string.IsNullOrEmpty(org.Id)) | ||
| 806 | + map[org.Id] = org.Id; | ||
| 807 | + | ||
| 808 | + if (!string.IsNullOrEmpty(org.FullName) && !map.ContainsKey(org.FullName)) | ||
| 809 | + map[org.FullName] = org.Id; | ||
| 810 | + } | ||
| 811 | + | ||
| 812 | + return map; | ||
| 813 | + } | ||
| 814 | + | ||
| 815 | + /// <summary> | ||
| 816 | + /// 组织归属值(ID 或名称)解析为标准组织ID;无法解析时抛出友好错误 | ||
| 817 | + /// </summary> | ||
| 818 | + private static string ResolveOrganizeId(string rawValue, Dictionary<string, string> orgAliasMap, string fieldLabel = null) | ||
| 819 | + { | ||
| 820 | + if (string.IsNullOrWhiteSpace(rawValue)) | ||
| 821 | + return rawValue; | ||
| 822 | + | ||
| 823 | + if (orgAliasMap != null && orgAliasMap.TryGetValue(rawValue, out var mappedId) && !string.IsNullOrEmpty(mappedId)) | ||
| 824 | + return mappedId; | ||
| 825 | + | ||
| 826 | + if (Regex.IsMatch(rawValue, @"^\d{15,}$")) | ||
| 827 | + return rawValue; | ||
| 828 | + | ||
| 829 | + var label = string.IsNullOrEmpty(fieldLabel) ? "组织归属" : fieldLabel; | ||
| 830 | + throw NCCException.Oh($"{label}「{rawValue}」无效,请重新选择部门"); | ||
| 831 | + } | ||
| 832 | + | ||
| 833 | + /// <summary> | ||
| 727 | /// 门店展示信息(含软删标记) | 834 | /// 门店展示信息(含软删标记) |
| 728 | /// </summary> | 835 | /// </summary> |
| 729 | private sealed class StoreDisplayInfo | 836 | private sealed class StoreDisplayInfo |
| @@ -735,14 +842,21 @@ namespace NCC.Extend.LqMdTarget | @@ -735,14 +842,21 @@ namespace NCC.Extend.LqMdTarget | ||
| 735 | /// <summary> | 842 | /// <summary> |
| 736 | /// 组织ID解析为名称,解析不到则保留原值 | 843 | /// 组织ID解析为名称,解析不到则保留原值 |
| 737 | /// </summary> | 844 | /// </summary> |
| 738 | - private static string ResolveOrganizeDisplayName(string organizeId, Dictionary<string, string> orgDict) | 845 | + private static string ResolveOrganizeDisplayName( |
| 846 | + string organizeValue, | ||
| 847 | + Dictionary<string, string> orgIdDict, | ||
| 848 | + Dictionary<string, string> orgNameDict) | ||
| 739 | { | 849 | { |
| 740 | - if (string.IsNullOrEmpty(organizeId)) | ||
| 741 | - return organizeId; | 850 | + if (string.IsNullOrEmpty(organizeValue)) |
| 851 | + return organizeValue; | ||
| 852 | + | ||
| 853 | + if (orgIdDict.TryGetValue(organizeValue, out var name) && !string.IsNullOrEmpty(name)) | ||
| 854 | + return name; | ||
| 855 | + | ||
| 856 | + if (orgNameDict.TryGetValue(organizeValue, out var existingName) && !string.IsNullOrEmpty(existingName)) | ||
| 857 | + return existingName; | ||
| 742 | 858 | ||
| 743 | - return orgDict.TryGetValue(organizeId, out var name) && !string.IsNullOrEmpty(name) | ||
| 744 | - ? name | ||
| 745 | - : organizeId; | 859 | + return organizeValue; |
| 746 | } | 860 | } |
| 747 | 861 | ||
| 748 | private async Task TryWriteBusinessLogAsync(string moduleCode, string actionCode, string bizType, string bizId, string summary, string detailJson = null) | 862 | private async Task TryWriteBusinessLogAsync(string moduleCode, string actionCode, string bizType, string bizId, string summary, string detailJson = null) |
store-pc/src/components/StoreTargetDialog.vue
| @@ -199,6 +199,7 @@ | @@ -199,6 +199,7 @@ | ||
| 199 | <script> | 199 | <script> |
| 200 | import { | 200 | import { |
| 201 | getLqMdTargetList, | 201 | getLqMdTargetList, |
| 202 | + getLqMdTargetInfo, | ||
| 202 | createLqMdTarget, | 203 | createLqMdTarget, |
| 203 | updateLqMdTarget, | 204 | updateLqMdTarget, |
| 204 | getStoreMdxxInfo, | 205 | getStoreMdxxInfo, |
| @@ -352,12 +353,22 @@ export default { | @@ -352,12 +353,22 @@ export default { | ||
| 352 | if (Number(target.storeLifeline || 0) > 0) return true | 353 | if (Number(target.storeLifeline || 0) > 0) return true |
| 353 | return false | 354 | return false |
| 354 | }, | 355 | }, |
| 356 | + resolveDeptId(value, options) { | ||
| 357 | + if (value == null || value === '') return '' | ||
| 358 | + const str = String(value) | ||
| 359 | + if (/^\d{15,}$/.test(str)) return str | ||
| 360 | + const list = options || [] | ||
| 361 | + const byId = list.find(item => item.id === str || item.Id === str) | ||
| 362 | + if (byId) return byId.id || byId.Id | ||
| 363 | + const byName = list.find(item => item.fullName === str || item.FullName === str) | ||
| 364 | + return byName ? (byName.id || byName.Id) : str | ||
| 365 | + }, | ||
| 355 | mapTargetToForm(target) { | 366 | mapTargetToForm(target) { |
| 356 | return { | 367 | return { |
| 357 | - businessUnit: this.normalizeDeptId(target.businessUnit), | ||
| 358 | - techDepartment: this.normalizeDeptId(target.techDepartment), | ||
| 359 | - educationDepartment: this.normalizeDeptId(target.educationDepartment), | ||
| 360 | - majorProjectDepartment: this.normalizeDeptId(target.majorProjectDepartment), | 368 | + businessUnit: this.resolveDeptId(target.businessUnit || target.BusinessUnit, this.businessUnitOptions), |
| 369 | + techDepartment: this.resolveDeptId(target.techDepartment || target.TechDepartment, this.techDepartmentOptions), | ||
| 370 | + educationDepartment: this.resolveDeptId(target.educationDepartment || target.EducationDepartment, this.educationDepartmentOptions), | ||
| 371 | + majorProjectDepartment: this.resolveDeptId(target.majorProjectDepartment || target.MajorProjectDepartment, this.majorProjectDepartmentOptions), | ||
| 361 | businessUnitTarget: target.businessUnitTarget != null ? target.businessUnitTarget : null, | 372 | businessUnitTarget: target.businessUnitTarget != null ? target.businessUnitTarget : null, |
| 362 | techDepartmentTarget: target.techDepartmentTarget != null ? target.techDepartmentTarget : null, | 373 | techDepartmentTarget: target.techDepartmentTarget != null ? target.techDepartmentTarget : null, |
| 363 | educationDepartmentTarget: target.educationDepartmentTarget != null ? target.educationDepartmentTarget : null, | 374 | educationDepartmentTarget: target.educationDepartmentTarget != null ? target.educationDepartmentTarget : null, |
| @@ -432,10 +443,18 @@ export default { | @@ -432,10 +443,18 @@ export default { | ||
| 432 | try { | 443 | try { |
| 433 | const res = await getStoreMdxxInfo(this.currentStoreId) | 444 | const res = await getStoreMdxxInfo(this.currentStoreId) |
| 434 | const store = res.data || {} | 445 | const store = res.data || {} |
| 435 | - if (!this.form.businessUnit && store.syb) this.form.businessUnit = this.normalizeDeptId(store.syb) | ||
| 436 | - if (!this.form.techDepartment && store.kjb) this.form.techDepartment = this.normalizeDeptId(store.kjb) | ||
| 437 | - if (!this.form.educationDepartment && store.jyb) this.form.educationDepartment = this.normalizeDeptId(store.jyb) | ||
| 438 | - if (!this.form.majorProjectDepartment && store.dxmb) this.form.majorProjectDepartment = this.normalizeDeptId(store.dxmb) | 446 | + if (!this.form.businessUnit && store.syb) { |
| 447 | + this.form.businessUnit = this.resolveDeptId(store.syb, this.businessUnitOptions) | ||
| 448 | + } | ||
| 449 | + if (!this.form.techDepartment && store.kjb) { | ||
| 450 | + this.form.techDepartment = this.resolveDeptId(store.kjb, this.techDepartmentOptions) | ||
| 451 | + } | ||
| 452 | + if (!this.form.educationDepartment && store.jyb) { | ||
| 453 | + this.form.educationDepartment = this.resolveDeptId(store.jyb, this.educationDepartmentOptions) | ||
| 454 | + } | ||
| 455 | + if (!this.form.majorProjectDepartment && store.dxmb) { | ||
| 456 | + this.form.majorProjectDepartment = this.resolveDeptId(store.dxmb, this.majorProjectDepartmentOptions) | ||
| 457 | + } | ||
| 439 | } catch (e) { | 458 | } catch (e) { |
| 440 | // 预填失败不影响设定 | 459 | // 预填失败不影响设定 |
| 441 | } | 460 | } |
| @@ -462,9 +481,17 @@ export default { | @@ -462,9 +481,17 @@ export default { | ||
| 462 | 481 | ||
| 463 | const list = res.data?.list || [] | 482 | const list = res.data?.list || [] |
| 464 | if (list.length > 0) { | 483 | if (list.length > 0) { |
| 465 | - const target = list[0] | 484 | + let target = list[0] |
| 485 | + try { | ||
| 486 | + const detailRes = await getLqMdTargetInfo(target.id) | ||
| 487 | + if (detailRes && detailRes.data) { | ||
| 488 | + target = detailRes.data | ||
| 489 | + } | ||
| 490 | + } catch (e) { | ||
| 491 | + // 详情失败时回退列表行 | ||
| 492 | + } | ||
| 466 | const configured = this.isTargetConfigured(target) | 493 | const configured = this.isTargetConfigured(target) |
| 467 | - this.savedTarget = { id: target.id, configured } | 494 | + this.savedTarget = { id: target.id || target.Id, configured } |
| 468 | this.form = this.mapTargetToForm(target) | 495 | this.form = this.mapTargetToForm(target) |
| 469 | } else { | 496 | } else { |
| 470 | await this.loadStoreDepartmentDefaults() | 497 | await this.loadStoreDepartmentDefaults() |
项目文档相关/sql/2026-08-02/lq_kd_pxmx_转卡品项回填yjsj.sql
0 → 100644
| 1 | +-- 转卡开单品项 yjsj 历史回填(品项开单明细按 yjsj 筛时间,空值会导致转卡明细查不到) | ||
| 2 | +-- 口径:yjsj 为空时,用开单主表 kdrq 回填 | ||
| 3 | + | ||
| 4 | +-- 预览影响行数 | ||
| 5 | +SELECT COUNT(*) AS will_update | ||
| 6 | +FROM lq_kd_pxmx px | ||
| 7 | +INNER JOIN lq_kd_kdjlb k ON px.glkdbh = k.F_Id | ||
| 8 | +WHERE px.yjsj IS NULL | ||
| 9 | + AND k.kdrq IS NOT NULL | ||
| 10 | + AND px.F_IsEffective = 1 | ||
| 11 | + AND k.F_IsEffective = 1 | ||
| 12 | + AND k.fkfs = '转卡'; | ||
| 13 | + | ||
| 14 | +-- 执行回填 | ||
| 15 | +UPDATE lq_kd_pxmx px | ||
| 16 | +INNER JOIN lq_kd_kdjlb k ON px.glkdbh = k.F_Id | ||
| 17 | +SET px.yjsj = k.kdrq | ||
| 18 | +WHERE px.yjsj IS NULL | ||
| 19 | + AND k.kdrq IS NOT NULL | ||
| 20 | + AND px.F_IsEffective = 1 | ||
| 21 | + AND k.F_IsEffective = 1 | ||
| 22 | + AND k.fkfs = '转卡'; |
项目文档相关/sql/2026-08-02/lq_kd_pxmx_转卡品项补全yjsj.sql
0 → 100644
| 1 | +-- 转卡开单品项明细 yjsj 为空导致品项开单报表按时间筛选查不到 | ||
| 2 | +-- 用开单主表 kdrq 回填(与代码 COALESCE(yjsj, kdrq) 口径一致) | ||
| 3 | + | ||
| 4 | +-- 预览 | ||
| 5 | +SELECT px.F_Id, px.glkdbh, px.yjsj, k.kdrq, k.fkfs, k.sfyj | ||
| 6 | +FROM lq_kd_pxmx px | ||
| 7 | +INNER JOIN lq_kd_kdjlb k ON px.glkdbh = k.F_Id | ||
| 8 | +WHERE px.yjsj IS NULL | ||
| 9 | + AND k.kdrq IS NOT NULL | ||
| 10 | + AND px.F_IsEffective = 1 | ||
| 11 | + AND k.F_IsEffective = 1 | ||
| 12 | + AND k.fkfs = '转卡' | ||
| 13 | +LIMIT 50; | ||
| 14 | + | ||
| 15 | +-- 修复 | ||
| 16 | +UPDATE lq_kd_pxmx px | ||
| 17 | +INNER JOIN lq_kd_kdjlb k ON px.glkdbh = k.F_Id | ||
| 18 | +SET px.yjsj = k.kdrq | ||
| 19 | +WHERE px.yjsj IS NULL | ||
| 20 | + AND k.kdrq IS NOT NULL | ||
| 21 | + AND px.F_IsEffective = 1 | ||
| 22 | + AND k.F_IsEffective = 1 | ||
| 23 | + AND k.fkfs = '转卡'; |
项目文档相关/sql/2026-08-02/lq_md_target_归属字段名称转组织ID.sql
0 → 100644
| 1 | +-- lq_md_target 归属字段:将误存的组织「名称」统一回填为 base_organize.F_Id | ||
| 2 | +-- 背景:规范要求 F_BusinessUnit / F_TechDepartment / F_EducationDepartment / F_MajorProjectDepartment 存组织ID | ||
| 3 | +-- 混存原因见脚本末尾说明 | ||
| 4 | + | ||
| 5 | +-- ============================================================ | ||
| 6 | +-- 1. 修复前检查(先看再改) | ||
| 7 | +-- ============================================================ | ||
| 8 | + | ||
| 9 | +-- 1.1 各字段「名称」vs「ID」数量 | ||
| 10 | +SELECT | ||
| 11 | + SUM(CASE WHEN F_BusinessUnit REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS business_unit_id_cnt, | ||
| 12 | + SUM(CASE WHEN F_BusinessUnit IS NOT NULL AND F_BusinessUnit != '' AND F_BusinessUnit NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS business_unit_name_cnt, | ||
| 13 | + SUM(CASE WHEN F_TechDepartment REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS tech_id_cnt, | ||
| 14 | + SUM(CASE WHEN F_TechDepartment IS NOT NULL AND F_TechDepartment != '' AND F_TechDepartment NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS tech_name_cnt, | ||
| 15 | + SUM(CASE WHEN F_EducationDepartment REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS edu_id_cnt, | ||
| 16 | + SUM(CASE WHEN F_EducationDepartment IS NOT NULL AND F_EducationDepartment != '' AND F_EducationDepartment NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS edu_name_cnt, | ||
| 17 | + SUM(CASE WHEN F_MajorProjectDepartment REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS major_id_cnt, | ||
| 18 | + SUM(CASE WHEN F_MajorProjectDepartment IS NOT NULL AND F_MajorProjectDepartment != '' AND F_MajorProjectDepartment NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS major_name_cnt | ||
| 19 | +FROM lq_md_target; | ||
| 20 | + | ||
| 21 | +-- 1.2 按月份查看(dev 库 202608 曾出现 28 条名称) | ||
| 22 | +SELECT | ||
| 23 | + F_Month, | ||
| 24 | + SUM(CASE WHEN F_BusinessUnit IS NOT NULL AND F_BusinessUnit != '' AND F_BusinessUnit NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS business_unit_name_cnt | ||
| 25 | +FROM lq_md_target | ||
| 26 | +GROUP BY F_Month | ||
| 27 | +HAVING business_unit_name_cnt > 0 | ||
| 28 | +ORDER BY F_Month DESC; | ||
| 29 | + | ||
| 30 | +-- 1.3 无法匹配到组织的名称(应为 0 行;有结果则先人工处理) | ||
| 31 | +SELECT DISTINCT t.F_BusinessUnit AS val, 'F_BusinessUnit' AS field | ||
| 32 | +FROM lq_md_target t | ||
| 33 | +WHERE t.F_BusinessUnit IS NOT NULL AND t.F_BusinessUnit != '' | ||
| 34 | + AND t.F_BusinessUnit NOT REGEXP '^[0-9]{15,}$' | ||
| 35 | + AND NOT EXISTS ( | ||
| 36 | + SELECT 1 FROM base_organize o | ||
| 37 | + WHERE o.F_FullName = t.F_BusinessUnit | ||
| 38 | + AND o.F_Category = 'department' | ||
| 39 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 40 | + ) | ||
| 41 | +UNION ALL | ||
| 42 | +SELECT DISTINCT t.F_TechDepartment, 'F_TechDepartment' | ||
| 43 | +FROM lq_md_target t | ||
| 44 | +WHERE t.F_TechDepartment IS NOT NULL AND t.F_TechDepartment != '' | ||
| 45 | + AND t.F_TechDepartment NOT REGEXP '^[0-9]{15,}$' | ||
| 46 | + AND NOT EXISTS ( | ||
| 47 | + SELECT 1 FROM base_organize o | ||
| 48 | + WHERE o.F_FullName = t.F_TechDepartment | ||
| 49 | + AND o.F_Category = 'department' | ||
| 50 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 51 | + ) | ||
| 52 | +UNION ALL | ||
| 53 | +SELECT DISTINCT t.F_EducationDepartment, 'F_EducationDepartment' | ||
| 54 | +FROM lq_md_target t | ||
| 55 | +WHERE t.F_EducationDepartment IS NOT NULL AND t.F_EducationDepartment != '' | ||
| 56 | + AND t.F_EducationDepartment NOT REGEXP '^[0-9]{15,}$' | ||
| 57 | + AND NOT EXISTS ( | ||
| 58 | + SELECT 1 FROM base_organize o | ||
| 59 | + WHERE o.F_FullName = t.F_EducationDepartment | ||
| 60 | + AND o.F_Category = 'department' | ||
| 61 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 62 | + ) | ||
| 63 | +UNION ALL | ||
| 64 | +SELECT DISTINCT t.F_MajorProjectDepartment, 'F_MajorProjectDepartment' | ||
| 65 | +FROM lq_md_target t | ||
| 66 | +WHERE t.F_MajorProjectDepartment IS NOT NULL AND t.F_MajorProjectDepartment != '' | ||
| 67 | + AND t.F_MajorProjectDepartment NOT REGEXP '^[0-9]{15,}$' | ||
| 68 | + AND NOT EXISTS ( | ||
| 69 | + SELECT 1 FROM base_organize o | ||
| 70 | + WHERE o.F_FullName = t.F_MajorProjectDepartment | ||
| 71 | + AND o.F_Category = 'department' | ||
| 72 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 73 | + ); | ||
| 74 | + | ||
| 75 | +-- 1.4 预览:名称 -> 将回填的 ID | ||
| 76 | +SELECT | ||
| 77 | + t.F_Id, | ||
| 78 | + t.F_Month, | ||
| 79 | + t.F_StoreId, | ||
| 80 | + t.F_BusinessUnit AS old_business_unit, | ||
| 81 | + ob.F_Id AS new_business_unit, | ||
| 82 | + t.F_TechDepartment AS old_tech, | ||
| 83 | + ot.F_Id AS new_tech, | ||
| 84 | + t.F_EducationDepartment AS old_edu, | ||
| 85 | + oe.F_Id AS new_edu, | ||
| 86 | + t.F_MajorProjectDepartment AS old_major, | ||
| 87 | + om.F_Id AS new_major | ||
| 88 | +FROM lq_md_target t | ||
| 89 | +LEFT JOIN base_organize ob ON ob.F_FullName = t.F_BusinessUnit AND ob.F_Category = 'department' AND (ob.F_DeleteMark IS NULL OR ob.F_DeleteMark != 1) | ||
| 90 | +LEFT JOIN base_organize ot ON ot.F_FullName = t.F_TechDepartment AND ot.F_Category = 'department' AND (ot.F_DeleteMark IS NULL OR ot.F_DeleteMark != 1) | ||
| 91 | +LEFT JOIN base_organize oe ON oe.F_FullName = t.F_EducationDepartment AND oe.F_Category = 'department' AND (oe.F_DeleteMark IS NULL OR oe.F_DeleteMark != 1) | ||
| 92 | +LEFT JOIN base_organize om ON om.F_FullName = t.F_MajorProjectDepartment AND om.F_Category = 'department' AND (om.F_DeleteMark IS NULL OR om.F_DeleteMark != 1) | ||
| 93 | +WHERE ( | ||
| 94 | + (t.F_BusinessUnit IS NOT NULL AND t.F_BusinessUnit != '' AND t.F_BusinessUnit NOT REGEXP '^[0-9]{15,}$') | ||
| 95 | + OR (t.F_TechDepartment IS NOT NULL AND t.F_TechDepartment != '' AND t.F_TechDepartment NOT REGEXP '^[0-9]{15,}$') | ||
| 96 | + OR (t.F_EducationDepartment IS NOT NULL AND t.F_EducationDepartment != '' AND t.F_EducationDepartment NOT REGEXP '^[0-9]{15,}$') | ||
| 97 | + OR (t.F_MajorProjectDepartment IS NOT NULL AND t.F_MajorProjectDepartment != '' AND t.F_MajorProjectDepartment NOT REGEXP '^[0-9]{15,}$') | ||
| 98 | +) | ||
| 99 | +ORDER BY t.F_Month DESC, t.F_StoreId; | ||
| 100 | + | ||
| 101 | +-- ============================================================ | ||
| 102 | +-- 2. 执行回填(确认预览无误后再执行) | ||
| 103 | +-- ============================================================ | ||
| 104 | + | ||
| 105 | +-- 2.1 事业部 | ||
| 106 | +UPDATE lq_md_target t | ||
| 107 | +INNER JOIN base_organize o | ||
| 108 | + ON t.F_BusinessUnit = o.F_FullName | ||
| 109 | + AND o.F_Category = 'department' | ||
| 110 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 111 | +SET t.F_BusinessUnit = o.F_Id | ||
| 112 | +WHERE t.F_BusinessUnit IS NOT NULL | ||
| 113 | + AND t.F_BusinessUnit != '' | ||
| 114 | + AND t.F_BusinessUnit NOT REGEXP '^[0-9]{15,}$'; | ||
| 115 | + | ||
| 116 | +-- 2.2 科技部 | ||
| 117 | +UPDATE lq_md_target t | ||
| 118 | +INNER JOIN base_organize o | ||
| 119 | + ON t.F_TechDepartment = o.F_FullName | ||
| 120 | + AND o.F_Category = 'department' | ||
| 121 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 122 | +SET t.F_TechDepartment = o.F_Id | ||
| 123 | +WHERE t.F_TechDepartment IS NOT NULL | ||
| 124 | + AND t.F_TechDepartment != '' | ||
| 125 | + AND t.F_TechDepartment NOT REGEXP '^[0-9]{15,}$'; | ||
| 126 | + | ||
| 127 | +-- 2.3 教育部 | ||
| 128 | +UPDATE lq_md_target t | ||
| 129 | +INNER JOIN base_organize o | ||
| 130 | + ON t.F_EducationDepartment = o.F_FullName | ||
| 131 | + AND o.F_Category = 'department' | ||
| 132 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 133 | +SET t.F_EducationDepartment = o.F_Id | ||
| 134 | +WHERE t.F_EducationDepartment IS NOT NULL | ||
| 135 | + AND t.F_EducationDepartment != '' | ||
| 136 | + AND t.F_EducationDepartment NOT REGEXP '^[0-9]{15,}$'; | ||
| 137 | + | ||
| 138 | +-- 2.4 大项目部 | ||
| 139 | +UPDATE lq_md_target t | ||
| 140 | +INNER JOIN base_organize o | ||
| 141 | + ON t.F_MajorProjectDepartment = o.F_FullName | ||
| 142 | + AND o.F_Category = 'department' | ||
| 143 | + AND (o.F_DeleteMark IS NULL OR o.F_DeleteMark != 1) | ||
| 144 | +SET t.F_MajorProjectDepartment = o.F_Id | ||
| 145 | +WHERE t.F_MajorProjectDepartment IS NOT NULL | ||
| 146 | + AND t.F_MajorProjectDepartment != '' | ||
| 147 | + AND t.F_MajorProjectDepartment NOT REGEXP '^[0-9]{15,}$'; | ||
| 148 | + | ||
| 149 | +-- ============================================================ | ||
| 150 | +-- 3. 修复后验证(名称应为 0) | ||
| 151 | +-- ============================================================ | ||
| 152 | +SELECT | ||
| 153 | + SUM(CASE WHEN F_BusinessUnit IS NOT NULL AND F_BusinessUnit != '' AND F_BusinessUnit NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS business_unit_name_cnt, | ||
| 154 | + SUM(CASE WHEN F_TechDepartment IS NOT NULL AND F_TechDepartment != '' AND F_TechDepartment NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS tech_name_cnt, | ||
| 155 | + SUM(CASE WHEN F_EducationDepartment IS NOT NULL AND F_EducationDepartment != '' AND F_EducationDepartment NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS edu_name_cnt, | ||
| 156 | + SUM(CASE WHEN F_MajorProjectDepartment IS NOT NULL AND F_MajorProjectDepartment != '' AND F_MajorProjectDepartment NOT REGEXP '^[0-9]{15,}$' THEN 1 ELSE 0 END) AS major_name_cnt | ||
| 157 | +FROM lq_md_target; | ||
| 158 | + | ||
| 159 | +-- ============================================================ | ||
| 160 | +-- 混存原因说明(排查结论) | ||
| 161 | +-- ============================================================ | ||
| 162 | +-- 1. 规范:归属字段应存 base_organize.F_Id(项目文档、日报/驾驶舱 SQL 均按 ID 关联) | ||
| 163 | +-- 2. 历史数据:202601~202607 基本全是 ID;仅 202608 出现 28 条名称(dev 库实测) | ||
| 164 | +-- 3. 直接原因:列表接口 EnrichExportNamesAsync 把 ID 转成名称返回给前端; | ||
| 165 | +-- 管理后台/门店 PC 编辑时直接用列表行回填表单,保存时把「事业一部」等名称写回库 | ||
| 166 | +-- 4. 后端 Create/Update 未做 ID 归一化,字符串原样入库 | ||
| 167 | +-- 5. 「同步上月」会原样复制上月值,若上月已是名称会继续扩散 | ||
| 168 | +-- | ||
| 169 | +-- 组织名称与 ID 对照(base_organize,department): | ||
| 170 | +-- 事业一部 734725158358484229 | 事业二部 734725192445592837 | 事业三部 734725229380633861 | ||
| 171 | +-- 事业四部 734725299018663173 | 事业五部 734725363116016901 | 事业六部 735107948883215621 | ||
| 172 | +-- 科技一部 734725579919590661 | 科技二部 734725628560934149 | ||
| 173 | +-- 教育一部 734725416912160005 | 教育二部 734725478136415493 | ||
| 174 | +-- 大项目一部 734725667203056901 | 大项目二部 734725746831918341 |