瀏覽代碼

导出填报工时占比

seyason 2 年之前
父節點
當前提交
343469542e

+ 67 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserCorpwxTimeController.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.management.platform.entity.*;
 import com.management.platform.entity.vo.SysRichFunction;
 import com.management.platform.mapper.*;
+import com.management.platform.service.DepartmentService;
 import com.management.platform.service.ExcelExportService;
 import com.management.platform.service.ReportService;
 import com.management.platform.service.WxCorpInfoService;
@@ -24,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.text.DecimalFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -57,6 +59,8 @@ public class UserCorpwxTimeController {
     @Resource
     ParticipationMapper participationMapper;
     @Resource
+    DepartmentService departmentService;
+    @Resource
     ProjectMapper projectMapper;
     @Resource
     ReportService reportService;
@@ -309,6 +313,69 @@ public class UserCorpwxTimeController {
         return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo, fileName, allData, path);
     }
 
+    //导出填报工时在考勤工时的占比
+    @RequestMapping("/exportProjectTimeRatio")
+    public HttpRespMsg exportProjectTimeRatio(String ymonth) throws Exception {
+        String token = request.getHeader("TOKEN");
+        User user = userMapper.selectById(token);
+        Integer companyId = user.getCompanyId();
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
+        Integer manageDeptId = user.getManageDeptId();
+
+        List<Map> list = new ArrayList<Map>();
+        List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "全部企微考勤");
+        if (functionList.size() > 0) {
+            //查看全部人员的
+            list = userCorpwxTimeMapper.getUserDataRatioList(user.getCompanyId(), ymonth, null);
+        } else {
+            if (manageDeptId != null && manageDeptId != 0) {
+                //一个人可能担任多个部门负责人
+                List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", user.getCompanyId()));
+                List<Integer> allManagedDeptIdList = departmentService.getAllManagedDeptIdList(user, allDeptList);
+                list = userCorpwxTimeMapper.getUserDataRatioList(user.getCompanyId(), ymonth, allManagedDeptIdList);
+            }
+        }
+
+
+        List<String> titles = new ArrayList<>();
+        titles.add("年月");
+        //titles.add("员工姓名");
+        titles.add(MessageUtils.message("entry.staffName"));
+        //titles.add("实际工作时长");
+        titles.add(MessageUtils.message("entry.actualWorkTime"));
+        titles.add("填报项目时长");
+        titles.add("填报项目时长占比");
+        List<List<String>> allData = new ArrayList<>();
+        allData.add(titles);
+
+        //数据填充
+        for (Map dataItem : list) {
+            List<String> dataList = new ArrayList<>();
+            dataList.add(ymonth);
+            if(wxCorpInfo.getSaasSyncContact()==1){
+                dataList.add("$userName="+(String)dataItem.get("corpwxUserid")+"$");
+            }else{
+                dataList.add((String)dataItem.get("username"));
+            }
+            double wt = (Double)dataItem.get("workHours");
+            double pt = (Double)dataItem.get("projectTime");
+            dataList.add(""+wt);
+            dataList.add(""+pt);
+            DecimalFormat decimalFormat = new DecimalFormat("#0.0%");
+            dataList.add(decimalFormat.format(pt/wt));
+            allData.add(dataList);
+        }
+        String fileName = companyMapper.selectById(user.getCompanyId()).getCompanyName();
+        if (manageDeptId != null && manageDeptId != 0) {
+            List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", user.getId()));
+            String departmentName = allDeptList.stream().map(Department::getDepartmentName).collect(Collectors.joining("+"));
+            fileName = departmentName;
+        }
+        //fileName += "_人员工时统计模板"+startDate+"至"+endDate;
+        fileName = ymonth + fileName;
+        fileName += "项目工时占比";
+        return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo, fileName, allData, path);
+    }
     @RequestMapping("/getPunchRecordBySelf")
     public HttpRespMsg getUserPunchRecord(String date, String userId){
         HttpRespMsg msg=new HttpRespMsg();

文件差異過大導致無法顯示
+ 5 - 7
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java


+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/UserCorpwxTimeMapper.java

@@ -18,5 +18,7 @@ public interface UserCorpwxTimeMapper extends BaseMapper<UserCorpwxTime> {
 
     public List<Map> getUserDataList(Integer companyId, String startDate, String endDate, Integer deptId);
 
+    public List<Map> getUserDataRatioList(Integer companyId, String ymonth, List<Integer> deptIds);
+
     List<Map> selectByAsk(Integer companyId,String startDate,String endDate);
 }

+ 0 - 119
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -4226,7 +4226,6 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
             int rowNum = 1;
             List<HashMap<String, Object>> allReportByDate = null;
 
-            System.out.println("开始查询"+LocalDateTime.now().toString());
             List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全公司工时");
             //获取部门的所有子部门
             List<Department> departments = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",companyId));
@@ -4285,13 +4284,11 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                     allReportByDate = reportMapper.getAllReportByDate(startDate, user.getCompanyId(), null, endDate, projectId,stateKey,branchDepartment);
                 }
             }
-            System.out.println("进度1"+LocalDateTime.now().toString());
             //获取企业微信考勤数据
             List<UserCorpwxTime> userCorpwxTimeList = new ArrayList<>();
             if(timeType.getSyncCorpwxTime()==1) {
                 userCorpwxTimeList = userCorpwxTimeMapper.selectList(new QueryWrapper<UserCorpwxTime>().eq("company_id", user.getCompanyId()).between("create_date", startDate, endDate));
             }
-            System.out.println("进度2"+LocalDateTime.now().toString());
             if (timeType.getMultiWorktime() == 1) {
                 java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
                 //重新处理一下数据,把工作时间和工作事项移出来
@@ -4367,7 +4364,6 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                 }
             }
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
-            System.out.println("进度3"+LocalDateTime.now().toString());
             long t1 = System.currentTimeMillis();
             DateTimeFormatter dft = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
             for (Map<String, Object> map : allReportByDate) {
@@ -4511,89 +4507,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                             sb.append(msg);
                         }
                     }
-                    //审核流程显示;//stream性能较差,换成for循环
-//                    for (int m=0; m <logDetails.size(); m++) {
-//                        ReportLogDetail audit = logDetails.get(m);
-//                        //仅处理当前日报的审核流程
-//                        if (audit.getReportId().intValue() == ((Integer)map.get("id")).intValue()) {
-//                            LocalDateTime operateDate = audit.getOperateDate();
-//                            if (company.getIsInternational() == 1) {
-//                                operateDate = operateDate.plusSeconds(offsetSeconds);
-//                            }
-//                            String time = dtf.format(operateDate);
-//                            String msg= "";
-//                            if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
-//                                Optional<User> first = userList.stream().filter(ul -> ul.getId().equals(audit.getOperatorId())).findFirst();
-//                                if(first.isPresent()){
-//                                    if(audit.getMsg().contains("提交了")){
-//                                        int i = audit.getMsg().indexOf("提");
-//                                        String substring = audit.getMsg().substring(0, i);
-//                                        msg = time+" " + audit.getMsg().replaceAll(substring,"\\$userName="+first.get().getCorpwxUserid()+"\\$");
-//                                    }else if(audit.getMsg().contains("审核通过了")){
-//                                        int i = audit.getMsg().indexOf("审");
-//                                        String substring = audit.getMsg().substring(0, i);
-//                                        msg = time+" " + audit.getMsg().replaceAll(substring,"\\$userName="+first.get().getCorpwxUserid()+"\\$");
-//                                    }else if(audit.getMsg().contains("驳回了")) {
-//                                        int i = audit.getMsg().indexOf("驳");
-//                                        String substring = audit.getMsg().substring(0, i);
-//                                        msg = time+" " + audit.getMsg().replaceAll(substring,"\\$userName="+first.get().getCorpwxUserid()+"\\$");
-//                                    }
-//                                }
-//                            }else {
-//                                msg = time+" " + audit.getMsg();
-//                            }
-//                            if (!isFirst) {
-//                                sb.append("->");
-//                            } else {
-//                                isFirst = false;
-//                            }
-//                            sb.append(msg);
-//                            //去掉这条记录,减少下次循环的次数
-//                            logDetails.remove(m);
-//                            m--;//因为删除了一条记录,所以要减少一次循环
-//                        }
-//                    }
                     item.add(sb.toString());
-//                    List<ReportLogDetail> detailList = logDetails.parallelStream().filter(log -> log.getReportId().equals((Integer) map.get("id"))).collect(Collectors.toList());
-//                    if (detailList.size() > 0) {
-//                        for (ReportLogDetail audit:detailList) {
-//                            LocalDateTime operateDate = audit.getOperateDate();
-//                            if (company.getIsInternational() == 1) {
-//                                operateDate = operateDate.plusSeconds(offsetSeconds);
-//                            }
-//                            String time = dtf.format(operateDate);
-//                            String msg= "";
-//                            if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
-//                                Optional<User> first = userList.stream().filter(ul -> ul.getId().equals(audit.getOperatorId())).findFirst();
-//                                if(first.isPresent()){
-//                                    if(audit.getMsg().contains("提交了")){
-//                                        int i = audit.getMsg().indexOf("提");
-//                                        String substring = audit.getMsg().substring(0, i);
-//                                        msg = time+" " + audit.getMsg().replaceAll(substring,"\\$userName="+first.get().getCorpwxUserid()+"\\$");
-//                                    }else if(audit.getMsg().contains("审核通过了")){
-//                                        int i = audit.getMsg().indexOf("审");
-//                                        String substring = audit.getMsg().substring(0, i);
-//                                        msg = time+" " + audit.getMsg().replaceAll(substring,"\\$userName="+first.get().getCorpwxUserid()+"\\$");
-//                                    }else if(audit.getMsg().contains("驳回了")) {
-//                                        int i = audit.getMsg().indexOf("驳");
-//                                        String substring = audit.getMsg().substring(0, i);
-//                                        msg = time+" " + audit.getMsg().replaceAll(substring,"\\$userName="+first.get().getCorpwxUserid()+"\\$");
-//                                    }
-//                                }
-//                            }else {
-//                                msg = time+" " + audit.getMsg();
-//                            }
-//                            if (!isFirst) {
-//                                sb.append("->");
-//                            } else {
-//                                isFirst = false;
-//                            }
-//                            sb.append(msg);
-//                        }
-//                        item.add(sb.toString());
-//                    } else {
-//                        item.add("");
-//                    }
                 }
                 item.add((String) map.get("content"));
                 if(stateKey==1){
@@ -4682,14 +4596,9 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                 dataList.add(item);
                 rowNum++;
             }
-            System.out.println("进度4"+LocalDateTime.now().toString());
-            long t2 = System.currentTimeMillis();
-            System.out.println("计算耗时:"+(t2-t1)+", 共"+rowNum+"条数据");
             //生成Excel文件
-            //String fileUrlSuffix = (startDate==null?"":(startDate+"至"+endDate))+"工作日报" + System.currentTimeMillis() + ".xls";
             String fileUrlSuffix = (startDate==null?"":(startDate+MessageUtils.message("leave.to")+endDate))+MessageUtils.message("excel.workReport") + System.currentTimeMillis();
             httpRespMsg = excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileUrlSuffix,dataList,path);
-            System.out.println("进度5, 导出结束"+LocalDateTime.now().toString());
         } catch (NullPointerException e) {
             //httpRespMsg.setError("验证失败或缺少数据");
             httpRespMsg.setError(MessageUtils.message("access.verErrorOrDataLack"));
@@ -4725,34 +4634,6 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                 userIds.add(userId);
             }
             List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", userIds));
-
-//            for (User subsUser : userList) {
-//                BigDecimal tempCost = new BigDecimal(0);
-//                if (subsUser.getCostApplyDate() != null) {
-//                    //检查有效期
-//                    if (subsUser.getCostApplyDate().compareTo(dtf.format(now)) > 0) {
-//                        //取上一个历史成本
-//                        List<UserSalary> list = userSalaryService.list(new QueryWrapper<UserSalary>().eq("user_id", subsUser.getId()).orderByDesc("indate").last("limit 2"));
-//                        if (list.size() > 1) {
-//                            tempCost = list.get(1).getCost();
-//                        } else {
-//                            //没有记录,又没有达到预设的起效时间,则默认为0
-//                            tempCost = new BigDecimal(0);
-//                        }
-//                    } else {
-//                        tempCost = subsUser.getCost();
-//                    }
-//                } else {
-//                    tempCost = subsUser.getCost();
-//                }
-//
-//                if (tempCost == null) {
-//                    tempCost = new BigDecimal(0);
-//                }
-//                //设置好时薪
-//                subsUser.setCost(tempCost);
-//            }
-
             for (Report report : reportList) {
                 //获取一下信息
                 if (report.getWorkingTime() <= 0.0) {

+ 0 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/WxCorpInfoServiceImpl.java

@@ -1406,7 +1406,6 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
                         if (needRecaculate) {
                             timeDelta = DateTimeUtil.getHoursFromSeconds(DateTimeUtil.getSecondsFromTime(ct.getEndTime()) - DateTimeUtil.getSecondsFromTime(ct.getStartTime()));
                             //超过下午上班的开始时间,需要减去午休的时间
-                            System.out.println("下午上班时间=="+baseAfternoonStart);
                             if (ct.getEndTime().compareTo(baseAfternoonStart) >= 0) {
                                 //重新计算打卡工时时,需要减去中间午休时间
                                 timeDelta -= restTime;

+ 18 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/UserCorpwxTimeMapper.xml

@@ -36,6 +36,24 @@
         </if>
         ORDER BY a.create_date ASC
     </select>
+
+    <select id="getUserDataRatioList" resultType="java.util.HashMap" >
+        SELECT user.id AS userId, user.`name` as username, user.`corpwx_userid` as corpwxUserid, SUM(a.work_hours) AS workHours, IFNULL(SUM(r.working_time), 0) AS projectTime
+        FROM user_corpwx_time a LEFT JOIN user ON user.`corpwx_userid` = a.corpwx_userid
+        left join report r on r.creator_id = user.id and r.create_date = a.create_date
+        WHERE DATE_FORMAT(a.create_date, '%Y%m') = #{ymonth}
+        AND (user.`is_active` = 1 OR (user.`is_active` = 0 AND DATE_FORMAT(user.`inactive_date`, '%Y%m') >= #{ymonth}))
+        AND a.company_id = #{companyId}
+        <if test="deptIds != null">
+            AND user.`department_id` in
+            <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
+                #{deptId}
+            </foreach>
+        </if>
+        group by user.id
+        ORDER BY user.id ASC
+    </select>
+
     <select id="selectByAsk" resultType="java.util.Map">
         select corpwx_userid ,create_date,ask_leave_time  from user_corpwx_time where company_id=#{companyId} and ask_leave_time>0
         <if test="startDate != null">

+ 55 - 0
fhKeeper/formulahousekeeper/timesheet/src/views/workReport/daily.vue

@@ -1604,6 +1604,7 @@
             <div  slot="title">
                 <span style="font-size:16px;">{{$t('other.Batchimportofworkinghours')}}</span>
                 <el-link v-if="active==0"  style="float:right;margin-right:100px;" type="primary" @click="toView()">{{$t('other.viewLaborImportRecords')}}</el-link>
+                <el-link v-if="active==0"  style="float:right;margin-right:100px;" type="primary" @click="downloadProjectRatio">下载填报工时占比表</el-link>
             </div>
             
             <span slot="footer">
@@ -1616,6 +1617,20 @@
             </span>
         </el-dialog>
 
+        
+        <el-dialog title="导出员工填报工时占比" v-if="exportUserRatio" :visible.sync="exportUserRatio"  width="200">
+            <div>
+                <span>请选择年月:</span>
+                <el-date-picker 
+                    v-model="ratioYmonth" :editable="false" 
+                    format="yyyyMM" value-format="yyyyMM" 
+                    type="month"
+                    ></el-date-picker>
+            </div>
+            <span slot="footer">
+            <el-button @click="confirmDownloadRatio" >导出</el-button>
+            </span>
+        </el-dialog>
         <!--工时批量代填 -->
         <el-dialog :title="$t('title.Fillinginbatchesofworkinghours')" v-if="batchSubFillDialog" :visible.sync="batchSubFillDialog" customClass="customWidth" width="90%">
             <div>
@@ -1688,6 +1703,7 @@
                 </el-timeline>
             </div>
         </el-dialog>
+        
     </section>
 </template>
 
@@ -1712,6 +1728,8 @@
         },
         data() {
             return {
+                exportUserRatio: false,
+                ratioYmonth:null,
                 hasWrittenReport: false,
                 today:null,
                 syncTimeLoading: false,
@@ -2351,6 +2369,43 @@
                     }
                 );
             },
+            //下载填报工时占比报表
+            downloadProjectRatio() {
+                this.exportUserRatio = true;
+                let now = new Date();
+                let month = now.getMonth();//默认看上个月的
+                let monthStr = month<10? '0'+month: month;
+                this.ratioYmonth = now.getFullYear()+monthStr;
+            },
+            confirmDownloadRatio() {
+                this.http.post('/user-corpwx-time/exportProjectTimeRatio',{ 
+                    ymonth: this.ratioYmonth
+                },
+                res => {
+                    if (res.code == "ok") {
+                        var filePath = res.data;
+                        const a = document.createElement('a'); // 创建a标签
+                        var data = filePath.split("/");
+                        a.setAttribute('download', data[data.length-1]);// download属性
+                        a.setAttribute('href', filePath);// href链接
+                        a.click(); //自执行点击事件
+                        a.remove();
+                    } else {
+                        this.$message({
+                            message: res.msg,
+                            type: "error"
+                        });
+                    }
+                },
+                error => {
+                    this.checkinLoading = false;
+                    this.$message({
+                        message: error,
+                        type: "error"
+                    });
+                    }
+                );
+            },
             //下载带企业微信考勤数据的工时统计模板
             downloadCheckInExcel() {
                 this.http.post('/user-corpwx-time/exportCheckInExcel',{