diff --git a/javascript/common/Utils.js b/javascript/common/Utils.js new file mode 100644 index 0000000..700864e --- /dev/null +++ b/javascript/common/Utils.js @@ -0,0 +1,141 @@ +window.Utils = { + /** + * @author youhong.ai + * @desc 发起请求 + */ + request: function (url, type = "GET", data, isAsync = true, success = () => { + }, error = () => { + }, complete = () => { + }, contentType = 'application/json', beforeSend = () => { + }) { + let options = { + url, + type, + dataType: "json", + contentType, + async: isAsync, + data, + beforeSend, + success, + error, + complete, + } + if (contentType == 'application/json') { + options.data = JSON.stringify(data) + } + return $.ajax(options) + }, + + /** + * @author youhong.ai + * @desc 发起请求 + */ + api: function (requestOptions = { + url: "", + type: "GET", + data: "", + isAsync: true, + success: () => { + }, + error: () => { + }, + complete: () => { + }, + contentType: 'application/json', + beforeSend: () => { + } + }) { + let options = Object.assign({ + url: "", + type: "GET", + data: "", + isAsync: true, + success: () => { + }, + error: () => { + }, + complete: () => { + }, + contentType: 'application/json', + beforeSend: () => { + } + }, requestOptions) + return $.ajax(options) + }, + + /** + * @author youhong.ai + * @desc 获取react组件实例 + */ + findReact: function (dom, traverseUp = 0) { + const key = Object.keys(dom).find(key => { + return key.startsWith("__reactFiber$") // react 17+ + || key.startsWith("__reactInternalInstance$") + || key.startsWith("__reactEventHandlers$"); // react <17 + }); + const domFiber = dom[key]; + if (domFiber == null) return null; + // react <16 + if (domFiber._currentElement) { + let compFiber = domFiber._currentElement._owner; + for (let i = 0; i < traverseUp; i++) { + compFiber = compFiber._currentElement._owner; + } + return compFiber._instance; + } + // react 16+ + const GetCompFiber = fiber => { + let parentFiber = fiber.return; + while (typeof parentFiber.type == "string") { + parentFiber = parentFiber.return; + } + return parentFiber; + }; + let compFiber = GetCompFiber(domFiber); + for (let i = 0; i < traverseUp; i++) { + compFiber = GetCompFiber(compFiber); + } + return compFiber.stateNode; + }, + + + /** + * 转换字段名为字段ID + * @param fieldName 字段名称 + * @returns {*|string} + */ + convertNameToIdUtil: function (fieldName) { + let fieldIds = []; + if (fieldName instanceof Array) { + fieldName.forEach(item => { + fieldIds.push(Utils.convertNameObjToId(item)) + }) + return fieldIds.join(',') + } + return Utils.convertNameObjToId(fieldName) + }, + + /** + * 将字段名称转为字段id + * @param fieldObj 字段名称对象 {string|object} + * @returns {*} + */ + convertNameObjToId: function (fieldObj = {fieldName: '', table: 'main'}) { + if (typeof fieldObj === 'object') { + return WfForm.convertFieldNameToId(fieldObj.fieldName, fieldObj.table) + } + return WfForm.convertFieldNameToId(fieldObj) + }, + + /** + * 根据字段名称查询字段值 + * @param fieldName 字段名称 + * @param rowIndex 明细行下表(明细获取才传递) + * @returns {*} 字段值 + */ + getFiledValueByName: function (fieldName, rowIndex) { + return WfForm.getFieldValue(Utils.convertNameObjToId(fieldName) + rowIndex ? '_' + rowIndex : '') + } + + +} diff --git a/javascript/youhong.ai/pcn/dev.js b/javascript/common/dev.js similarity index 58% rename from javascript/youhong.ai/pcn/dev.js rename to javascript/common/dev.js index 0cdfdb8..3956a6f 100644 --- a/javascript/youhong.ai/pcn/dev.js +++ b/javascript/common/dev.js @@ -27,7 +27,7 @@ WfForm.OPER_SAVECOMPLETE = '保存后页面跳转前 KB900210501' WfForm.OPER_WITHDRAW = '撤回 KB900201101' WfForm.OPER_CLOSE = '页面关闭' -WfForm.registerCheckEvent = (type, callback) => { +WfForm.registerCheckEvent = (type, callback = (callback) = {}) => { // WfForm.registerCheckEvent(WfForm.OPER_SAVE+","+WfForm.OPER_SUBMIT,function(callback){ // //... 执行自定义逻辑 // callback(); @@ -66,7 +66,8 @@ WfForm.getFieldValue = function (fieldMark) { // var fieldvalue = WfForm.getFieldValue("field110"); } -WfForm.bindFieldChangeEvent = function (fieldMarkStr, funobj) { +WfForm.bindFieldChangeEvent = function (fieldMarkStr, funobj = (obj, id, value) => { +}) { // fieldMarkStr String 是 绑定字段标示,可多个拼接逗号隔开,例如:field110(主字段),field111_2(明细字段)…… // funobj Function 是 字段值变化触发的自定义函数,函数默认传递以下三个参数,参数1:触发字段的DOM对象,参数2:触发字段的标示(field27555等),参数3:修改后的值 // WfForm.bindFieldChangeEvent("field27555,field27556", function (obj, id, value) { @@ -74,5 +75,64 @@ WfForm.bindFieldChangeEvent = function (fieldMarkStr, funobj) { // }); } +WfForm.controlBtnDisabled = function (isDisabled) { + // isDisabled boolean 是 true:按钮全部置灰不可操作,false:恢复按钮可操作状态 + // function subimtForm(params){ + // WfForm.controlBtnDisabled(true); //操作按钮置灰 + // ... + // WfForm.controlBtnDisabled(false); + // } +} + + +WfForm.showMessage = function (msg, type, duration) { + // 参数 参数类型 必须 说明 + // msg String true 提示信息内容 + // type int false 提示类型,1(警告)、2(错误)、3(成功)、4(一般),默认为1,不同类型提示信息效果不同 + // duration Float false 多长时间自动消失,单位秒,默认为1.5秒 + // WfForm.showMessage("结束时间需大于开始时间"); //警告信息,1.5s后自动消失 + // WfForm.showMessage("运算错误", 2, 10); //错误信息,10s后消失 + +} + +WfForm.getBaseInfo = function () { +// console.log(WfForm.getBaseInfo()); //返回当前请求基础信息 +// //输出对象说明: + return { + f_weaver_belongto_userid: "5240", //用户信息 + f_weaver_belongto_usertype: "0", + formid: -2010, //表单id + isbill: "1", //新表单/老表单 + nodeid: 19275, //节点id + requestid: 4487931, //请求id + workflowid: 16084, //路径id + } +} + +WfForm.changeFieldValue = function (fieldMark, valueInfo) { + // fieldMark String 是 字段标示,格式field${字段ID}_${明细行号} + // valueInfo JSON 是 字段值信息,非浏览按钮字段格式为{value:”修改的值”};specialobj为浏览按钮信息,数组格式;showhtml属性只在单行文本类型且只读情况下生效; + //修改文本框、多行文本、选择框等字段类型 +// WfForm.changeFieldValue("field123", {value:"1.234"}); +// //修改浏览框字段的值,必须有specialobj数组结构对象 +// WfForm.changeFieldValue("field11_2", { +// value: "2,3", +// specialobj:[ +// {id:"2",name:"张三"}, +// {id:"3",name:"李四"} +// ] +// }); +// //修改check框字段(0不勾选、1勾选) +// WfForm.changeFieldValue("field123", {value:"1"}); +// //针对单行文本框字段类型,只读情况,支持显示值跟入库值不一致 +// WfForm.changeFieldValue("field123", { +// value: "入库真实值", +// specialobj: { +// showhtml: "界面显示值" +// } +// }); +} + + diff --git a/javascript/youhong.ai/fentian/ecode/workflow_controller.js b/javascript/youhong.ai/fentian/ecode/workflow_controller.js new file mode 100644 index 0000000..1279b85 --- /dev/null +++ b/javascript/youhong.ai/fentian/ecode/workflow_controller.js @@ -0,0 +1,158 @@ +/* ******************* 丰田纺织流程代码块 可选择流程中的字段配置流程标题生成规则******************* */ + +class ConfigWorkflowTitle { + + constructor(config) { + this.config = config + console.log(config) + } + + + /** + * 初始化参数 + */ + init = () => { + console.log("init") + let baseInfo = WfForm.getBaseInfo(); + if (baseInfo.workflowid != this.config.workflowId) { + return + } + let filedArr = [] + console.log("jahh") + this.config.rules.filter(item => item.type === RulesType.FIELD_VALUE + || item.type === RulesType.SELECT_VALUE + || item.type === RulesType.RADIO_VALUE).forEach(item => filedArr.push(item.fieldName)) + console.log("bind", filedArr) + this.addListenerEvent(filedArr) + } + + /** + * 修改流程标题字段值 + */ + changeWorkflowTitle = () => { + let workflowTitle = [] + this.config.rules.forEach(item => { + workflowTitle.push(item.type.run(item)) + }) + WfForm.changeFieldValue(this.config.titleFieldName === 'field-1' ? 'field-1' : + Utils.convertNameToIdUtil(this.config.titleFieldName), { + value: workflowTitle.join("") + }) + } + + /** + * 添加监听方法 + * @param fileNameArr 需要监听的字段数组 + */ + addListenerEvent = (fileNameArr) => { + console.log(Utils.convertNameToIdUtil(fileNameArr)) + WfForm.bindFieldChangeEvent(Utils.convertNameToIdUtil(fileNameArr), (obj, id, value) => { + this.changeWorkflowTitle() + }) + } + +} + +class RulesType { + // 固定值 + static FIX_STRING = { + value: 0, + run: item => item.value + } + // 字段值 + static FIELD_VALUE = { + value: 1, + run: item => Utils.getFiledValueByName(item.fieldName) + } + // 下拉框显示值 + static SELECT_VALUE = { + value: 2, + run: item => $(`div[data-fieldname='${item.fieldName}'] .ant-select-selection-selected-value`).text() + } + // 单选按钮 + static RADIO_VALUE = { + value: 3, + run: item => $(`div[data-fieldname='${item.fieldName}'] .ant-radio.ant-radio.ant-radio-checked.ant-radio-checked`).next().text() + } + // 当前日期 yyyy-mm-dd + static CURRENT_DATE = { + value: 4, + run: () => { + const date = new Date(); + let year = date.getFullYear(); + let month = date.getMonth() + 1; + let day = date.getDay(); + return year + "-" + month + "-" + day + } + } + // 当前时间 HH:mm:ss + static CURRENT_TIME = { + value: 5, + run: () => { + const date = new Date(); + let hours = date.getHours(); + let minutes = date.getMinutes(); + let seconds = date.getSeconds(); + return hours + ":" + minutes + ":" + seconds + } + } + // 当前年份 + static CURRENT_YEAR = { + value: 6, + run: () => new Date().getFullYear() + + } + // 当前月份 + static CURRENT_MONTH = { + value: 7, + run: () => new Date().getMonth() + 1 + + } + // 当前天数 + static CURRENT_DAY = { + value: 8, + run: () => new Date().getDay() + + } + // 当前小时 + static CURRENT_HOUR = { + value: 9, + run: () => new Date().getHours() + + } + // 当前分钟 + static CURRENT_MINUTE = { + value: 10, + run: () => new Date().getMinutes() + + } + // 当前秒数 + static CURRENT_SECOND = { + value: 11, + run: () => new Date().getSeconds() + } + // 当前时间戳 + static CURRENT_TIME_STAMP = { + value: 12, + run: () => new Date().getTime() + } + // 流水号 + static RANDOM = { + value: 13, + run: item => { + let result = [] + let range = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] + for (let i = 0; i < item.length; i++) { + let index = parseInt(Math.random(0, 10) * 10) + result.push(range[index]) + } + return result.join("") + } + } +} + + +window.RulesType = RulesType +window.ConfigWorkflowTitle = ConfigWorkflowTitle + +/* ******************* 可选择流程中的字段配置流程标题生成规则 end ******************* */ \ No newline at end of file diff --git a/javascript/youhong.ai/fentian/workflow_code_block.js b/javascript/youhong.ai/fentian/workflow_code_block.js new file mode 100644 index 0000000..5bb77b3 --- /dev/null +++ b/javascript/youhong.ai/fentian/workflow_code_block.js @@ -0,0 +1,29 @@ +/* ******************* youhong.ai 丰田纺织流程代码块 可选择流程中的字段配置流程标题生成规则******************* */ + +$(() => { + let workflowTitleConfig = { + workflowId: '44', + titleFieldName: 'field-1', + rules: [{ + type: RulesType.CURRENT_DATE + }, + { + type: RulesType.FIX_STRING, + value: '-' + }, { + type: RulesType.FIELD_VALUE, + fieldName: 'mc' + }, { + type: RulesType.FIELD_VALUE, + fieldName: 'sjid' + }, { + type: RulesType.RANDOM, + length: 5 + }, { + type: RulesType.RANDOM, + length: 5 + }] + } + new ConfigWorkflowTitle(workflowTitleConfig).init() +}) +/* ******************* 可选择流程中的字段配置流程标题生成规则 end ******************* */ diff --git a/javascript/youhong.ai/pcn/Utils.js b/javascript/youhong.ai/pcn/Utils.js deleted file mode 100644 index abe0dac..0000000 --- a/javascript/youhong.ai/pcn/Utils.js +++ /dev/null @@ -1,40 +0,0 @@ -$(() => { - /** - * @author youhong.ai - * @desc 获取react组件实例 - */ - function findReact(dom, traverseUp = 0) { - const key = Object.keys(dom).find(key => { - return key.startsWith("__reactFiber$") // react 17+ - || key.startsWith("__reactInternalInstance$") // react <17 - }); - const domFiber = dom[key]; - if (domFiber == null) return null; - // react <16 - if (domFiber._currentElement) { - let compFiber = domFiber._currentElement._owner; - for (let i = 0; i < traverseUp; i++) { - compFiber = compFiber._currentElement._owner; - } - return compFiber._instance; - } - // react 16+ - const GetCompFiber = fiber => { - let parentFiber = fiber.return; - while (typeof parentFiber.type == "string") { - parentFiber = parentFiber.return; - } - return parentFiber; - }; - let compFiber = GetCompFiber(domFiber); - for (let i = 0; i < traverseUp; i++) { - compFiber = GetCompFiber(compFiber); - } - return compFiber.stateNode; - } - - window.Utils = { - findReact, - } - -}) diff --git a/javascript/youhong.ai/pcn/workflow_code_block.js b/javascript/youhong.ai/pcn/workflow_code_block.js index 2e07303..2eab958 100644 --- a/javascript/youhong.ai/pcn/workflow_code_block.js +++ b/javascript/youhong.ai/pcn/workflow_code_block.js @@ -13,9 +13,13 @@ function doNotClickSubmit() { } if (submitButton.length !== 0) { let buttonReact = window.Utils.findReact(submitButton[0]) - console.log(buttonReact) - buttonReact.props.disabled = true - buttonReact.setState({disabled: true}) + let rightBtn = Utils.findReact($(".ant-menu-item.text-elli[ecid='_Route@vmt0lk_Comp@upn4fo_WeaRightMenu@1ok9r0_Item@eu37n0_li@zyccqn']")[0]) + setTimeout(() => { + buttonReact.props.disabled = true + buttonReact.setState({}) + rightBtn.props.disabled = true + rightBtn.setState({}) + }, 100) } } @@ -32,21 +36,21 @@ function allowClickSubmit() { submitButton = $("#weareqtop_9v5e5i_1670481049632 div.ant-row.wea-new-top-req div.ant-col-xs-18.ant-col-sm-18.ant-col-md-16.ant-col-lg-14 button[title='提交'],[title='Submit '],[title='Submit']") } if (submitButton.length !== 0) { + WfForm.controlBtnDisabled(false) let buttonReact = window.Utils.findReact(submitButton[0]) - console.log(buttonReact) buttonReact.props.disabled = false - buttonReact.setState({disabled: false}) + buttonReact.setState({}) } } /** * 监听qzhj字段值改变 + * @author youhong.ai * @param id 字段id * @param value 字段值 * @param obj 字段值对象 */ -function onQzhjFieldChangeValue(id, value, obj) { - console.log(value) +function onQzhjFieldChangeValue(obj, id, value) { if (value != '100') { doNotClickSubmit() } else { @@ -56,18 +60,70 @@ function onQzhjFieldChangeValue(id, value, obj) { /** * 检查qzhj字段值 + * @author youhong.ai * @param fieldId qzhj字段id */ function checkOnQzhJfiedlChangeValue(fieldId) { let value = WfForm.getFieldValue(fieldId); - onQzhjFieldChangeValue(null, value) + onQzhjFieldChangeValue(null, null, value) +} + + +/** + * 检查提交按钮是否符合条件 + * @author youhong.ai + * @param fieldId 字段id + * @returns {(function(function()=): void)|*} + */ +function checkClickSubmit(fieldId) { + return (callback = () => { + }) => { + let value = WfForm.getFieldValue(fieldId); + if (value != 100) { + WfForm.showMessage("~`~`7 目标设定的总值必须是100%,请检查并修改后提交。 " + "`~`8 The total value of target setting must be 100%,please check to submit after modification! " + "`~`9 目标设定的总值必须是100%,请检查并修改后提交。`~`~", 2, 5); + } else { + callback() + } + } +} + +/** + * 保存按钮触发流程转数据 + * @author youhong.ai + * @param callback 保存后页面跳转前回调 + */ +async function saveTriggerWorkflowToModel() { + let baseInfo = WfForm.getBaseInfo() + if (baseInfo && baseInfo.requestid != '-1') { + let result = await Utils.api({ + url: "/api/aiyh/workflow/target-setting/save-trigger", + type: "POST", + contentType: "application/json", + data: JSON.stringify({requestId: baseInfo.requestid}) + }) + if (result && result.code === 200) { + localStorage.setItem("saveTriggerWorkflowToModel", "false") + } + } +} + + +function saveAfterCallback(callback) { + localStorage.setItem("saveTriggerWorkflowToModel", "true") + callback() } $(() => { let qzhjFieldId = WfForm.convertFieldNameToId("qzhj") checkOnQzhJfiedlChangeValue(qzhjFieldId) + WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, checkClickSubmit(qzhjFieldId)) + WfForm.registerCheckEvent(WfForm.OPER_SAVECOMPLETE, saveAfterCallback) WfForm.bindFieldChangeEvent(qzhjFieldId, onQzhjFieldChangeValue) + let flag = localStorage.getItem("saveTriggerWorkflowToModel") + if (flag === "true") { + saveTriggerWorkflowToModel() + } }) /* ******************* 保时捷target setting流程提交控制 end ******************* */ diff --git a/src/main/java/com/api/youhong/ai/pcn/workflow/doworkflowtomodel/controller/TriggerWorkflowToModelController.java b/src/main/java/com/api/youhong/ai/pcn/workflow/doworkflowtomodel/controller/TriggerWorkflowToModelController.java new file mode 100644 index 0000000..21df1b6 --- /dev/null +++ b/src/main/java/com/api/youhong/ai/pcn/workflow/doworkflowtomodel/controller/TriggerWorkflowToModelController.java @@ -0,0 +1,49 @@ +package com.api.youhong.ai.pcn.workflow.doworkflowtomodel.controller; + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import com.api.youhong.ai.pcn.workflow.doworkflowtomodel.service.TriggerWorkflowToModelService; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import org.apache.log4j.Logger; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.Map; + +/** + *
create: 2022-12-08 18:09
+ * + * @author youHong.ai + */ + +@Path("/aiyh/workflow/target-setting") +public class TriggerWorkflowToModelController { + + private final TriggerWorkflowToModelService service = new TriggerWorkflowToModelService(); + private final Logger logger = Util.getLogger(); + + @Path("/save-trigger") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String saveTriggerWorkflowToModel(@RequestBody Mapcreate: 2022-12-09 22:26
+ * + * @author youHong.ai + */ + +@SqlMapper +public interface TriggerWorkflowToModelMapper { + + + /** + *create: 2022-12-09 10:49
+ * + * @author youHong.ai + */ + +public class TriggerWorkflowToModelService { + private final RequestService service = new RequestService(); + + private final TriggerWorkflowToModelMapper mapper = Util.getMapper(TriggerWorkflowToModelMapper.class); + + public String saveTriggerWorkflowToModel(Map