|
@@ -0,0 +1,102 @@
|
|
|
+package com.boman.web.core.mapper;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
+import com.boman.domain.jflow.ProcessNodeCandidator;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.ibatis.annotations.*;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static com.mysql.cj.util.StringUtils.isNullOrEmpty;
|
|
|
+
|
|
|
+
|
|
|
+ * 流程针对业务数据层面接口
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author zhong.h
|
|
|
+ */
|
|
|
+@Mapper
|
|
|
+@Component
|
|
|
+public interface JFTaskBusinessMapper {
|
|
|
+ Logger LOGGER = LoggerFactory.getLogger(JFTaskBusinessMapper.class);
|
|
|
+
|
|
|
+ @InsertProvider(type = StandardMapper.SqlProvider.class, method = "insert")
|
|
|
+ int insert(@Param("tableName") String var1, @Param("model") JSONObject var2);
|
|
|
+
|
|
|
+ @UpdateProvider(type = StandardMapper.SqlProvider.class, method = "update")
|
|
|
+ int updateByIdList(@Param("tableName") String tableName, @Param("pkName") String pkName
|
|
|
+ , @Param("idList") List<Long> idList, @Param("model") JSONObject models);
|
|
|
+
|
|
|
+
|
|
|
+ @Select("select * from process_node_candidators t where t.business_code = #{businessCode} and t.module_id = #{moduleId} and t.node_id = #{nodeId}")
|
|
|
+ ProcessNodeCandidator selectData(@Param("businessCode") Long businessCode, @Param("moduleId") Long moduleId, @Param("nodeId") Long nodeId);
|
|
|
+
|
|
|
+ class SqlProvider {
|
|
|
+
|
|
|
+ public String insertList(Map<String, Object> para) {
|
|
|
+ List<JSONObject> dataList = (List<JSONObject>) para.get("dataList");
|
|
|
+ String tableName = (String) para.get("tableName");
|
|
|
+ if (isNullOrEmpty(tableName)) {
|
|
|
+ throw new IllegalArgumentException("tableName 无效");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtils.isEmpty(dataList)) {
|
|
|
+ throw new IllegalArgumentException("需要插入的数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ stringBuilder.append("insert into ").append(tableName).append(" ( ");
|
|
|
+ JSONObject keySet = dataList.get(0);
|
|
|
+ stringBuilder.append(String.join(", ", keySet.keySet()));
|
|
|
+ stringBuilder.append(" ) ").append("values ");
|
|
|
+
|
|
|
+ for (JSONObject data : dataList) {
|
|
|
+ StringBuilder values = new StringBuilder();
|
|
|
+ values.append(" ( ");
|
|
|
+ for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
|
+ values.append("#{model.").append(entry.getKey()).append("}, ");
|
|
|
+ }
|
|
|
+
|
|
|
+ String beforeLast = StringUtils.substringBeforeLast(values.toString(), ", ");
|
|
|
+ stringBuilder.append(beforeLast).append(" ) ");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sqlStr = stringBuilder.toString();
|
|
|
+ LOGGER.info("批量新增的sql语句为: {} \r\n 新增的数据为: {}", sqlStr, dataList);
|
|
|
+ return sqlStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String update(Map<String, Object> para) {
|
|
|
+ String tableName = (String) para.get("tableName");
|
|
|
+ String pkName = (String) para.get("pkName");
|
|
|
+ List<Long> idList = (List<Long>) para.get("idList");
|
|
|
+ JSONObject models = (JSONObject) para.get("model");
|
|
|
+
|
|
|
+ StringBuilder wholeSql = new StringBuilder();
|
|
|
+ wholeSql.append("update ").append(tableName).append(" set ");
|
|
|
+ for (Map.Entry<String, Object> entry : models.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Object value = entry.getValue();
|
|
|
+ wholeSql.append(key).append(" = ").append(value).append(" , ");
|
|
|
+ }
|
|
|
+
|
|
|
+ wholeSql = new StringBuilder(StringUtils.substringBeforeLast(wholeSql.toString(), ","));
|
|
|
+ wholeSql.append(" where ").append(pkName).append(" in ( ");
|
|
|
+
|
|
|
+ for (int i = 0; i < idList.size(); ++i) {
|
|
|
+ wholeSql.append(String.format("#{idList[%d]}", i));
|
|
|
+ wholeSql.append(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ wholeSql.setCharAt(wholeSql.length() - 1, ')');
|
|
|
+ String sqlStr = wholeSql.toString();
|
|
|
+ LOGGER.info("批量更新的sql语句为: {} \r\n 更改的数据为: {} \r\n idList: {}", sqlStr, models, idList);
|
|
|
+ return sqlStr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|