|
|
@@ -4,20 +4,29 @@ import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
|
|
|
import com.actionsoft.bpms.server.bind.annotation.Controller;
|
|
|
import com.actionsoft.bpms.server.bind.annotation.Mapping;
|
|
|
import com.actionsoft.bpms.server.UserContext;
|
|
|
-import com.actionsoft.bpms.commons.database.RowMap;
|
|
|
-import com.actionsoft.bpms.util.DBSql;
|
|
|
-import com.actionsoft.sdk.local.SDK;
|
|
|
import com.actionsoft.bpms.bo.engine.BO;
|
|
|
+import com.actionsoft.sdk.local.SDK;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
|
public class testController {
|
|
|
-
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(testController.class);
|
|
|
+ private static final String RICH_TEXT_FIELD = "RESOLUTION";
|
|
|
+ private static final String BO_TABLE = "BO_EU_DNSDK_TASK";
|
|
|
+ private static final String CONTENT_SEPARATOR = "<br/><br/>";
|
|
|
+ private static final String PARAGRAPH_START = "<p>";
|
|
|
+ private static final String PARAGRAPH_END = "</p>";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 富文本字段更新接口:先获取原有内容,再拼接新内容
|
|
|
+ */
|
|
|
@Mapping(value = "com.awspaas.user.apps.donenow_tst_updatex")
|
|
|
public ResponseObject updateResolution(UserContext uc, String id, String newSolution) {
|
|
|
- // 参数校验
|
|
|
if (StringUtils.isBlank(id)) {
|
|
|
return ResponseObject.newErrResponse("ID不能为空");
|
|
|
}
|
|
|
@@ -26,47 +35,81 @@ public class testController {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- // 1. 查询当前解决方案(仅获取需要的字段)
|
|
|
- String querySql = "select RESOLUTION from BO_EU_DNSDK_TASK where ID = ?";
|
|
|
- RowMap rowMap = DBSql.getMap(querySql, new Object[]{id});
|
|
|
-
|
|
|
- // 2. 检查记录是否存在
|
|
|
- if (rowMap == null) {
|
|
|
+ BO bo = SDK.getBOAPI().get(BO_TABLE, id);
|
|
|
+ if (bo == null) {
|
|
|
+ logger.warn("未找到ID为【{}】的记录,无法获取富文本内容", id);
|
|
|
return ResponseObject.newErrResponse("未找到ID为【" + id + "】的记录");
|
|
|
}
|
|
|
|
|
|
- // 3. 拼接新旧内容
|
|
|
- String currentResolution = rowMap.getString("RESOLUTION");
|
|
|
- String updatedResolution = StringUtils.isNotBlank(currentResolution)
|
|
|
- ? currentResolution + " " + newSolution
|
|
|
- : newSolution;
|
|
|
+ String currentContent = bo.getString(RICH_TEXT_FIELD);
|
|
|
+ currentContent = StringUtils.defaultString(currentContent).trim();
|
|
|
+ logger.debug("获取到ID为【{}】的富文本原始内容:{}", id, currentContent);
|
|
|
+
|
|
|
+ String formattedNewContent = formatNewContent(newSolution);
|
|
|
+
|
|
|
+ String finalContent =拼接内容(currentContent, formattedNewContent);
|
|
|
|
|
|
- // 4. 使用BOAPI更新(仅修改RESOLUTION字段,其他字段不变)
|
|
|
- BO bo = SDK.getBOAPI().get("BO_EU_DNSDK_TASK", id); // 获取BO对象
|
|
|
- bo.set("RESOLUTION", updatedResolution); // 仅更新需要修改的字段
|
|
|
- int updateCount = SDK.getBOAPI().update("BO_EU_DNSDK_TASK", bo); // 执行更新
|
|
|
+ bo.set(RICH_TEXT_FIELD, finalContent);
|
|
|
+ int updateCount = SDK.getBOAPI().update(BO_TABLE, bo);
|
|
|
|
|
|
- // 5. 处理更新结果
|
|
|
if (updateCount <= 0) {
|
|
|
- return ResponseObject.newErrResponse("ID为【" + id + "】的记录更新失败(无变更或异常)");
|
|
|
+ logger.warn("ID为【{}】的富文本更新失败", id);
|
|
|
+ return ResponseObject.newErrResponse("富文本更新失败,无有效变更");
|
|
|
}
|
|
|
|
|
|
- // 6. 封装返回数据
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("updatedResolution", updatedResolution);
|
|
|
+ Map<String, Object> result = new HashMap<>(4);
|
|
|
result.put("id", id);
|
|
|
+ result.put("originalContent", currentContent);
|
|
|
+ result.put("updatedContent", finalContent);
|
|
|
+ result.put("updateTime", System.currentTimeMillis());
|
|
|
|
|
|
- // 7. 返回成功响应
|
|
|
- ResponseObject responseObject = ResponseObject.newOkResponse();
|
|
|
- responseObject.setData(result);
|
|
|
- return responseObject;
|
|
|
+ ResponseObject response = ResponseObject.newOkResponse();
|
|
|
+ response.setData(result);
|
|
|
+ return response;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- // 捕获并返回异常信息
|
|
|
+ logger.error("富文本更新异常,ID:{}", id, e);
|
|
|
return ResponseObject.newErrResponse("更新失败:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 拼接新旧富文本内容
|
|
|
+ * @param currentContent 现有内容
|
|
|
+ * @param newContent 新内容
|
|
|
+ * @return 拼接后的完整内容
|
|
|
+ */
|
|
|
+ private String 拼接内容(String currentContent, String newContent) {
|
|
|
+ // 如果现有内容为空,直接返回新内容
|
|
|
+ if (currentContent.isEmpty()) {
|
|
|
+ return newContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果现有内容以段落结束标签结尾,在其前面插入新内容
|
|
|
+ if (currentContent.endsWith(PARAGRAPH_END)) {
|
|
|
+ int endIndex = currentContent.lastIndexOf(PARAGRAPH_END);
|
|
|
+ return currentContent.substring(0, endIndex) +
|
|
|
+ newContent +
|
|
|
+ PARAGRAPH_END;
|
|
|
+ } else {
|
|
|
+ // 其他情况直接拼接
|
|
|
+ return currentContent + CONTENT_SEPARATOR + newContent;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 格式化新内容,确保富文本格式正确
|
|
|
+ */
|
|
|
+ private String formatNewContent(String newContent) {
|
|
|
+ String trimmedContent = newContent.trim();
|
|
|
+ // 如果新内容已经包含段落标签,直接返回
|
|
|
+ if (trimmedContent.startsWith(PARAGRAPH_START) && trimmedContent.endsWith(PARAGRAPH_END)) {
|
|
|
+ return trimmedContent;
|
|
|
+ }
|
|
|
+ // 否则添加段落标签
|
|
|
+ return PARAGRAPH_START + trimmedContent + PARAGRAPH_END;
|
|
|
+ }
|
|
|
+
|
|
|
// 状态更新方法(建议也统一使用BOAPI风格)
|
|
|
@Mapping(value = "com.awspaas.user.apps.donenow_tst_updatestatus")
|
|
|
public ResponseObject updateStatus(UserContext uc, String id, String status) {
|
|
|
@@ -101,4 +144,4 @@ public class testController {
|
|
|
return ResponseObject.newErrResponse("状态更新失败:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|