浏览代码

通过导出 导入的方式修改日报的审核时间

Min 1 年之前
父节点
当前提交
64dbb88c16

+ 258 - 7
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ReportLogController.java

@@ -3,22 +3,38 @@ package com.management.platform.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.management.platform.entity.CompanyDingding;
-import com.management.platform.entity.ReportLog;
-import com.management.platform.entity.User;
-import com.management.platform.entity.WxCorpInfo;
-import com.management.platform.mapper.CompanyDingdingMapper;
-import com.management.platform.mapper.UserMapper;
-import com.management.platform.mapper.WxCorpInfoMapper;
+import com.management.platform.entity.*;
+import com.management.platform.mapper.*;
 import com.management.platform.service.ReportLogService;
 import com.management.platform.service.ReportService;
+import com.management.platform.util.ExcelUtil;
 import com.management.platform.util.HttpRespMsg;
+import com.management.platform.util.MessageUtils;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.hamcrest.core.Is;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.util.StringUtils;
 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;
+import java.io.*;
+import java.lang.reflect.Array;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -40,6 +56,16 @@ public class ReportLogController {
     WxCorpInfoMapper wxCorpInfoMapper;
     @Resource
     private CompanyDingdingMapper companyDingdingMapper;
+    @Resource
+    private HttpServletRequest request;
+    @Resource
+    private ReportMapper reportMapper;
+    @Resource
+    private ProjectMapper projectMapper;
+    @Value(value = "${upload.path}")
+    private String path;
+    @Resource
+    private ReportService reportService;
 
     @RequestMapping("/get")
     public HttpRespMsg get(String creatorId, String createDate) {
@@ -66,5 +92,230 @@ public class ReportLogController {
         msg.data = list;
         return msg;
     }
+
+    @RequestMapping("/exportReportLog")
+    public HttpRespMsg exportReportLog(String startDate,String endDate){
+        HttpRespMsg msg = new HttpRespMsg();
+        Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        List<ReportLog> list = reportLogService.list(new LambdaQueryWrapper<ReportLog>().eq(ReportLog::getCompanyId,companyId).between(ReportLog::getCreateDate, startDate,endDate));
+        list=list.stream().filter(l->l.getMsg().contains("审核通过了")).collect(Collectors.toList());
+        List<List<String>> dataList=new ArrayList<>();
+        List<String> titleList=new ArrayList<>();
+        titleList.add("编号(不可随意修改)");
+        titleList.add("姓名");
+        titleList.add("工号");
+        titleList.add("工作日期");
+        titleList.add("项目名称");
+        titleList.add("项目编号");
+        titleList.add("审核通过时间");
+        dataList.add(titleList);
+        List<String> reportIds = list.stream().map(ReportLog::getReportIds).collect(Collectors.toList());
+        List<Integer> reportIdList=new ArrayList<>();
+        reportIds.forEach(r->{
+            String[] split = r.split(",");
+            List<Integer> reportIdListSub = Arrays.asList(split).stream().map(i -> Integer.valueOf(i)).collect(Collectors.toList());
+            reportIdList.addAll(reportIdListSub);
+        });
+        reportIdList.add(-1);
+        List<Report> reportList = reportMapper.selectList(new LambdaQueryWrapper<Report>().in(Report::getId, reportIdList));
+        List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId,companyId));
+        List<Integer> projectIds= reportList.stream().map(Report::getProjectId).distinct().collect(Collectors.toList());
+        projectIds.add(-1);
+        List<Project> projectList = projectMapper.selectList(new LambdaQueryWrapper<Project>().in(Project::getId, projectIds));
+        for (ReportLog reportLog : list) {
+            List<String> item=new ArrayList<>();
+            item.add(String.valueOf(reportLog.getId()));
+            Optional<User> user = userList.stream().filter(u -> u.getId().equals(reportLog.getCreatorId())).findFirst();
+            if(user.isPresent()){
+                item.add(String.valueOf(user.get().getName()));
+                item.add(String.valueOf(user.get().getJobNumber()));
+            }else {
+                item.add("");
+                item.add("");
+            }
+            item.add(String.valueOf(df.format(reportLog.getCreateDate())));
+            String ids = reportLog.getReportIds();
+            String[] split = ids.split(",");
+            StringBuilder projectNames=new StringBuilder();
+            StringBuilder projectCodes=new StringBuilder();
+            for (int i = 0; i < split.length; i++) {
+                String reportId = split[i];
+                Optional<Report> report = reportList.stream().filter(r -> r.getId().equals(Integer.valueOf(reportId))).findFirst();
+                if(report.isPresent()){
+                    Optional<Project> first = projectList.stream().filter(p -> p.getId().equals(report.get().getProjectId())).findFirst();
+                    if(first.isPresent()){
+                        if(i==0){
+                            projectNames.append(first.get().getProjectName());
+                            projectCodes.append((first.get().getProjectCode()==null?"":first.get().getProjectCode()));
+                        }else {
+                            projectNames.append(","+first.get().getProjectName());
+                            projectCodes.append(","+(first.get().getProjectCode()==null?"":first.get().getProjectCode()));
+                        }
+                    }
+                }
+            }
+            item.add(projectNames.toString());
+            item.add(projectCodes.toString());
+            item.add(String.valueOf(df1.format(reportLog.getOperateDate())));
+            dataList.add(item);
+        }
+        String resp = ExcelUtil.exportGeneralExcelByTitleAndList("日报审核记录", dataList, path);
+        msg.setData(resp);
+        return msg;
+    }
+
+    @RequestMapping("/importReportLogChange")
+    public HttpRespMsg importReportLogChange(MultipartFile multipartFile){
+        HttpRespMsg msg=new HttpRespMsg();
+        //然后处理文件
+        String fileName = multipartFile.getOriginalFilename();
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        File file = new File(fileName == null ? "file" : fileName);
+        InputStream inputStream = null;
+        OutputStream outputStream = null;
+        try {
+            inputStream = multipartFile.getInputStream();
+            outputStream = new FileOutputStream(file);
+            byte[] buffer = new byte[4096];
+            int temp = 0;
+            while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
+                outputStream.write(buffer, 0, temp);
+            }
+            inputStream.close();
+            outputStream.close();
+            //然后解析表格
+            XSSFWorkbook workbook = new XSSFWorkbook(file);
+            //我们只需要第一个sheet
+            XSSFSheet sheet = workbook.getSheetAt(0);
+            //由于第一行需要指明列对应的标题
+            int rowNum = sheet.getLastRowNum();
+            List<Integer> reportLogIds=new ArrayList<>();
+            for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
+                XSSFRow row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    continue;
+                }
+                //跳过空行
+                if (ExcelUtil.isRowEmpty(row)) {
+                    continue;
+                }
+                XSSFCell numCell = row.getCell(0);
+                if (numCell != null) {
+                    String code = numCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
+                    if ((code.equals("编号(不可随意修改)")||(code.equals("编号(不可随意修改)")) && rowIndex == 0)){
+                        //跳过第一行标题
+                        continue;
+                    }
+                }
+                if (numCell != null)numCell.setCellType(CellType.STRING);
+                Integer numCellValue = Integer.valueOf(numCell.getStringCellValue());
+                reportLogIds.add(numCellValue);
+            }
+            List<ReportLog> reportLogList = reportLogService.list(new LambdaQueryWrapper<ReportLog>().in(ReportLog::getId, reportLogIds));
+            List<String> reportIds = reportLogList.stream().map(ReportLog::getReportIds).collect(Collectors.toList());
+            List<Integer> reportIdList =new ArrayList<>();
+            reportIds.forEach(r->{
+                String[] split = r.split(",");
+                List<Integer> reportSubIds = Arrays.asList(split).stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList());
+                reportIdList.addAll(reportSubIds);
+            });
+            List<Report> reportList = reportMapper.selectList(new LambdaQueryWrapper<Report>().in(Report::getId, reportIdList));
+            StringBuilder sb=new StringBuilder();
+            List<Report> needUpdateReportList=new ArrayList<>();
+            List<ReportLog> needUpdateReportLogList=new ArrayList<>();
+            for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
+                XSSFRow row = sheet.getRow(rowIndex);
+                if (row == null) {
+                    continue;
+                }
+                //跳过空行
+                if (ExcelUtil.isRowEmpty(row)) {
+                    continue;
+                }
+                XSSFCell numCell = row.getCell(0);
+                XSSFCell nameCell = row.getCell(1);
+                XSSFCell jobNumCell = row.getCell(2);
+                XSSFCell createDateCell = row.getCell(3);
+                XSSFCell projectNameCell = row.getCell(4);
+                XSSFCell projectCodeCell = row.getCell(5);
+                XSSFCell auditDateCell = row.getCell(6);
+
+                if (numCell != null) {
+                    String code = numCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
+                    if ((code.equals("编号(不可随意修改)")||(code.equals("编号(不可随意修改)")) && rowIndex == 0)){
+                        //跳过第一行标题
+                        continue;
+                    }
+                }
+
+                if (numCell != null)numCell.setCellType(CellType.STRING);
+                if (nameCell != null)nameCell.setCellType(CellType.STRING);
+                if (jobNumCell != null)jobNumCell.setCellType(CellType.STRING);
+                if (createDateCell != null)createDateCell.setCellType(CellType.STRING);
+                if (projectNameCell != null)projectNameCell.setCellType(CellType.STRING);
+                if (projectCodeCell != null)projectCodeCell.setCellType(CellType.STRING);
+                if (auditDateCell != null)auditDateCell.setCellType(CellType.STRING);
+
+                Integer numCellValue = Integer.valueOf(numCell.getStringCellValue());
+                String nameCellValue = nameCell.getStringCellValue();
+                String jobNumCellValue =jobNumCell.getStringCellValue();
+                String createDateCellValue = createDateCell.getStringCellValue();
+                String projectNameCellValue = projectNameCell.getStringCellValue();
+                String projectCodeCellValue = projectCodeCell.getStringCellValue();
+                String auditDateCellValue = auditDateCell.getStringCellValue();
+
+
+                Optional<ReportLog> first = reportLogList.stream().filter(r -> r.getId().equals(numCellValue)).findFirst();
+                if(first.isPresent()){
+                    ReportLog reportLog = first.get();
+                    String reportIdSplit = reportLog.getReportIds();
+                    List<Integer> ids = Arrays.asList(reportIdSplit.split(",")).stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList());
+                    List<Report> reports = reportList.stream().filter(r -> ids.contains(r.getId())).collect(Collectors.toList());
+                    if(auditDateCellValue!=null){
+                        LocalDateTime time = null;
+                        try {
+                             time = LocalDateTime.parse(auditDateCellValue, df);
+                        }catch (Exception e){
+                            msg.setError("第"+row+"行审核时间格式错误,请检查审核时间数据");
+                            return msg;
+                        }
+                        reportLog.setOperateDate(time);
+                        needUpdateReportLogList.add(reportLog);
+                        LocalDateTime finalTime = time;
+                        reports.forEach(r->{
+                            r.setProjectAuditTime(finalTime);
+                        });
+                        needUpdateReportList.addAll(reports);
+                    }
+                }else {
+                    if(sb.toString().length()==0){
+                        sb.append(numCell);
+                    }else {
+                        sb.append(","+numCell);
+                    }
+                }
+            }
+            if(needUpdateReportList.size()>0){
+                reportService.updateBatchById(needUpdateReportList);
+            }
+            if(needUpdateReportLogList.size()>0){
+                reportLogService.updateBatchById(needUpdateReportLogList);
+            }
+            if(sb.length()>0){
+                msg.setMsg("更新完成,其中编号["+sb.toString()+"]的填报数据不存在");
+            }else {
+                msg.setMsg("更新完成");
+            }
+        }catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (InvalidFormatException e) {
+            e.printStackTrace();
+        }
+        return msg;
+    }
 }
 

+ 12 - 12
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -4952,9 +4952,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         if (!StringUtils.isEmpty(part)) {
                             String[] partSplit = part.split("\\,|\\,");
                             for (String str : partSplit) {
-                                if(str.equals(inchargerCell.getStringCellValue())){
-                                    continue;
-                                }
+//                                if(str.equals(inchargerCell.getStringCellValue())){
+//                                    continue;
+//                                }
                                 ProjectAuditor projectAuditor = new ProjectAuditor();
                                 String s1;
                                 if(str.startsWith("/")){
@@ -5068,9 +5068,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         if (!StringUtils.isEmpty(part)) {
                             String[] partSplit = part.split("\\,|\\,");
                             for (String str : partSplit) {
-                                if(str.equals(inchargerCell.getStringCellValue())){
-                                    continue;
-                                }
+//                                if(str.equals(inchargerCell.getStringCellValue())){
+//                                    continue;
+//                                }
                                 ProjectAuditor projectAuditor = new ProjectAuditor();
                                 String s1;
                                 if(str.startsWith("/")){
@@ -6346,9 +6346,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         if (!StringUtils.isEmpty(part)) {
                             String[] partSplit = part.split("\\,|\\,");
                             for (String str : partSplit) {
-                                if(str.equals(inchargerCell.getStringCellValue())){
-                                    continue;
-                                }
+//                                if(str.equals(inchargerCell.getStringCellValue())){
+//                                    continue;
+//                                }
                                 ProjectAuditor projectAuditor = new ProjectAuditor();
                                 String s1;
                                 if(str.startsWith("/")){
@@ -6462,9 +6462,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                         if (!StringUtils.isEmpty(part)) {
                             String[] partSplit = part.split("\\,|\\,");
                             for (String str : partSplit) {
-                                if(str.equals(inchargerCell.getStringCellValue())){
-                                    continue;
-                                }
+//                                if(str.equals(inchargerCell.getStringCellValue())){
+//                                    continue;
+//                                }
                                 String s1;
                                 if(str.startsWith("/")){
                                     s1=str.substring(1,str.length());

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ExcelUtil.java

@@ -117,6 +117,8 @@ public class ExcelUtil {
             cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
             cellStyle.setBorderTop(BorderStyle.THIN);//上边框
             cellStyle.setBorderRight(BorderStyle.THIN);//右边框
+            DataFormat dataFormat = workBook.createDataFormat();
+            cellStyle.setDataFormat(dataFormat.getFormat("@"));
 
             if(list.size() > 0) {
                 //标题(如果需要在EXCEL内容最上面加标题,请打开下面的注释,修改start)

+ 107 - 2
fhKeeper/formulahousekeeper/timesheet/src/views/workReport/daily.vue

@@ -141,6 +141,7 @@
                                     <el-link type="primary" v-if="user.manageDeptId != 0" style="margin-right:10px;" :underline="false" @click="showExportTimeDialog">{{$t('textLink.exportingTimeStatistics')}}</el-link>
                                     <el-link type="primary" v-if="user.timeType.pushReportData == 1 && permissions.reportPush" :underline="false" @click="pushWorkTime">推送工时</el-link>
                                     <el-link type="primary" v-if="user.timeType.pushReportData == 1 && user.companyId==3092 && permissions.reportPush" :underline="false" @click="pushWorkTimeLogDig=true,getPushWorkLogData()">工时推送日志</el-link>
+                                    <el-link type="primary" v-if="user.roleName == '超级管理员' && user.companyId==839" :underline="false" @click="reportLogCheckDialog=true">日报审核修改</el-link>
                                     <!-- <el-button v-if="user.timeType.pushReportData == 1 && permissions.reportPush" style="margin-left:10px;" icon="iconfont firerock-icontuisong" size="mini" @click="pushWorkTime"></el-button> -->
 
                                 </span>
@@ -1318,6 +1319,33 @@
             </div>
         </el-dialog>
 
+        <!-- 日报审核修改 -->
+        <el-dialog
+        title="日报审核修改"
+        :visible.sync="reportLogCheckDialog"
+        width="30%"
+        :before-close="handleClose">
+        <el-form ref="form3" :model="exportReportLogParam" >
+            <el-form-item prop="projectId" :label="$t('time.dateRange')">
+                    <el-date-picker
+                        v-model="exportReportLogParam.dateRange" :editable="false" 
+                        format="yyyy-MM-dd" value-format="yyyy-MM-dd" 
+                        :range-separator="$t('other.to')"
+                        type="daterange" 
+                        :start-placeholder="$t('time.startDate')"
+                        :end-placeholder="$t('time.endDate')"
+                    ></el-date-picker>
+                </el-form-item>
+        </el-form>
+        <el-link type="primary" @click="exportReportLog">导出日报审核记录数据</el-link>
+        <br>
+        <el-upload ref="upload"  action="#" :limit="1" :http-request="importReportLog" :show-file-list="false">
+        <el-link type="primary" @click="importReportLog">导入日报审核记录修改数据</el-link></el-upload>
+        <span slot="footer" class="dialog-footer">
+            <el-button  type="primary" @click="reportLogCheckDialog = false">关闭</el-button>
+        </span>
+        </el-dialog>
+
         
         <!-- 按部门选择人员 -->
         <el-dialog :title="$t('defaultText.selectthepersonwhneedstofillinthereport')"  v-if="chooseParticipVisible" :visible.sync="chooseParticipVisible" :close-on-click-modal="false" customClass="customWidth" width="500px">
@@ -2218,6 +2246,7 @@
                 statusStyle:["waiting", "filledReportStyle", "RejectStyle", "waitSubmitStyle"],
                 fillStatusList: [],
                 exportParam:{projectId: null, dateRange:[], departmentId: null},
+                exportReportLogParam:{dateRange:[]},
                 exportDialog:false,
                 timeFields:['timeType', 'workingTime', 'startTime', 'progress'],
                 subProjectList:[],
@@ -2431,7 +2460,8 @@
                 pushWorkTimeLogData:[],
 
                 userReportDeptList: [],
-                isReminder:true
+                isReminder:true,
+                reportLogCheckDialog:false,
             };
         },
         watch: {
@@ -2474,6 +2504,7 @@
             this.today = t;
             var startStr = util.formatDate.format(new Date(), 'yyyy-MM') + "-01";
             this.exportParam.dateRange = [startStr,t];
+            this.exportReportLogParam.dateRange = [startStr,t];
             this.getAllDate(1);
             this.getReportList();
             this.getProjectList();
@@ -5712,7 +5743,12 @@
                 res => {
                     this.exportingData = false;
                     if (res.code == "ok") {
-                        location.href = res.data;
+                        var filePath = res.data;
+                        const a = document.createElement('a'); // 创建a标签
+                        a.setAttribute('download', this.$t('projectexport') + '.xlsx');// download属性
+                        a.setAttribute('href', filePath);// href链接
+                        a.click(); //自执行点击事件
+                        a.remove();
                         this.exportDialog = false;
                     } else {
                         this.$message({
@@ -5730,6 +5766,75 @@
                 });
             },
 
+             //导出日报审核记录
+             exportReportLog() {
+                this.exportingData = true;
+                var param = {};
+                if (this.exportReportLogParam.dateRange != null) {
+                    param = {startDate:this.exportReportLogParam.dateRange[0], endDate: this.exportReportLogParam.dateRange[1], exportType: this.exportType};
+                }
+                this.http.post('/report-log/exportReportLog', param,
+                res => {
+                    this.exportingData = false;
+                    if (res.code == "ok") {
+                        var filePath = res.data;
+                        const a = document.createElement('a'); // 创建a标签
+                        a.setAttribute('download', this.$t('projectexport') + '.xlsx');// download属性
+                        a.setAttribute('href', filePath);// href链接
+                        a.click(); //自执行点击事件
+                        a.remove();
+                        this.exportDialog = false;
+                    } else {
+                        this.$message({
+                            message: res.msg,
+                            type: "error"
+                        });
+                    }
+                },
+                error => {
+                    this.exportingData = false;
+                    this.$message({
+                        message: error,
+                        type: "error"
+                    });
+                });
+            },
+            importReportLog(item){
+                //首先判断文件类型
+                let str = item.file.name.split(".");
+                let format = str[str.length - 1];
+                if (format != "xls" && format != "xlsx") {
+                    this.$message({
+                        message: this.$t('other.PleaseselecttheXLSorXLSXfile'),
+                        type: "error"
+                    });
+                } else {
+                    let formData = new FormData();
+                    formData.append("multipartFile", item.file);
+                    this.http.uploadFile('/report-log/importReportLogChange', formData,
+                    res => {
+                        this.$refs.upload.clearFiles();
+                        if (res.code == "ok") {
+                            this.$message({
+                            message: res.msg,
+                            type: "success"
+                        });
+                        } else {
+                            this.$message({
+                            message: res.msg,
+                            type: "error"
+                        });
+                        }
+                    },
+                    error => {
+                        this.$refs.upload.clearFiles();
+                        this.$message({
+                            message: error,
+                            type: "error"
+                        });
+                    });
+                }
+            },
             //获取项目列表
             getProjectList() {
                 this.listLoading = true;