Background
The company’s equipment has always been in a state of no maintenance task schedule. When it is used, it is often found that the equipment is broken or abnormal and cannot be used. In order to solve this problem, this simple application was built to solve the equipment maintenance task plan management.
The basic functions are as follows:
1. Establish an equipment maintenance task list. One piece of equipment has multiple maintenance items, and each maintenance item has a corresponding maintenance person and maintenance time.
2. When the equipment maintenance project time is about to expire, the equipment maintenance process is automatically generated and sent to the corresponding maintenance person to perform the maintenance. After the maintenance is completed, the maintenance completion time and the next required maintenance time are written back to complete the maintenance cycle.
Involving OA module
1. Form modeling
2. Plan tasks
3. Process
Description of main functions
1. Modeling is mainly to establish an equipment maintenance task list. The interface is as follows:
Implement one maintenance task form for one device.
Note: A separate device number and hidden identification field need to be added to the details, which are used to write back data in the process and determine whether the planned task has been executed.
2. Set up a process and use the process to data function to write back information such as the next maintenance time and the most recent maintenance time. The process interface is as follows:
Note: The process can be built according to actual needs. As long as there are fields related to maintenance tasks and they can be used as write-backs later, a process number field is also hidden in the process details for the purpose of It can be used for matching when transferring data to the process.
When selecting a device number on the form, the device number hidden in the detail list will be automatically synchronized.
Use the formula function in the process.
The configuration of process archiving written back to the device task list is as follows:
1. Generate writeback based on maintenance effect conditions.
2. The operation type only updates, not adds, so the update condition is that the device numbers are consistent.
3. Write back in the detail table, the equipment number and maintenance item ID in the condition association detail. The identification here also needs to be written back, but there is no value assigned before, so a null value is written back (the main function is to identify the settings after the planned task is executed) If it is 1, it means that the planned task has been executed, and there is no need to execute the planned task again. However, after the maintenance is completed, the flag must be changed to empty, and the planned task can be executed again in the future).
4. Preparation of planned tasks
It mainly rewrites the scheduled task method and executes it once a day to determine whether there are any due maintenance items. If so, generate the process. The above parameters indicate how many days BeforeDays is used to generate the process before expiration. ErpDataSource is mainly our equipment information. It comes from ERP, so set up a data source for querying device information in the code.
The implementation code is as follows:
import weaver.conn.RecordSet; import weaver.conn.RecordSetDataSource; import weaver.conn.RecordSetTrans; import weaver.general.BaseBean; import weaver.interfaces.schedule.BaseCronJob; import weaver.soa.workflow.request.*; import java.text.SimpleDateFormat; import java.util.*; public class CJSBBYRWToWorkflowJob extends BaseCronJob {<!-- --> private String BeforeDays; public String getBeforeDays() {<!-- --> return BeforeDays; } public void setBeforeDays(String BeforeDays) {<!-- --> this.BeforeDays = BeforeDays; } private String ErpDataSource; public String getErpDataSource() {<!-- --> return ErpDataSource; } public void setErpDataSource(String ErpDataSource) {<!-- --> this.ErpDataSource = ErpDataSource; } @Override public void execute() {<!-- --> Map<String, String> result = new HashMap<String, String>(); try {<!-- --> int workflowid = 127; //Manufacturing-equipment maintenance order process id //------Please write the business logic code below------ //Get the person's name RecordSet rs = new RecordSet(); //Get the number of processes that need to be created, differentiate according to personnel rs.execute("select distinct sbbh,byr,dbo.GetUserName(byr)as lastname,departmentid,xcbyrq from uf_sbbyrw_dt1 B left join HrmResource A on B.byr=A.id where xcbyrq<=GETDATE() + " + BeforeDays + " and (bs is null or bs='')"); while (rs.next()) {<!-- --> Map<String, String> mainMap = new HashMap<String, String>(); List<Map<String, String>> detailMapsList = new ArrayList<Map<String, String>>(); //Get main table data //02. Create the structure needed for the process based on data combination String creator = rs.getString("byr"); Date date=new Date(); SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); String sqrq = ft.format(date); //Application date String sbbh = rs.getString("sbbh"); String byr = rs.getString("byr"); String sqbm = rs.getString("departmentid"); String title = "Manufacturing-Equipment Maintenance Order" + "-" + rs.getString("lastname") + "-" + sqrq + "-" + sbbh; RecordSetDataSource rs1=new RecordSetDataSource(ErpDataSource); rs1.execute("select MJ005,MJ006,MJ029 FROM EQTMJ WHERE MJ002='" + sbbh + "'" ); if(rs1.next()) {<!-- --> //Determine whether the form header content exists String sbmc = rs1.getString("MJ006"); String sbxh = rs1.getString("MJ005"); String sydd = rs1.getString("MJ029"); //02. Create the structure needed for the process based on data combination mainMap.put("sqr", byr); //applicant mainMap.put("sqrq", sqrq);//Application date mainMap.put("sqbm", sqbm);//Application department mainMap.put("sbbh", sbbh);//Device number mainMap.put("sbmc", sbmc);//Device name mainMap.put("sbxh", sbxh);//Device model // mainMap.put("bz", "");//Remarks mainMap.put("sydd", sydd);//Use location // mainMap.put("byxg", "");//Maintenance effect RecordSet rs2 = new RecordSet(); //Get detailed content rs2.execute("select id,byxm,byyqsm,xcbyrq from uf_sbbyrw_dt1 where sbbh='" + sbbh + "' and byr='" + byr + "' and xcbyrq<=GETDATE() + " + BeforeDays + " and ( bs is null or bs='')"); while (rs2.next()) {<!-- --> Map<String, String> detailMap = new HashMap<String, String>(); //You must use some method to create a new one, you cannot use it directly later detailMap.clear(); String byxm = rs2.getString("id"); String byyqsm = rs2.getString("byyqsm"); String jhbyrq =rs2.getString("xcbyrq"); detailMap.put("byxm",byxm);//Maintenance item ID detailMap.put("byyqsm",byyqsm);//Maintenance requirements instructions detailMap.put("jhbyrq",jhbyrq);//Planned maintenance date detailMap.put("sbbh",sbbh);//Device number // detailMap.put("byjg","");//Maintenance results detailMap.put("byblxgscs","");//Measures when maintenance fails detailMap.put("wcbyrq","");//Complete maintenance date // detailMap.put("sfjswc","");//Whether it is completed in time detailMap.put("xcbyrq","");//Next maintenance date detailMap.put("byjgsm","");//Explanation of maintenance results // detailMap.put("byxg","");//Maintenance effect detailMap.put("bs",""); //Identification, judgment detailMapsList.add(detailMap); //Add to LIST } //03. Create a process based on detailed loops. RequestInfo workflowrequestInfo = WorkFlowUtil.getRequestInfo(Integer.toString(workflowid),creater, title, mainMap, detailMapsList); RequestService requestService = new RequestService(); String requestId = requestService.createRequest(workflowrequestInfo); (new BaseBean()).writeLog("Result of creating equipment maintenance process: " + requestId); if (requestId.indexOf("-")>=0) {<!-- --> (new BaseBean()).writeLog("Exception: Failed to call the interface and cannot create the process"); }else{<!-- --> RecordSetTrans rst = new RecordSetTrans(); rst.setAutoCommit(false); try {<!-- --> rst.executeUpdate("update uf_sbbyrw_dt1 set bs='1' where sbbh='" + sbbh + "' and byr='" + byr + "' and xcbyrq<=GETDATE() + " + BeforeDays + " and (bs is null or bs='')");//The maintenance item identification after creating the process is set to 1 //Manually submit transaction rst.commit(); } catch (Exception e) {<!-- --> //Execution failed, rollback data rst.rollback(); e.printStackTrace(); } } mainMap.clear(); detailMapsList.clear(); } } } catch (Exception e) {<!-- --> (new BaseBean()).writeLog("Exception: Failed to call the interface and cannot create the process"); } } }
Remarks: The code involves a process data formatting tool WorkFlowUtil. Please refer to the following article “Pan Micro Startup Process JAVA Code”
Copyright statement: This article is an original article by CSDN blogger “Dream in Xitian” and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement when reprinting.
Original link: https://blog.csdn.net/flying86/article/details/119887985
That’s all. If you have any questions, please leave a message.