소스 검색

新增新版考勤导入

anderx 1 년 전
부모
커밋
80705a4004

+ 18 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -29,8 +29,10 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  *  项目管理
@@ -487,4 +489,20 @@ public class ProjectTaskController extends BaseController {
     public AjaxResult getAllProjectMonth(){
         return AjaxResult.success(projectStaffRecordService.getAllProjectMonth());
     }
+
+
+
+
+    /**
+     * 导入打卡数据
+     */
+    @PostMapping("/importClockData")
+    @Log(title = "项目管理", businessType = BusinessType.IMPORT)
+    @ApiOperation("导入打卡数据")
+    public AjaxResult importClockData(@RequestParam(value = "file") MultipartFile file) throws Exception
+    {
+        ExcelUtil<Map> util = new ExcelUtil<>(Map.class);
+        List<Map<Integer,String >>  list = util.importMapExcel(file.getInputStream(),0);
+        return success(projectStaffRecordService.importClockData(list));
+    }
 }

+ 12 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -235,4 +235,16 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         cal.setTime(parseDate(dates));
         return cal.get(Calendar.DAY_OF_WEEK)-1;
     }
+
+    public static Date LocalDateToDate(LocalDate date) {
+        return Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
+    }
+
+    public static String LocalDateToStr(LocalDate date) {
+        // 定义日期格式
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+        // 将LocalDate转换为字符串
+        return date.format(formatter);
+    }
 }

+ 7 - 3
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java

@@ -321,7 +321,7 @@ public class ExcelUtil<T>
      * @param titleNum 标题占用行数
      * @return 转换后集合
      */
-    public List<Map<Integer,String >> importMapExcel(InputStream is, int titleNum) throws Exception {
+    public List<Map<Integer,String >> importMapExcel(InputStream is, int titleNum) {
         List<Map<Integer,String >> list =null;
         try {
             list =importMapExcel(StringUtils.EMPTY, is, titleNum);
@@ -391,9 +391,11 @@ public class ExcelUtil<T>
                 }
                 for (int x=0; x<=row.getLastCellNum(); x++){
                     String val=null;
-                    if (row.getCell(x) !=null){
-                         val= row.getCell(x).getStringCellValue();
+                    Cell cell = row.getCell(x);
+                    if (cell !=null){
+                         val = this.getCellValue(row, x).toString();
                     }
+                    System.out.println(x+"="+val);
                         map.put( x,val);
                 }
                 list.add(map);
@@ -2073,4 +2075,6 @@ public class ExcelUtil<T>
         styles.put("total", style);
         return styles;
     }
+
+
 }

+ 26 - 0
ruoyi-system/src/main/java/com/ruoyi/project/bo/UserClockDataBo.java

@@ -0,0 +1,26 @@
+package com.ruoyi.project.bo;
+
+import java.util.List;
+
+public class UserClockDataBo {
+    private String username;
+
+    private List<UserClockDataDetailsBo> list;
+
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public List<UserClockDataDetailsBo> getList() {
+        return list;
+    }
+
+    public void setList(List<UserClockDataDetailsBo> list) {
+        this.list = list;
+    }
+}

+ 34 - 0
ruoyi-system/src/main/java/com/ruoyi/project/bo/UserClockDataDetailsBo.java

@@ -0,0 +1,34 @@
+package com.ruoyi.project.bo;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+
+public class UserClockDataDetailsBo {
+    private String dateStr;
+    private LocalDate date;
+    private BigDecimal duration;
+
+    public LocalDate getDate() {
+        return date;
+    }
+
+    public void setDate(LocalDate date) {
+        this.date = date;
+    }
+
+    public BigDecimal getDuration() {
+        return duration;
+    }
+
+    public void setDuration(BigDecimal duration) {
+        this.duration = duration;
+    }
+
+    public String getDateStr() {
+        return dateStr;
+    }
+
+    public void setDateStr(String dateStr) {
+        this.dateStr = dateStr;
+    }
+}

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectStaffRecordService.java

@@ -4,12 +4,14 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.OutMontClockBo;
 import com.ruoyi.project.bo.ProjectStaffRecordInput;
 import com.ruoyi.project.bo.ProjectStaffRecordOut;
+import com.ruoyi.project.bo.UserClockDataBo;
 import com.ruoyi.project.bo.batchExamineRecordInput;
 import com.ruoyi.project.domain.ProjectStaffRecord;
 import com.ruoyi.project.domain.ProjectStaffRecordLog;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+import java.util.Map;
 
 public interface ProjectStaffRecordService {
     AjaxResult add(ProjectStaffRecord in);
@@ -48,4 +50,6 @@ public interface ProjectStaffRecordService {
     void getMonthClockExport(Integer id, String yearMonth, HttpServletResponse response);
 
     Object getAllProjectMonth();
+
+    Object importClockData(List<Map<Integer,String >> list);
 }

+ 103 - 0
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectStaffRecordServiceImpl.java

@@ -887,6 +887,8 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         return projectTaskMapper.getAllProjectMonth(companyId);
     }
 
+
+
     private void pushDurationAndProportion(List<Map<String, Object>> listData) {
         for (Map<String, Object> map : listData) {
             BigDecimal projectDuration = new BigDecimal(0);
@@ -964,7 +966,108 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         map.put("data", new ArrayList<>(list));
         listData.add(map);
     }
+    @Override
+    public String importClockData(List<Map<Integer,String >> list) {
+        List<UserClockDataBo> userClockDataBos = clockDataToList(list);
+        StringBuilder res = new StringBuilder();
+        Long companyId = deptService.selectCompanyByDeptId();
+
+        for (UserClockDataBo userClockDataBo : userClockDataBos) {
+            SysUser sysUser=null;
+            try {
+                sysUser = sysUserMapper.selectByNikeName(userClockDataBo.getUsername(), companyId);
+            }catch (Exception e){
+                res.append("<br/>").append("员工[").append(userClockDataBo.getUsername()).append("]查询异常,可能存在重名。");
+            }
+
+            if (sysUser==null){
+                res.append("<br/>").append("员工[").append(userClockDataBo.getUsername()).append("]不存在。");
+            }else {
+                List<UserClockDataDetailsBo> list1 = userClockDataBo.getList();
+                for (UserClockDataDetailsBo e : list1) {
+                    String dateStr=DateUtils.LocalDateToStr(e.getDate());
+                    List<ProjectStaffRecord> projectStaffRecords = projectStaffRecordMapper.selectByAidAndTime(sysUser.getUserId(), dateStr, dateStr + " 23:59:59");
+                    if (projectStaffRecords==null|| projectStaffRecords.isEmpty()){
+                        res.append("<br/>").append("员工[").append(userClockDataBo.getUsername()).append("]日期[").append(dateStr).append("]不存在。");
+                    }else {
+                        for (ProjectStaffRecord psr : projectStaffRecords) {
+                            ProjectStaffRecord update =new ProjectStaffRecord();
+                            update.setId(psr.getId());
+                            update.setCheckDuration(e.getDuration().doubleValue());
+                            projectStaffRecordMapper.updateByPrimaryKeySelective(update);
+                            res.append("<br/>").append("员工[").append(userClockDataBo.getUsername()).append("]日期[").append(dateStr).append("]修改成功。");
+                        }
+                    }
+
+
+                }
+            }
+
+        }
+        return res.toString();
+    }
+
 
+    public List<UserClockDataBo> clockDataToList(List<Map<Integer,String >> list) {
+        List<UserClockDataBo> listData = new ArrayList<>();
+        String title;
+        String title2;
+        //第一行标题
+        title = list.get(0).get(0);
+        System.out.println(title);
+        String[] split = title.split(" ");
+        String date =split[split.length - 1];
+        System.out.println(date);
+
+        //第二号生成信息
+        title2 = list.get(1).get(0);
+        System.out.println(title2);
+        //标题
+        List<String> title3 = new ArrayList<>(list.get(3).values());
+        title3 = title3.subList(36, title3.size() - 1);
+        System.out.println(title3);
+        //最大标签
+        int size = title3.size();
+        for (int i = 4; i < list.size() ; i++) {
+            Map map = list.get(i);
+            String name = (String) map.get(0);
+            List<String> list1 = new ArrayList<>();
+            List list2 = new ArrayList<>(map.values());
+            list2 = list2.subList(36, list2.size() - 1);
+            UserClockDataBo userClockDataBo = new UserClockDataBo();
+            userClockDataBo.setUsername(name);
+            List<UserClockDataDetailsBo> ul = new ArrayList<>();
+            int index = 0;
+            int day = 0;
+            for (Object o : list2) {
+                UserClockDataDetailsBo userClockDataDetailsBo = new UserClockDataDetailsBo();
+                String str = o.toString();
+                userClockDataDetailsBo.setDuration(new BigDecimal(str));
+                String s = title3.get(index);
+                userClockDataDetailsBo.setDateStr(s);
+                LocalDate localDate = LocalDate.parse(date);
+                if (s.equals("六")||s.equals("日")){
+                    day++;
+                    LocalDate localDate1 = localDate.withDayOfMonth(day);
+                    userClockDataDetailsBo.setDate(localDate1);
+                }else {
+                    day=Integer.parseInt(s);
+                    LocalDate localDate1 = localDate.withDayOfMonth(day);
+                    userClockDataDetailsBo.setDate(localDate1);
+                }
+                ul.add(userClockDataDetailsBo);
+                if (list2.size() == index + 1){
+                    index=0;
+                }else {
+                    index++;
+                }
+
+            }
+            userClockDataBo.setList(ul);
+            listData.add(userClockDataBo);
+        }
+        return listData;
+    }