浏览代码

SgTimeSheet

zhoutao 5 年之前
父节点
当前提交
5b5f6bc001

+ 5 - 0
pigx-inventory/pigx-inventory-biz/pom.xml

@@ -30,6 +30,11 @@
 			<artifactId>fastdfs-client-java</artifactId>
 			<version>1.27.0.0</version>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi-ooxml</artifactId>
+			<version>3.17</version>
+		</dependency>
 		<dependency>
 			<groupId>com.pig4cloud</groupId>
 			<artifactId>pigx-common-data</artifactId>

+ 44 - 0
pigx-inventory/pigx-inventory-biz/src/main/java/com/pig4cloud/pigx/qa/controller/SgTimeSheetController.java

@@ -17,6 +17,12 @@
 
 package com.pig4cloud.pigx.qa.controller;
 
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.ExcelReader;
+import cn.hutool.poi.excel.ExcelUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.pig4cloud.pigx.common.core.util.R;
@@ -28,6 +34,10 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.List;
 
 
 /**
@@ -107,4 +117,38 @@ public class SgTimeSheetController {
         return R.ok(sgTimeSheetService.removeById(id));
     }
 
+
+    /**
+     * excel上传勤数据
+     *
+     * @return R
+     */
+    @PostMapping("/excle" )
+    @ApiOperation(value = "excel上传考勤数据")
+    public R uploadExcel(@RequestParam("file") MultipartFile file) throws IOException {
+
+        ExcelReader reader = ExcelUtil.getReader(file.getResource().getInputStream());
+        List<List<Object>> readAll = reader.read();
+        String timeMonth = StrUtil.sub(readAll.get(0).get(0).toString().trim(), 10, 16);
+        SgTimeSheet condition = new SgTimeSheet();
+        condition.setTimeMonth(Convert.toLong(timeMonth));
+        int count= sgTimeSheetService.count(new QueryWrapper<>(condition));
+        if (count>0){
+            return R.failed(null, "本月数据已传,请勿重复!");
+
+        }
+
+        List<List<Object>> readTimeDatas = reader.read(4);
+        String messages = sgTimeSheetService.uploadTimeExcel(readTimeDatas,timeMonth);
+        if (!messages.isEmpty())
+           {return R.failed(null, "数据表无数据,请检查!");}
+        else {return R.ok(true);}
+
+
+    }
+
+
+
+
+
 }

+ 3 - 1
pigx-inventory/pigx-inventory-biz/src/main/java/com/pig4cloud/pigx/qa/service/SgTimeSheetService.java

@@ -4,8 +4,10 @@ package com.pig4cloud.pigx.qa.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.pig4cloud.pigx.qa.entity.SgTimeSheet;
 
-public interface SgTimeSheetService extends IService<SgTimeSheet> {
+import java.util.List;
 
+public interface SgTimeSheetService extends IService<SgTimeSheet> {
 
+    String uploadTimeExcel(List<List<Object>> readTimeDatas, String timemonth);
 
 }

+ 55 - 1
pigx-inventory/pigx-inventory-biz/src/main/java/com/pig4cloud/pigx/qa/service/impl/SgTimeSheetServiceImpl.java

@@ -1,12 +1,66 @@
 package com.pig4cloud.pigx.qa.service.impl;
 
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.pig4cloud.pigx.qa.entity.SgTimeSheet;
 import com.pig4cloud.pigx.qa.mapper.SgTimeSheetMapper;
 import com.pig4cloud.pigx.qa.service.SgTimeSheetService;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
 
 @Service
 public class SgTimeSheetServiceImpl extends ServiceImpl<SgTimeSheetMapper, SgTimeSheet> implements SgTimeSheetService {
 
-}
+    @Override
+    @Transactional
+    public String uploadTimeExcel(List<List<Object>> readTimeDatas, String timemonth) {
+
+       // Integer userId = SecurityUtils.getUser().getId();
+        List<SgTimeSheet> sgTimeSheets = new ArrayList<>();
+        for (List<Object> data : readTimeDatas) {
+
+            String name = (String) data.get(0);
+            //code为空,继续循环
+            if (StrUtil.isBlank(name)) {continue;}
+            SgTimeSheet sgTimeSheet = new  SgTimeSheet();
+
+                try {
+                    sgTimeSheet.setECnname(data.get(0).toString().trim());
+                    sgTimeSheet.setMonthOvertimeAdd(Convert.toBigDecimal(data.get(1)));
+                    sgTimeSheet.setMonthOvertimeDecrease(Convert.toBigDecimal(data.get(2)));
+                    sgTimeSheet.setMonthOvertimeSurplus(Convert.toBigDecimal(data.get(3)));
+                    sgTimeSheet.setAnnualLeaveDecrease(Convert.toBigDecimal(data.get(4)));
+                    sgTimeSheet.setAnnualLeaveSurplus(Convert.toBigDecimal(data.get(5)));
+                    sgTimeSheet.setSilkLeaveAdd(Convert.toBigDecimal(data.get(6)));
+                    sgTimeSheet.setSilkLeaveAll(Convert.toBigDecimal(data.get(7)));
+                    sgTimeSheet.setLeaveAbsenceAdd(Convert.toBigDecimal(data.get(8)));
+                    sgTimeSheet.setLeaveAbsenceAll(Convert.toBigDecimal(data.get(9)));
+                    sgTimeSheet.setLateLess5(Convert.toLong(data.get(10)));
+                    sgTimeSheet.setLateGreate6(Convert.toLong(data.get(11)));
+                    sgTimeSheet.setLateAll(Convert.toLong(data.get(12)));
+                    sgTimeSheet.setTimeMonth(Long.valueOf(timemonth));
+                    sgTimeSheet.setEId(1L);
+
+                }catch (Exception e) {
+                    return  " 错误";
+                }
+
+             sgTimeSheets.add(sgTimeSheet);
+            }
+
+        sgTimeSheets.forEach(k->saveOrUpdate(k));
+        //rocketMQTemplate.convertAndSend("CSPRODUCTION:supplierQuoted",sgNewQuotes.stream().map(k->k.getPCode()).collect(Collectors.toList())+" 供应商已报价,请尽快查看_"+SecurityUtils.getUser().getUsername());
+        return "";
+    }
+
+
+    }
+
+
+
+
+