Ver Fonte

新增代办功能

zh há 3 anos atrás
pai
commit
ac994d671d

+ 106 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/SqlProviderUtils.java

@@ -0,0 +1,106 @@
+package com.boman.common.core.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.*;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.escapeStr;
+import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
+import static com.boman.domain.constant.FormDataConstant.*;
+
+public class SqlProviderUtils {
+
+    /**
+     * 功能描述: 判断传过来的值是否需要转义
+     *
+     * @param packCondition 封装的条件
+     * @param wholeSql      sql
+     */
+    public static void packCondition(JSONObject packCondition, StringBuilder wholeSql) {
+        if (isEmpty(packCondition)) {
+            return;
+        }
+
+        wholeSql.append(" where ");
+        StringBuilder conditionSql = new StringBuilder();
+        for (Map.Entry<String, Object> entry : packCondition.entrySet()) {
+            String key = entry.getKey();
+            Object valueObj = entry.getValue();
+            List<String> types = ((List<String>) valueObj);
+            /** {@link com.boman.web.core.utils.ColumnUtils.packColCondition} 这里是拼参数的地方 **/
+            Object value = types.get(0);
+            String queryType = types.get(1);
+            String columnType = types.get(2);
+            conditionSql.append(key).append(covert(queryType, columnType, key, value)).append(" and ");
+        }
+
+        wholeSql.append(StringUtils.substringBeforeLast(conditionSql.toString(), " and"));
+    }
+
+    /**
+     * 功能描述: 仅此用来拼装查询条件,不做他用
+     *
+     * @param queryType  like > < =
+     * @param columnType varchar char textarea timestamp
+     * @param key        key
+     * @param valueObj   valueObj
+     * @return java.lang.String
+     */
+    public static String covert(String queryType, String columnType, String key, Object valueObj) {
+        // false 不需要转义
+        boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR) || columnType.contains(DATETIME) || columnType.contains(TIMESTAMP);
+        Object value;
+        switch (queryType) {
+            case EQ:
+                value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                return " = " + value;
+            case LIKE:
+                return " like concat('%', #{condition." + key + "}, '%')";
+            case NE:
+                value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                return " != " + value;
+            case GT:
+                value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                return " > " + value;
+            case GTE:
+                value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                return " >= " + value;
+            case LT:
+                value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                return " < " + value;
+            case LTE:
+                value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
+                return " <= " + value;
+            default:
+                // in
+                List<Object> list  = new ArrayList<>();
+                if(valueObj instanceof List) {
+                    list = ((List<Object>) valueObj);
+                }else{
+                    Collections.addAll(list, valueObj);
+                }
+                return " in (" + joinList(list) + ")";
+        }
+    }
+
+    /**
+     * 连接字符串数组集合
+     * eg: System.out.println(joinList(Lists.newArrayList(1, 3, 2, 5))); 输出 "'1', '3', '2', '5'"
+     *
+     * @param iterable 集合
+     * @return 连接结果
+     */
+    public static <T> String joinList(Iterable<T> iterable) {
+        Iterator<T> iterator = iterable.iterator();
+        StringBuilder stringBuilder = new StringBuilder();
+        while (iterator.hasNext()) {
+            T next = iterator.next();
+            String s = "'" + next + "', ";
+            stringBuilder.append(s);
+        }
+        String result = stringBuilder.toString();
+        return result.substring(0, result.length() - 2);
+    }
+
+}

+ 5 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/MessageController.java

@@ -1,6 +1,7 @@
 package com.boman.web.core.controller;
 
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.QueryBySqlDto;
 import com.boman.web.core.service.message.MessageService;
 import org.springframework.web.bind.annotation.*;
@@ -66,4 +67,8 @@ public class MessageController {
         return service.notFinishMessages(queryBySql);
     }
 
+    @PostMapping("/toDoMessage")
+    public AjaxResult toDoMessage(@RequestBody FormDataDto dto) {
+        return service.toDoMessage(dto);
+    }
 }

+ 63 - 0
boman-web-core/src/main/java/com/boman/web/core/mapper/MessageMapper.java

@@ -0,0 +1,63 @@
+package com.boman.web.core.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.utils.SqlProviderUtils;
+import com.boman.domain.jflow.ProcessNodeCandidator;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.SelectProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.isNotEmpty;
+import static com.boman.domain.constant.FormDataConstant.EQ;
+
+@Mapper
+@Component
+public interface MessageMapper {
+
+    Logger LOGGER = LoggerFactory.getLogger(MessageMapper.class);
+
+    /**
+     * 功能描述: 自定义查询,需要查询的字段和value都在condition中
+     * {@link StandardMapper.SqlProvider#countByCondition(Map)}
+     *
+     * @param username username
+     * @return int
+     */
+    @SelectProvider(type = MessageMapper.SqlProvider.class, method = "countByCondition")
+    int countByCondition(@Param("username") String username);
+
+
+    @SelectProvider(type = MessageMapper.SqlProvider.class, method = "selectByCondition")
+    List<JSONObject> toDoMessage(@Param("username") String username
+            , @Param("limit") int limit
+            , @Param("offset") int offset);
+
+    class SqlProvider {
+
+        public String countByCondition(Map<String, Object> para) {
+            String result = "SELECT count( 1 )  FROM boman_message t " +
+                    " JOIN urge_read_message u ON u.message_id = t.id  AND u.receive_user_name = '"  + para.get("username") +  "' " +
+                    " join boman_message_receive r on r.receive_user_name = u.receive_user_name and r.message_id = t.id WHERE t.is_del = 'N' and r.`status` = 'N' ";
+            LOGGER.info("查询count拼出的sql语句为: {} \r\n ", result);
+            return result;
+        }
+
+        public String selectByCondition(Map<String, Object> para) {
+            String result = "SELECT t.message_title, t.message_code, t.send_user_id, t.send_user_name, t.create_dept_name, r.receive_time, t.id, "
+                    + " t.finish_time FROM boman_message t JOIN urge_read_message u ON u.message_id = t.id  AND u.receive_user_name = '" + para.get("username") + "' "
+                    + " JOIN boman_message_receive r on r.receive_user_name = u.receive_user_name and r.message_id = t.id "
+                    + " WHERE t.is_del = 'N'  and r.`status` = 'N' ORDER BY t.create_time DESC  LIMIT " + para.get("limit") + "," + para.get("offset");
+
+            LOGGER.info("查询拼出的sql语句为:{} \r\n", result);
+            return result;
+        }
+    }
+}

+ 3 - 11
boman-web-core/src/main/java/com/boman/web/core/mapper/StandardMapper.java

@@ -536,18 +536,10 @@ public interface StandardMapper {
             String tableName = (String) params.get("tableName");
             String pkName = (String) params.get("pkName");
             Long id = (Long) params.get("id");
-            String other = (String) params.get("other");
             StringBuilder sqlBuilder = new StringBuilder();
-            if (StringUtils.isEmpty(other)) {
-                sqlBuilder.append("select * from ")
-                        .append(tableName).append(" where ")
-                        .append(pkName).append(" = ").append(id).append(" limit 1");
-            } else if ("leave".equals(other)) {
-                sqlBuilder.append("select t.*,u.nick_name  from ")
-                        .append(tableName).append(" t ").append(" JOIN sys_user u ON u.user_name = t.leavefrom_user_name ")
-                        .append(" where ")
-                        .append("t.").append(pkName).append(" = ").append(id).append(" limit 1");
-            }
+            sqlBuilder.append("select * from ")
+                    .append(tableName).append(" where ")
+                    .append(pkName).append(" = ").append(id).append(" limit 1");
             return sqlBuilder.toString();
         }
 

+ 9 - 0
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageService.java

@@ -1,6 +1,7 @@
 package com.boman.web.core.service.message;
 
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.QueryBySqlDto;
 
 /**
@@ -32,4 +33,12 @@ public interface MessageService {
      * @return List<JSONObject>
      */
     AjaxResult notFinishMessages(QueryBySqlDto queryBySql);
+
+    /**
+     * 功能描述: 代办
+     *
+     * @param dto queryBySql
+     * @return List<JSONObject>
+     */
+    AjaxResult toDoMessage(FormDataDto dto);
 }

+ 29 - 2
boman-web-core/src/main/java/com/boman/web/core/service/message/MessageServiceImpl.java

@@ -1,25 +1,31 @@
 package com.boman.web.core.service.message;
 
 import com.alibaba.fastjson.JSONObject;
+import com.boman.domain.constant.FormDataConstant;
 import com.boman.domain.dto.AjaxResult;
+import com.boman.domain.dto.FormDataDto;
 import com.boman.domain.dto.QueryBySqlDto;
 import com.boman.domain.dto.UpdateDto;
+import com.boman.web.core.mapper.MessageMapper;
 import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.service.bomanMessageReceive.IBomanMessageReceiveService;
 import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.utils.AuthUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import static com.boman.common.core.utils.number.NumberUtils.eqZero;
-import static com.boman.common.core.utils.number.NumberUtils.gtZero;
 import static com.boman.common.core.utils.obj.ObjectUtils.*;
-
+import static com.boman.domain.constant.FormDataConstant.*;
 /**
  * @author shiqian
  * @date 2021年07月08日 13:56
@@ -45,6 +51,8 @@ public class MessageServiceImpl implements MessageService {
     private IBomanMessageReceiveService receiveService;
     @Resource
     private TableServiceCmdService cmdService;
+    @Autowired
+    private MessageMapper messageMapper;
 
     /**
      * 功能描述: 撤回
@@ -114,4 +122,23 @@ public class MessageServiceImpl implements MessageService {
     public AjaxResult notFinishMessages(QueryBySqlDto queryBySql) {
         return cmdService.queryListByUnionTable(queryBySql);
     }
+
+    @Override
+    public AjaxResult toDoMessage(FormDataDto dto) {
+        JSONObject rows = new JSONObject();
+        int total = messageMapper.countByCondition(dto.getUsername());
+        rows.put(FormDataConstant.PAGE_TOTAL, total);
+
+        if (total <= 0) {
+            rows.put(FormDataConstant.PAGE_ROWS, new ArrayList<>());
+            return AjaxResult.success(rows);
+        }
+        if (total <= 0) {
+            rows.put(FormDataConstant.PAGE_ROWS, new ArrayList<>());
+            return AjaxResult.success(rows);
+        }
+        List<JSONObject> result = messageMapper.toDoMessage(dto.getUsername(), dto.getLimit(), dto.getOffset());
+        rows.put(PAGE_ROWS, result);
+        return AjaxResult.success(rows);
+    }
 }