浏览代码

月 年 请假人数

shiqian 4 年之前
父节点
当前提交
9a93b672fc

+ 19 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/constant/LeaveConst.java

@@ -0,0 +1,19 @@
+package com.boman.domain.constant;
+
+
+/**
+ * @author shiqian
+ * @date 2021年06月17日 17:24
+ **/
+public class LeaveConst {
+
+    public static final String TABLE_NAME = "leavefrom";
+    public static final String LEAVEFROM_START_TIME = "leavefrom_start_time";
+    public static final String LEAVEFROM_END_TIME = "leavefrom_end_time";
+    public static final int DAY = 1;
+    public static final int MONTH = 2;
+    public static final int YEAR = 3;
+
+    public static final String MONTH_LEAVE_COUNT = "month";
+    public static final String YEAR_LEAVE_COUNT = "year";
+}

+ 55 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/DateUtils.java

@@ -68,6 +68,61 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         return dateTimeNow(YYYY);
     }
 
+
+    public static String getMonth() {
+        Calendar calendar = Calendar.getInstance();
+        int month = calendar.get(Calendar.MONTH) + 1;
+        return month < 10 ? "0" + month : month + "";
+    }
+
+    public static String getFirstDayOfYearStr() {
+        return getYear() + "-01-01 00:00:00";
+    }
+
+    public static String getFirstDayOfMonthStr() {
+        return getYear() + "-01 00:00:00";
+    }
+
+    public static Date getFirstDayOfMonth() {
+        String str = getFirstDayOfMonthStr();
+        return dateTime(YYYY_MM_DD_HH_MM_SS, str);
+    }
+
+    public static String getLastDayOfMonthStr() {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.DATE, 1);
+        calendar.roll(Calendar.DATE, -1);
+        return dateTime(calendar.getTime()) + " 23:59:59";
+    }
+
+    public static String getLastDayOfMonthStr(String yyyy) {
+        String re = getLastDayOfMonthStr();
+        re = re.substring(4);
+        return yyyy + re;
+    }
+
+    public static void main(String[] args) {
+        String re = getLastDayOfMonthStr();
+        re = re.substring(4);
+        System.out.println(getYear() + re);
+    }
+
+
+    public static Date getLastDayOfMonth() {
+        String str = getLastDayOfMonthStr();
+        return dateTime(YYYY_MM_DD_HH_MM_SS, str);
+    }
+
+
+    public static String getLastDayOfYearStr() {
+        return getYyyy_Mm() + "-12-31 23:59:59";
+    }
+
+    public static int dayOfMonth() {
+        Calendar calendar = Calendar.getInstance();
+        return calendar.get(Calendar.DAY_OF_MONTH);
+    }
+
     public static final String getYyyyMm() {
         return dateTimeNow(YYYYMM);
     }

+ 34 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/LeaveController.java

@@ -0,0 +1,34 @@
+package com.boman.web.core.controller;
+
+import com.boman.domain.dto.AjaxResult;
+import com.boman.web.core.service.leave.LeaveService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.Map;
+
+/**
+ * @author shiqian
+ * @date 2021年06月03日 15:41
+ **/
+@RequestMapping("/leave")
+@RestController
+public class LeaveController {
+
+    @Resource
+    private LeaveService service;
+
+    /**
+     * 功能描述: 本月请假人数、本年请假人数
+     *
+     * @return com.boman.domain.dto.AjaxResult
+     */
+    @GetMapping("/statistic/count/{yyyy}")
+    public AjaxResult statisticCount(@PathVariable String yyyy) {
+        Map<String, Integer> result = service.statisticByType(yyyy);
+        return AjaxResult.success(result);
+    }
+}

+ 4 - 4
boman-web-core/src/main/java/com/boman/web/core/mapper/StandardlyMapper.java

@@ -670,16 +670,16 @@ public interface StandardlyMapper {
                     return " != " + value;
                 case GT:
                     value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
-                    return " &gt; " + value;
+                    return " > " + value;
                 case GTE:
                     value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
-                    return " &gt;= " + value;
+                    return " >= " + value;
                 case LT:
                     value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
-                    return " &lt; " + value;
+                    return " < " + value;
                 case LTE:
                     value = needEscape ? escapeStr(String.valueOf(valueObj)) : valueObj;
-                    return " &lt;= " + value;
+                    return " <= " + value;
                 default:
                     // in
                     List<Object> list = valueObj instanceof List ? ((List<Object>) valueObj) : Lists.newArrayList(valueObj);

+ 19 - 0
boman-web-core/src/main/java/com/boman/web/core/service/leave/LeaveService.java

@@ -0,0 +1,19 @@
+package com.boman.web.core.service.leave;
+
+import java.util.Map;
+
+/**
+ * @author shiqian
+ * @date 2021年06月17日 16:04
+ **/
+public interface LeaveService {
+
+
+    /**
+     * 功能描述: 直接查询一年的
+     *
+     * @param yyyy yyyy
+     * @return int
+     */
+    Map<String, Integer> statisticByType(String yyyy);
+}

+ 79 - 0
boman-web-core/src/main/java/com/boman/web/core/service/leave/LeaveServiceImpl.java

@@ -0,0 +1,79 @@
+package com.boman.web.core.service.leave;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.common.core.utils.DateUtils;
+import com.boman.web.core.service.common.ICommonService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static com.boman.common.core.utils.DateUtils.YYYY_MM_DD_HH_MM_SS;
+import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
+import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
+import static com.boman.domain.constant.LeaveConst.*;
+
+/**
+ * @author shiqian
+ * @date 2021年06月17日 16:04
+ **/
+@Service
+public class LeaveServiceImpl implements LeaveService {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(LeaveServiceImpl.class);
+
+    @Resource
+    private ICommonService commonService;
+
+    /**
+     * 功能描述: 直接查询一年的
+     *
+     * @param yyyy yyyy
+     * @return int
+     */
+    @Override
+    public Map<String, Integer> statisticByType(String yyyy) {
+        requireNonNull(yyyy, "statisticByType yyyy is empty");
+        Map<String, Integer> map = new HashMap<>(2);
+
+        String yearStartTime = yyyy + "-01-01 00:00:00";
+        String yearEndTime = yyyy + "-12-31 23:59:59";
+
+        List<JSONObject> result = listByTime(yearStartTime, yearEndTime);
+        if (isEmpty(result)) {
+            map.put(YEAR_LEAVE_COUNT, 0);
+            map.put(MONTH_LEAVE_COUNT, 0);
+            return map;
+        }
+
+        Date firstDayOfMonth = DateUtils.dateTime(YYYY_MM_DD_HH_MM_SS, yyyy + "-" + DateUtils.getMonth() + "-01 00:00:00");
+        Date lastDayOfMonth = DateUtils.dateTime(YYYY_MM_DD_HH_MM_SS, DateUtils.getLastDayOfMonthStr(yyyy));
+        int count = 0;
+        for (JSONObject jsonObject : result) {
+            Timestamp startTime = jsonObject.getTimestamp(LEAVEFROM_START_TIME);
+            // 并且是当月的
+            if (startTime.after(firstDayOfMonth) && startTime.before(lastDayOfMonth)) {
+                count++;
+            }
+        }
+
+        map.put(YEAR_LEAVE_COUNT, result.size());
+        map.put(MONTH_LEAVE_COUNT, count);
+        return map;
+    }
+
+    private List<JSONObject> listByTime(String startTime, String endTime) {
+        JSONObject condition = new JSONObject();
+        condition.put(LEAVEFROM_START_TIME, startTime);
+        condition.put(LEAVEFROM_END_TIME, endTime);
+        return commonService.getByMap(TABLE_NAME, condition);
+    }
+
+
+}