huaz
2022-12-30 c3ad779e9ededcd8b9184da53921f24654e1840b
项目成本
10 files added
2 files modified
966 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/domain/ProjectCost.java 79 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/repository/ProjectCostRepository.java 28 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/rest/ProjectCostController.java 103 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/ProjectCostService.java 85 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/dto/ProjectCostDto.java 60 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/dto/ProjectCostQueryCriteria.java 46 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java 272 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/mapstruct/ProjectCostMapper.java 32 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/SysUserLevelInsuranceRepository.java 11 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/SysUserLevelWageRepository.java 11 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/api/project/projectCost.js 43 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/views/project/projectCost/index.vue 196 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/domain/ProjectCost.java
New file
@@ -0,0 +1,79 @@
/*
*  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.project.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.math.BigDecimal;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author HuaZhe
* @date 2022-12-27
**/
@Entity
@Data
@Table(name="project_cost")
public class ProjectCost extends BaseEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "ID")
    private Long id;
    @Column(name = "`project_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "项目ID")
    private Long projectId;
    @Column(name = "`user_id`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "用户ID")
    private Long userId;
    @Column(name = "`enter_project_time`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "进入项目时间")
    private Timestamp enterProjectTime;
    @Column(name = "`exit_project_time`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "退出项目时间")
    private Timestamp exitProjectTime;
    @Column(name = "`project_cost`",nullable = false)
    @NotNull
    @ApiModelProperty(value = "项目成本")
    private BigDecimal projectCost;
    @Column(name = "`remarks`")
    @ApiModelProperty(value = "备注")
    private String remarks;
    public void copy(ProjectCost source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/repository/ProjectCostRepository.java
New file
@@ -0,0 +1,28 @@
/*
*  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.project.repository;
import me.zhengjie.modules.project.domain.ProjectCost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @website https://eladmin.vip
* @author HuaZhe
* @date 2022-12-27
**/
public interface ProjectCostRepository extends JpaRepository<ProjectCost, Long>, JpaSpecificationExecutor<ProjectCost> {
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/rest/ProjectCostController.java
New file
@@ -0,0 +1,103 @@
/*
*  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.project.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.project.domain.ProjectCost;
import me.zhengjie.modules.project.service.ProjectCostService;
import me.zhengjie.modules.project.service.dto.ProjectCostQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @author HuaZhe
* @date 2022-12-27
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "项目成本管理")
@RequestMapping("/api/projectCost")
public class ProjectCostController {
    private final ProjectCostService projectCostService;
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('projectCost:download')")
    public void exportProjectCost(HttpServletResponse response, ProjectCostQueryCriteria criteria) throws IOException {
        projectCostService.download(projectCostService.queryAll(criteria), response);
    }
    @GetMapping
    @Log("查询项目成本")
    @ApiOperation("查询项目成本")
    @PreAuthorize("@el.check('projectCost:list')")
    public ResponseEntity<Object> queryProjectCost(ProjectCostQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(projectCostService.queryAll(criteria,pageable),HttpStatus.OK);
    }
    @GetMapping(value = "/all")
    @Log("查询项目成本")
    @ApiOperation("查询项目成本")
    @PreAuthorize("@el.check('projectCost:list')")
    public ResponseEntity<Object> queryProjectCostAll(ProjectCostQueryCriteria criteria){
        return new ResponseEntity<>(projectCostService.queryAll(criteria),HttpStatus.OK);
    }
    @PostMapping
    @Log("新增项目成本")
    @ApiOperation("新增项目成本")
    @PreAuthorize("@el.check('projectCost:add')")
    public ResponseEntity<Object> createProjectCost(@Validated @RequestBody ProjectCost resources){
        return new ResponseEntity<>(projectCostService.create(resources),HttpStatus.CREATED);
    }
    @PutMapping
    @Log("修改项目成本")
    @ApiOperation("修改项目成本")
    @PreAuthorize("@el.check('projectCost:edit')")
    public ResponseEntity<Object> updateProjectCost(@Validated @RequestBody ProjectCost resources){
        projectCostService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    @DeleteMapping
    @Log("删除项目成本")
    @ApiOperation("删除项目成本")
    @PreAuthorize("@el.check('projectCost:del')")
    public ResponseEntity<Object> deleteProjectCost(@RequestBody Long[] ids) {
        projectCostService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
    @GetMapping(value = "/getcost")
    @Log("查询项目成本")
    @ApiOperation("查询项目成本")
    @PreAuthorize("@el.check('projectCost:list')")
    public ResponseEntity<Object> getProjectCost(ProjectCostQueryCriteria criteria){
        return new ResponseEntity<>(projectCostService.getCost(criteria),HttpStatus.OK);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/ProjectCostService.java
New file
@@ -0,0 +1,85 @@
/*
*  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.project.service;
import me.zhengjie.modules.project.domain.ProjectCost;
import me.zhengjie.modules.project.service.dto.ProjectCostDto;
import me.zhengjie.modules.project.service.dto.ProjectCostQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @description 服务接口
* @author HuaZhe
* @date 2022-12-27
**/
public interface ProjectCostService {
    /**
    * 查询数据分页
    * @param criteria 条件
    * @param pageable 分页参数
    * @return Map<String,Object>
    */
    Map<String,Object> queryAll(ProjectCostQueryCriteria criteria, Pageable pageable);
    /**
    * 查询所有数据不分页
    * @param criteria 条件参数
    * @return List<ProjectCostDto>
    */
    List<ProjectCostDto> queryAll(ProjectCostQueryCriteria criteria);
    /**
     * 根据ID查询
     * @param id ID
     * @return ProjectCostDto
     */
    ProjectCostDto findById(Long id);
    /**
    * 创建
    * @param resources /
    * @return ProjectCostDto
    */
    ProjectCostDto create(ProjectCost resources);
    /**
    * 编辑
    * @param resources /
    */
    void update(ProjectCost resources);
    /**
    * 多选删除
    * @param ids /
    */
    void deleteAll(Long[] ids);
    ProjectCost getCost(ProjectCostQueryCriteria criteria);
    /**
    * 导出数据
    * @param all 待导出的数据
    * @param response /
    * @throws IOException /
    */
    void download(List<ProjectCostDto> all, HttpServletResponse response) throws IOException;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/dto/ProjectCostDto.java
New file
@@ -0,0 +1,60 @@
/*
*  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.project.service.dto;
import lombok.Data;
import me.zhengjie.base.BaseDTO;
import java.sql.Timestamp;
import java.math.BigDecimal;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author HuaZhe
* @date 2022-12-27
**/
@Data
public class ProjectCostDto extends BaseDTO implements Serializable {
    /** ID */
    private Long id;
    /** 项目ID */
    private Long projectId;
    /** 用户ID */
    private Long userId;
    /** 进入项目时间 */
    private Timestamp enterProjectTime;
    /** 退出项目时间 */
    private Timestamp exitProjectTime;
    /** 项目成本 */
    private BigDecimal projectCost;
    /** 备注 */
    private String remarks;
    /** 用户姓名 */
    private String userName;
    /** 姓名名称 */
    private String projectName;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/dto/ProjectCostQueryCriteria.java
New file
@@ -0,0 +1,46 @@
/*
*  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.project.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.util.List;
import me.zhengjie.annotation.Query;
/**
* @website https://eladmin.vip
* @author HuaZhe
* @date 2022-12-27
**/
@Data
public class ProjectCostQueryCriteria{
    /** 精确 */
    @Query
    private Long projectId;
    /** 精确 */
    @Query
    private Long userId;
    /** 精确 */
    @Query
    private Timestamp enterProjectTime;
    /** 精确 */
    @Query
    private Timestamp exitProjectTime;
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/impl/ProjectCostServiceImpl.java
New file
@@ -0,0 +1,272 @@
/*
*  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.project.service.impl;
import lombok.Data;
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.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.project.repository.ProjectCostRepository;
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.apache.tomcat.util.bcel.Const;
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.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import java.text.*;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.function.Function;
/**
* @website https://eladmin.vip
* @description 服务实现
* @author HuaZhe
* @date 2022-12-27
**/
@Service
@RequiredArgsConstructor
public class ProjectCostServiceImpl implements ProjectCostService {
    private final ProjectCostRepository projectCostRepository;
    private final ProjectCostMapper projectCostMapper;
    private final ProjectRepository projectRepository;
    private final UserRepository userRepository;
    private final SysUserLevelWageRepository sysUserLevelWageRepository;
    private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository;
    private final SysConfigHolidayRepository sysConfigHolidayRepository;
    @Override
    public Map<String,Object> queryAll(ProjectCostQueryCriteria criteria, Pageable pageable){
        Page<ProjectCost> page = projectCostRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
        // 将实体类转换为DTO(重写)
        Function<ProjectCost, ProjectCostDto> func = new Function<ProjectCost, ProjectCostDto>() {
            @Override
            public ProjectCostDto apply(ProjectCost projectCost) {
                // 将实体类转换成DTO
                ProjectCostDto projectCostDto = projectCostMapper.toDto(projectCost);
                // 根据项目ID查询项目信息
                Project project = projectRepository.findById(projectCostDto.getProjectId()).orElseGet(Project::new);
                ValidationUtil.isNull(projectCostDto.getId(),"Project","id",projectCostDto.getProjectId());
                // 项目名称
                projectCostDto.setProjectName(project.getName());
                User user = userRepository.findById(projectCostDto.getUserId()).orElseGet(User::new);
                ValidationUtil.isNull(projectCostDto.getId(),"User","id",projectCostDto.getUserId());
                projectCostDto.setUserName(user.getNickName());
                return projectCostDto;
            }
        };
        return PageUtil.toPage(page.map(func));
    }
    @Override
    public List<ProjectCostDto> queryAll(ProjectCostQueryCriteria criteria){
        return projectCostMapper.toDto(projectCostRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
    }
    @Override
    @Transactional
    public ProjectCostDto findById(Long id) {
        ProjectCost projectCost = projectCostRepository.findById(id).orElseGet(ProjectCost::new);
        ValidationUtil.isNull(projectCost.getId(),"ProjectCost","id",id);
        return projectCostMapper.toDto(projectCost);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ProjectCostDto create(ProjectCost resources) {
        return projectCostMapper.toDto(projectCostRepository.save(resources));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(ProjectCost resources) {
        ProjectCost projectCost = projectCostRepository.findById(resources.getId()).orElseGet(ProjectCost::new);
        ValidationUtil.isNull( projectCost.getId(),"ProjectCost","id",resources.getId());
        projectCost.copy(resources);
        projectCostRepository.save(projectCost);
    }
    @Override
    public void deleteAll(Long[] ids) {
        for (Long id : ids) {
            projectCostRepository.deleteById(id);
        }
    }
    @Override
    public ProjectCost getCost(ProjectCostQueryCriteria criteria){
        ProjectCost projectCost = new ProjectCost();
        // 创建Calendar类实例
        Calendar instance = Calendar.getInstance();
        Date date = new Date();
//        BigDecimal d = BigDecimal.valueOf(20);
        int workDays = 0;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<SysUserLevelWage> sysUserLevelWage = sysUserLevelWageRepository.findByUserId(criteria.getUserId());
        List<SysUserLevelInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(criteria.getUserId());
//        for(int i=0; i<=sysUserLevelWage.size();i++ ){
            // 判断项目开始时间是否小于级别结束时间
            if(criteria.getEnterProjectTime().before(sysUserLevelWage.get(0).getEndDate())){
                // 判断项目结束时间是否小于级别结束时间
                if(criteria.getExitProjectTime().before(sysUserLevelWage.get(0).getEndDate())){
                    // 项目总用时
                    for(int i = 1;i<= (criteria.getExitProjectTime().getTime() - criteria.getEnterProjectTime().getTime())/(1000 * 60 * 60 * 24);i++){
//                        sysUserLevelWage.get(0).getLevelWage().divide(d,2,BigDecimal.ROUND_CEILING);
//                        BigDecimal multiply = sysUserLevelInsurances.get(0).getAccumulationRadix().multiply(sysUserLevelInsurances.get(0).getAccumulationCompanyProportion());
                        // 增加天数
                        String res = simpleDateFormat.format(criteria.getEnterProjectTime().getTime() + (i * 24 * 60 * 60 * 1000));
                        try {
                            date = simpleDateFormat.parse(res);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
//                        System.out.println(date);
                        instance.setTime(date);
                        // 判断周六周日
                        if(instance.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY || instance.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
                            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(res);
                            // 判断周六周日是否为工作日 是工作日工作天数加一天
                            if(sysConfigHoliday != null){
                                if(sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_WEEKEND || sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_LEGAL_HOLIDAYS){
                                    workDays++;
                                }
                            }
                        } else {
                            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(res);
                            // 判断周一到周五是否为节假日 不是节假日工作天数加一天
                            if(sysConfigHoliday == null){
                                workDays++;
                            } else {
                                if(sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_LEGAL_HOLIDAYS){
                                    workDays++;
                                }
                            }
                        }
                    }
                } else {
                    // 用户在第一个级别时所在的项目时间
                    for(int i = 1;i<= (sysUserLevelWage.get(0).getEndDate().getTime() - criteria.getEnterProjectTime().getTime())/(1000 * 60 * 60 * 24);i++){
                        String res = simpleDateFormat.format(criteria.getEnterProjectTime().getTime() + (i *( 24 * 60 * 60 * 1000)));
                        try {
                            date = simpleDateFormat.parse(res);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
//                        System.out.println(date);
                        instance.setTime(date);
                        // 判断周六周日
                        if(instance.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY || instance.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
                            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(res);
                            // 判断周六周日是否为工作日 是工作日工作天数加一天
                            if(sysConfigHoliday != null){
                                if(sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_WEEKEND || sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_LEGAL_HOLIDAYS){
                                    workDays++;
                                }
                            }
                        } else {
                            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(res);
                            // 判断周一到周五是否为节假日 不是节假日工作天数加一天
                            if(sysConfigHoliday == null){
                                workDays++;
                            } else {
                                if(sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_LEGAL_HOLIDAYS){
                                    workDays++;
                                }
                            }
                        }
                    }
                    // 项目在第二个级别时所在项目的时间
                    for(int f = 1; f<= (criteria.getExitProjectTime().getTime()- sysUserLevelWage.get(1).getStartDate().getTime())/(1000 * 60 * 60 * 24);f++){
                        String res = simpleDateFormat.format(sysUserLevelWage.get(1).getStartDate().getTime()+ (f * 24 * 60 * 60 * 1000));
                        try {
                            date = simpleDateFormat.parse(res);
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        instance.setTime(date);
                        // 判断周六周日
                        if(instance.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY || instance.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
                            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(res);
                            // 判断周六周日是否为工作日 是工作日工作天数加一天
                            if(sysConfigHoliday != null){
                                if(sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_WEEKEND || sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_LEGAL_HOLIDAYS){
                                    workDays++;
                                }
                            }
                        } else {
                            SysConfigHoliday sysConfigHoliday = sysConfigHolidayRepository.findByHolidayDate(res);
                            // 判断周一到周五是否为节假日 不是节假日工作天数加一天
                            if(sysConfigHoliday == null){
                                workDays++;
                            } else {
                                if(sysConfigHoliday.getDateType()!= Constant.DATE_TYPE_LEGAL_HOLIDAYS){
                                    workDays++;
                                }
                            }
                        }
                    }
                }
            } else {
            }
//        }
//        BigDecimal d = BigDecimal.valueOf(20);
//        sysUserLevelWage.get(0).getLevelWage().divide(d,2,BigDecimal.ROUND_CEILING);
        return projectCost;
    }
    @Override
    public void download(List<ProjectCostDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (ProjectCostDto projectCost : all) {
            String projectName = projectCost.getProjectId() != null ? projectRepository.findById(projectCost.getProjectId()).orElseGet(Project::new).getName() : "";
            String user = projectCost.getUserId() != null ? userRepository.findById(projectCost.getUserId()).orElseGet(User::new).getNickName() : "";
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("项目", projectName);
            map.put("用户", user);
            map.put("进入项目时间", projectCost.getEnterProjectTime());
            map.put("退出项目时间", projectCost.getExitProjectTime());
            map.put("项目成本", projectCost.getProjectCost());
            map.put("备注", projectCost.getRemarks());
            map.put("创建者", projectCost.getCreateBy());
            map.put("创建时间", projectCost.getCreateTime());
            map.put("更新者", projectCost.getUpdateBy());
            map.put("更新时间", projectCost.getUpdateTime());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/project/service/mapstruct/ProjectCostMapper.java
New file
@@ -0,0 +1,32 @@
/*
*  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.project.service.mapstruct;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.project.domain.ProjectCost;
import me.zhengjie.modules.project.service.dto.ProjectCostDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://eladmin.vip
* @author HuaZhe
* @date 2022-12-27
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ProjectCostMapper extends BaseMapper<ProjectCostDto, ProjectCost> {
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/SysUserLevelInsuranceRepository.java
@@ -16,9 +16,12 @@
package me.zhengjie.modules.system.repository;
import me.zhengjie.modules.system.domain.SysUserLevelInsurance;
import me.zhengjie.modules.system.domain.SysUserLevelWage;
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;
/**
* @website https://eladmin.vip
@@ -34,4 +37,12 @@
     */
    @Query(value = "SELECT * FROM sys_user_level_insurance WHERE user_id = ?1 ORDER BY start_date DESC, create_time DESC LIMIT 1", nativeQuery = true)
    SysUserLevelInsurance findLastByUserId(Long userId);
    /**
     * 根据用户ID查询
     * @param userId /
     * @return /
     */
    @Query(value = "SELECT * FROM sys_user_level_insurance WHERE user_id = ?1", nativeQuery = true)
    List<SysUserLevelInsurance> findByUserId(Long userId);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/SysUserLevelWageRepository.java
@@ -20,6 +20,8 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @website https://eladmin.vip
* @author 赵士淞
@@ -42,4 +44,13 @@
     */
    @Query(value = "SELECT count(1) FROM sys_user_level_wage WHERE level_id IN ?1", nativeQuery = true)
    int countByLevels(Long[] ids);
    /**
     * 根据用户ID查询
     * @param userId /
     * @return /
     */
    @Query(value = "SELECT * FROM sys_user_level_wage WHERE user_id = ?1", nativeQuery = true)
    List<SysUserLevelWage> findByUserId(Long userId);
}
eladmin-web-master/src/api/project/projectCost.js
New file
@@ -0,0 +1,43 @@
import request from '@/utils/request'
export function getAll(params) {
  return request({
    url: 'api/projectCost/all',
    method: 'get',
    params
  })
}
export function add(data) {
  return request({
    url: 'api/projectCost',
    method: 'post',
    data
  })
}
export function del(ids) {
  return request({
    url: 'api/projectCost/',
    method: 'delete',
    data: ids
  })
}
export function edit(data) {
  return request({
    url: 'api/projectCost',
    method: 'put',
    data
  })
}
export function getCost(params) {
  return request({
    url: 'api/projectCost/getcost',
    method: 'get',
    params
  })
}
export default { getAll, add, edit, del, getCost }
eladmin-web-master/src/views/project/projectCost/index.vue
New file
@@ -0,0 +1,196 @@
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.projectId" clearable filterable 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.userId" clearable filterable placeholder="请选择用户" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in userList"
            :key="item.id"
            :label="item.nickName"
            :value="item.id"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <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="110px">
          <el-form-item label="项目" prop="projectId">
            <el-select v-model="form.projectId" clearable filterable placeholder="请选择" style="width: 340px;">
              <el-option
                v-for="item in projectList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="用户" prop="userId">
            <el-select v-model="form.userId" clearable filterable placeholder="请选择" style="width: 340px;" @change="getProjectCost">
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.nickName"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="进入项目时间" prop="enterProjectTime">
            <el-date-picker v-model="form.enterProjectTime" type="datetime" style="width: 340px;" @change="timeChange" />
          </el-form-item>
          <el-form-item label="退出项目时间" prop="exitProjectTime">
            <el-date-picker v-model="form.exitProjectTime" type="datetime" style="width: 340px;" @change="timeChange" />
          </el-form-item>
          <el-form-item label="项目成本" prop="projectCost">
            <el-input v-model="form.projectCost" style="width: 340px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 340px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <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>
          <template slot-scope="scope">
            <el-tag>{{ scope.row.projectName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="用户" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag>{{ scope.row.userName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="enterProjectTime" label="进入项目时间" />
        <el-table-column prop="exitProjectTime" label="退出项目时间" />
        <el-table-column prop="projectCost" label="项目成本" />
        <el-table-column prop="remarks" label="备注" />
        <el-table-column v-if="checkPer(['admin','projectCost:edit','projectCost:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
<script>
import crudProjectCost from '@/api/project/projectCost'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudUser from '@/api/system/user'
import crudProject from '@/api/project/project'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
const defaultForm = { id: null, projectId: null, userId: null, enterProjectTime: null, exitProjectTime: null, projectCost: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'ProjectCost',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '项目成本', url: 'api/projectCost', idField: 'id', sort: 'id,desc', crudMethod: { ...crudProjectCost }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'projectCost:add'],
        edit: ['admin', 'projectCost:edit'],
        del: ['admin', 'projectCost:del'],
        download: ['admin', 'projectCost:download']
      },
      rules: {
        projectId: [
          { required: true, message: '项目ID不能为空', trigger: 'blur' }
        ],
        userId: [
          { required: true, message: '用户ID不能为空', trigger: 'blur' }
        ],
        enterProjectTime: [
          { required: true, message: '进入项目时间不能为空', trigger: 'blur' }
        ],
        exitProjectTime: [
          { required: true, message: '退出项目时间不能为空', trigger: 'blur' }
        ],
        projectCost: [
          { required: true, message: '项目成本不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'projectId', display_name: '项目ID' },
        { key: 'userId', display_name: '用户ID' },
        { key: 'enterProjectTime', display_name: '进入项目时间' },
        { key: 'exitProjectTime', display_name: '退出项目时间' }
      ],
      // 用户列表
      userList: [],
      // 项目列表
      projectList: []
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      this.getUserList()
      this.getProjectList()
      return true
    },
    getUserList() {
      crudUser.getAll().then(res => {
        this.userList = res
      }).catch(() => {
      })
    },
    getProjectList() {
      crudProject.getAll().then(res => {
        this.projectList = res
      })
    }
    // timeChange(){
    //   if(this.form.enterProjectTime != null && this.form.exitProjectTime != null){
    //     this.getProjectCost()
    //   }
    // },
    // getProjectCost() {
    //   if (this.form.userId != null) {
    //     crudProjectCost.getCost({
    //       userId: this.form.userId,
    //       enterProjectTime: this.form.enterProjectTime,
    //       exitProjectTime: this.form.exitProjectTime,
    //       }).then(res => {
    //     })
    //   }
    // }
  }
}
</script>
<style scoped>
</style>