瀏覽代碼

"考勤报表"

yangjunfeng 3 月之前
父節點
當前提交
8e35f0359a

+ 6 - 0
hnls-gps/hnls-gps-api/src/main/java/com/tofly/pojo/plan/Pdasignhis.java

@@ -42,6 +42,12 @@ public class Pdasignhis extends Model<Pdasignhis> {
      */
     @ApiModelProperty(value = "签到用户ID")
     private Long signUser;
+    @TableField(exist = false)
+    @ApiModelProperty(value = "签到用户名称")
+    private String signUserName;
+    @TableField(exist = false)
+    @ApiModelProperty(value = "部门名称")
+    private String deptName;
     /**
      * 移动设备ID
      */

+ 102 - 0
hnls-gps/hnls-gps-api/src/main/java/com/tofly/pojo/plan/vo/AttendanceReportVo.java

@@ -0,0 +1,102 @@
+package com.tofly.pojo.plan.vo;
+
+import com.tofly.common.core.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 考勤报表
+ *
+ * @author JF
+ * @date
+ */
+@Data
+@ApiModel
+public class AttendanceReportVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 序号
+     */
+    @ApiModelProperty(value = "序号")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "序号",column = "A")
+    private Integer id;
+
+    /**
+     * 考勤人员ID
+     */
+    @ApiModelProperty(value = "考勤人员ID")
+    private Long userId;
+
+    /**
+     * 考勤人员名称
+     */
+    @ApiModelProperty(value = "考勤人员名称")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "姓名",column = "C")
+    private String userName;
+
+    /**
+     * 部门名称
+     */
+    @ApiModelProperty(value = "部门名称")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "所属部门",column = "B")
+    private String deptName;
+
+    /**
+     * 上班时间(最早一次)
+     */
+    @ApiModelProperty(value = "上班时间(最早一次)")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "上班时间",column = "D",dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date onTime;
+
+    /**
+     * 上班打卡位置
+     */
+    @ApiModelProperty(value = "上班打卡位置")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "上班打卡位置",column = "E")
+    private String onAddress;
+
+    /**
+     * 上班打卡次数
+     */
+    @ApiModelProperty(value = "上班打卡次数")
+    private BigDecimal onNumber;
+
+    /**
+     * 下班时间(最晚一次)
+     */
+    @ApiModelProperty(value = "下班时间(最晚一次)")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "下班时间",column = "F",dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date offTime;
+
+    /**
+     * 下班打卡位置
+     */
+    @ApiModelProperty(value = "下班打卡位置")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "下班打卡位置",column = "G")
+    private String offAddress;
+
+    /**
+     * 下班打卡次数
+     */
+    @ApiModelProperty(value = "下班打卡次数")
+    private BigDecimal offNumber;
+
+    /**
+     * 累计打卡次数
+     */
+    @ApiModelProperty(value = "累计打卡次数")
+    @com.haiqiu.tools.excel.annotation.Excel(name = "累计打卡次数",column = "H")
+    private BigDecimal signNumber;
+
+    /**
+     * 统计工时
+     */
+    @ApiModelProperty(value = "统计工时")
+    private BigDecimal workHour;
+}

+ 24 - 0
hnls-gps/hnls-gps-boot/src/main/java/com/tofly/gpsboot/controller/sign/PdasignhisController.java

@@ -5,20 +5,27 @@
 package com.tofly.gpsboot.controller.sign;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.haiqiu.tools.excel.utils.ExcelUtils;
 import com.tofly.common.core.entity.ResultRespone;
 
 import com.tofly.common.log.annotation.ToFlyAppLog;
 import com.tofly.gpsboot.controller.BaseController;
 import com.tofly.pojo.plan.dto.PdasignhisDto;
+import com.tofly.pojo.plan.vo.AttendanceReportVo;
 import com.tofly.pojo.plan.vo.PdasignhisVo;
 import com.tofly.pojo.plan.Pdasignhis;
 import com.tofly.gpsboot.service.sign.PdasignhisService;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.ModelAttribute;
 
+import java.util.List;
+
 /**
  * 上下班签到历史信息
  *
@@ -45,4 +52,21 @@ public class PdasignhisController extends BaseController<Pdasignhis, PdasignhisV
         rest.setResult(buildPage);
         return rest;
     }
+
+    @GetMapping("/attendanceReport")
+    @ApiOperation(value = "考勤报表")
+    @ToFlyAppLog(title = "考勤报表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "startTime", value = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "endTime", value = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "deptIds", value = "部门ID 多个用,隔开", dataType = "String"),
+            @ApiImplicitParam(name = "isExport", value = "是否导出(0否1是)", dataType = "String"),
+    })
+    public ResultRespone<List<AttendanceReportVo>> attendanceReport(String startTime, String endTime, String deptIds, String isExport) {
+        List<AttendanceReportVo> attendanceReportVoList = service.attendanceReport(startTime, endTime, deptIds);
+        if (StringUtils.isNotBlank(isExport) && isExport.equals("1")) {
+            ExcelUtils.getListToExcel(AttendanceReportVo.class, attendanceReportVoList, "考勤报表");
+        }
+        return ResultRespone.success(attendanceReportVoList);
+    }
 }

+ 4 - 0
hnls-gps/hnls-gps-boot/src/main/java/com/tofly/gpsboot/mapper/plan/PdasignhisMapper.java

@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import com.tofly.pojo.plan.Pdasignhis;
 
+import java.util.List;
+
 /**
  * 上下班签到历史信息表:TF_YWPN_PDASIGNHIS_W
  *
@@ -15,4 +17,6 @@ import com.tofly.pojo.plan.Pdasignhis;
  * @date Thu Mar 18 00:00:00 CST 2021
  */
 public interface PdasignhisMapper extends BaseMapper<Pdasignhis> {
+
+    List<Long> getUserIdList(String deptIds);
                                             }

+ 5 - 0
hnls-gps/hnls-gps-boot/src/main/java/com/tofly/gpsboot/service/sign/PdasignhisService.java

@@ -6,10 +6,13 @@ package com.tofly.gpsboot.service.sign;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.tofly.pojo.plan.dto.PdasignhisDto;
+import com.tofly.pojo.plan.vo.AttendanceReportVo;
 import com.tofly.pojo.plan.vo.PdasignhisVo;
 import com.tofly.pojo.plan.Pdasignhis;
 import com.tofly.gpsboot.service.IBaseService;
 
+import java.util.List;
+
 
 /**
  * 上下班签到历史信息表:TF_YWPN_PDASIGNHIS_W
@@ -26,4 +29,6 @@ public interface PdasignhisService extends IBaseService<Pdasignhis, PdasignhisVo
      * @return
      */
     Page<PdasignhisVo> getPdaSignHisPage(Page page, PdasignhisDto parDto);
+
+    List<AttendanceReportVo> attendanceReport(String startTime, String endTime, String deptIds);
 }

+ 82 - 4
hnls-gps/hnls-gps-boot/src/main/java/com/tofly/gpsboot/service/sign/impl/PdasignhisServiceImpl.java

@@ -4,6 +4,7 @@
  */
 package com.tofly.gpsboot.service.sign.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -16,6 +17,7 @@ import com.tofly.common.oauth.util.SecurityUtils;
 import com.tofly.gpsboot.common.system.SignFlagEnum;
 import com.tofly.gpsboot.common.system.SignTypeEnum;
 import com.tofly.pojo.plan.dto.PdasignhisDto;
+import com.tofly.pojo.plan.vo.AttendanceReportVo;
 import com.tofly.pojo.plan.vo.PdasignhisVo;
 import com.tofly.gpsboot.mapper.plan.PdasignhisMapper;
 import com.tofly.pojo.User;
@@ -24,10 +26,9 @@ import com.tofly.gpsboot.service.sign.PdasignhisService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 
@@ -93,4 +94,81 @@ public class PdasignhisServiceImpl extends ServiceImpl<PdasignhisMapper, Pdasign
         infoPageList.setRecords(this.viewConversion(infoPageList.getRecords()));
         return infoPageList;
     }
+
+    @Override
+    public List<AttendanceReportVo> attendanceReport(String startTime, String endTime, String deptIds) {
+        List<AttendanceReportVo> res = new ArrayList<>();
+        List<Date> dateList = getBetweenDate(startTime, endTime, 1);
+        List<Long> queryUserIds = this.baseMapper.getUserIdList(deptIds);
+        List<Pdasignhis> pdasignhisList = this.list();
+        AtomicInteger num = new AtomicInteger(1);
+        dateList.forEach(date -> {
+            List<Pdasignhis> pdasignhisListFinal = pdasignhisList.stream()
+                    .filter(e -> DateUtil.format(e.getSignTime(), "yyyy-MM-dd").equals(DateUtil.format(date, "yyyy-MM-dd")))
+                    .collect(Collectors.toList());
+            Map<Long, List<Pdasignhis>> pdUserMap = pdasignhisListFinal.stream().collect(Collectors.groupingBy(Pdasignhis::getSignUser));
+            pdUserMap.forEach((k,v) -> {
+                if (!queryUserIds.contains(k)) {
+                    return;
+                }
+                AttendanceReportVo vo = new AttendanceReportVo();
+                vo.setId(num.get());
+                vo.setUserId(k);
+                vo.setUserName(v.get(0).getSignUserName());
+                vo.setDeptName(v.get(0).getDeptName());
+                vo.setOnNumber(BigDecimal.ZERO);
+                vo.setOffNumber(BigDecimal.ZERO);
+                Map<String, List<Pdasignhis>> pdOnOffMap = v.stream().collect(Collectors.groupingBy(Pdasignhis::getSignType));
+                pdOnOffMap.forEach((k1,v1) -> {
+                    v1.sort(Comparator.comparing(Pdasignhis::getSignTime));
+                    if (k1.equals("1")) {
+                        vo.setOnTime(v1.get(0).getSignTime());
+                        vo.setOnAddress(v1.get(0).getSignAddress());
+                        vo.setOnNumber(BigDecimal.valueOf(v1.size()));
+                    } else if (k1.equals("2")) {
+                        vo.setOffTime(v1.get(v1.size() - 1).getSignTime());
+                        vo.setOffAddress(v1.get(v1.size() - 1).getSignAddress());
+                        vo.setOffNumber(BigDecimal.valueOf(v1.size()));
+                    }
+                });
+                vo.setSignNumber(vo.getOnNumber().add(vo.getOffNumber()));
+                if (vo.getOnTime() != null && vo.getOffTime() != null) {
+                    BigDecimal workHours = new BigDecimal(DateUtil.format(vo.getOffTime(), "HH"))
+                            .subtract(new BigDecimal(DateUtil.format(vo.getOnTime(), "HH")));
+                    vo.setWorkHour(workHours);
+                }
+                res.add(vo);
+                num.getAndIncrement();
+            });
+        });
+        return res;
+    }
+
+    /**
+     * 获取两个日期之间的所有日期
+     * @param start 开始日期
+     * @param end 结束日期
+     * @param type 0小时 12
+     * @return list
+     */
+    List<Date> getBetweenDate(String start, String end, Integer type) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(DateUtil.parse(start, "yyyy-MM-dd HH:mm:ss"));
+        List<Date> dateList = new ArrayList<>();
+        while (DateUtil.format(cal.getTime(), "yyyy-MM-dd HH:mm:ss").compareTo(end) < 0) {
+            dateList.add(cal.getTime());
+            switch (type) {
+                case 0:
+                    cal.add(Calendar.HOUR, +1);
+                    break;
+                case 1:
+                    cal.add(Calendar.DATE, +1);
+                    break;
+                case 2:
+                    cal.add(Calendar.MONTH, +1);
+                    break;
+            }
+        }
+        return dateList;
+    }
 }

+ 20 - 0
hnls-gps/hnls-gps-boot/src/main/resources/mapper/plan/PdasignhisMapper.xml

@@ -16,7 +16,27 @@
         <result property="note" column="NOTE"/>
         <result property="flag" column="FLAG"/>
         <result property="signTime" column="SIGN_TIME"/>
+        <association property="signUserName" column="SIGN_USER" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
+        <association property="deptName" column="SIGN_USER" select="getDeptName"/>
     </resultMap>
 
+    <select id="getUserIdList" resultType="long">
+        select ID
+        from TF_SMPN_USER_X
+        <if test="deptIds != null and deptIds != ''">
+            where DEPARTMENT_ID in
+            <foreach item="deptId" collection="deptIds.split(',')" open="(" separator="," close=")">
+                #{deptId}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="getDeptName" resultType="string">
+        select b.NAME
+        from TF_SMPN_USER_X a
+                 left join TF_SMPN_DEPARTMENT_X b on b.ID = a.DEPARTMENT_ID
+        where a.ID = #{signUser}
+    </select>
+
 
 </mapper>

+ 6 - 0
hnls-gps/pom.xml

@@ -45,6 +45,12 @@
             <version>3.3.2</version>
             <scope>compile</scope>
         </dependency>
+        <!--文档处理Excel-->
+        <dependency>
+            <groupId>com.haiqiu.tools</groupId>
+            <artifactId>hq-all-tools</artifactId>
+            <version>1.1.1</version>
+        </dependency>
     </dependencies>