qfrjava
2025-04-18 a1d8f2ba242f93decbeec31f0f8b2bc23510effc
feat(server): 添加工单管理功能

- 新增创建工单、更新工单状态和查询工单列表的接口
- 实现工单相关数据的数据库操作
- 添加定时任务检查工单状态变化
- 更新请求映射,支持新的工单管理接口
已修改4个文件
已添加1个文件
288 ■■■■■ 文件已修改
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTJavaAIControl.java 162 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/graph/SMTAIGraphNode.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/scheduledTasks/checkForTicketStatusChanges.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/web/SMTAIServerWebApplication.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JAVA/SMTAIServer/src/main/resources/requestmap/java_ai.json 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTJavaAIControl.java
@@ -1,19 +1,5 @@
package com.smtaiserver.smtaiserver.control;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.util.*;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.smtaiserver.smtaiserver.attach.SMTAIAttachMetricDef;
import com.smtaiserver.smtaiserver.attach.SMTAIAttachTableDef;
import com.smtaiserver.smtaiserver.attach.SMTAIAttachTableDef.SMTAIAttachTableColumn;
@@ -34,6 +20,18 @@
import com.smtservlet.util.Json;
import com.smtservlet.util.SMTJsonWriter;
import com.smtservlet.util.SMTStatic;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.util.*;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
public class SMTJavaAIControl 
{
@@ -298,6 +296,142 @@
        return tranReq.returnJson(jsonWr);
    }
    
    public ModelAndView createOrder(SMTAIServerRequest tranReq) throws Exception
    {
        String title = tranReq.convParamToString("title", true);
        String wstypeid = tranReq.convParamToString("wstypeid", false);
        String wstypename = tranReq.convParamToString("wstypename", false);
        String urgencylevel = tranReq.convParamToString("urgencylevel", false);
        String shape = tranReq.convParamToString("shape", false);
        String deadline = tranReq.convParamToString("deadline", false);
        String stepstatus = tranReq.convParamToString("stepstatus", false);
        String originatetypetext = tranReq.convParamToString("originatetypetext", false);
        String content = tranReq.convParamToString("content", false);
        String address = tranReq.convParamToString("address", false);
        String stepid = tranReq.convParamToString("stepid", false);
        String org = tranReq.convParamToString("org", false);
        String deptname = tranReq.convParamToString("deptname", false);
        String dealtime = tranReq.convParamToString("dealtime", false);
        String username = tranReq.convParamToString("username", false);
        String contactname = tranReq.convParamToString("contactname", false);
        String contactphone = tranReq.convParamToString("contactphone", false);
        String acceptuserid = tranReq.convParamToString("acceptuserid", false);
        String acceptusername = tranReq.convParamToString("acceptusername", false);
        String acceptuseraccount = tranReq.convParamToString("acceptuseraccount", false);
        String dealuserid = tranReq.convParamToString("dealuserid", false);
        String dealusername = tranReq.convParamToString("dealusername", false);
        String dealuseraccount = tranReq.convParamToString("dealuseraccount", false);
        String flowstatus = tranReq.convParamToString("flowstatus", false);
        String attachment = tranReq.convParamToString("attachment", false);
        String creator = tranReq.convParamToString("creator", false);
        String createtime = tranReq.convParamToString("createtime", false);
        String isplan = tranReq.convParamToString("isplan", false);
        String originateid = tranReq.convParamToString("originateid", false);
        String appointstarttime = tranReq.convParamToString("appointstarttime", false);
        String appointendtime = tranReq.convParamToString("appointendtime", false);
        String parentid = tranReq.convParamToString("parentid", false);
        String relateids = tranReq.convParamToString("relateids", false);
            SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
            try
            {
      db.executeSQL(
          "INSERT INTO work_order_list("
              + "order_id, title, wstypeid, wstypename, urgencylevel, shape, deadline, stepstatus, "
              + "originatetypetext, content, address, stepid, org, deptname, dealtime, username, contactname, "
              + "contactphone, acceptuserid, acceptusername, acceptuseraccount, dealuserid, dealusername, "
              + "dealuseraccount, flowstatus, attachment, creator, createtime, isplan, originateid, "
              + "appointstarttime, appointendtime, parentid, relateids,is_notify"
              + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)",
          new Object[] {
            SMTStatic.newUUID(),
            title,
            wstypeid,
            wstypename,
            urgencylevel,
            shape,
            deadline,
            stepstatus,
            originatetypetext,
            content,
            address,
            stepid,
            org,
            deptname,
            dealtime,
            username,
            contactname,
            contactphone,
            acceptuserid,
            acceptusername,
            acceptuseraccount,
            dealuserid,
            dealusername,
            dealuseraccount,
            flowstatus,
            attachment,
            creator,
            new Date(),
            isplan,
            originateid,
            appointstarttime,
            appointendtime,
            parentid,
            relateids,
            "N"
          });
            }catch (Exception e){
                throw new Exception("数据库错误", e);
            }
            return tranReq.returnJsonState(true, null, null);
    }
  public ModelAndView updateOrderStatus(SMTAIServerRequest tranReq) throws Exception {
    String id = tranReq.convParamToString("id", true);
    Integer stepstatus = tranReq.convParamToInteger("stepstatus", true); // çŠ¶æ€ä»£å·ï¼Œå¦‚å·²å®Œæˆ
    SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
    try {
      db.executeSQL(
          "UPDATE work_order_list SET stepstatus = ? and status_update_time = ?  WHERE id = ?",
          new Object[] {stepstatus,  new Date(),id});
    } catch (Exception e) {
      throw new Exception("更新工单状态失败", e);
    }
    return tranReq.returnJsonState(true, null, null);
  }
    public ModelAndView getOrderList(SMTAIServerRequest tranReq) throws Exception {
        SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
        try {
            DBRecords recs = db.querySQL("SELECT * FROM work_order_list", null);
            if (recs.getRowCount() != 0) {
                SMTJsonWriter jsonWr = new SMTJsonWriter(false);
                jsonWr.beginArray("values");  // å¼€å§‹ä¸€ä¸ªæ•°ç»„,key为 "values"
                for (DBRecord rec : recs.getRecords()) {
                    jsonWr.beginMap(null);  // æ¯æ¡è®°å½•是一个对象
                    for (String colName : rec.getColNames()) {
                        jsonWr.addKeyValue(colName, rec.getString(colName));  // æ·»åŠ æ¯ä¸ªå­—æ®µ
                    }
                    jsonWr.endMap();  // ç»“束一个对象
                }
                jsonWr.endArray();  // ç»“束数组
                return tranReq.returnJson(jsonWr);  // è¿”回整个结构
            } else {
                return tranReq.returnJsonState(false, "未找到工单", null);
            }
        } catch (Exception e) {
            throw new Exception("查询工单失败", e);
        }
    }
    public ModelAndView disconnectBroadcastChat(SMTAIServerRequest tranReq) throws Exception 
    {
        String userId = tranReq.getLoginUserId();
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/graph/SMTAIGraphNode.java
@@ -1,14 +1,13 @@
package com.smtaiserver.smtaiserver.graph;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.smtaiserver.smtaiserver.database.SMTDatabase;
import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecord;
import com.smtaiserver.smtaiserver.database.SMTDatabase.DBRecords;
import com.smtservlet.util.Json;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class SMTAIGraphNode
{
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/scheduledTasks/checkForTicketStatusChanges.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,47 @@
package com.smtaiserver.smtaiserver.scheduledTasks;
import com.smtaiserver.smtaiserver.core.SMTAIServerApp;
import com.smtaiserver.smtaiserver.database.SMTDatabase;
import java.util.Calendar;
import java.util.Date;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
 * è¿™ä¸ªç±»æ˜¯ï¼š
 *
 * @author: adeng
 * @date: 2025/4/17 17:03
 * @version: 1.0
 */
@Log4j2
@Component
public class checkForTicketStatusChanges {
  private static Logger _logger = LogManager.getLogger(checkForTicketStatusChanges.class);
  // ä¸€ç§’一次
  @Scheduled(cron = "0/1 * * * * ?")
  public void checkForTicketStatusChanges() throws Exception {
    _logger.info("start checkForTicketStatusChanges task");
    SMTDatabase db = SMTAIServerApp.getApp().allocDatabase();
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.MINUTE, -5);
    Date time = cal.getTime();
    try {
      SMTDatabase.DBRecords dbRecords =
          db.querySQL(
              "select * from work_order_list where is_notify =? and  status_update_time > ?",
              new Object[] {"N", time});
      _logger.info("查询到的数量:{}",dbRecords.getRowCount());
      dbRecords.getRecords().forEach(record -> {});
    } catch (Exception e) {
      _logger.error("checkForTicketStatusChanges error", e);
    }
  }
}
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/web/SMTAIServerWebApplication.java
@@ -4,9 +4,11 @@
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableAutoConfiguration
@EnableScheduling
@ComponentScan(basePackages = {"com.smtaiserver"})
public class SMTAIServerWebApplication
{
JAVA/SMTAIServer/src/main/resources/requestmap/java_ai.json
@@ -395,5 +395,73 @@
                ]
            }
        ]
    },
    "sys/create_order":{"map":{"class":"#SMTJavaAIControl", "method":"createOrder"}, "no_shrio":false,
            "swaggers":[
            {    "tags" : ["创建工单"],
                "title" : "创建工单",
                "parameters" : [
                    {"name": "title", "title": "标题", "required": true},
                    {"name": "wstypeid", "title": "类型编号", "required": false},
                    {"name": "wstypename", "title": "类型名称", "required": false},
                    {"name": "urgencylevel", "title": "紧急级别", "required": false},
                    {"name": "shape", "title": "派单坐标", "required": false},
                    {"name": "deadline", "title": "处理时限", "required": false},
                    {"name": "stepstatus", "title": "工单进度状态", "required": false},
                    {"name": "originatetypetext", "title": "来源类型", "required": false},
                    {"name": "content", "title": "内容", "required": false},
                    {"name": "address", "title": "地址", "required": false},
                    {"name": "stepid", "title": "工单步骤", "required": false},
                    {"name": "org", "title": "所属分公司", "required": false},
                    {"name": "deptname", "title": "工单所属部门名称", "required": false},
                    {"name": "dealtime", "title": "处理时间", "required": false},
                    {"name": "username", "title": "用户名称", "required": false},
                    {"name": "contactname", "title": "联系人", "required": false},
                    {"name": "contactphone", "title": "联系电话", "required": false},
                    {"name": "acceptuserid", "title": "接单人id", "required": false},
                    {"name": "acceptusername", "title": "接单人名称", "required": false},
                    {"name": "acceptuseraccount", "title": "接单人账号", "required": false},
                    {"name": "dealuserid", "title": "处理人id", "required": false},
                    {"name": "dealusername", "title": "处理人名称", "required": false},
                    {"name": "dealuseraccount", "title": "处理人账号", "required": false},
                    {"name": "flowstatus", "title": "工单状态", "required": false},
                    {"name": "attachment", "title": "附件", "required": false},
                    {"name": "creator", "title": "创建人", "required": false},
                    {"name": "createtime", "title": "创建时间", "required": false},
                    {"name": "isplan", "title": "是否计划工单", "required": false},
                    {"name": "originateid", "title": "来源编号", "required": false},
                    {"name": "appointstarttime", "title": "预约开始时间", "required": false},
                    {"name": "appointendtime", "title": "预约结束时间", "required": false},
                    {"name": "parentid", "title": "父级编号", "required": false},
                    {"name": "relateids", "title": "关联编号", "required": false}
                ]
            }
        ]
    },
    "sys/update_order_status":{
        "map":{"class":"#SMTJavaAIControl", "method":"updateOrderStatus"}, "no_shrio":false,
        "swaggers":[
            {
                "tags" : ["工单流转"],
                "title" : "更新工单状态",
                "parameters" : [
                    {"name": "id", "title": "工单ID", "required": true},
                    {"name": "stepstatus", "title": "工单状态代号", "required": true}
                ]
            }
        ]
    },
    "sys/get_order_list":{
        "map":{"class":"#SMTJavaAIControl", "method":"getOrderList"}, "no_shrio":false,
        "swaggers":[
            {
                "tags" : ["查询工单"],
                "title" : "根据ID查询工单",
                "parameters" : [
                ]
            }
        ]
    }
}