diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index 4176e53..39d0130 100644 --- a/api/app/lib/controllers/project/group.js +++ b/api/app/lib/controllers/project/group.js @@ -587,30 +587,30 @@ async function groupProject (ctx) { } -async function getProjectWorkOrders(){ +async function getProjectWorkOrders(ctx){ try{ // 计算一个月前的日期 const oneMonthAgo = moment().subtract(1, 'months').toDate() const { models } = ctx.fs.dc - const {Op, fn, col} = ctx.fs.dc.ORM.sequelize + const sequelize = ctx.fs.dc.ORM const { projectIds } = ctx.query if(projectIds&&projectIds.length){ const projectIdsArr=projectIds.split(',').map(Number) const res= await models.FormDataTable.findAll({ attributes: [ 'projectId', - [fn('COUNT', col('id')), 'count'], + [sequelize.fn('COUNT', sequelize.col('id')), 'count'], ], where: { - projectIds: { - [Op.in]: projectIdsArr, + projectId: { + $in: projectIdsArr, }, startTime: { - [Op.gte]: oneMonthAgo, + $gte: oneMonthAgo, }, }, group: ['projectId'], - order: [[fn('COUNT', col('id')), 'DESC']], + order: [[sequelize.fn('COUNT', sequelize.col('id')), 'DESC']], }) ctx.body=res ctx.status=200 @@ -628,24 +628,25 @@ async function getProjectWorkOrders(){ } } -async function getWorkOrdersRepairRank(){ +async function getWorkOrdersRepairRank(ctx){ try{ const oneMonthAgo = moment().subtract(1, 'months').toDate() const { models } = ctx.fs.dc - const {Op, fn, col} = ctx.fs.dc.ORM.sequelize + const sequelize = ctx.fs.dc.ORM const { projectIds } = ctx.query + if(projectIds&&projectIds.length){ const res= await models.FormDataTable.findAll({ where: { - projectIds: { - [Op.in]: projectIds.split(',').map(Number), + projectId: { + $in: projectIds.split(',').map(Number) }, startTime: { - [Op.gte]: oneMonthAgo, + $gte: oneMonthAgo, } }, order: [ - [fn('TIMESTAMPDIFF', literal('SECOND'), col('endTime'), col('startTime')), 'DESC'] + [sequelize.literal('(EXTRACT(EPOCH FROM "end_time" - "start_time"))'), 'DESC'] ] }) ctx.body=res diff --git a/api/app/lib/schedule/workOrder.js b/api/app/lib/schedule/workOrder.js index b573847..1b27edf 100644 --- a/api/app/lib/schedule/workOrder.js +++ b/api/app/lib/schedule/workOrder.js @@ -53,37 +53,40 @@ module.exports = function (app, opts) { ON fgroup.id = fprocess.group_id INNER JOIN ${camWorkflow}.act_hi_procinst AS procin ON procin.id_ = story.procinst_id + AND procin.state_='COMPLETED' ${rescount ?` WHERE procin.end_time_ is not null AND procin.end_time_ > '${lastExecutionTime}' AND procin.end_time_ <='${startTime}'` : ''}` ).toPromise() - console.log('formRes1',formRes) const procinstIds = [...new Set(formRes.map(e => e.procinstId))]; + console.log('formRes1',procinstIds) // 获取流程实例变量 if(formRes && formRes.length > 0){ let procinstsVariables = await ctx.app.camunda.request.post(encodeURI(`/engine-rest/history/variable-instance`), { processInstanceIdIn: procinstIds }) + console.log('formRes2',procinstsVariables) for (let f of formRes) { const parseData = parseProcessData({ formSchema: JSON.parse(f.formSchema), formData: JSON.parse(f.formData) }) - await models.Workorder.create({ + const res=await models.Workorder.create({ projectId:parseData.pomsProjectId.value || null, formname:procinstsVariables.find(item=>item.id===f.procinstId).name||null, state: f.state||null, endTime:f.endTime||null, startTime:f.createTime||null }) + console.log('formRes3',res) console.log('工单数据抽取结束') } } }catch(error){ - console.error(error) + console.error('失败原因',error) } } ); diff --git a/web/client/src/layout/actions/workOrders.js b/web/client/src/layout/actions/workOrders.js index 7881bbe..aabc268 100644 --- a/web/client/src/layout/actions/workOrders.js +++ b/web/client/src/layout/actions/workOrders.js @@ -3,7 +3,6 @@ import { ApiTable, basicAction } from '$utils' export function getWorkOrders () { //获取工单的待办 - console.log('xxxxx',ApiTable.workOrders) return dispatch => basicAction({ type: 'get', dispatch: dispatch, diff --git a/web/client/src/sections/projectGroup/containers/bigscreen.jsx b/web/client/src/sections/projectGroup/containers/bigscreen.jsx index 08f6d00..4890a67 100644 --- a/web/client/src/sections/projectGroup/containers/bigscreen.jsx +++ b/web/client/src/sections/projectGroup/containers/bigscreen.jsx @@ -25,7 +25,7 @@ const Bigscreen = (props) => { const [proportion, setProportion] = useState([]) const [formatter, setFormatter] = useState({}) const [groupDetail, setGroupDetail] = useState({}) - + const [allProjects,setAllProjects]=useState([]) const [alarmData, setAlarmData] = useState()//第三项之后的数据 const [biggest, setBiggest] = useState()//最大的刻度值 const [mockData, setMockData] = useState()//所有的告警数据 @@ -67,7 +67,11 @@ const Bigscreen = (props) => { setGroupDetail(res.payload.data) } }) - + dispatch(actions.workOrder.getPomsProjectBasicAll()).then(res => { + if (res.success) { + setAllProjects(res.payload.data) + } + }) @@ -135,27 +139,27 @@ const Bigscreen = (props) => { } }, [mockData]) -console.log('xxx1',actions) + useEffect(() => { - if(groupDetail?.pomsProjectIds&&groupDetail?.pomsProjectIds.length){ - const query=groupDetail?.pomsProjectIds+'' + if(groupDetail?.pomsProjectIds&&groupDetail?.pomsProjectIds.length&&allProjects&&allProjects.length){ + const query=groupDetail?.pomsProjectIds dispatch(actions.projectGroup.getProjectWorkOrders({projectIds:query})).then(res=>{ if(res.success){ - setProportion([...res.payload.data?.slice(0, 3)?.map(v => ({ name: pomsProjectBasicAll.find(item=>item.valiue===v.projectId)?.label, value: v.count })), - { value: res.payload.data&&res.payload.data.length>3?res.payload.data?.slice(3)?.reduce((p,c)=>{ - return p+c.count - },0):0, name: '其它' }]) + setProportion([...res.payload.data?.slice(0, 3)?.map(v => ({ name: allProjects?.find(item=>item.value===v.projectId)?.label, value: Number(v.count) })), + { name: '其它', value: res.payload.data&&res.payload.data.length>3?res.payload.data?.slice(3)?.reduce((p,c)=>{ + return p+Number(c.count) + },0):0 }]) } }) - dispatch(actions.projectGroup.getProjectWorkOrders({projectIds:query})).then(res=>{ + dispatch(actions.projectGroup.getWorkOrdersRepairRank({projectIds:query})).then(res=>{ if(res.success){ - setGroupProject(res.payload.data?.slice(0, 10).map(v => ({name:v.formname,duration:v?.endTime.diff(v?.startTime,'hours') })) || []) + setGroupProject(res.payload.data?.slice(0, 10).map(v => ({name:v.formname,duration:moment(v?.endTime).diff(v?.startTime,'hours') })) || []) } }) } - },[groupDetail]) + },[groupDetail,allProjects]) let statisticOnline = (groupId) => { dispatch(actions.projectGroup.groupStatisticOnline({ groupId })).then(res => { @@ -502,12 +506,16 @@ console.log('xxx1',actions) } function mapStateToProps (state) { - const { auth, global, groupStatisticOnline } = state; + + const { auth, global, groupStatisticOnline,pomsProjectBasicAll } = state; + console.log('global1',global) return { user: auth.user, actions: global.actions, clientHeight: global.clientHeight, - groupStatisticOnline: groupStatisticOnline?.data + groupStatisticOnline: groupStatisticOnline?.data, + pomsProjectBasicAll: pomsProjectBasicAll.data || [], + }; }