Browse Source

导入考勤数据,特殊日期设置

yusm 2 weeks ago
parent
commit
aed6d72ee3
13 changed files with 551 additions and 1 deletions
  1. 35 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/AttendanceController.java
  2. 74 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/SpecialDateSetController.java
  3. 81 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/entity/Attendance.java
  4. 56 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/entity/SpecialDateSet.java
  5. 16 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/mapper/AttendanceMapper.java
  6. 16 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/mapper/SpecialDateSetMapper.java
  7. 21 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/AttendanceService.java
  8. 16 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/SpecialDateSetService.java
  9. 175 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/AttendanceServiceImpl.java
  10. 20 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/SpecialDateSetServiceImpl.java
  11. 1 1
      fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/CodeGenerator.java
  12. 22 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/AttendanceMapper.xml
  13. 18 0
      fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/SpecialDateSetMapper.xml

+ 35 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/AttendanceController.java

@@ -0,0 +1,35 @@
+package com.management.platform.controller;
+
+
+import com.management.platform.service.AttendanceService;
+import com.management.platform.util.HttpRespMsg;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-16
+ */
+@RestController
+@RequestMapping("/attendance")
+public class AttendanceController {
+
+    @Resource
+    private AttendanceService attendanceService;
+
+    @RequestMapping("/importAttendanceData")
+    public HttpRespMsg importAttendanceData(String month, MultipartFile file, HttpServletRequest request){
+        return attendanceService.importAttendanceData(month,file,request);
+    }
+
+}
+

+ 74 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/controller/SpecialDateSetController.java

@@ -0,0 +1,74 @@
+package com.management.platform.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.management.platform.entity.SpecialDateSet;
+import com.management.platform.service.SpecialDateSetService;
+import com.management.platform.util.HttpRespMsg;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-17
+ */
+@RestController
+@RequestMapping("/special-date-set")
+public class SpecialDateSetController {
+
+    @Resource
+    private SpecialDateSetService specialDateSetService;
+
+
+    @RequestMapping("/list")
+    private HttpRespMsg getSpecialDateSetList(){
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        List<SpecialDateSet> setList = specialDateSetService.list(new QueryWrapper<SpecialDateSet>().orderByDesc("id"));
+        httpRespMsg.setData(setList);
+        return httpRespMsg;
+    }
+
+    @RequestMapping("/saveOrUpdate")
+    private HttpRespMsg saveOrUpdate(SpecialDateSet specialDateSet){
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        if (specialDateSet.getSpecialDate()==null||specialDateSet.getType()==null){
+            httpRespMsg.setError("请选择日期或日期类型");
+            return httpRespMsg;
+        }
+        if (specialDateSet.getId() == null){
+            int count = specialDateSetService.count(new QueryWrapper<SpecialDateSet>().eq("special_date", specialDateSet.getSpecialDate()));
+            if (count > 0){
+                httpRespMsg.setError("该日期已被设置为特殊日期");
+                return httpRespMsg;
+            }
+            specialDateSetService.save(specialDateSet);
+        }else {
+            int count = specialDateSetService.count(new QueryWrapper<SpecialDateSet>()
+                    .eq("special_date", specialDateSet.getSpecialDate())
+                    .ne("id", specialDateSet.getId()));
+            if (count > 0){
+                httpRespMsg.setError("该日期已被设置为特殊日期");
+                return httpRespMsg;
+            }
+            specialDateSetService.updateById(specialDateSet);
+        }
+        return httpRespMsg;
+    }
+
+    @RequestMapping("/deleteSpecial")
+    private HttpRespMsg deleteSpecial(Integer id){
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        specialDateSetService.removeById(id);
+        return httpRespMsg;
+    }
+
+}
+

+ 81 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/entity/Attendance.java

@@ -0,0 +1,81 @@
+package com.management.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import java.util.Date;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-16
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class Attendance extends Model<Attendance> {
+
+    private static final long serialVersionUID=1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 月份
+     */
+    @TableField("month")
+    private String month;
+
+    /**
+     * 工号
+     */
+    @TableField("job_number")
+    private String jobNumber;
+
+    /**
+     * 名称
+     */
+    @TableField("name")
+    private String name;
+
+    /**
+     * 部门名称
+     */
+    @TableField("dept_name")
+    private String deptName;
+
+    /**
+     * 打卡时间
+     */
+    @TableField("clock_time")
+    private Date clockTime;
+
+    /**
+     * 周几
+     */
+    @TableField("week")
+    private String week;
+
+    /**
+     * 打卡地点
+     */
+    @TableField("clock_address")
+    private String clockAddress;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 56 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/entity/SpecialDateSet.java

@@ -0,0 +1,56 @@
+package com.management.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import java.util.Date;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-17
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class SpecialDateSet extends Model<SpecialDateSet> {
+
+    private static final long serialVersionUID=1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 特殊日期
+     */
+    @TableField("special_date")
+    private Date specialDate;
+
+    /**
+     * 日期类型: 0节假日,工作日
+     */
+    @TableField("type")
+    private Integer type;
+
+    /**
+     * 描述
+     */
+    @TableField("desc")
+    private String desc;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/mapper/AttendanceMapper.java

@@ -0,0 +1,16 @@
+package com.management.platform.mapper;
+
+import com.management.platform.entity.Attendance;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-16
+ */
+public interface AttendanceMapper extends BaseMapper<Attendance> {
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/mapper/SpecialDateSetMapper.java

@@ -0,0 +1,16 @@
+package com.management.platform.mapper;
+
+import com.management.platform.entity.SpecialDateSet;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-17
+ */
+public interface SpecialDateSetMapper extends BaseMapper<SpecialDateSet> {
+
+}

+ 21 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/AttendanceService.java

@@ -0,0 +1,21 @@
+package com.management.platform.service;
+
+import com.management.platform.entity.Attendance;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.management.platform.util.HttpRespMsg;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-16
+ */
+public interface AttendanceService extends IService<Attendance> {
+
+    HttpRespMsg importAttendanceData(String month, MultipartFile file, HttpServletRequest request);
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/SpecialDateSetService.java

@@ -0,0 +1,16 @@
+package com.management.platform.service;
+
+import com.management.platform.entity.SpecialDateSet;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-17
+ */
+public interface SpecialDateSetService extends IService<SpecialDateSet> {
+
+}

+ 175 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/AttendanceServiceImpl.java

@@ -0,0 +1,175 @@
+package com.management.platform.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.management.platform.entity.Attendance;
+import com.management.platform.entity.CustomerInfo;
+import com.management.platform.entity.User;
+import com.management.platform.mapper.AttendanceMapper;
+import com.management.platform.service.AttendanceService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.management.platform.service.UserService;
+import com.management.platform.util.ExcelUtil;
+import com.management.platform.util.HttpRespMsg;
+import com.management.platform.util.MessageUtils;
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-16
+ */
+@Service
+public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attendance> implements AttendanceService {
+    @Resource
+    private UserService userService;
+
+    @Resource
+    private AttendanceService attendanceService;
+
+    @Override
+    public HttpRespMsg importAttendanceData(String month, MultipartFile file, HttpServletRequest request) {
+        HttpRespMsg msg=new HttpRespMsg();
+        try(InputStream inputStream= file.getInputStream()) {
+            //然后解析表格
+            Workbook workbook = WorkbookFactory.create(inputStream);
+//            Integer companyId=userService.getById(request.getHeader("token")).getCompanyId();
+            //获取公司所有员工
+//            List<User> userList = userService.list(new QueryWrapper<User>().eq("company_id", companyId));
+
+            //获取对应月份的考勤记录
+            List<Attendance> attendanceList = attendanceService.list(new QueryWrapper<Attendance>().eq("month", month));
+
+            Sheet sheet = workbook.getSheetAt(0);
+            //由于第一行需要指明列对应的标题
+            int rowNum = sheet.getLastRowNum();
+            if (rowNum == 0) {
+                //msg.setError("请填写客户数据");
+                msg.setError("请填写考勤数据");
+                return msg;
+            }
+            List<String> nameList=new ArrayList<>();
+            int dataCount = 0;
+            ArrayList<Attendance> list = new ArrayList<>();
+            for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
+                Row row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    continue;
+                }
+                if (ExcelUtil.isRowEmpty(row)) {
+                    continue;
+                }
+                for (int i = 0; i < 8; i++) {
+                    Cell cell = row.getCell(0);
+                    if (cell!=null) {
+                        cell.setCellType(CellType.STRING);
+                    }
+                }
+                Attendance attendance = new Attendance();
+                attendance.setMonth(month);
+                Cell numCell = row.getCell(2);
+                if (numCell!=null&&!StringUtils.isEmpty(numCell.getStringCellValue())) {
+                    String num = numCell.getStringCellValue();
+                    String trim = num.trim();
+                    attendance.setJobNumber("LEW"+trim);
+                }else {
+                    attendance.setJobNumber("");
+                }
+
+                Cell nameCell = row.getCell(3);
+                if (nameCell!=null&&!StringUtils.isEmpty(nameCell.getStringCellValue())) {
+                    attendance.setName(nameCell.getStringCellValue());
+                }else {
+                    attendance.setName("");
+                }
+
+                Cell deptCell = row.getCell(4);
+                if (deptCell!=null&&!StringUtils.isEmpty(deptCell.getStringCellValue())) {
+                    attendance.setDeptName(deptCell.getStringCellValue());
+                }else {
+                    attendance.setDeptName("");
+                }
+
+                Cell timeCell = row.getCell(5);
+                if (timeCell!=null&&!StringUtils.isEmpty(timeCell.getStringCellValue())) {
+                    String stringCellValue = timeCell.getStringCellValue();
+                    int index = stringCellValue.indexOf("星");
+                    String timeValue = stringCellValue.substring(0,index-1);
+                    String weekValue = stringCellValue.substring(index);
+
+                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    Date date = simpleDateFormat.parse(timeValue);
+                    attendance.setClockTime(date);
+                    attendance.setWeek(weekValue);
+
+                }else {
+                    attendance.setClockTime(null);
+                    attendance.setWeek("");
+                }
+
+                Cell addressCell = row.getCell(6);
+                if (addressCell!=null&&!StringUtils.isEmpty(addressCell.getStringCellValue())) {
+                    attendance.setClockAddress(addressCell.getStringCellValue());
+                }else {
+                    attendance.setDeptName("");
+                }
+                long count = attendanceList.stream().filter(a -> a != null
+                                && a.getMonth().equals(attendance.getMonth())
+                                && a.getJobNumber().equals(attendance.getJobNumber())
+                                && a.getClockTime().equals(attendance.getClockTime())
+                                && a.getClockAddress().equals(attendance.getClockAddress()))
+                        .count();
+                if (count>0) {
+                    continue;
+                }else {
+                    dataCount++;
+                    list.add(attendance);
+                }
+            }
+            attendanceService.saveBatch(list);
+            msg.data=dataCount;
+            return msg;
+        } catch (IOException e){
+            e.printStackTrace();
+            //msg.setError("文件处理出错");
+            msg.setError(MessageUtils.message("file.error"));
+            return msg;
+        } catch (InvalidFormatException e) {
+            e.printStackTrace();
+            //msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
+            msg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
+            return msg;
+        } catch (EncryptedDocumentException e) {
+            e.printStackTrace();
+            //msg.setError("文件加密状态,需要先解除加密状态再上传");
+            msg.setError(MessageUtils.message("file.encryption"));
+            return msg;
+        } catch (ParseException e) {
+            msg.setError("日期解析有问题");
+            return msg;
+        }
+    }
+}

+ 20 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/service/impl/SpecialDateSetServiceImpl.java

@@ -0,0 +1,20 @@
+package com.management.platform.service.impl;
+
+import com.management.platform.entity.SpecialDateSet;
+import com.management.platform.mapper.SpecialDateSetMapper;
+import com.management.platform.service.SpecialDateSetService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2025-06-17
+ */
+@Service
+public class SpecialDateSetServiceImpl extends ServiceImpl<SpecialDateSetMapper, SpecialDateSet> implements SpecialDateSetService {
+
+}

+ 1 - 1
fhKeeper/formulahousekeeper/management-workshop/src/main/java/com/management/platform/util/CodeGenerator.java

@@ -92,7 +92,7 @@ public class CodeGenerator {
 
         // 数据源配置
         DataSourceConfig dsc = new DataSourceConfig();
-        dsc.setUrl("jdbc:mysql://47.101.180.183:17089/man_workshop_lew?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8");
+        dsc.setUrl("jdbc:mysql://1.94.62.58:17089/man_workshop_lew?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8");
 //        dsc.setSchemaName("public");
         dsc.setDriverName("com.mysql.cj.jdbc.Driver");
         dsc.setUsername("root");

+ 22 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/AttendanceMapper.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.management.platform.mapper.AttendanceMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.management.platform.entity.Attendance">
+        <id column="id" property="id" />
+        <result column="month" property="month" />
+        <result column="job_number" property="jobNumber" />
+        <result column="name" property="name" />
+        <result column="dept_name" property="deptName" />
+        <result column="clock_time" property="clockTime" />
+        <result column="week" property="week" />
+        <result column="clock_address" property="clockAddress" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, month, job_number, name, dept_name, clock_time, week, clock_address
+    </sql>
+
+</mapper>

+ 18 - 0
fhKeeper/formulahousekeeper/management-workshop/src/main/resources/mapper/SpecialDateSetMapper.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.management.platform.mapper.SpecialDateSetMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.management.platform.entity.SpecialDateSet">
+        <id column="id" property="id" />
+        <result column="special_date" property="specialDate" />
+        <result column="type" property="type" />
+        <result column="desc" property="desc" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, special_date, type, desc
+    </sql>
+
+</mapper>