Administrator 4 жил өмнө
parent
commit
c99545064a

+ 42 - 46
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/DateUtils.java

@@ -3,16 +3,21 @@ package com.boman.common.core.utils;
 import java.lang.management.ManagementFactory;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
 import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 /**
  * 时间工具类
- * 
+ *
  * @author ruoyi
  */
-public class DateUtils extends org.apache.commons.lang3.time.DateUtils
-{
+public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
     public static String YYYY = "yyyy";
 
     public static String YYYY_MM = "yyyy-MM";
@@ -22,65 +27,54 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
 
     public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
-    
+
     private static String[] parsePatterns = {
-            "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", 
+            "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
             "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
             "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
 
     /**
      * 获取当前Date型日期
-     * 
+     *
      * @return Date() 当前日期
      */
-    public static Date getNowDate()
-    {
+    public static Date getNowDate() {
         return new Date();
     }
 
     /**
      * 获取当前日期, 默认格式为yyyy-MM-dd
-     * 
+     *
      * @return String
      */
-    public static String getDate()
-    {
+    public static String getDate() {
         return dateTimeNow(YYYY_MM_DD);
     }
 
-    public static final String getTime()
-    {
+    public static final String getTime() {
         return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
     }
 
-    public static final String dateTimeNow()
-    {
+    public static final String dateTimeNow() {
         return dateTimeNow(YYYYMMDDHHMMSS);
     }
 
-    public static final String dateTimeNow(final String format)
-    {
+    public static final String dateTimeNow(final String format) {
         return parseDateToStr(format, new Date());
     }
 
-    public static final String dateTime(final Date date)
-    {
+    public static final String dateTime(final Date date) {
         return parseDateToStr(YYYY_MM_DD, date);
     }
 
-    public static final String parseDateToStr(final String format, final Date date)
-    {
+    public static final String parseDateToStr(final String format, final Date date) {
         return new SimpleDateFormat(format).format(date);
     }
 
-    public static final Date dateTime(final String format, final String ts)
-    {
-        try
-        {
+    public static final Date dateTime(final String format, final String ts) {
+        try {
             return new SimpleDateFormat(format).parse(ts);
-        }
-        catch (ParseException e)
-        {
+        } catch (ParseException e) {
             throw new RuntimeException(e);
         }
     }
@@ -88,8 +82,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     /**
      * 日期路径 即年/月/日 如2018/08/08
      */
-    public static final String datePath()
-    {
+    public static final String datePath() {
         Date now = new Date();
         return DateFormatUtils.format(now, "yyyy/MM/dd");
     }
@@ -97,8 +90,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     /**
      * 日期路径 即年/月/日 如20180808
      */
-    public static final String dateTime()
-    {
+    public static final String dateTime() {
         Date now = new Date();
         return DateFormatUtils.format(now, "yyyyMMdd");
     }
@@ -106,27 +98,21 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     /**
      * 日期型字符串转化为日期 格式
      */
-    public static Date parseDate(Object str)
-    {
-        if (str == null)
-        {
+    public static Date parseDate(Object str) {
+        if (str == null) {
             return null;
         }
-        try
-        {
+        try {
             return parseDate(str.toString(), parsePatterns);
-        }
-        catch (ParseException e)
-        {
+        } catch (ParseException e) {
             return null;
         }
     }
-    
+
     /**
      * 获取服务器启动时间
      */
-    public static Date getServerStartDate()
-    {
+    public static Date getServerStartDate() {
         long time = ManagementFactory.getRuntimeMXBean().getStartTime();
         return new Date(time);
     }
@@ -134,8 +120,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     /**
      * 计算两个时间差
      */
-    public static String getDatePoor(Date endDate, Date nowDate)
-    {
+    public static String getDatePoor(Date endDate, Date nowDate) {
         long nd = 1000 * 24 * 60 * 60;
         long nh = 1000 * 60 * 60;
         long nm = 1000 * 60;
@@ -152,4 +137,15 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         // long sec = diff % nd % nh % nm / ns;
         return day + "天" + hour + "小时" + min + "分钟";
     }
+
+    /**
+     * 获取两个日期之间所有日期
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<LocalDate> getDatesBetween(LocalDate startDate, LocalDate endDate) {
+        long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate) + 1;
+        return IntStream.iterate(0, i -> i + 1).limit(numOfDaysBetween).mapToObj(startDate::plusDays).collect(Collectors.toList());
+    }
 }

+ 65 - 18
boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceCmdService.java

@@ -18,15 +18,17 @@ import com.boman.system.utils.IdUtils;
 import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpMethod;
 import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
+import java.net.URI;
 import java.sql.Timestamp;
 import java.util.*;
 import java.util.stream.Collectors;
 
-import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
-import static com.boman.common.core.utils.obj.ObjectUtils.requiredNonNull;
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
 import static com.boman.system.common.FormDataConstant.CONDITION;
 import static com.boman.system.common.FormDataConstant.SHOW_DATA;
 
@@ -48,6 +50,8 @@ public class TableServiceCmdService {
     private IBaseSelectService selectService;
     @Resource
     private IBaseSubmitService submitService;
+    @Resource
+    private  RestTemplate restTemplate;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
 
@@ -65,7 +69,8 @@ public class TableServiceCmdService {
         // 拿到pkName和maxId
         List<GenTableColumn> columns = context.getTable().getColumns();
         String pkName = IdUtils.getPkName(columns);
-        requireNonNull(pkName, "主键名称为空");;
+        requireNonNull(pkName, "主键名称为空");
+        ;
 
         //
         List<String> allColumnNameList = columns.stream()
@@ -117,7 +122,7 @@ public class TableServiceCmdService {
         GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
         String pkName = IdUtils.getPkName(genTable.getColumns());
 
-        JSONObject jsonObject= new JSONObject();
+        JSONObject jsonObject = new JSONObject();
         jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
 
         RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"), jsonObject);
@@ -137,15 +142,15 @@ public class TableServiceCmdService {
         // 拿到每个字段对应的查询类型,=、 like、 >、 <
         GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
         JSONObject fixedData = dto.getFixedData();
-        fixedData = ObjectUtils.ifNullSetEmpty(fixedData);
+        fixedData = ifNullSetEmpty(fixedData);
 
         // 查询条件
-        JSONObject condition = ObjectUtils.ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
+        JSONObject condition = ifNullSetEmpty(fixedData.getJSONObject(CONDITION));
         List<GenTableColumn> columns = genTable.getColumns();
         // 封装好以后的查询条件
-        JSONObject packCondition = ObjectUtils.ifNullSetEmpty(packColCondition(columns, condition));
+        JSONObject packCondition = ifNullSetEmpty(packColCondition(columns, condition));
         // 需要返回到前台的列
-        JSONArray showData = ObjectUtils.ifNullSetEmpty(fixedData.getJSONArray(SHOW_DATA));
+        JSONArray showData = ifNullSetEmpty(fixedData.getJSONArray(SHOW_DATA));
         JSONObject rows = new JSONObject();
         int total = selectService.countByCondition(genTable.getTableName(), condition, packCondition);
         rows.put(FormDataConstant.PAGE_TOTAL, total);
@@ -160,7 +165,7 @@ public class TableServiceCmdService {
         return AjaxResult.success(rows);
     }
 
- /**
+    /**
      * 功能描述: 获取单表单数据
      *
      * @param dto condition
@@ -175,7 +180,7 @@ public class TableServiceCmdService {
         String pkName = IdUtils.getPkName(genTable.getColumns());
 
         JSONObject fixedData = dto.getFixedData();
-        fixedData = ObjectUtils.ifNullSetEmpty(fixedData);
+        fixedData = ifNullSetEmpty(fixedData);
         Long id = fixedData.getLong(FormDataConstant.ID);
         requireNonNull(id);
 
@@ -186,7 +191,7 @@ public class TableServiceCmdService {
 
     /**
      * 功能描述: 封装成查询条件 key: 列名,  value:查询条件_查询类别
-     *              eg: [{"config_name":"系统配置_like"}, {"config_name":"_like"}]
+     * eg: [{"config_name":"系统配置_like"}, {"config_name":"_like"}]
      *
      * @param columns columns
      * @return com.alibaba.fastjson.JSONObject
@@ -215,10 +220,10 @@ public class TableServiceCmdService {
      * 功能描述: 获取表单查询字段、按钮、表头
      * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
      * 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
-     *
-     *                    eg:{
-     *                          "table": "sys_config",
-     *                        }
+     * <p>
+     * eg:{
+     * "table": "sys_config",
+     * }
      *
      * @param condition condition
      * @return com.boman.common.core.web.domain.AjaxResult
@@ -315,7 +320,7 @@ public class TableServiceCmdService {
         // 不符合条件的需要提交的
         List<JSONObject> notNeedCommitList = Lists.newArrayListWithCapacity(16);
         Iterator<JSONObject> iterator = beforeList.iterator();
-        while (iterator.hasNext()){
+        while (iterator.hasNext()) {
             JSONObject next = iterator.next();
             String dbStatus = next.getString(FormDataConstant.STATUS);
             // 只能是未提交的状态下,才能调用提交
@@ -356,10 +361,52 @@ public class TableServiceCmdService {
     }
 
 
+    /**
+     * 是否定制
+     * 判断是否需要转发到定制接口
+     * @param tableName 表明
+     * @param result 结果
+     * @param action 动作
+     * @return 结果
+     */
+    public List<JSONObject> isCustomized(String tableName, List<JSONObject> result, String action) {
+        requireNonNull(tableName);
+        requireNonNull(action);
+        if (result != null && result.size() > 0){
+            //获取到服务名称
+            String triggerName = getTriggerName(tableName, action);
+            requireNonNull(triggerName);
+            //组织请求 acos + RestTemplate
+            return restTemplate.postForObject("http://" + triggerName, result, List.class);
+        }
+        return result;
+    }
+
+    /**
+     * 判断是什么action
+     * @param tableName 表明
+     * @param action 动作
+     * @return
+     */
+    private String getTriggerName(String tableName, String action){
+        GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, tableName);
+        requireNonNull(genTable);
+        if (action.equals(TriggerActionConstant.ACTION_CREATE)){
+            return genTable.getTriggerCreate();
+        }else if (action.equals(TriggerActionConstant.ACTION_RETRIEVE)){
+            return genTable.getTriggerRetrieve();
+        }else if (action.equals(TriggerActionConstant.ACTION_UPDATE)){
+            return genTable.getTriggerUpdate();
+        }else if (action.equals(TriggerActionConstant.ACTION_DELETE)){
+            return genTable.getTriggerDelete();
+        }else if (action.equals(TriggerActionConstant.ACTION_SUBMIT)){
+            return genTable.getTriggerSubmit();
+        }
+        return null;
+    }
     // todo redis中未找到,要去查数据库,然后再塞进去
-    private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName){
+    private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName) {
         GenTable genTable = redisService.getCacheObject(redisKeyPrefix + requireNonNull(tableName));
         return requireNonNull(genTable);
     }
-
 }

+ 30 - 0
boman-modules/boman-system/src/main/java/com/boman/system/common/TriggerActionConstant.java

@@ -0,0 +1,30 @@
+package com.boman.system.common;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/01/16:33
+ */
+public class TriggerActionConstant {
+
+    /**
+     * 新增
+     */
+    public static final String ACTION_CREATE = "trigger_create";
+
+    /**
+     * 查询
+     */
+    public static final String ACTION_RETRIEVE = "trigger_retrieve";
+    /**
+     * 修改
+     */
+    public static final String ACTION_UPDATE = "trigger_update";
+    /**
+     * 删除
+     */
+    public static final String ACTION_DELETE = "trigger_delete";
+    /**
+     * 提交
+     */
+    public static final String ACTION_SUBMIT = "trigger_submit";
+}

+ 19 - 0
boman-modules/boman-system/src/main/java/com/boman/system/config/RestTemplateConfiguration.java

@@ -0,0 +1,19 @@
+package com.boman.system.config;
+
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/01/18:20
+ */
+@Configuration
+public class RestTemplateConfiguration {
+    @Bean
+    @LoadBalanced
+    public RestTemplate getRestTemplate(){
+        return new RestTemplate();
+    }
+}

+ 37 - 0
boman-modules/boman-system/src/main/java/com/boman/system/controller/SysScheduleController.java

@@ -0,0 +1,37 @@
+package com.boman.system.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.web.controller.BaseController;
+import com.boman.system.common.BaseTableSaveDTO;
+import com.boman.system.service.ISysScheduleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/02/9:45
+ */
+@RestController
+@RequestMapping("/schedule")
+public class SysScheduleController extends BaseController {
+
+    @Autowired
+    private ISysScheduleService sysScheduleService;
+
+
+    /**
+     * 为日程表定制日程时间接口
+     * @param result 结果
+     * @return
+     */
+    @PostMapping("/setDay")
+    public List<JSONObject> setDay(@Validated @RequestBody List<JSONObject> result) {
+        return sysScheduleService.setDay(result);
+    }
+}

+ 22 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/ISysScheduleService.java

@@ -0,0 +1,22 @@
+package com.boman.system.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.system.common.BaseTableSaveDTO;
+
+import java.util.List;
+
+/**
+ * 日程表
+ *
+ * @author tjf
+ * @Date: 2021/04/02/9:46
+ */
+public interface ISysScheduleService {
+
+    /**
+     * 为日程表定制日程时间接口
+     * @param result
+     * @return
+     */
+    public List<JSONObject> setDay(List<JSONObject> result);
+}

+ 61 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysScheduleServiceImpl.java

@@ -0,0 +1,61 @@
+package com.boman.system.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.utils.DateUtils;
+import com.boman.system.common.BaseTableSaveDTO;
+import com.boman.system.service.ISysScheduleService;
+import org.springframework.stereotype.Service;
+
+import javax.xml.crypto.Data;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author tjf
+ * @Date: 2021/04/02/9:47
+ */
+@Service
+public class SysScheduleServiceImpl implements ISysScheduleService {
+
+    /**
+     * 为日程表定制日程时间接口
+     *
+     * @param result
+     * @return
+     */
+    @Override
+    public List<JSONObject> setDay(List<JSONObject> result) {
+        int num = 0;
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        for (JSONObject jsonObject : result) {
+            num = 0;
+            Set<Map.Entry<String, Object>> entries = jsonObject.entrySet();
+            //开始时间
+            LocalDate beginTime = null;
+            //结束时间
+            LocalDate endTime = null;
+            for (Map.Entry<String, Object> entry : entries) {
+                String key = entry.getKey();
+                if ("begin_time".equals(key)) {
+                    beginTime = LocalDate.parse(String.valueOf(entry.getValue()), formatter);
+                    num++;
+                } else if ("end_time".equals(key)) {
+                    endTime = LocalDate.parse(String.valueOf(entry.getValue()), formatter);
+                    num++;
+                } else if (num == 2) {
+                    if (beginTime != null && endTime != null) {
+                        List<LocalDate> datesBetween = DateUtils.getDatesBetween(beginTime, endTime);
+                        jsonObject.put("all_date",datesBetween);
+                        break;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+}