eladmin-master/eladmin-common/src/main/java/me/zhengjie/utils/QueryHelp.java
@@ -78,8 +78,14 @@ String[] blurrys = blurry.split(","); List<Predicate> orPredicate = new ArrayList<>(); for (String s : blurrys) { orPredicate.add(cb.like(root.get(s) String[] joinNames = s.split(">"); if (joinNames.length == 2) { orPredicate.add(cb.like(root.join(joinNames[0], JoinType.LEFT).get(joinNames[1]) .as(String.class), "%" + val.toString() + "%")); } else { orPredicate.add(cb.like(root.get(joinNames[0]) .as(String.class), "%" + val.toString() + "%")); } } Predicate[] p = new Predicate[orPredicate.size()]; list.add(cb.or(orPredicate.toArray(p))); eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/constant/Constant.java
@@ -90,10 +90,6 @@ // 项目区分 public static final String PROJECT_DISTINGUISH = "project_distinguish"; // 项目区分:a public static final String PROJECT_DISTINGUISH_A = "project_distinguish_a"; // 项目区分:b public static final String PROJECT_DISTINGUISH_B = "project_distinguish_b"; // 单价币种 public static final String STANDARD_UNIT_CURRENCY = "standard_unit_currency"; eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/domain/Project.java
@@ -68,10 +68,20 @@ @ApiModelProperty(value = "单价币种") private String unitCurrency; @Column(name = "`unit_price`",nullable = false) @Column(name = "`quotation_price`",nullable = false) @NotNull @ApiModelProperty(value = "单价金额") private BigDecimal unitPrice; @ApiModelProperty(value = "报价单金") private BigDecimal quotationPrice; @Column(name = "`performance_price`",nullable = false) @NotNull @ApiModelProperty(value = "绩效单金") private BigDecimal performancePrice; @Column(name = "`contract_price`",nullable = false) @NotNull @ApiModelProperty(value = "合同金额") private BigDecimal contractPrice; @Column(name = "`total_price`") @ApiModelProperty(value = "报价金额") eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/domain/ProjectProgress.java
@@ -23,8 +23,8 @@ import javax.persistence.*; import javax.validation.constraints.*; import java.sql.Timestamp; import java.io.Serializable; import java.util.Date; /** * @website https://eladmin.vip @@ -53,10 +53,16 @@ @ApiModelProperty(value = "周度") private Integer belongWeek; @Column(name = "`project_id`",nullable = false) @Column(name = "`belong_date`",nullable = false) @NotNull @ApiModelProperty(value = "生成日") private Date belongDate; @ManyToOne @JoinColumn(name = "`project_id`",nullable = false) @NotNull @ApiModelProperty(value = "项目ID") private Long projectId; private Project project; @Column(name = "`estimated_progress`") @ApiModelProperty(value = "预计进度") @@ -71,15 +77,30 @@ @ApiModelProperty(value = "批准状态") private String approveStatus; @Column(name = "`settlement_status`",nullable = false) @NotBlank @ApiModelProperty(value = "结算状态") private String settlementStatus; @Column(name = "`remarks`") @ApiModelProperty(value = "备注") private String remarks; @Column(name = "`time_total_init`") @ApiModelProperty(value = "总绩效工时") private Double timeTotalInit; @Column(name = "`time_total_cost`") @ApiModelProperty(value = "总消耗绩效工时") private Double timeTotalCost; @Column(name = "`real_last_cost`") @ApiModelProperty(value = "实际消化工时") private Double realLastCost; @Column(name = "`work_total_init`") @ApiModelProperty(value = "总工作量") private Double workTotalInit; @Column(name = "`work_total_cost`") @ApiModelProperty(value = "总消耗工作量") private Double workTotalCost; public void copy(ProjectProgress source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/repository/ProjectProgressRepository.java
@@ -16,11 +16,13 @@ package me.zhengjie.modules.project.repository; import me.zhengjie.modules.project.domain.ProjectProgress; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import java.util.List; import java.util.Optional; /** * @website https://eladmin.vip @@ -41,4 +43,16 @@ * @return */ List<ProjectProgress> findByBelongYearAndBelongWeekAndProjectIdIn(Integer belongYear, Integer belongWeek, List<Long> projectIds); @Query(value = "SELECT * FROM project_progress WHERE project_id = ?1 ORDER BY belong_year, belong_week DESC LIMIT 2", nativeQuery = true) List<ProjectProgress> findLastWeekReport(Long projectId); Optional<ProjectProgress> findByBelongYearAndBelongWeekAndProjectId(int year, int weeks, Long projectId); @Query(value = "SELECT distinct belong_year FROM project_progress", nativeQuery = true) List<Integer> findAllBelongYear(); @Query(value = "SELECT distinct belong_week FROM project_progress WHERE belong_year = ?1", nativeQuery = true) List<Integer> findAllBelongWeekByBelongYear(Integer year); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/repository/ProjectRepository.java
@@ -17,7 +17,6 @@ import org.springframework.data.jpa.repository.Query; import me.zhengjie.modules.project.domain.Project; import me.zhengjie.modules.project.domain.ProjectType; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -39,4 +38,6 @@ @Query(value = "SELECT * FROM project WHERE id = ?1", nativeQuery = true) Project findByIdUpdate(Long id); List<Project> findByProjectStatus(String projectStatus); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/rest/ProjectProgressController.java
@@ -59,6 +59,22 @@ return new ResponseEntity<>(projectProgressService.queryAll(criteria,pageable),HttpStatus.OK); } @GetMapping(value = "/year") @Log("查询可选年度") @ApiOperation("查询可选年度") @PreAuthorize("@el.check('projectProgress:list')") public ResponseEntity<Object> queryYearSelection(){ return new ResponseEntity<>(projectProgressService.queryYearSelection(),HttpStatus.OK); } @GetMapping(value = "/weeks/{year}") @Log("查询可选周数") @ApiOperation("查询可选周数") @PreAuthorize("@el.check('projectProgress:list')") public ResponseEntity<Object> queryWeeksSelection(@PathVariable Integer year){ return new ResponseEntity<>(projectProgressService.queryWeeksSelection(year),HttpStatus.OK); } @GetMapping(value = "/all") @Log("查询项目进度") @ApiOperation("查询项目进度") eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/ProjectProgressService.java
@@ -80,4 +80,15 @@ * @throws IOException / */ void download(List<ProjectProgressDto> all, HttpServletResponse response) throws IOException; /** * 查询可选年度 */ List<Integer> queryYearSelection(); /** * 查询可选周数 * @param year / */ List<Integer> queryWeeksSelection(Integer year); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/dto/ProjectDto.java
@@ -49,11 +49,20 @@ /** 单价币种 */ private String unitCurrency; /** 单价金额 */ private BigDecimal unitPrice; /** 报价单金 */ private BigDecimal quotationPrice; /** 报价金额 */ private BigDecimal totalPrice; /** 绩效单金 */ private BigDecimal performancePrice; /** 合同金额 */ private BigDecimal contractPrice; /** 任务合计 */ private Double totalTaskTime; /** 成本合计 */ private BigDecimal totalLaborCost; /** 责任人ID */ private Long liableUserId; @@ -61,9 +70,15 @@ /** 计划开始日期 */ private Timestamp planStartDate; /** 任务开始日期 */ private Timestamp taskStartDate; /** 计划结束日期 */ private Timestamp planEndDate; /** 任务结束日期 */ private Timestamp taskEndDate; /** 项目状态 */ private String projectStatus; eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/dto/ProjectProgressDto.java
@@ -15,11 +15,11 @@ */ package me.zhengjie.modules.project.service.dto; import java.io.Serializable; import lombok.Data; import me.zhengjie.base.BaseDTO; import java.sql.Timestamp; import java.io.Serializable; import me.zhengjie.modules.project.domain.Project; /** * @website https://eladmin.vip @@ -39,11 +39,14 @@ /** 周度 */ private Integer belongWeek; /** 项目ID */ private Long projectId; /** 项目 */ private ProjectDto project; /** 预计进度 */ private Double estimatedProgress; /** 上周预计进度 */ private Double lastedProgress; /** 项目进度 */ private Double projectProgress; @@ -51,13 +54,28 @@ /** 批准状态 */ private String approveStatus; /** 结算状态 */ private String settlementStatus; /** 备注 */ private String remarks; /** 项目名称 */ private String projectName; /** 总绩效工时 */ private Double timeTotalInit; /** 总消耗绩效工时 */ private Double timeTotalCost; /** 本周消化绩效工时 */ private Double timeLastCost; /** 实际消化工时 */ private Double realLastCost; /** 总工作量 */ private Double workTotalInit; /** 总消耗工作量 */ private Double workTotalCost; /** 本周消化工作量 */ private Double workLastCost; } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/dto/ProjectProgressQueryCriteria.java
@@ -16,7 +16,6 @@ package me.zhengjie.modules.project.service.dto; import lombok.Data; import java.util.List; import me.zhengjie.annotation.Query; /** @@ -27,11 +26,19 @@ @Data public class ProjectProgressQueryCriteria{ /** 模糊 */ @Query(blurry = "project>name") private String blurry; /** 精确 */ @Query private Long projectId; @Query(joinName = "project", propName = "projectDistinguish") private String distinguish; /** 精确 */ @Query private String settlementStatus; private Integer belongYear; /** 精确 */ @Query private Integer belongWeek; } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java
@@ -15,46 +15,61 @@ */ package me.zhengjie.modules.project.service.impl; import java.io.IOException; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.function.Function; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.attendance.domain.Calculate; import me.zhengjie.modules.attendance.service.AttendanceService; import me.zhengjie.modules.constant.Constant; import me.zhengjie.modules.project.domain.Project; import me.zhengjie.modules.project.domain.ProjectCost; import me.zhengjie.modules.project.repository.ProjectRepository; import me.zhengjie.modules.system.domain.SysConfigHoliday; import me.zhengjie.modules.system.domain.SysUserLevelInsurance; import me.zhengjie.modules.system.domain.SysUserLevelWage; import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; import me.zhengjie.modules.system.repository.SysUserLevelInsuranceRepository; import me.zhengjie.modules.system.repository.SysUserLevelWageRepository; import me.zhengjie.modules.system.repository.UserRepository; import me.zhengjie.modules.system.service.UserService; import me.zhengjie.modules.system.service.dto.UserDto; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.FileUtil; import lombok.RequiredArgsConstructor; import me.zhengjie.modules.project.repository.ProjectCostRepository; import me.zhengjie.modules.project.repository.ProjectRepository; import me.zhengjie.modules.project.service.ProjectCostService; import me.zhengjie.modules.project.service.dto.ProjectCostDto; import me.zhengjie.modules.project.service.dto.ProjectCostQueryCriteria; import me.zhengjie.modules.project.service.mapstruct.ProjectCostMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import me.zhengjie.modules.system.domain.SysConfigHoliday; import me.zhengjie.modules.system.domain.SysLevel; import me.zhengjie.modules.system.domain.SysUserLevelInsurance; import me.zhengjie.modules.system.domain.SysUserLevelWage; import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; import me.zhengjie.modules.system.repository.SysLevelRepository; import me.zhengjie.modules.system.repository.SysUserLevelInsuranceRepository; import me.zhengjie.modules.system.repository.SysUserLevelWageRepository; import me.zhengjie.modules.system.repository.UserRepository; import me.zhengjie.modules.system.service.UserService; import me.zhengjie.modules.system.service.dto.SysRosteringDto; import me.zhengjie.modules.system.service.dto.UserDto; import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.QueryHelp; import java.math.BigDecimal; import java.text.*; import java.time.*; import java.time.temporal.ChronoUnit; import java.util.*; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import java.util.function.Function; import me.zhengjie.utils.ValidationUtil; /** * @website https://eladmin.vip @@ -74,7 +89,8 @@ private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository; private final SysConfigHolidayRepository sysConfigHolidayRepository; private final UserService userService; private final AttendanceService attendanceService; private final SysLevelRepository sysLevelRepository; @Override public Map<String,Object> queryAll(ProjectCostQueryCriteria criteria, Pageable pageable){ @@ -139,28 +155,26 @@ ProjectCost projectCost = new ProjectCost(); // 工资 BigDecimal wageCost = BigDecimal.valueOf(0); // 保险 BigDecimal insurancesCost = BigDecimal.valueOf(0); Date date = new Date(); Date dateExit = new Date(); // 工作天数 Calculate calculate=new Calculate(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date enterProjectTimeOne = simpleDateFormat.parse(criteria.getEnterProjectTime()); Date exitProjectTimeOne = simpleDateFormat.parse(criteria.getExitProjectTime()); LocalDateTime enterProject = LocalDateTime.parse(criteria.getEnterProjectTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime exitProject = LocalDateTime.parse(criteria.getExitProjectTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); Set<String> availableZoneIds = ZoneOffset.getAvailableZoneIds(); LocalDateTime enterProject = LocalDateTime.ofInstant(enterProjectTimeOne.toInstant(),ZoneOffset.UTC); LocalDateTime exitProject = LocalDateTime.ofInstant(exitProjectTimeOne.toInstant(),ZoneOffset.UTC); calculate.setStart(enterProject); calculate.setEnd(exitProject); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date startDate = simpleDateFormat.parse(criteria.getEnterProjectTime()); Date endDate = simpleDateFormat.parse(criteria.getExitProjectTime()); // 通过id获取用户级别工资 List<SysUserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findByUserId(criteria.getUserId()); // 通过id获取用户级别保险 List<SysUserLevelInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(criteria.getUserId()); // 通过id获取用户信息 UserDto user = userService.findById(criteria.getUserId()); // 通过id获取用户级别工资 List<SysUserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findByUserId(criteria.getUserId()) .stream().filter(sysUserLevelWage -> !((sysUserLevelWage.getEndDate() != null && sysUserLevelWage.getEndDate().before(startDate)) || sysUserLevelWage.getStartDate().after(endDate))) .collect(Collectors.toList()); // 通过id获取用户级别保险 List<SysUserLevelInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(criteria.getUserId()) .stream().filter(sysUserLevelInsurance -> !((sysUserLevelInsurance.getEndDate() != null && sysUserLevelInsurance.getEndDate().before(startDate)) || sysUserLevelInsurance.getStartDate().after(endDate))) .collect(Collectors.toList()); // 判断是否有用户级别工资 if(sysUserLevelWages.size() <= 0){ throw new BadRequestException("此用户暂无级别工资"); @@ -169,203 +183,101 @@ if(sysUserLevelInsurances.size() <= 0){ throw new BadRequestException("此用户暂无级别保险"); } for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) { Date enterProjectTime = simpleDateFormat.parse(criteria.getEnterProjectTime()); Date exitProjectTime = simpleDateFormat.parse(criteria.getExitProjectTime()); if (exitProjectTime.before(sysUserLevelInsurance.getStartDate())) { // nothing to do } else if (sysUserLevelInsurance.getEndDate() !=null && enterProjectTime.after(sysUserLevelInsurance.getEndDate())) { // nothing to do } else { if (enterProjectTime.before(sysUserLevelInsurance.getStartDate())) { enterProjectTime = sysUserLevelInsurance.getStartDate(); } if (sysUserLevelInsurance.getEndDate() !=null && exitProjectTime.after(sysUserLevelInsurance.getEndDate())) { exitProjectTime = sysUserLevelInsurance.getEndDate(); } int workDays = 0; // Integer a= attendanceService.calculateDays(exitProjectTime); for(long x = 0; x<= calculateDays(calculate);x++){ // 增加天数 String res = simpleDateFormat.format(enterProjectTime.getTime() + (x * 24 * 60 * 60 * 1000)); String resExit = simpleDateFormat.format(exitProjectTime.getTime() + (x * 24 * 60 * 60 * 1000)); try { date = simpleDateFormat.parse(res); dateExit = simpleDateFormat.parse(resExit); } catch (ParseException e) { e.printStackTrace(); } if(enterProjectTimeOne.equals(date)){ int workHours = 0; LocalTime parse = LocalTime.parse(res.substring(11)); // 判断是否是工作日 workHours=checkSun(res,date,workHours); if(workHours > 0){ // 是工作日与用户排班下的工作开始时间,工作结束时间,午休结束时间进行比较 if(parse.isBefore(user.getSysRostering().getWorkStartTime()) || parse.equals(user.getSysRostering().getWorkStartTime())){ workHours = 8; // insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); } else if (parse.isBefore(user.getSysRostering().getLunchStartTime())){ workHours = user.getSysRostering().getLunchStartTime().getHour() - parse.getHour() +5; insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); continue; } else if (parse.isBefore(user.getSysRostering().getLunchEndTime()) || parse.equals(user.getSysRostering().getLunchEndTime())){ workHours = 5; insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); continue; } else if (parse.isBefore(user.getSysRostering().getWorkEndTime())){ workHours = user.getSysRostering().getWorkEndTime().getHour() - parse.getHour(); insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); continue; } else { // nothing to do workHours = 0; } // 计算小时的花费 continue; } else{ // 不是工作日 nothing to do continue; } } if(x+1 == (exitProjectTime.getTime() - enterProjectTime.getTime())/(1000 * 60 * 60 * 24)){ int workHours = 0; LocalTime parse = LocalTime.parse(res.substring(11)); // 判断是否是工作日 workHours=checkSun(res,dateExit,workHours); if(workHours > 0){ // 是工作日与用户排班下的工作开始时间,工作结束时间,午休结束时间进行比较 if(parse.isBefore(user.getSysRostering().getWorkStartTime()) || parse.equals(user.getSysRostering().getWorkStartTime())){ // 不工作 nothing to do workHours = 0; } else if (parse.isBefore(user.getSysRostering().getLunchStartTime())){ workHours = parse.getHour() - user.getSysRostering().getWorkStartTime().getHour(); insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); continue; } else if (parse.isBefore(user.getSysRostering().getLunchEndTime()) || parse.equals(user.getSysRostering().getLunchStartTime())){ workHours = 3; insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); continue; } else if (parse.isBefore(user.getSysRostering().getWorkEndTime())){ workHours = parse.getHour() - user.getSysRostering().getLunchEndTime().getHour() + 3; insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); continue; } else if (parse.isAfter(user.getSysRostering().getWorkEndTime()) || parse.equals(user.getSysRostering().getWorkEndTime())){ workHours = 8; insurancesCost = insurancesCost.add(costInsurancesCalcuHour(sysUserLevelInsurance,workHours)); continue; } // 计算小时的花费 continue; } else{ // 不是工作日 nothing to do continue; } } workDays=calculateDays(calculate)-1; } insurancesCost = insurancesCost.add(costInsurancesCalcu(sysUserLevelInsurance, workDays)); } } List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findByHolidayDateBetween(simpleDateFormat.parse(criteria.getEnterProjectTime()), simpleDateFormat.parse(criteria.getExitProjectTime())); Map<Long, Long> sysUserLevelWageHoursMap = new HashMap<Long, Long>(); for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) { Date enterProjectTime = simpleDateFormat.parse(criteria.getEnterProjectTime()); Date exitProjectTime = simpleDateFormat.parse(criteria.getExitProjectTime()); if (exitProjectTime.before(sysUserLevelWage.getStartDate())) { // nothing to do } else if (sysUserLevelWage.getEndDate() !=null && enterProjectTime.after(sysUserLevelWage.getEndDate())) { // nothing to do sysUserLevelWageHoursMap.put(sysUserLevelWage.getLevelId(), 0L); } Map<Long, Long> sysUserLevelInsuranceHoursMap = new HashMap<Long, Long>(); for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) { sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getLevelId(), 0L); } for (LocalDate currentLocalDate = enterProject.toLocalDate(); currentLocalDate.isBefore(exitProject.toLocalDate()) || currentLocalDate.isEqual(exitProject.toLocalDate()); currentLocalDate = currentLocalDate.plusDays(1)) { String dateType = ""; for (SysConfigHoliday sysConfigHoliday : sysConfigHolidayList) { if (currentLocalDate.isEqual(sysConfigHoliday.getHolidayDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())) { dateType = sysConfigHoliday.getDateType(); break; } } if ("".equals(dateType)) { dateType = currentLocalDate.getDayOfWeek() == DayOfWeek.SATURDAY || currentLocalDate.getDayOfWeek() == DayOfWeek.SUNDAY ? Constant.DATE_TYPE_WEEKEND : Constant.DATE_TYPE_WEEKDAY; } if (Constant.DATE_TYPE_WEEKEND.equals(dateType) || Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType)) { continue; } Date currentDate = Date.from(currentLocalDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Long costHours = 0L; SysRosteringDto sysRostering = user.getSysRostering(); if (currentLocalDate.isEqual(enterProject.toLocalDate())) { if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) <= 0) { costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); } else if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) <= 0) { costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + enterProject.toLocalTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); } else if (enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) { if (enterProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) < 0) { enterProject = enterProject.with(sysRostering.getLunchEndTime()); } costHours = costHours + enterProject.toLocalTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS); } } else if (currentLocalDate.isEqual(exitProject.toLocalDate())) { if (exitProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && exitProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) <= 0) { if (exitProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0) { exitProject = exitProject.with(sysRostering.getLunchStartTime()); } costHours = costHours + sysRostering.getWorkStartTime().until(exitProject.toLocalTime(), ChronoUnit.HOURS); } else if (exitProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) > 0 && exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) { costHours = costHours + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS) + sysRostering.getLunchEndTime().until(exitProject.toLocalTime(), ChronoUnit.HOURS); } else if (exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) >= 0) { costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); } } else { if (enterProjectTime.before(sysUserLevelWage.getStartDate())) { enterProjectTime = sysUserLevelWage.getStartDate(); costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); } if ( sysUserLevelWage.getEndDate() != null && exitProjectTime.after(sysUserLevelWage.getEndDate())) { exitProjectTime = sysUserLevelWage.getEndDate(); } int workDays = 0; // 项目总用时 项目的出去时间减去项目的进入时间 for ( long x = 0;x <= calculateDays(calculate); x++ ) { // 增加天数 String res = simpleDateFormat.format(enterProjectTime.getTime() + (x * 24 * 60 * 60 * 1000)); String resExit = simpleDateFormat.format(exitProjectTime.getTime() + (x * 24 * 60 * 60 * 1000)); try { date = simpleDateFormat.parse(res); dateExit = simpleDateFormat.parse(resExit); } catch (ParseException e) { e.printStackTrace(); } if(enterProjectTimeOne.equals(date)){ int workHours = 0; LocalTime parse = LocalTime.parse(res.substring(11)); // 判断是否是工作日 workHours=checkSun(res,date,workHours); if(workHours > 0){ // 是工作日与用户排班下的工作开始时间,工作结束时间,午休结束时间进行比较 if(parse.isBefore(user.getSysRostering().getWorkStartTime()) || parse.equals(user.getSysRostering().getWorkStartTime())){ workHours = 8; wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); continue; } else if (parse.isBefore(user.getSysRostering().getLunchStartTime())){ workHours = user.getSysRostering().getLunchStartTime().getHour() - parse.getHour() +5; wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); continue; } else if (parse.isBefore(user.getSysRostering().getLunchEndTime()) || parse.equals(user.getSysRostering().getLunchEndTime())){ workHours = 5; wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); continue; } else if (parse.isBefore(user.getSysRostering().getWorkEndTime())){ workHours = user.getSysRostering().getWorkEndTime().getHour() - parse.getHour(); wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); continue; } else { workHours = 0; } // 计算小时的花费 continue; } else{ // 不是工作日 nothing to do continue; for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) { if (sysUserLevelWage.getEndDate() == null || sysUserLevelWage.getEndDate().after(currentDate) || sysUserLevelWage.getEndDate().equals(currentDate)) { sysUserLevelWageHoursMap.put(sysUserLevelWage.getLevelId(), costHours + sysUserLevelWageHoursMap.get(sysUserLevelWage.getLevelId())); break; } } if(x+1 == (exitProjectTime.getTime() - enterProjectTime.getTime())/(1000 * 60 * 60 * 24)){ int workHours = 0; LocalTime parse = LocalTime.parse(resExit.substring(11)); // 判断是否是工作日 workHours=checkSun(res,dateExit,workHours); if(workHours > 0){ // 是工作日与用户排班下的工作开始时间,工作结束时间,午休结束时间进行比较 if(parse.isBefore(user.getSysRostering().getWorkStartTime()) || parse.equals(user.getSysRostering().getWorkStartTime())){ // 不工作 workHours = 0; } else if (parse.isBefore(user.getSysRostering().getLunchStartTime())){ // 上午工作 workHours = parse.getHour() - user.getSysRostering().getWorkStartTime().getHour(); wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); } else if (parse.isBefore(user.getSysRostering().getLunchEndTime()) || parse.equals(user.getSysRostering().getLunchStartTime()) || parse.equals(user.getSysRostering().getLunchEndTime())){ // 工作一上午 workHours = 3; wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); } else if (parse.isBefore(user.getSysRostering().getWorkEndTime())){ // 下午工作 workHours = parse.getHour() - user.getSysRostering().getLunchEndTime().getHour() + 3; wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); } else if (parse.isAfter(user.getSysRostering().getWorkEndTime()) || parse.equals(user.getSysRostering().getWorkEndTime())){ // 工作一天 workHours = 8; wageCost = wageCost.add(costWageCalcuHour(sysUserLevelWage,workHours)); } // 计算小时的花费 continue; } else{ // 不是工作日 nothing to do continue; for (SysUserLevelInsurance sysUserLevelInsurance : sysUserLevelInsurances) { if (sysUserLevelInsurance.getEndDate() == null || sysUserLevelInsurance.getEndDate().after(currentDate) || sysUserLevelInsurance.getEndDate().equals(currentDate)) { sysUserLevelInsuranceHoursMap.put(sysUserLevelInsurance.getLevelId(), costHours + sysUserLevelInsuranceHoursMap.get(sysUserLevelInsurance.getLevelId())); break; } } workDays=calculateDays(calculate)-1; } wageCost = wageCost.add(costWageCalcu( sysUserLevelWage, workDays)); for (Entry<Long, Long> entry : sysUserLevelWageHoursMap.entrySet()) { SysLevel sysLevel = sysLevelRepository.findById(entry.getKey()).orElseGet(SysLevel::new); wageCost = wageCost.add(sysLevel.getLevelWage().multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING)); } for (Entry<Long, Long> entry : sysUserLevelInsuranceHoursMap.entrySet()) { SysLevel sysLevel = sysLevelRepository.findById(entry.getKey()).orElseGet(SysLevel::new); BigDecimal accumulationRadix = sysLevel.getAccumulationRadix().multiply(BigDecimal.valueOf(sysLevel.getAccumulationCompanyProportion() / 100)); BigDecimal pensionRadix = sysLevel.getPensionRadix().multiply(BigDecimal.valueOf(sysLevel.getPensionCompanyProportion() / 100)); BigDecimal medicalRadix = sysLevel.getMedicalRadix().multiply(BigDecimal.valueOf(sysLevel.getMedicalCompanyProportion() / 100)); BigDecimal unemploymentRadix = sysLevel.getUnemploymentRadix().multiply(BigDecimal.valueOf(sysLevel.getUnemploymentCompanyProportion() / 100)); BigDecimal maternityRadix = sysLevel.getMaternityRadix().multiply(BigDecimal.valueOf(sysLevel.getMaternityCompanyProportion() / 100)); BigDecimal industrialInjuryRadix = sysLevel.getIndustrialInjuryRadix().multiply(BigDecimal.valueOf(sysLevel.getIndustrialInjuryCompanyProportion() / 100)); wageCost = wageCost.add(accumulationRadix.add(pensionRadix).add(medicalRadix).add(unemploymentRadix).add(maternityRadix).add(industrialInjuryRadix).multiply(BigDecimal.valueOf(entry.getValue())).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING)); } projectCost.setProjectCost(wageCost.add(insurancesCost)); projectCost.setProjectCost(wageCost); return projectCost; } @@ -389,99 +301,5 @@ list.add(map); } FileUtil.downloadExcel(list, response); } // 获取工作天数 public int checkSun(String res, Date date, int workDays) { // 创建Calendar类实例 Calendar instance = Calendar.getInstance(); instance.setTime(date); SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(res); // 判断周六周日 if(instance.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY || instance.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){ // 判断周六周日是否为工作日 是工作日工作天数加一天 if(sysConfigHoliday != null){ if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY) || sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)){ workDays++; } } } else { // 判断周一到周五是否为节假日 不是节假日工作天数加一天 if(sysConfigHoliday == null){ workDays++; } else { if(!sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)){ workDays++; } } } return workDays; } // 计算工资成本 public BigDecimal costWageCalcu(SysUserLevelWage sysUserLevelWage,int workDays){ BigDecimal average = BigDecimal.valueOf(21.75); BigDecimal wage = sysUserLevelWage.getLevelWage().divide(average,2,BigDecimal.ROUND_CEILING); return wage.multiply(BigDecimal.valueOf(workDays)); } // 计算小时工资成本 public BigDecimal costWageCalcuHour(SysUserLevelWage sysUserLevelWage,int workDays){ // 每个月的平均工时 BigDecimal average = BigDecimal.valueOf(21.75); // 每天的工时 BigDecimal averHour = BigDecimal.valueOf(8); BigDecimal wage = (sysUserLevelWage.getLevelWage().divide(average,2,BigDecimal.ROUND_CEILING)).divide(averHour,2,BigDecimal.ROUND_CEILING); // System.out.println("wage:" +wage.multiply(BigDecimal.valueOf(workDays))); return wage.multiply(BigDecimal.valueOf(workDays)); } // 计算小时保险成本 public BigDecimal costInsurancesCalcuHour(SysUserLevelInsurance sysUserLevelInsurance,int workDays){ BigDecimal average = BigDecimal.valueOf(21.75); BigDecimal avarHour = BigDecimal.valueOf(8); BigDecimal accumulationRadix = (sysUserLevelInsurance.getAccumulationRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getAccumulationCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING)).divide(avarHour,2,BigDecimal.ROUND_CEILING); BigDecimal pensionRadix = (sysUserLevelInsurance.getPensionRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getPensionCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING)).divide(avarHour,2,BigDecimal.ROUND_CEILING); BigDecimal medicalRadix = (sysUserLevelInsurance.getMedicalRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getMedicalCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING)).divide(avarHour,2,BigDecimal.ROUND_CEILING); BigDecimal unemploymentRadix = (sysUserLevelInsurance.getUnemploymentRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getUnemploymentCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING)).divide(avarHour,2,BigDecimal.ROUND_CEILING); BigDecimal maternityRadix = (sysUserLevelInsurance.getMaternityRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getMaternityCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING)).divide(avarHour,2,BigDecimal.ROUND_CEILING); BigDecimal industrialInjuryRadix = (sysUserLevelInsurance.getIndustrialInjuryRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getIndustrialInjuryCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING)).divide(avarHour,2,BigDecimal.ROUND_CEILING); // System.out.println("calcuhour:" + accumulationRadix.add(pensionRadix.add(medicalRadix.add(unemploymentRadix.add(maternityRadix.add(industrialInjuryRadix))))).multiply(BigDecimal.valueOf(workDays))); return accumulationRadix.add(pensionRadix.add(medicalRadix.add(unemploymentRadix.add(maternityRadix.add(industrialInjuryRadix))))).multiply(BigDecimal.valueOf(workDays)); } // 计算保险成本 public BigDecimal costInsurancesCalcu(SysUserLevelInsurance sysUserLevelInsurance,int workDays){ BigDecimal average = BigDecimal.valueOf(21.75); BigDecimal accumulationRadix = sysUserLevelInsurance.getAccumulationRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getAccumulationCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING); BigDecimal pensionRadix = sysUserLevelInsurance.getPensionRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getPensionCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING); BigDecimal medicalRadix = sysUserLevelInsurance.getMedicalRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getMedicalCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING); BigDecimal unemploymentRadix = sysUserLevelInsurance.getUnemploymentRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getUnemploymentCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING); BigDecimal maternityRadix = sysUserLevelInsurance.getMaternityRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getMaternityCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING); BigDecimal industrialInjuryRadix = sysUserLevelInsurance.getIndustrialInjuryRadix().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getIndustrialInjuryCompanyProportion()/100)).divide(average,2,BigDecimal.ROUND_CEILING); return accumulationRadix.add(pensionRadix.add(medicalRadix.add(unemploymentRadix.add(maternityRadix.add(industrialInjuryRadix))))).multiply(BigDecimal.valueOf(workDays)); } public Integer calculateDays(Calculate calculate) { List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>(); //查询节假日表 List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll(); for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){ if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){ //工作日 isWork.add(sysConfigHoliday.getHolidayDate().toString()); }else{ holiday.add(sysConfigHoliday.getHolidayDate().toString()); } } Long chronoUnit = ChronoUnit.DAYS.between(calculate.getStart().toLocalDate(), calculate.getEnd().toLocalDate()); Integer count = 0; for (Integer i = 0; i <= chronoUnit; i++) { LocalDate date = calculate.getStart().toLocalDate().plusDays(i); Boolean isWeekend = date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY; if ((!isWeekend && !holiday.contains(date.toString())) || (isWeekend && isWork.contains(date.toString()))) { count++; } } return count; } } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectProgressServiceImpl.java
@@ -15,39 +15,42 @@ */ package me.zhengjie.modules.project.service.impl; import java.io.IOException; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.ZoneId; import java.time.temporal.WeekFields; import java.util.ArrayList; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.Function; import javax.servlet.http.HttpServletResponse; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.constant.Constant; import me.zhengjie.modules.project.domain.Project; import me.zhengjie.modules.project.domain.ProjectProgress; import me.zhengjie.modules.project.domain.ProjectTask; import me.zhengjie.modules.project.domain.ProjectType; import me.zhengjie.modules.project.repository.ProjectRepository; import me.zhengjie.modules.project.service.dto.ProjectDto; import me.zhengjie.modules.project.service.dto.ProjectTaskDto; import me.zhengjie.modules.system.domain.Job; import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.repository.DictDetailRepository; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.FileUtil; import lombok.RequiredArgsConstructor; import me.zhengjie.modules.project.repository.ProjectProgressRepository; import me.zhengjie.modules.project.repository.ProjectRepository; import me.zhengjie.modules.project.service.ProjectProgressService; import me.zhengjie.modules.project.service.dto.ProjectProgressDto; import me.zhengjie.modules.project.service.dto.ProjectProgressQueryCriteria; import me.zhengjie.modules.project.service.mapstruct.ProjectProgressMapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import me.zhengjie.modules.system.repository.DictDetailRepository; import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.PageUtil; import me.zhengjie.utils.QueryHelp; import java.util.List; import java.util.Map; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.function.Function; import me.zhengjie.utils.ValidationUtil; /** * @website https://eladmin.vip @@ -67,6 +70,9 @@ @Override public Map<String,Object> queryAll(ProjectProgressQueryCriteria criteria, Pageable pageable){ Page<ProjectProgress> page = projectProgressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); WeekFields wfs = WeekFields.of(DayOfWeek.MONDAY, 4); // 将实体类转换为DTO(重写) Function<ProjectProgress, ProjectProgressDto> func = new Function<ProjectProgress, ProjectProgressDto>() { @Override @@ -74,10 +80,44 @@ // 将实体类转换成DTO ProjectProgressDto projectProgressDto =projectProgressMapper.toDto(projectProgress); // 根据项目ID查询项目信息 Project project = projectRepository.findById(projectProgressDto.getProjectId()).orElseGet(Project::new); ValidationUtil.isNull(projectProgress.getId(),"Project","id",projectProgressDto.getProjectId()); // 项目名称 projectProgressDto.setProjectName(project.getName()); LocalDate localDate = LocalDate.now() .with(wfs.weekBasedYear(), projectProgress.getBelongYear()) .with(wfs.weekOfWeekBasedYear(), projectProgress.getBelongWeek()) .with(wfs.dayOfWeek(), 1L) .minusDays(7); Optional<ProjectProgress> projectProgressOpl = projectProgressRepository.findByBelongYearAndBelongWeekAndProjectId(localDate.get(wfs.weekBasedYear()), localDate.get(wfs.weekOfWeekBasedYear()), projectProgressDto.getProject().getId()); if (!projectProgressOpl.isPresent()) { projectProgressDto.setTimeLastCost(projectProgressDto.getTimeTotalCost()); projectProgressDto.setWorkLastCost(projectProgressDto.getWorkTotalCost()); projectProgressDto.setLastedProgress(0.0); } else { if (projectProgressDto.getTimeTotalCost() != null) { if (projectProgressOpl.get().getTimeTotalCost() != null) { projectProgressDto.setTimeLastCost(projectProgressDto.getTimeTotalCost() - projectProgressOpl.get().getTimeTotalCost()); } else { projectProgressDto.setTimeLastCost(projectProgressDto.getTimeTotalCost()); } } if (projectProgressDto.getWorkTotalCost() != null) { if (projectProgressOpl.get().getWorkTotalCost() != null) { projectProgressDto.setWorkLastCost(projectProgressDto.getWorkTotalCost() - projectProgressOpl.get().getWorkTotalCost()); } else { projectProgressDto.setWorkLastCost(projectProgressDto.getWorkTotalCost()); } } projectProgressDto.setLastedProgress(projectProgressOpl.get().getEstimatedProgress() != null ? projectProgressOpl.get().getEstimatedProgress() : 0.0); } if (projectProgressDto.getProjectProgress() == null) { projectProgressDto.setProjectProgress(0.0); } if (projectProgressDto.getEstimatedProgress() == null) { projectProgressDto.setEstimatedProgress(0.0); } // // 项目名称 // projectProgressDto.setProjectName(project.getName()); return projectProgressDto; } }; @@ -101,6 +141,15 @@ @Transactional(rollbackFor = Exception.class) public ProjectProgressDto create(ProjectProgress resources) { checkProjectProgress(resources); WeekFields wfs = WeekFields.of(DayOfWeek.MONDAY, 4); if (resources.getBelongDate() == null) { LocalDate localDate = LocalDate.now() .with(wfs.weekBasedYear(), resources.getBelongYear()) .with(wfs.weekOfWeekBasedYear(), resources.getBelongWeek()) .with(wfs.dayOfWeek(), 1L); resources.setBelongDate(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); } return projectProgressMapper.toDto(projectProgressRepository.save(resources)); } @@ -124,28 +173,44 @@ public void download(List<ProjectProgressDto> all, HttpServletResponse response) throws IOException { List<Map<String, Object>> list = new ArrayList<>(); for (ProjectProgressDto projectProgress : all) { String projectName = projectProgress.getProjectId() != null ? projectRepository.findById(projectProgress.getProjectId()).orElseGet(Project::new).getName() : ""; String settlemtnStatus= projectProgress.getSettlementStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.SETTLEMENT_STATUS, projectProgress.getSettlementStatus()).getLabel() : ""; String projectName = projectProgress.getProject().getId() != null ? projectRepository.findById(projectProgress.getProject().getId()).orElseGet(Project::new).getName() : ""; String approveStatus= projectProgress.getApproveStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.APPROVAL_STATUS, projectProgress.getApproveStatus()).getLabel() : ""; Map<String,Object> map = new LinkedHashMap<>(); map.put("项目", projectName); map.put("项目进度", projectProgress.getProjectProgress()); map.put("结算状态", settlemtnStatus); map.put("批准状态", approveStatus); map.put("备注", projectProgress.getRemarks()); map.put("创建者", projectProgress.getCreateBy()); map.put("创建时间", projectProgress.getCreateTime()); map.put("更新者", projectProgress.getUpdateBy()); map.put("更新时间", projectProgress.getUpdateTime()); map.put("总绩效工时", projectProgress.getTimeTotalInit()); map.put("总消耗绩效工时", projectProgress.getTimeTotalCost()); map.put("本周消化绩效工时", projectProgress.getTimeLastCost()); map.put("实际消化工时", projectProgress.getRealLastCost()); map.put("总工作量", projectProgress.getWorkTotalInit()); map.put("总消耗工作量", projectProgress.getWorkTotalCost()); map.put("本周消化工作量", projectProgress.getWorkLastCost()); list.add(map); } FileUtil.downloadExcel(list, response); } public void checkProjectProgress(ProjectProgress resources){ List<ProjectProgress> list = projectProgressRepository.findByProjectId(resources.getProjectId()); if(list.size()>0){ List<ProjectProgress> list = projectProgressRepository.findByProjectId(resources.getProject().getId()); if (list.size() > 0 && list.get(0).getProjectProgress() != null) { if(resources.getProjectProgress()<=list.get(0).getProjectProgress()){ throw new BadRequestException("项目进度必须大于上一次的项目进度"); } } } @Override public List<Integer> queryYearSelection() { return projectProgressRepository.findAllBelongYear(); } @Override public List<Integer> queryWeeksSelection(Integer year) { return projectProgressRepository.findAllBelongWeekByBelongYear(year); } } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectServiceImpl.java
@@ -187,8 +187,9 @@ map.put("项目区分:", projectDistinguish); map.put("需求说明", project.getRequirement()); map.put("单价币种", unitCurrency); map.put("单价金额", project.getUnitPrice()); map.put("报价金额", project.getTotalPrice()); // TODO // map.put("单价金额", project.getUnitPrice()); // map.put("报价金额", project.getTotalPrice()); map.put("责任人", getLiableUser); map.put("计划开始日期", project.getPlanStartDate()); map.put("计划结束日期", project.getPlanEndDate()); eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/WeekReportMethod.java
New file @@ -0,0 +1,117 @@ package me.zhengjie.modules.quartz.task; import java.math.BigDecimal; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.ZoneId; import java.time.temporal.WeekFields; import java.util.Date; import java.util.List; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhengjie.modules.constant.Constant; import me.zhengjie.modules.project.domain.Project; import me.zhengjie.modules.project.domain.ProjectProgress; import me.zhengjie.modules.project.repository.ProjectProgressRepository; import me.zhengjie.modules.project.repository.ProjectRepository; import me.zhengjie.modules.task.domain.Task; import me.zhengjie.modules.task.domain.TaskDaliyCollectInterface; import me.zhengjie.modules.task.repository.TaskDaliyRepository; import me.zhengjie.modules.task.repository.TaskRepository; /** * 钉钉定时任务(取考勤记录) */ @Slf4j @Service @RequiredArgsConstructor @Async public class WeekReportMethod { private final ProjectRepository projectRepository; private final ProjectProgressRepository projectProgressRepository; private final TaskRepository taskRepository; private final TaskDaliyRepository taskDaliyRepository; /** * 生成周报 * @throws Exception */ public void createWeekReport() throws Exception { // String date = null; // LocalDate localDate = null; // if (date == null) { // localDate = LocalDate.now().with(wfs.dayOfWeek(), 1L); // } else { // localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")); // } WeekFields wfs = WeekFields.of(DayOfWeek.MONDAY, 4); LocalDate localDate = LocalDate.now().with(wfs.dayOfWeek(), 1L); int year = localDate.minusDays(7).get(wfs.weekBasedYear()); int weeks = localDate.minusDays(7).get(wfs.weekOfWeekBasedYear()); // 周初查询进行中的任务 TODO // List<Project> projectList = projectRepository.findByProjectStatus(Constant.PROJECT_STATUS_UNDER_WAY); List<Project> projectList = projectRepository.findAll(); projectList.forEach(project -> { // 存在则更新,不存在则插入 ProjectProgress projectProgress = projectProgressRepository.findByBelongYearAndBelongWeekAndProjectId(year, weeks, project.getId()).orElseGet(ProjectProgress::new); if (projectProgress.getId() == null) { projectProgress.setBelongYear(year); projectProgress.setBelongWeek(weeks); projectProgress.setBelongDate(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); projectProgress.setProject(project); projectProgress.setApproveStatus(Constant.APPROVE_STATUS_UNRECOGNIZED); } // 总工时 Double timeTotalInit = 0.0; // 总消化工时 Double timeTotalCost = 0.0; // 总工作量 Double workTotalInit = 0.0; // 总消耗工作量 Double workTotalCost = 0.0; // 真实时长 Double realLastCost = 0.0; List<Task> taskList = taskRepository.findByProjectIdUntilDate(project.getId(), projectProgress.getBelongDate()); for (Task task : taskList) { timeTotalInit = timeTotalInit + task.getPlanHours(); workTotalInit = workTotalInit + (task.getPlanWorkload() == null ? 0.0 : task.getPlanWorkload()); TaskDaliyCollectInterface taskDaliyCollection = taskDaliyRepository.collectTaskDaliyUntilDate(task.getId(), projectProgress.getBelongDate()); boolean flg = true; if (flg) { // TODO 任务状态:未结束 task.getStatus() timeTotalCost += BigDecimal.valueOf(task.getPlanHours()).multiply(BigDecimal.valueOf(taskDaliyCollection.getTaskProgress())).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_CEILING).doubleValue(); } else { timeTotalCost += task.getPlanHours(); } workTotalCost += taskDaliyCollection.getConsumedWorkload(); realLastCost += taskDaliyCollection.getConsumedHours(); } // 真实时长 projectProgress.setRealLastCost(realLastCost); // 总消化工时 projectProgress.setTimeTotalCost(timeTotalCost); // 总工时 projectProgress.setTimeTotalInit(timeTotalInit); // 总消耗工作量 projectProgress.setWorkTotalCost(workTotalCost); // 总工作量 projectProgress.setWorkTotalInit(workTotalInit); // 存在则更新,不存在则插入 projectProgressRepository.save(projectProgress); }); } } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/SysConfigHolidayRepository.java
@@ -16,6 +16,10 @@ package me.zhengjie.modules.system.repository; import me.zhengjie.modules.system.domain.SysConfigHoliday; import java.util.Date; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; @@ -29,4 +33,6 @@ /** 根据日期查询 */ @Query(value = "SELECT * FROM `sys_config_holiday` WHERE holiday_date = ? ", nativeQuery = true) SysConfigHoliday findByHolidayDate(String holidayDate); List<SysConfigHoliday> findByHolidayDateBetween(Date start, Date end); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/domain/Task.java
@@ -92,6 +92,11 @@ @ApiModelProperty(value = "计划工作量单位") private String planWorkloadUnit; @Column(name = "`task_status`",nullable = false) @NotBlank @ApiModelProperty(value = "任务状态") private String taskStatus; @Column(name = "`remarks`") @ApiModelProperty(value = "备注") private String remarks; eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/domain/TaskDaliyCollectInterface.java
New file @@ -0,0 +1,43 @@ /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.modules.task.domain; /** * @website https://eladmin.vip * @description / * @author 赵士淞 * @date 2022-12-30 **/ public interface TaskDaliyCollectInterface { /** * 消耗工时 * @return */ Double getConsumedHours(); /** * 消耗工作量 * @return */ Double getConsumedWorkload(); /** * 任务进度 * @return */ Double getTaskProgress(); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/repository/TaskDaliyRepository.java
@@ -16,11 +16,14 @@ package me.zhengjie.modules.task.repository; import me.zhengjie.modules.task.domain.TaskDaliy; import me.zhengjie.modules.task.domain.TaskDaliyCollectInterface; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import java.sql.Timestamp; import java.util.Date; import java.util.List; import java.util.Map; @@ -47,6 +50,10 @@ @Query(value = "SELECT * FROM task_daliy WHERE project_id = ?1 AND task_id = ?2 AND user_id = ?3 AND fill_date > ?4 ORDER BY fill_date ASC LIMIT 1", nativeQuery = true) TaskDaliy findNextByProjectIdAndTaskIdAndAndUserId(Long projectId, Long taskId, Long userId, Timestamp fillDate); @Query(value = "SELECT avg(task_progress) as taskProgress, COALESCE(sum(consumed_workload), 0.0) as consumedWorkload, sum(consumed_hours) as consumedHours FROM task_daliy WHERE task_id = ?1 AND create_time < ?2", nativeQuery = true) TaskDaliyCollectInterface collectTaskDaliyUntilDate(Long taskId, Date belongDate); /** * 根据项目ID、任务ID查询各用户填报的最大任务进度日报信息 * @param projectId eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/repository/TaskRepository.java
@@ -18,7 +18,9 @@ import me.zhengjie.modules.task.domain.Task; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import java.util.Date; import java.util.List; /** @@ -34,4 +36,14 @@ * @return */ List<Task> findByPid(Long pid); /** * 根据项目ID查询 * @param pid * @return */ List<Task> findByProjectId(Long id); @Query(value = "SELECT * FROM task WHERE project_id = ?1 AND create_time < ?2", nativeQuery = true) List<Task> findByProjectIdUntilDate(Long projectId, Date belongDate); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/dto/TaskDto.java
@@ -67,6 +67,9 @@ /** 计划工作量单位 */ private String planWorkloadUnit; /** 任务状态 */ private String taskStatus; /** 备注 */ private String remarks; eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/dto/TaskQueryCriteria.java
@@ -55,5 +55,9 @@ @Query(propName = "id", type = Query.Type.IN) private List<Long> idInList; /** 精确 */ @Query private String taskStatus; private Long taskUserId; } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java
@@ -328,7 +328,7 @@ // 本日任务分配 TaskUser taskUserDay = taskUserDayList.get(0); // 本日最大任务进度列表 List<ProjectProgress> projectProgressLastDayList = projectProgressLastList.stream().filter(item -> item.getProjectId() == taskDaliyDay.getProjectId()).collect(Collectors.toList()); List<ProjectProgress> projectProgressLastDayList = projectProgressLastList.stream().filter(item -> item.getProject().getId() == taskDaliyDay.getProjectId()).collect(Collectors.toList()); // 判断本日最大任务进度列表 if (projectProgressLastDayList.size() > 1) { throw new BadRequestException("任务进度存在多条同年同周情况!"); eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskServiceImpl.java
@@ -201,6 +201,7 @@ String priority = task.getPriority() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PRIORITY, task.getPriority()).getLabel() : ""; String taskClassification = task.getTaskClassification() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_CLASSIFICATION, task.getTaskClassification()).getLabel() : ""; String planWorkloadUnit = task.getPlanWorkloadUnit() != null ? dictDetailRepository.findByDictNameAndValue(Constant.STANDARD_WORKLOAD_UNIT, task.getPlanWorkloadUnit()).getLabel() : ""; String taskStatus = task.getTaskStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, task.getTaskStatus()).getLabel() : ""; Map<String,Object> map = new LinkedHashMap<>(); map.put("项目名称", projectName); map.put("父任务名称", pidName); @@ -213,6 +214,7 @@ map.put("计划工时", task.getPlanHours()); map.put("计划工作量", task.getPlanWorkload()); map.put("计划工作量单位", planWorkloadUnit); map.put("任务状态", taskStatus); map.put("备注", task.getRemarks()); map.put("创建者", task.getCreateBy()); map.put("创建时间", task.getCreateTime()); eladmin-web-master/src/api/project/projectProgress.js
@@ -32,4 +32,18 @@ }) } export default { getAll, add, edit, del } export function getBelongYear() { return request({ url: 'api/projectProgress/year', method: 'get' }) } export function getBelongWeek(year) { return request({ url: 'api/projectProgress/weeks/' + year, method: 'get' }) } export default { getAll, add, edit, del, getBelongYear, getBelongWeek } eladmin-web-master/src/utils/constant.js
@@ -181,10 +181,6 @@ // 项目区分 export const PROJECT_DISTINGUISH = 'project_distinguish' // 项目区分:a export const PROJECT_DISTINGUISH_A = 'project_distinguish_a' // 项目区分:b export const PROJECT_DISTINGUISH_B = 'project_distinguish_b' // 结算状态 export const SETTLEMENT_STATUS = 'settlement_status' @@ -339,8 +335,6 @@ CARD_APPROVE_STATUS_AGREE, CARD_APPROVE_STATUS_REFUSE, PROJECT_DISTINGUISH, PROJECT_DISTINGUISH_A, PROJECT_DISTINGUISH_B, SETTLEMENT_STATUS, SETTLEMENT_STATUS_SETTLED, SETTLEMENT_STATUS_UNSETTLED, eladmin-web-master/src/views/project/projectProgress/index.vue
@@ -4,20 +4,29 @@ <div class="head-container"> <div v-if="crud.props.searchToggle"> <!-- 搜索 --> <el-select v-model="query.projectId" filterable clearable placeholder="请输入项目" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"> <el-input v-model="query.blurry" clearable placeholder="请输入项目名" style="width: 185px" class="filter-item" @keyup.enter.native="crud.toQuery" /> <el-select v-model="query.distinguish" filterable clearable placeholder="请选择项目区分" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"> <el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> <el-select v-model="query.settlementStatus" filterable clearable placeholder="请选择结算状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"> <el-option v-for="item in dict[settlementStatus]" v-for="item in dict[projectDistinguish]" :key="item.id" :label="item.label" :value="item.value" /> </el-select> <el-select v-model="query.belongYear" filterable clearable placeholder="请选择年度" style="width: 185px;" class="filter-item"> <el-option v-for="item in belongYearList" :key="item" :label="item" :value="item" /> </el-select> <el-select v-model="query.belongWeek" filterable clearable placeholder="请选择周数" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"> <el-option v-for="item in belongWeekList" :key="item" :label="item" :value="item" /> </el-select> <rrOperation :crud="crud" /> @@ -27,14 +36,35 @@ <!--表单组件--> <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px"> <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px"> <el-form-item label="项目" prop="projectId"> <el-select v-model="form.projectId" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="disabled"> <el-form-item label="项目" prop="project.id"> <el-select v-model="form.project.id" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="disabled || crud.status.add !== 1"> <el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id" :disabled="item.approveStatus == approveStatusAcknowledged" :disabled="item.approveStatus == approveStatusUnsettled" /> </el-select> </el-form-item> <el-form-item label="年度" prop="belongYear"> <el-select v-model="form.belongYear" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="disabled || crud.status.add !== 1"> <el-option v-for="item in belongYearList" :key="item" :label="item" :value="item" /> </el-select> </el-form-item> <el-form-item label="周数" prop="belongWeek"> <el-select v-model="form.belongWeek" filterable clearable placeholder="请选择" style="width: 370px;" :disabled="disabled || crud.status.add !== 1"> <el-option v-for="item in belongWeekList2" :key="item" :label="item" :value="item" :disabled="item.approveStatus == approveStatusUnsettled" /> </el-select> </el-form-item> @@ -43,10 +73,10 @@ <template slot="append">%</template> </el-input> </el-form-item> <el-form-item label="结算状态" prop="settlementStatus"> <el-select v-model="form.settlementStatus" filterable clearable :disabled="disabled" placeholder="请选择" style="width: 370px;"> <el-form-item label="批准状态" prop="approveStatus"> <el-select v-model="form.approveStatus" filterable clearable :disabled="disabled" placeholder="请选择" style="width: 370px;"> <el-option v-for="item in dict[settlementStatus]" v-for="item in dict[approveStatus]" :key="item.id" :label="item.label" :value="item.value" @@ -65,23 +95,31 @@ <!--表格渲染--> <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler"> <el-table-column type="selection" width="55" /> <el-table-column prop="projectName" label="项目" show-overflow-tooltip> <el-table-column prop="belongYear" label="年度" width="70" /> <el-table-column prop="belongWeek" label="周数" width="50" /> <el-table-column prop="projectName" label="项目" show-overflow-tooltip width="170"> <template slot-scope="scope"> <el-tag>{{ scope.row.projectName }}</el-tag> <el-tag>{{ scope.row.project.name }}</el-tag> </template> </el-table-column> <el-table-column prop="projectProgress" label="项目进度" show-overflow-tooltip> <el-table-column prop="projectProgress" label="项目进度" show-overflow-tooltip width="70"> <template slot-scope="scope"> {{ scope.row.projectProgress + '%' }} {{ (scope.row.projectProgress ? scope.row.projectProgress : 0) + '%' }} </template> </el-table-column> <el-table-column prop="settlementStatus" label="结算状态" show-overflow-tooltip> <el-table-column prop="approveStatus" label="批准状态" width="80"> <template slot-scope="scope"> <el-tag>{{ dict.label[settlementStatus][scope.row.settlementStatus] }}</el-tag> <el-tag>{{ dict.label[approveStatus][scope.row.approveStatus] }}</el-tag> </template> </el-table-column> <el-table-column prop="timeTotalInit" label="总绩效工时" align="center" width="100" /> <el-table-column prop="timeTotalCost" label="总消耗绩效工时" align="center" width="120" /> <el-table-column prop="timeLastCost" label="本周消化绩效工时" align="center" width="120" /> <el-table-column prop="realLastCost" label="实际消化工时" align="center" width="100" /> <el-table-column prop="workTotalInit" label="总工作量" align="center" width="100" /> <el-table-column prop="workTotalCost" label="总消耗工作量" align="center" width="100" /> <el-table-column prop="workLastCost" label="本周消化工作量" align="center" width="110" /> <el-table-column prop="remarks" label="备注" show-overflow-tooltip /> <el-table-column prop="createTime" label="创建时间" width="140" /> <el-table-column v-if="checkPer(['admin','projectProgress:edit','projectProgress:del'])" label="操作" width="150px" align="center"> <template slot-scope="scope"> <udOperation @@ -107,14 +145,14 @@ import pagination from '@crud/Pagination' import constant from '../../../utils/constant' const defaultForm = { id: null, projectId: null, projectProgress: null, settlementStatus: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null } const defaultForm = { id: null, project: { id: null }, belongYear: null, belongWeek: null, approveStatus: null, projectProgress: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null } export default { name: 'ProjectProgress', components: { pagination, crudOperation, rrOperation, udOperation }, mixins: [presenter(), header(), form(defaultForm), crud()], dicts: [constant.SETTLEMENT_STATUS], dicts: [constant.APPROVE_STATUS, constant.PROJECT_DISTINGUISH], cruds() { return CRUD({ title: '项目进度', url: 'api/projectProgress', idField: 'id', sort: 'id,desc', crudMethod: { ...crudProjectProgress }}) return CRUD({ title: '项目进度', url: 'api/projectProgress', idField: 'id', sort: ['belongYear,desc', 'belongWeek,desc'], crudMethod: { ...crudProjectProgress }}) }, data() { var checkProjectProgress = (rule, value, callback) => { @@ -133,43 +171,94 @@ download: ['admin', 'projectProgress:download'] }, rules: { projectId: [ { required: true, message: '项目不能为空', trigger: 'blur' } 'project.id': [ { required: true, message: '项目不能为空', trigger: 'onblur' } ], projectProgress: [ { required: true, validator: checkProjectProgress, trigger: 'blur' } { required: true, message: '进度不能为空', trigger: 'onblur' }, { required: true, validator: checkProjectProgress, trigger: 'onblur' } ], settlementStatus: [ { required: true, message: '结算状态不能为空', trigger: 'blur' } approveStatus: [ { required: true, message: '进度不能为空', trigger: 'onblur' } ] }, queryTypeOptions: [ { key: 'projectId', display_name: '项目' }, { key: 'settlementStatus', display_name: '结算状态' } { key: 'projectDistinguish', display_name: '项目区分' }, { key: 'belongYear', display_name: '年度' }, { key: 'belongWeek', display_name: '周数' } ], // 项目 projectList: [], // 年度 belongYearList: [], // 周数 belongWeekList: [], // 周数 belongWeekList2: [], // 禁用状态 disabled: false, // 结算状态 settlementStatus: constant.SETTLEMENT_STATUS, // 结算状态:已结算 settlementStatusSettled: constant.SETTLEMENT_STATUS_SETTLED, // 结算状态:未结算 settlementStatusUnsettled: constant.SETTLEMENT_STATUS_UNSETTLED, projectDistinguish: constant.PROJECT_DISTINGUISH, // 承认状态 approveStatus: constant.APPROVE_STATUS, // 未承认 approveStatusUnsettled: constant.APPROVE_STATUS_UNRECOGNIZED, // 已承认 approveStatusAcknowledged: constant.APPROVE_STATUS_ACKNOWLEDGED } }, watch: { 'query.belongYear'(newValue) { // 年度变更后,周数初始化 if (this.query.belongWeek) { this.query.belongWeek = null } this.belongWeekList = [] // 年度清空后不需要查询数据 if (!newValue) { return } // 查询年度对应的周数 crudProjectProgress.getBelongWeek(newValue).then(res => { res.forEach(item => { this.belongWeekList.push(item) }) }) }, 'form.belongYear'(newValue, oldValue) { if (this.disabled || this.crud.status.add !== 1) { return } // 年度变更后,周数初始化 if (this.form.belongWeek) { this.form.belongWeek = null } this.belongWeekList2 = [] // 年度清空后不需要查询数据 if (!newValue) { return } // 查询年度对应的周数 crudProjectProgress.getBelongWeek(newValue).then(res => { res.forEach(item => { this.belongWeekList2.push(item) }) }) } }, methods: { // 钩子:在获取表格数据之前执行,false 则代表不获取数据 [CRUD.HOOK.beforeRefresh]() { this.getProject() this.getBelongYear() return true }, // 新增与编辑前做的操作 [CRUD.HOOK.afterToCU](crud, form) { this.getDisabled() this.belongWeekList2.splice(0, this.belongWeekList2.length) }, // 获取项目信息 getProject() { @@ -177,13 +266,28 @@ this.projectList = res }) }, getBelongYear() { crudProjectProgress.getBelongYear().then(res => { this.belongYearList = res }) }, // 是否可以修改 getDisabled() { if (this.form.settlementStatus === this.settlementStatusSettled) { this.disabled = false if (this.form.approveStatus === this.approveStatusAcknowledged) { this.disabled = true } else if (this.form.settlementStatus === this.settlementStatusUnsettled) { } else if (this.form.approveStatus === this.approveStatusUnsettled) { this.disabled = false } this.rules['project.id'].forEach(element => { element.required = !(this.disabled || this.crud.status.add !== 1) }) this.rules.projectProgress.forEach(element => { element.required = !(this.disabled) }) this.rules.approveStatus.forEach(element => { element.required = !(this.disabled) }) } } } eladmin-web-master/src/views/task/task/index.vue
@@ -29,6 +29,14 @@ :value="item.value" /> </el-select> <el-select v-model="query.taskStatus" filterable clearable placeholder="任务状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery"> <el-option v-for="item in dict[taskStatus]" :key="item.id" :label="item.label" :value="item.value" /> </el-select> <rrOperation :crud="crud" /> </div> <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'--> @@ -120,6 +128,16 @@ /> </el-select> </el-form-item> <el-form-item label="任务状态" prop="taskStatus"> <el-select v-model="form.taskStatus" filterable placeholder="请选择" style="width: 340px;"> <el-option v-for="item in dict[taskStatus]" :key="item.id" :label="item.label" :value="item.value" /> </el-select> </el-form-item> <el-form-item label="备注"> <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 340px;" /> </el-form-item> @@ -166,6 +184,11 @@ <el-table-column :show-overflow-tooltip="true" prop="planWorkloadUnit" label="计划工作量单位" width="110"> <template slot-scope="scope"> <el-tag v-if="scope.row.planWorkloadUnit != null && scope.row.planWorkloadUnit != ''">{{ dict.label[standardWorkloadUnit][scope.row.planWorkloadUnit] }}</el-tag> </template> </el-table-column> <el-table-column :show-overflow-tooltip="true" prop="taskStatus" label="任务状态" width="80"> <template slot-scope="scope"> <el-tag>{{ dict.label[taskStatus][scope.row.taskStatus] }}</el-tag> </template> </el-table-column> <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注" width="140" /> @@ -250,7 +273,7 @@ import crudProject from '@/api/project/project' import crudUser from '@/api/system/user' const defaultForm = { id: null, name: null, projectId: null, pid: null, priority: null, taskClassification: null, description: null, planStartTime: null, planEndTime: null, planHours: null, planWorkload: null, planWorkloadUnit: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null } const defaultForm = { id: null, name: null, projectId: null, pid: null, priority: null, taskClassification: null, description: null, planStartTime: null, planEndTime: null, planHours: null, planWorkload: null, planWorkloadUnit: null, taskStatus: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null } export default { name: 'Task', components: { pagination, crudOperation, rrOperation, udOperation }, @@ -299,13 +322,17 @@ ], planWorkload: [ { validator: durationValidate, trigger: 'blur' } ], taskStatus: [ { required: true, message: '任务状态不能为空', trigger: 'change' } ] }, queryTypeOptions: [ { key: 'name', display_name: '名称' }, { key: 'projectId', display_name: '所属项目' }, { key: 'priority', display_name: '优先度' }, { key: 'taskClassification', display_name: '任务分类' } { key: 'taskClassification', display_name: '任务分类' }, { key: 'taskStatus', display_name: '任务状态' } ], // 计划开始时间选项 planStartTimePickerOptions: { @@ -327,6 +354,8 @@ taskClassification: constant.TAST_CLASSIFICATION, // 字典:标准工作量单位 standardWorkloadUnit: constant.STANDARD_WORKLOAD_UNIT, // 字典:任务状态 taskStatus: constant.TASK_STATUS, // CRUD状态 crudStatusPrepared: CRUD.STATUS.PREPARED, // 项目列表