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/models/form_data_table.js b/api/app/lib/models/form_data_table.js index 34613f4..4166237 100644 --- a/api/app/lib/models/form_data_table.js +++ b/api/app/lib/models/form_data_table.js @@ -9,11 +9,11 @@ module.exports = dc => { id: { type: DataTypes.INTEGER, allowNull: false, - defaultValue: "nextval(\"formDataTable_id_seq\"::regclass)", + defaultValue: null, comment: "id", primaryKey: true, field: "id", - autoIncrement: false + autoIncrement: true }, projectId: { type: DataTypes.INTEGER, diff --git a/api/app/lib/schedule/workOrder.js b/api/app/lib/schedule/workOrder.js index b573847..dd2a6c1 100644 --- a/api/app/lib/schedule/workOrder.js +++ b/api/app/lib/schedule/workOrder.js @@ -1,9 +1,11 @@ const schedule = require('node-schedule'); const moment = require('moment') +const request = require('superagent'); + let isDev = true -module.exports = function (app, opts) { +module.exports = function (app, opts,ctx) { const workOrder = app.fs.scheduleInit( { interval: '0 * * * *',//一小时执行一次 @@ -14,16 +16,18 @@ module.exports = function (app, opts) { try{ //前一次执行时间 console.log('工单数据抽取开始') + const username = "admin" + const password = "fs-workflow" let lastExecutionTime = null; const { parseProcessData } = app.fs.utils - const startTime = moment() + const startTime = moment().format('YYYY-MM-DD HH:mm:ss') const { models } = app.fs.dc const { clickHouse } = app.fs const { database: camWorkflow } = clickHouse.camWorkflow.opts.config //新建表是否有数据 const rescount=await models.FormDataTable.count() if (lastExecutionTime === null) { - lastExecutionTime = moment().subtract(1, 'hour'); + lastExecutionTime = moment().subtract(1, 'hour').format('YYYY-MM-DD HH:mm:ss') } const formRes = await clickHouse.pepEmis.query( `SELECT @@ -53,37 +57,48 @@ 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 - }) - for (let f of formRes) { + let procinstsVariables = await request.post(encodeURI(opts.camundarest.host+'/'+opts.camundarest.root+`/engine-rest/history/variable-instance`)) + .auth(username, password) + .set('Content-Type', 'application/json') + .send({processInstanceIdIn: procinstIds}) + console.log('formRes2',procinstsVariables) + if(procinstsVariables.body&&procinstsVariables.body.length){ + 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.FormDataTable.create({ projectId:parseData.pomsProjectId.value || null, - formname:procinstsVariables.find(item=>item.id===f.procinstId).name||null, + formname:procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName') ? procinstsVariables.body.find(t => t.name == 'fsEmisBusinessName').value : '', state: f.state||null, endTime:f.endTime||null, startTime:f.createTime||null }) + console.log('formRes3',res) console.log('工单数据抽取结束') } + }else{ + console.log('未查询到数据') + } + + }else{ + console.log('未查询到数据') } }catch(error){ - console.error(error) + console.error('失败原因',error) } } ); diff --git a/api/config.js b/api/config.js index 4a64382..d8b3d7a 100644 --- a/api/config.js +++ b/api/config.js @@ -206,6 +206,8 @@ const product = { { p: '/project/group/statistic/alarm', o: 'GET' }, { p: '/project/group/list', o: 'GET' }, { p: '/project/group/:groupId/detail', o: 'GET' }, + {p:'/project/workOrders/repairRank',o:'GET'}, + {p:'/project/workOrders',o:'GET'} ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 apMergeDeVeAnxinProjectId: AP_MERGE_DEVE_ANXINPROJECT_ID, anxinCloud: { 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..7b5d530 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()//所有的告警数据 @@ -36,6 +36,7 @@ const Bigscreen = (props) => { useEffect(() => { + let groupIdLocal = JSON.parse(localStorage.getItem('project_group'))?.find(v => user?.id == v.userId)?.projectGroupId let search = restProps?.location?.search || ''; @@ -67,7 +68,11 @@ const Bigscreen = (props) => { setGroupDetail(res.payload.data) } }) - + dispatch(actions.workOrder.getPomsProjectBasicAll()).then(res => { + if (res.success) { + setAllProjects(res.payload.data) + } + }) @@ -135,27 +140,27 @@ const Bigscreen = (props) => { } }, [mockData]) -console.log('xxx1',actions) + useEffect(() => { - if(groupDetail?.pomsProjectIds&&groupDetail?.pomsProjectIds.length){ + 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,startTime:moment(v?.startTime).format('YYYY-MM-DD'),duration:moment(v?.endTime).add(8, 'hours').diff(v?.startTime,'hours') })) || []) } }) } - },[groupDetail]) + },[groupDetail,allProjects]) let statisticOnline = (groupId) => { dispatch(actions.projectGroup.groupStatisticOnline({ groupId })).then(res => { @@ -225,6 +230,7 @@ console.log('xxx1',actions) }, [proportion]); return (