Commit d9071e9f authored by 彭俊龙's avatar 彭俊龙

feat:自动化工单方案优化时间计算

parent dada7c30
Pipeline #96514 failed with stages
......@@ -128,7 +128,7 @@ const CaseModify = props => {
} else if (planType === 'ByMonth' && timeType == 'week') {
setTip(getTipByWeek(timeValues, weekValues, weekValues1));
}
}, [timeUnit.current, num, timeValues, weekValues, dayValues]);
}, [timeUnit.current, num, timeValues, weekValues, dayValues, startTime]);
useEffect(() => {
if (visible) {
......@@ -432,33 +432,34 @@ const CaseModify = props => {
//计算循环的下次执行时间
const handleTimeInfo = (timeUnit, num) => {
if (startTime) {
setTip(startTime.add(num, timeUnit).format('YYYY-MM-DD HH:mm:ss'));
setTip(moment(startTime).add(num, timeUnit).format('YYYY-MM-DD HH:mm:ss'));
}
};
//计算下次执行时间每月按日
const getTipByDay = (dayVals, timeVals) => {
if (!timeVals.length || !dayVals.length) return;
const now = moment(startTime)
const times = timeVals.sort((a, b) => a - b);
if (dayVals.length == 1 && dayVals[0] === allDays[allDays.length - 1]) {
return moment()
return now
.endOf('month')
.hour(times[0])
.minute(0)
.second(0)
.format(`YYYY-MM-DD HH:mm:ss`);
}
const dayOfMonth = moment().date(); //当前第几天
const dayOfMonth = now.date(); //当前第几天
const dayvals = dayVals.sort((a, b) => a - b).filter(v => v >= dayOfMonth);
if (dayvals.length > 0) {
return moment()
return now
.hour(times[0])
.minute(0)
.second(0)
.format(`YYYY-MM-${dayvals[0] < 10 ? `0${dayvals[0]}` : dayvals[0]} HH:mm:ss`);
} else {
const days = dayVals.filter(v => v !== allDays[allDays.length - 1]);
return moment()
return now
.add(1, 'month')
.hour(times[0])
.minute(0)
......@@ -478,7 +479,7 @@ const CaseModify = props => {
};
const getNextDateByTierAndWeekday = (y, m, tier, weekday, timeVals) => {
let now = moment();
let now = moment(startTime);
let year = y || now.year();
let month = m || now.month() + 1; // 获取当前月份(1~12)
......@@ -526,34 +527,34 @@ const CaseModify = props => {
const weekObj = {};
weeks.forEach((v, i) => (weekObj[v] = i + 1));
const weekNum = weekObj[targetWeekday];
const today = moment();
const today = moment(startTime);
const nextDay =
today.isoWeekday() < weekNum
? today.isoWeekday(weekNum) // 本周还没到目标周几
: today.add(1, 'weeks').isoWeekday(weekNum); // 目标周几已过,跳到下周
return nextDay.format(`YYYY-MM-DD ${times[0]}:mm:ss`);
return nextDay.format(`YYYY-MM-DD ${times[0]}:00:00`);
};
//计算每天的下次请求时间
const getNextClosestTime = hourArray => {
if (!hourArray.length) return;
const timeArry = hourArray.sort((a, b) => a - b);
const now = moment();
const now = moment(startTime);
const currentHour = now.hour();
// 找到大于当前小时的最近时间
// const nextHour = timeArry.find(h => h > currentHour);
if (timeArry[0] > currentHour) {
return moment()
if (timeArry[0] >= currentHour) {
return now
.hour(timeArry[0])
.minute(0)
.second(0)
.format('YYYY-MM-DD HH:mm:ss');
} else {
// 如果所有时间都已经过了,返回明天的最早时间
return moment()
return now
.add(1, 'days')
.hour(timeArry[0])
.minute(0)
......@@ -978,32 +979,46 @@ const CaseModify = props => {
return;
}
console.log(e, 'eeeeeeee');
let list = ruleInfos;
if (person.length) {
list = list.map(v =>
v.id === (id || currentRuleId.current)
? {
...v,
userIds: person.map(x => {
return { id: Number(x.value), name: x.label };
}),
}
: v,
);
}
list = list.map(v =>
v.id === (id || currentRuleId.current)
? {
...v,
userIds: person.length > 0 ? person.map(x => {
return { id: Number(x.value), name: x.label };
}) : [] ,
userIds: person.length > 0 ? person.map(x => {
return { id: Number(x.value), name: x.label };
}) : [] ,
}
: v,
);
// if (person.length) {
// list = list.map(v =>
// v.id === (id || currentRuleId.current)
// ? {
// ...v,
// userIds: person.length > 0 ? person.map(x => {
// return { id: Number(x.value), name: x.label };
// }) : [] ,
// }
// : v,
// );
// }
if (role.length) {
list = list.map(v =>
v.id === (id || currentRuleId.current)
? {
...v,
roleIds: role.map(x => {
return { id: x.value, name: x.label };
}),
}
: v,
);
}
// if (role.length) {
// list = list.map(v =>
// v.id === (id || currentRuleId.current)
// ? {
// ...v,
// roleIds: role.length > 0 ? role.map(x => {
// return { id: x.value, name: x.label };
// }) : [],
// }
// : v,
// );
// }
setRuleInfos(list);
setShowPersonSelect(false);
} else if (type == 'rule') {
......@@ -1024,7 +1039,7 @@ const CaseModify = props => {
};
const hasValue = field => field !== undefined && field !== null && field.trim?.() !== '';
const isValid = () => {
const { schemeName, flowId, activityId, userIds } = configInfo;
const { schemeName, flowId, activityId, userIds, roleIds } = configInfo;
let schemeNameErrMsg = '';
let flowIdErrMsg = '';
let activityIdErrMsg = '';
......@@ -1049,7 +1064,7 @@ const CaseModify = props => {
} else {
activityIdErrMsg = '';
}
if (userIds.length < 1) {
if (userIds.length < 1 && roleIds.length < 1) {
userIdsErrMsg = '请选择下一节点办理人';
} else {
userIdsErrMsg = '';
......@@ -1066,7 +1081,7 @@ const CaseModify = props => {
isOk =
isOk &&
ruleInfos.every(
v => v.userIds.length > 0 && hasValue(v.ruleContent) && hasValue(v.ruleName),
v => (v.userIds.length > 0 || v.roleIds.length > 0) && hasValue(v.ruleContent) && hasValue(v.ruleName),
);
let infos = ruleInfos;
for (let i of infos) {
......@@ -1081,7 +1096,7 @@ const CaseModify = props => {
i.ruleContentErrMsg = '';
}
if (i.userIds.length < 1) {
if (i.userIds.length < 1 && i.roleIds.length < 1) {
i.userIdsErrMsg = '下一节点办理人必填';
} else {
i.userIdsErrMsg = '';
......@@ -1745,10 +1760,10 @@ const lineText = v => {
<span style={{ color: 'red' }}>{v.ruleContentErrMsg}</span>
<Button
block
style={{ color: '#1890ff', border: '1px solid #1890ff' }}
style={{ color: '#1890ff', border: '1px solid #1890ff', overflow: 'hidden' }}
onClick={() => handleRuleClick(() => setShowPersonSelect(true), v.id)}
>
{v.userIds.length ? v.userIds.map(v => v.name).join(',') : '选择下一节点办理人'}
{(v.userIds.length || v.roleIds.length) ? [...(v.userIds), ...(v.roleIds)].map(v => v.name).join(',') : '选择下一节点办理人'}
</Button>
<span style={{ color: 'red' }}>{v.userIdsErrMsg}</span>
</Space>
......@@ -1776,20 +1791,22 @@ const lineText = v => {
</Row>
<div
style={{
width: '500px',
width: '540px',
padding: '10px',
margin: '10px auto',
}}
>
<Space>
<span>开始时间:</span>
<DatePicker locale={locale} value={startTime} onChange={t => setStartTime(t)} />
<DatePicker showTime={{
format: 'HH'
}} locale={locale} format={'YYYY-MM-DD HH:00'} value={startTime} onChange={t => setStartTime(t)} />
<span>结束时间:</span>
<DatePicker locale={locale} value={endTime} onChange={t => setEndTime(t)} />
</Space>
<div
style={{
width: '500px',
width: '540px',
background: 'rgb(243, 243, 243)',
padding: '10px',
margin: '10px auto',
......
......@@ -141,6 +141,7 @@ const AutoCase = props => {
{
align: 'center',
title: '操作',
fixed: 'right',
render: (text, record, i) => {
return (
<Space size={'middle'} direction={'horizontal'}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment