Browse Source

临时代码

shiqian 3 years ago
parent
commit
939826e524

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

@@ -263,18 +263,20 @@ public interface StandardMapper {
             stringBuilder.append(String.join(", ", keySet.keySet()));
             stringBuilder.append(" ) ").append("values ");
 
-            for (JSONObject data : dataList) {
+            for (int i = 0; i < dataList.size(); i++) {
+                JSONObject data = dataList.get(i);
                 StringBuilder values = new StringBuilder();
                 values.append(" ( ");
                 for (Map.Entry<String, Object> entry : data.entrySet()) {
-                    values.append("#{model.").append(entry.getKey()).append("}, ");
+                    values.append(String.format("#{dataList[%d].", i)).append(entry.getKey()).append("}, ");
                 }
 
                 String beforeLast = StringUtils.substringBeforeLast(values.toString(), ", ");
-                stringBuilder.append(beforeLast).append(" ) ");
+                stringBuilder.append(beforeLast).append(" ), ");
             }
 
             String sqlStr = stringBuilder.toString();
+            sqlStr = sqlStr.substring(0, sqlStr.lastIndexOf(","));
             LOGGER.info("批量新增的sql语句为: {} \r\n 新增的数据为: {}", sqlStr, dataList);
             return sqlStr;
         }

+ 67 - 27
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -28,6 +28,7 @@ import com.boman.system.api.RemoteUserService;
 import com.boman.web.core.domain.ActionType;
 import com.boman.web.core.domain.RowResult;
 import com.boman.web.core.domain.TableContext;
+import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.service.delete.IBaseDeleteService;
 import com.boman.web.core.service.save.IBaseSaveService;
 import com.boman.web.core.service.select.IBaseSelectService;
@@ -100,8 +101,6 @@ public class TableServiceCmdService {
     private RemoteJflowProcessService remoteJflowProcessService;
     @Resource
     private RemoteWechatService remoteWechatService;
-    @Resource
-    private RemoteUserService remoteUserService;
 
 
     private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
@@ -132,7 +131,7 @@ public class TableServiceCmdService {
         if (ActionType.INSERT.equals(context.getActionType())) {
             List<GenTableColumn> columns = context.getColumns();
             Long maxId = IdUtils.getMaxId(dto.getTable(), pkName);
-            packUpdateByAndTime(columns, commitData, new Timestamp(System.currentTimeMillis()), true);
+            packUpdateByAndTime(columns, commitData, true);
             // 处理默认值
             handlerDefaultValue(commitData, columns);
             // 如果有单据、按照单据编号规则
@@ -177,6 +176,8 @@ public class TableServiceCmdService {
         boolean primaryTableUpdate = !ltZero(dto.getObjId());
         recursionAllChildrenFromDto(dto, result);
 
+        List<FormDataDto> child = new ArrayList<>();
+
         List<AjaxResult> resultList = new ArrayList<>(result.size());
         Map<String, Long> tableNameIdMap = new HashMap<>(result.size());
         AjaxResult ajaxResult;
@@ -189,39 +190,57 @@ public class TableServiceCmdService {
             TableServiceCmdService proxy = (TableServiceCmdService) AopContext.currentProxy();
             proxy.putFkValue(tableNameIdMap, formDataDto, optPrimaryTable, primaryTableUpdate);
             String tableName = formDataDto.getTable();
-            ajaxResult = objectSave(formDataDto);
-            if (AjaxResult.checkFail(ajaxResult)) {
-                throw new RuntimeException(String.format("保存失败, 表名为: %s ", tableName));
-            }
+            // 暂且如此处理
+            if (optPrimaryTable) {
+                ajaxResult = objectSave(formDataDto);
+                if (AjaxResult.checkFail(ajaxResult)) {
+                    throw new RuntimeException(String.format("保存失败, 表名为: %s ", tableName));
+                }
 
-            Long fkId = (Long) ajaxResult.get(AjaxResult.DATA_TAG);
-            if (null == fkId || NumberUtils.ltEqZero(fkId)) {
-                throw new RuntimeException(String.format("保存失败, 表名为: %s ,主表id: %s", tableName, fkId));
+                Long fkId = (Long) ajaxResult.get(AjaxResult.DATA_TAG);
+                if (null == fkId || NumberUtils.ltEqZero(fkId)) {
+                    throw new RuntimeException(String.format("保存失败, 表名为: %s ,主表id: %s", tableName, fkId));
+                }
+
+                tableNameIdMap.put(tableName, fkId);
+                resultList.add(ajaxResult);
+            } else {
+                child.add(formDataDto);
             }
 
-            tableNameIdMap.put(tableName, fkId);
-            resultList.add(ajaxResult);
+            // 小程序推送消息 参数设置
+            putAppletParamValue(dto.getTable(), receiveUserIds, messageInfo, formDataDto, optPrimaryTable);
+        }
 
-            if ("boman_message".equals(dto.getTable())) {
-                if (optPrimaryTable) {
-                    messageInfo.put("thing1", formDataDto.getFixedData().getString("message_title"));
-                    messageInfo.put("thing2", formDataDto.getFixedData().getString("send_user_name"));
-                    messageInfo.put("thing4", formDataDto.getFixedData().getString("message_title"));
-                    messageInfo.put("thing5", formDataDto.getFixedData().getString("send_user_name"));
-                } else {
-                    receiveUserIds.add(formDataDto.getFixedData().getLong("receive_user_id"));
-                }
-            }
+        List<JSONObject> dataList = new ArrayList<>();
+        for (FormDataDto formDataDto : child) {
+            JSONObject fixedData = formDataDto.getFixedData();
+            dataList.add(fixedData);
         }
 
-        // 获取发文相关信息
-        if ("boman_message".equals(dto.getTable())) {
+        saveService.insertRelList("boman_message_receive", dataList);
+
+        // 小程序发送推送消息
+        sendMsgByApplet(dto.getTable(), receiveUserIds, messageInfo);
+
+        return AjaxResult.success(resultList);
+    }
+
+    /**
+     * 功能描述: 小程序发送推送消息
+     *
+     * @param tableName      tableName
+     * @param receiveUserIds 需要发送的userIds
+     * @param messageInfo    发送消息的参数
+     */
+    private void sendMsgByApplet(String tableName, List<Long> receiveUserIds, Map<String, Object> messageInfo) {
+        if ("boman_message".equals(tableName)) {
             WxMsgDto wxMsgDto = new WxMsgDto();
             wxMsgDto.setIds(receiveUserIds);
             wxMsgDto.setParams(messageInfo);
             LOGGER.info("收文人id:{}, 发送数据: {}", receiveUserIds, messageInfo);
             remoteWechatService.pushMsg(wxMsgDto);
-            List<Long> userIds = new ArrayList<>(new HashSet(receiveUserIds));
+            /*List<Long> userIds = new ArrayList<>(new HashSet(receiveUserIds));
             AjaxResult userList = remoteUserService.selectUserByIds(userIds);
             List<Map<String, Object>> users = (List<Map<String, Object>>) userList.get("data");
             String accessKeyId = "LTAI5tNA2fcBJH6EWRH6Pxr6";
@@ -239,7 +258,7 @@ public class TableServiceCmdService {
                     }
                 }
             }
-            /*if (StringUtils.isNotBlank(sb.toString())) {
+            if (StringUtils.isNotBlank(sb.toString())) {
                 try {
                     String phoneNumbers = sb.toString().substring(0, sb.toString().length() - 1);
                     SendSmsUtils.sendSms(phoneNumbers, templateParam, accessKeyId, accessKeySecret, signName, templateCode);
@@ -248,7 +267,28 @@ public class TableServiceCmdService {
                 }
             }*/
         }
-        return AjaxResult.success(resultList);
+    }
+
+    /**
+     * 功能描述: 小程序发送推送消息的参数
+     *
+     * @param tableName       tableName
+     * @param receiveUserIds  收件人
+     * @param messageInfo     小程序推送单数
+     * @param formDataDto     formDataDto
+     * @param optPrimaryTable 是否是主表
+     */
+    private void putAppletParamValue(String tableName, List<Long> receiveUserIds, Map<String, Object> messageInfo, FormDataDto formDataDto, boolean optPrimaryTable) {
+        if ("boman_message".equals(tableName)) {
+            if (optPrimaryTable) {
+                messageInfo.put("thing1", formDataDto.getFixedData().getString("message_title"));
+                messageInfo.put("thing2", formDataDto.getFixedData().getString("send_user_name"));
+                messageInfo.put("thing4", formDataDto.getFixedData().getString("message_title"));
+                messageInfo.put("thing5", formDataDto.getFixedData().getString("send_user_name"));
+            } else {
+                receiveUserIds.add(formDataDto.getFixedData().getLong("receive_user_id"));
+            }
+        }
     }
 
     /**

+ 17 - 9
boman-web-core/src/main/java/com/boman/web/core/service/save/BaseSaveServiceImpl.java

@@ -3,7 +3,9 @@ package com.boman.web.core.service.save;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyuncs.exceptions.ClientException;
 import com.boman.common.core.utils.StringUtils;
+import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
+import com.boman.domain.GenTable;
 import com.boman.domain.GenTableColumn;
 import com.boman.domain.constant.FormDataConstant;
 import com.boman.domain.constant.TableNameConst;
@@ -12,6 +14,7 @@ import com.boman.domain.dto.WxMsgDto;
 import com.boman.system.api.RemoteUserService;
 import com.boman.web.core.domain.RowResult;
 import com.boman.web.core.mapper.StandardMapper;
+import com.boman.web.core.service.TableServiceCmdService;
 import com.boman.web.core.utils.ColumnUtils;
 import com.boman.web.core.utils.IdUtils;
 import com.boman.web.core.utils.SendSmsUtils;
@@ -47,6 +50,8 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
 
     @Resource
     private RemoteUserService remoteUserService;
+    @Resource
+    private TableServiceCmdService cmdService;
 
     /**
      * 功能描述: 保存一行
@@ -73,10 +78,13 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
         requireNonNull(dataList, "insertRelList dataList is empty");
 
         String pkName = IdUtils.getPkName(tableName);
+        GenTable genTable = cmdService.getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
+        List<GenTableColumn> columns = genTable.getColumns();
 
         for (JSONObject data : dataList) {
             Long maxId = IdUtils.getMaxId(tableName, pkName);
             data.put(TableNameConst.ID, maxId);
+            packUpdateByAndTime(columns, data, true);
         }
 
         return mapper.insertList(tableName, dataList);
@@ -101,7 +109,7 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
         Map<String, Object> messageInfo = new HashMap<>();
         for (JSONObject commitData : dataList) {
             Long maxId = IdUtils.getMaxId(tableName, pkName);
-            packUpdateByAndTime(columns, commitData, new Timestamp(System.currentTimeMillis()), true);
+            packUpdateByAndTime(columns, commitData, true);
             // 处理默认值
             handlerDefaultValue(commitData, columns);
             // 如果有单据、按照单据编号规则
@@ -142,14 +150,14 @@ public class BaseSaveServiceImpl implements IBaseSaveService {
                     }
                 }
             }
-            if (StringUtils.isNotBlank(sb.toString())) {
-                try {
-                    String phoneNumbers = sb.toString().substring(0, sb.toString().length() - 1);
-                    SendSmsUtils.sendSms(phoneNumbers, templateParam, accessKeyId, accessKeySecret, signName, templateCode);
-                } catch (ClientException e) {
-                    e.printStackTrace();
-                }
-            }
+//            if (StringUtils.isNotBlank(sb.toString())) {
+//                try {
+//                    String phoneNumbers = sb.toString().substring(0, sb.toString().length() - 1);
+//                    SendSmsUtils.sendSms(phoneNumbers, templateParam, accessKeyId, accessKeySecret, signName, templateCode);
+//                } catch (ClientException e) {
+//                    e.printStackTrace();
+//                }
+//            }
         }
         return rowResults;
     }

+ 2 - 4
boman-web-core/src/main/java/com/boman/web/core/service/update/BaseUpdateServiceImpl.java

@@ -53,9 +53,8 @@ public class BaseUpdateServiceImpl implements IBaseUpdateService {
         requireNonNull(idList, "需要修改的idList为空");
         JSONObject commitData = requireNonNull(context.getCommitData(), "需要更改的参数为空");
         List<GenTableColumn> columns = context.getColumns();
-        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
 
-        ColumnUtils.packUpdateByAndTime(columns, commitData, currentTime, false);
+        ColumnUtils.packUpdateByAndTime(columns, commitData, false);
         commitData = ifNullSetEmpty(escapeByQueryType(columns, commitData));
 
         return mapper.updateByIdList(tableName, pkName, idList, commitData);
@@ -77,9 +76,8 @@ public class BaseUpdateServiceImpl implements IBaseUpdateService {
 
         GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
         List<GenTableColumn> columns = genTable.getColumns();
-        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
 
-        ColumnUtils.packUpdateByAndTime(columns, commitData, currentTime, false);
+        ColumnUtils.packUpdateByAndTime(columns, commitData, false);
 
         JSONObject packColCondition = ColumnUtils.packColCondition(columns, condition);
         JSONObject packCommitData = ColumnUtils.packColCondition(columns, commitData);

+ 6 - 5
boman-web-core/src/main/java/com/boman/web/core/utils/ColumnUtils.java

@@ -1,6 +1,7 @@
 package com.boman.web.core.utils;
 
 import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.collection.CollectionUtils;
 import com.alibaba.fastjson.util.TypeUtils;
 import com.boman.common.core.utils.SecurityUtils;
@@ -27,7 +28,6 @@ import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.springframework.web.client.RestTemplate;
 
-import java.sql.Timestamp;
 import java.util.*;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
@@ -47,10 +47,11 @@ public class ColumnUtils {
      *
      * @param columns     所有的列
      * @param commitData  需要返回的数据
-     * @param currentTime currentTime
      * @param isSave      新增true、修改false
      */
-    public static void packUpdateByAndTime(List<GenTableColumn> columns, JSONObject commitData, Timestamp currentTime, boolean isSave) {
+    public static void packUpdateByAndTime(List<GenTableColumn> columns, JSONObject commitData, boolean isSave) {
+        String now = DateUtils.getTime();
+
         for (GenTableColumn column : columns) {
             String columnName = column.getColumnName();
             if (UPDATE_BY.equalsIgnoreCase(columnName)) {
@@ -59,13 +60,13 @@ public class ColumnUtils {
             }
 
             if (UPDATE_TIME.equalsIgnoreCase(columnName)) {
-                commitData.put(columnName, currentTime);
+                commitData.put(columnName, now);
                 continue;
             }
 
             if (isSave) {
                 if (CREATE_TIME.equalsIgnoreCase(columnName)) {
-                    commitData.put(columnName, currentTime);
+                    commitData.put(columnName, now);
                     continue;
                 }
                 if (CREATE_BY.equalsIgnoreCase(columnName)) {