diff --git a/api/app/lib/models/report_automatic.js b/api/app/lib/models/report_automatic.js index 88b8029..e0dfeb1 100644 --- a/api/app/lib/models/report_automatic.js +++ b/api/app/lib/models/report_automatic.js @@ -17,7 +17,7 @@ module.exports = dc => { }, reportName: { type: DataTypes.STRING, - allowNull: false, + allowNull: true, defaultValue: null, comment: "", primaryKey: false, @@ -87,8 +87,17 @@ module.exports = dc => { field: "ratifier", autoIncrement: false }, + coverTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: "", + primaryKey: false, + field: "cover_time", + autoIncrement: false + }, structId: { - type: DataTypes.INTEGER, + type: DataTypes.ARRAY(DataTypes.INTEGER), allowNull: false, defaultValue: null, comment: "", @@ -96,9 +105,18 @@ module.exports = dc => { field: "struct_id", autoIncrement: false }, + structList: { + type: DataTypes.JSON, + allowNull: true, + defaultValue: null, + comment: "", + primaryKey: false, + field: "struct_list", + autoIncrement: false + }, projectOverview: { type: DataTypes.STRING, - allowNull: false, + allowNull: true, defaultValue: null, comment: "", primaryKey: false, @@ -107,7 +125,7 @@ module.exports = dc => { }, reportStartTime: { type: DataTypes.DATE, - allowNull: false, + allowNull: true, defaultValue: null, comment: "开始时间", primaryKey: false, @@ -116,7 +134,7 @@ module.exports = dc => { }, reportEndTime: { type: DataTypes.DATE, - allowNull: false, + allowNull: true, defaultValue: null, comment: "开始时间", primaryKey: false, @@ -134,7 +152,7 @@ module.exports = dc => { }, factors: { type: DataTypes.JSON, - allowNull: false, + allowNull: true, defaultValue: null, comment: "", primaryKey: false, diff --git a/script/4.4/schema/1.update_report_automatic.sql b/script/4.4/schema/1.update_report_automatic.sql new file mode 100644 index 0000000..7c4e4a1 --- /dev/null +++ b/script/4.4/schema/1.update_report_automatic.sql @@ -0,0 +1,22 @@ +alter table report_automatic alter column report_name drop not null; + +alter table report_automatic alter column report_start_time drop not null; + +alter table report_automatic alter column report_end_time drop not null; + +alter table report_automatic alter column factors drop not null; + +alter table report_automatic alter column project_overview drop not null; + +alter table report_automatic + add cover_time timestamp; + +alter table report_automatic + add struct_list json; + +alter table report_automatic drop column struct_id; + +alter table report_automatic + add struct_id integer[] not null; + + diff --git a/web/client/src/sections/service/components/automatic-Modal.jsx b/web/client/src/sections/service/components/automatic-Modal.jsx index b3d5460..33df7ba 100644 --- a/web/client/src/sections/service/components/automatic-Modal.jsx +++ b/web/client/src/sections/service/components/automatic-Modal.jsx @@ -12,10 +12,11 @@ const AutomaticModal = ({ actions, dispatch, apiRoot, qiniuUrl, visible, eidtDat const [strucData, setStrucData] = useState([]) //结构物数据 const [projectId, setProjectId] = useState(); //项目id - const [structId, setStructId] = useState(); //结构物id + const [structId, setStructId] = useState([]); //结构物id const [factorId, setFactorId] = useState([]); //监测因素id const [factorList, setFactorList] = useState([]); //监测因素 - const [factorChech, setFactorChech] = useState([]); //选中的监测因素 + const [structChech, setStructChech] = useState([]); //选中的结构物 + const [factorChech, setFactorChech] = useState({}); //选中的结构物 const [activeKey, setActiveKey] = useState([]); // const [correlationId, setCorrelationId] = useState([]); // @@ -23,13 +24,18 @@ const AutomaticModal = ({ actions, dispatch, apiRoot, qiniuUrl, visible, eidtDat useEffect(async () => { if (eidtData?.id) { setProjectId(eidtData?.projectId) - setStructId(eidtData?.structId) + setStructId(eidtData?.structId || []) setFactorId(eidtData?.factors?.map(s => s.codeName) || []) let data = await getData(eidtData?.projectId) - let Factor = data?.find(s => s.strucId == eidtData?.structId)?.factor || [] - setFactorList(Factor) - setFactorChech(Factor?.filter(s => eidtData?.factors?.map(s => s.codeName)?.includes(s.proto))) + let struc = data?.filter(s => eidtData?.structId?.includes(s.strucId)) || [] + + setStructChech(struc) + let Factor = {} + struc?.forEach(d => { + Factor[d.strucId] = d.factor?.filter(w => eidtData?.structList?.find(h => h.structId == d.strucId)?.factors?.map(g => g.codeName)?.includes(w.proto)) + }) + setFactorChech(Factor) // setActiveKey(eidtData?.factors?.map(s => s.codeName) || []) } }, []) @@ -55,67 +61,100 @@ const AutomaticModal = ({ actions, dispatch, apiRoot, qiniuUrl, visible, eidtDat onOk={() => { form.current.validate().then((v) => { + console.log(11, v); let data = { id: eidtData?.id, - reportName: v.reportName, - projectId: v.projectId, - projectName: v.projectName, - reportType: v.reportType, - reportPicPath: v.reportPicPath[0]?.response?.url, - overview: v.overview[0]?.response?.url, - framer: v.framer, - auditor: v.auditor, - ratifier: v.ratifier, - structId: v.structId, - projectOverview: v.projectOverview, - reportStartTime: moment(v.reportTime[0]).format('YYYY-MM-DD HH:mm:ss'), - reportEndTime: moment(v.reportTime[1]).format('YYYY-MM-DD HH:mm:ss'), - time: eidtData?.time && moment(eidtData?.time).format('YYYY-MM-DD HH:mm:ss') || null, - factors: [] + reportName: v.reportName, //报表名称 + projectId: v.projectId, //所属项目 + projectName: v.projectName, //项目名称 + reportType: v.reportType, //报表类型 + reportPicPath: v.reportPicPath && v.reportPicPath[0] && v.reportPicPath[0]?.response?.url || eidtData.reportPicPath, //首页图片 + framer: v.framer, //制定者 + auditor: v.auditor, //审核者 + ratifier: v.ratifier, //批准者 + coverTime: v.coverTime && moment(v.coverTime).format('YYYY-MM-DD'), + structId: v.structId, //结构物id + structList: [] } - v.factorId?.forEach(d => { - let index = d.length - let factorData = {} + v.structId?.forEach(p => { + let structFind = eidtData?.structList?.find(d => d.structId == p) || {} + let structData = { structId: p } + let structNameIndex = p.toString().length || 0 + for (let key in v) { - factorData.codeName = d - factorData.tempName = factorData.tempName || [] - if (key?.indexOf(d) != -1) { - if (key?.slice(index) == 'pointDescrip') factorData.pointDescrip = v[key] - if (key?.slice(index) == 'pointPicPath') factorData.pointPicPath = v[key] && v[key][0]?.response?.url - if (key?.slice(index) == 'factorDescrip') factorData.factorDescrip = v[key] - if (key?.slice(index) == 'sensorNames') factorData.sensorNames = factorChech?.find(p => p.proto == d)?.sensor?.filter(f => v[key]?.includes(f.id))?.map(c => ({ id: c.id, name: c.name })) || [] - if (key?.slice(index) == 'startEndTime') { - factorData.startTime = v[key] && moment(v[key][0]).format('YYYY-MM-DD HH:mm:ss') - factorData.endTime = v[key] && moment(v[key][1]).format('YYYY-MM-DD HH:mm:ss') - } - if (key?.slice(index) == 'tempName1') { - factorData.tempName?.push({ - index: 1, - id: v[key], - name: factorChech?.find(p => p.proto == d)?.sensor?.find(f => v[key] == f.id)?.name - }) - } - if (key?.slice(index) == 'tempName2') { - factorData.tempName?.push({ - index: 2, - id: v[key], - name: factorChech?.find(p => p.proto == 1004)?.sensor?.find(f => v[key] == f.id)?.name - }) - } - if (key?.slice(index) == 'factorDescrip') factorData.factorDescrip = v[key] - // if (key?.slice(index) == 'glStaName') factorData.glStaName = v[key] - // if (key?.slice(index) == 'tempStaName') factorData.tempStaName = v[key] - if (key?.slice(index) == 'initialTime') factorData.initialTime = v[key] && moment(v[key]).format('YYYY-MM-DD HH:mm:ss') - if (key?.slice(index) == 'releTime') { - factorData.releStartTime = v[key] && moment(v[key][0]).format('YYYY-MM-DD HH:mm:ss') - factorData.releEndTime = v[key] && moment(v[key][1]).format('YYYY-MM-DD HH:mm:ss') + if (key?.indexOf(p) != -1) { + //结构物概况图片 + if (key?.slice(structNameIndex) == 'overview') structData.overview = v[key] && v[key][0]?.response?.url || structFind.overview + //结构物描述 + if (key?.slice(structNameIndex) == 'projectOverview') structData.projectOverview = v[key] + //结论 + if (key?.slice(structNameIndex) == 'conclusion') structData.conclusion = v[key] + //开始结束时间 + if (key?.slice(structNameIndex) == 'reportTime') { + structData.reportStartTime = v[key] && v[key][0] && moment(v[key][0]).format('YYYY-MM-DD HH:mm:ss') + structData.reportEndTime = v[key] && v[key][1] && moment(v[key][1]).format('YYYY-MM-DD HH:mm:ss') } + //包含的监测因素 + structData.factors = [] } } - factorData.glStaName = factorData?.tempName?.find(s => s.index == 1)?.name - factorData.tempStaName = factorData?.tempName?.find(s => s.index == 2)?.name || factorData?.tempName?.find(s => s.index == 1)?.name - data.factors?.push(factorData) + + // debugger + + v[p + 'factorId']?.forEach(d => { + let factorFind = structFind?.factors?.find(c => c.codeName == d) || {} + let index = d.length + structNameIndex + 5 + let factorData = {} + for (let key in v) { + factorData.codeName = d + factorData.tempName = factorData.tempName || [] + if (key?.indexOf(p + 'struc') != -1 && key?.indexOf('struc' + d) != -1) { + //布点描述 + if (key?.slice(index) == 'pointDescrip') factorData.pointDescrip = v[key] + //布点图片 + if (key?.slice(index) == 'pointPicPath') factorData.pointPicPath = v[key] && v[key][0]?.response?.url || + factorFind.pointPicPath + //索力监测描述 + if (key?.slice(index) == 'factorDescrip') factorData.factorDescrip = v[key] + //测点选择 + if (key?.slice(index) == 'sensorNames') factorData.sensorNames = factorChech[p]?.find(p => p.proto == d)?.sensor?.filter(f => v[key]?.includes(f.id))?.map(c => ({ id: c.id, name: c.name })) || [] + //开始结束时间 + if (key?.slice(index) == 'startEndTime') { + factorData.startTime = v[key] && v[key][0] && moment(v[key][0]).format('YYYY-MM-DD HH:mm:ss') + factorData.endTime = v[key] && v[key][1] && moment(v[key][1]).format('YYYY-MM-DD HH:mm:ss') + } + //关联温度的测点 + if (key?.slice(index) == 'tempName1') { + factorData.tempName?.push({ + index: 1, + id: v[key], + name: factorChech[p]?.find(p => p.proto == d)?.sensor?.find(f => v[key] == f.id)?.name + }) + } + //温度测点 + if (key?.slice(index) == 'tempName2') { + factorData.tempName?.push({ + index: 2, + id: v[key], + name: factorChech[p]?.find(p => p.proto == 1004)?.sensor?.find(f => v[key] == f.id)?.name + }) + } + //数据初始时间 + if (key?.slice(index) == 'initialTime') factorData.initialTime = v[key] && moment(v[key]).format('YYYY-MM-DD HH:mm:ss') + //关联开始结束时间 + if (key?.slice(index) == 'releTime') { + factorData.releStartTime = v[key] && v[key][0] && moment(v[key][0]).format('YYYY-MM-DD HH:mm:ss') + factorData.releEndTime = v[key] && v[key][1] && moment(v[key][1]).format('YYYY-MM-DD HH:mm:ss') + } + } + } + factorData.glStaName = factorData?.tempName?.find(s => s.index == 1)?.name + factorData.tempStaName = factorData?.tempName?.find(s => s.index == 2)?.name || factorData?.tempName?.find(s => s.index == 1)?.name + structData.factors?.push(factorData) + }) + + data.structList.push(structData) }) dispatch(service.postAutomaticReport(data)).then((res) => { @@ -127,7 +166,7 @@ const AutomaticModal = ({ actions, dispatch, apiRoot, qiniuUrl, visible, eidtDat }) }} - width={700} + width={770} onCancel={() => close()} >