From b87ff0b094eec62b1b4602f51ed4eadf1ba1e169 Mon Sep 17 00:00:00 2001
From: 赵士淞 <zhaoss@yhzhg.cn>
Date: Fri, 10 Feb 2023 07:13:59 +0000
Subject: [PATCH] 合同项目关联
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/ContractProjectService.java | 83 +++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectDto.java | 57 +++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectQueryCriteria.java | 41 ++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/domain/ContractProject.java | 74 ++++
eladmin-web-master/src/api/contract/contractProject.js | 35 ++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractProjectServiceImpl.java | 191 +++++++++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/mapstruct/ContractProjectMapper.java | 32 ++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/repository/ContractProjectRepository.java | 71 ++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/rest/ContractProjectController.java | 95 +++++
eladmin-web-master/src/views/contract/contractProject/index.vue | 222 +++++++++++++
10 files changed, 901 insertions(+), 0 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/domain/ContractProject.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/domain/ContractProject.java
new file mode 100644
index 0000000..f7bad19
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/domain/ContractProject.java
@@ -0,0 +1,74 @@
+/*
+* 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.contract.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 赵士淞
+* @date 2023-02-10
+**/
+@Entity
+@Data
+@Table(name="contract_project")
+public class ContractProject extends BaseEntity implements Serializable {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "`id`")
+ @ApiModelProperty(value = "ID")
+ private Long id;
+
+ @Column(name = "`contract_id`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "所属合同")
+ private Long contractId;
+
+ @Column(name = "`project_id`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "所属项目")
+ private Long projectId;
+
+ @Column(name = "`fund_type`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "款项类型")
+ private String fundType;
+
+ @Column(name = "`allocated_amount`",nullable = false)
+ @NotNull
+ @ApiModelProperty(value = "分配金额")
+ private BigDecimal allocatedAmount;
+
+ @Column(name = "`remarks`")
+ @ApiModelProperty(value = "备注信息")
+ private String remarks;
+
+ public void copy(ContractProject source){
+ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
+ }
+}
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/repository/ContractProjectRepository.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/repository/ContractProjectRepository.java
new file mode 100644
index 0000000..4996ccf
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/repository/ContractProjectRepository.java
@@ -0,0 +1,71 @@
+/*
+* 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.contract.repository;
+
+import me.zhengjie.modules.contract.domain.ContractProject;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+* @website https://eladmin.vip
+* @author 赵士淞
+* @date 2023-02-10
+**/
+public interface ContractProjectRepository extends JpaRepository<ContractProject, Long>, JpaSpecificationExecutor<ContractProject> {
+
+ /**
+ * 根据项目ID删除
+ * @param projectId
+ */
+ void deleteByProjectId(Long projectId);
+
+ /**
+ * 根据合同ID删除
+ * @param contractId
+ */
+ void deleteByContractId(Long contractId);
+
+ /**
+ * 根据合同ID、款项类型查询合同项目数量
+ * @param contractId
+ * @param fundType
+ * @return
+ */
+ @Query(value = "SELECT COUNT(*) FROM contract_project WHERE contract_id = ?1 AND fund_type = ?2",nativeQuery = true)
+ Integer countByContractIdAndFundType(Long contractId, String fundType);
+
+ /**
+ * 根据合同ID、款项类型查询合同项目金额
+ * @param contractId
+ * @param fundType
+ * @return
+ */
+ @Query(value = "SELECT SUM(allocated_amount) FROM contract_project WHERE contract_id = ?1 AND fund_type = ?2",nativeQuery = true)
+ BigDecimal sumAllocatedAmountByContractIdAndFundType(Long contractId, String fundType);
+
+ /**
+ * 根据合同ID、项目ID、款项类型查询
+ * @param contractId
+ * @param projectId
+ * @param fundType
+ * @return
+ */
+ List<ContractProject> findByContractIdAndProjectIdAndFundType(Long contractId, Long projectId, String fundType);
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/rest/ContractProjectController.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/rest/ContractProjectController.java
new file mode 100644
index 0000000..542d08f
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/rest/ContractProjectController.java
@@ -0,0 +1,95 @@
+/*
+* 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.contract.rest;
+
+import me.zhengjie.annotation.Log;
+import me.zhengjie.modules.contract.domain.ContractProject;
+import me.zhengjie.modules.contract.service.ContractProjectService;
+import me.zhengjie.modules.contract.service.dto.ContractProjectQueryCriteria;
+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 赵士淞
+* @date 2023-02-10
+**/
+@RestController
+@RequiredArgsConstructor
+@Api(tags = "合同项目关联管理")
+@RequestMapping("/api/contractProject")
+public class ContractProjectController {
+
+ private final ContractProjectService contractProjectService;
+
+ @Log("导出数据")
+ @ApiOperation("导出数据")
+ @GetMapping(value = "/download")
+ @PreAuthorize("@el.check('contractProject:download')")
+ public void exportContractProject(HttpServletResponse response, ContractProjectQueryCriteria criteria) throws IOException {
+ contractProjectService.download(contractProjectService.queryAll(criteria), response);
+ }
+
+ @GetMapping
+ @Log("查询合同项目关联")
+ @ApiOperation("查询合同项目关联")
+ @PreAuthorize("@el.check('contractProject:list')")
+ public ResponseEntity<Object> queryContractProject(ContractProjectQueryCriteria criteria, Pageable pageable){
+ return new ResponseEntity<>(contractProjectService.queryAll(criteria,pageable),HttpStatus.OK);
+ }
+
+ @GetMapping(value = "/all")
+ @Log("查询合同项目关联")
+ @ApiOperation("查询合同项目关联")
+ @PreAuthorize("@el.check('contractProject:list')")
+ public ResponseEntity<Object> queryContractProject(ContractProjectQueryCriteria criteria){
+ return new ResponseEntity<>(contractProjectService.queryAll(criteria),HttpStatus.OK);
+ }
+
+ @PostMapping
+ @Log("新增合同项目关联")
+ @ApiOperation("新增合同项目关联")
+ @PreAuthorize("@el.check('contractProject:add')")
+ public ResponseEntity<Object> createContractProject(@Validated @RequestBody ContractProject resources){
+ return new ResponseEntity<>(contractProjectService.create(resources),HttpStatus.CREATED);
+ }
+
+ @PutMapping
+ @Log("修改合同项目关联")
+ @ApiOperation("修改合同项目关联")
+ @PreAuthorize("@el.check('contractProject:edit')")
+ public ResponseEntity<Object> updateContractProject(@Validated @RequestBody ContractProject resources){
+ contractProjectService.update(resources);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ }
+
+ @DeleteMapping
+ @Log("删除合同项目关联")
+ @ApiOperation("删除合同项目关联")
+ @PreAuthorize("@el.check('contractProject:del')")
+ public ResponseEntity<Object> deleteContractProject(@RequestBody Long[] ids) {
+ contractProjectService.deleteAll(ids);
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/ContractProjectService.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/ContractProjectService.java
new file mode 100644
index 0000000..c852336
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/ContractProjectService.java
@@ -0,0 +1,83 @@
+/*
+* 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.contract.service;
+
+import me.zhengjie.modules.contract.domain.ContractProject;
+import me.zhengjie.modules.contract.service.dto.ContractProjectDto;
+import me.zhengjie.modules.contract.service.dto.ContractProjectQueryCriteria;
+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 赵士淞
+* @date 2023-02-10
+**/
+public interface ContractProjectService {
+
+ /**
+ * 查询数据分页
+ * @param criteria 条件
+ * @param pageable 分页参数
+ * @return Map<String,Object>
+ */
+ Map<String,Object> queryAll(ContractProjectQueryCriteria criteria, Pageable pageable);
+
+ /**
+ * 查询所有数据不分页
+ * @param criteria 条件参数
+ * @return List<ContractProjectDto>
+ */
+ List<ContractProjectDto> queryAll(ContractProjectQueryCriteria criteria);
+
+ /**
+ * 根据ID查询
+ * @param id ID
+ * @return ContractProjectDto
+ */
+ ContractProjectDto findById(Long id);
+
+ /**
+ * 创建
+ * @param resources /
+ * @return ContractProjectDto
+ */
+ ContractProjectDto create(ContractProject resources);
+
+ /**
+ * 编辑
+ * @param resources /
+ */
+ void update(ContractProject resources);
+
+ /**
+ * 多选删除
+ * @param ids /
+ */
+ void deleteAll(Long[] ids);
+
+ /**
+ * 导出数据
+ * @param all 待导出的数据
+ * @param response /
+ * @throws IOException /
+ */
+ void download(List<ContractProjectDto> all, HttpServletResponse response) throws IOException;
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectDto.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectDto.java
new file mode 100644
index 0000000..cc03623
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectDto.java
@@ -0,0 +1,57 @@
+/*
+* 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.contract.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 赵士淞
+* @date 2023-02-10
+**/
+@Data
+public class ContractProjectDto extends BaseDTO implements Serializable {
+
+ /** ID */
+ private Long id;
+
+ /** 所属合同 */
+ private Long contractId;
+
+ /** 所属项目 */
+ private Long projectId;
+
+ /** 款项类型 */
+ private String fundType;
+
+ /** 分配金额 */
+ private BigDecimal allocatedAmount;
+
+ /** 备注信息 */
+ private String remarks;
+
+ /** 合同名称 */
+ private String contractName;
+
+ /** 项目名称 */
+ private String projectName;
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectQueryCriteria.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectQueryCriteria.java
new file mode 100644
index 0000000..1bb4169
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/dto/ContractProjectQueryCriteria.java
@@ -0,0 +1,41 @@
+/*
+* 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.contract.service.dto;
+
+import lombok.Data;
+import java.util.List;
+import me.zhengjie.annotation.Query;
+
+/**
+* @website https://eladmin.vip
+* @author 赵士淞
+* @date 2023-02-10
+**/
+@Data
+public class ContractProjectQueryCriteria{
+
+ /** 精确 */
+ @Query
+ private Long contractId;
+
+ /** 精确 */
+ @Query
+ private Long projectId;
+
+ /** 精确 */
+ @Query
+ private String fundType;
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractProjectServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractProjectServiceImpl.java
new file mode 100644
index 0000000..5b4c6cb
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/impl/ContractProjectServiceImpl.java
@@ -0,0 +1,191 @@
+/*
+* 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.contract.service.impl;
+
+import me.zhengjie.exception.BadRequestException;
+import me.zhengjie.modules.constant.Constant;
+import me.zhengjie.modules.contract.domain.ContractProject;
+import me.zhengjie.modules.contract.service.dto.ContractDto;
+import me.zhengjie.modules.project.service.dto.ProjectDto;
+import me.zhengjie.modules.project.service.impl.ProjectServiceImpl;
+import me.zhengjie.modules.system.repository.DictDetailRepository;
+import me.zhengjie.utils.ValidationUtil;
+import me.zhengjie.utils.FileUtil;
+import lombok.RequiredArgsConstructor;
+import me.zhengjie.modules.contract.repository.ContractProjectRepository;
+import me.zhengjie.modules.contract.service.ContractProjectService;
+import me.zhengjie.modules.contract.service.dto.ContractProjectDto;
+import me.zhengjie.modules.contract.service.dto.ContractProjectQueryCriteria;
+import me.zhengjie.modules.contract.service.mapstruct.ContractProjectMapper;
+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.math.BigDecimal;
+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;
+
+/**
+* @website https://eladmin.vip
+* @description 服务实现
+* @author 赵士淞
+* @date 2023-02-10
+**/
+@Service
+@RequiredArgsConstructor
+public class ContractProjectServiceImpl implements ContractProjectService {
+
+ private final ContractProjectRepository contractProjectRepository;
+ private final ContractProjectMapper contractProjectMapper;
+ private final ProjectServiceImpl projectServiceImpl;
+ private final ContractServiceImpl contractServiceImpl;
+ private final DictDetailRepository dictDetailRepository;
+
+ @Override
+ public Map<String,Object> queryAll(ContractProjectQueryCriteria criteria, Pageable pageable){
+ Page<ContractProject> page = contractProjectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
+ // 将实体类转换为DTO(重写)
+ Function<ContractProject, ContractProjectDto> func = new Function<ContractProject, ContractProjectDto>(){
+ @Override
+ public ContractProjectDto apply(ContractProject t) {
+ // 将实体类转换成DTO
+ ContractProjectDto contractProjectDto = contractProjectMapper.toDto(t);
+ // 根据项目ID查询项目
+ ProjectDto projectDto = projectServiceImpl.findById(t.getProjectId());
+ // 项目名称
+ contractProjectDto.setProjectName(projectDto.getName());
+ // 根据合同ID查询合同
+ ContractDto contractDto = contractServiceImpl.findById(t.getContractId());
+ // 合同名称
+ contractProjectDto.setContractName(contractDto.getContractName());
+ // 返回处理好的DTO
+ return contractProjectDto;
+ }
+ };
+ return PageUtil.toPage(page.map(func));
+ }
+
+ @Override
+ public List<ContractProjectDto> queryAll(ContractProjectQueryCriteria criteria){
+ return contractProjectMapper.toDto(contractProjectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
+ }
+
+ @Override
+ @Transactional
+ public ContractProjectDto findById(Long id) {
+ ContractProject contractProject = contractProjectRepository.findById(id).orElseGet(ContractProject::new);
+ ValidationUtil.isNull(contractProject.getId(),"ContractProject","id",id);
+ return contractProjectMapper.toDto(contractProject);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public ContractProjectDto create(ContractProject resources) {
+ // 新增修改校验
+ createOrUpdateCheck(null, resources);
+ return contractProjectMapper.toDto(contractProjectRepository.save(resources));
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(ContractProject resources) {
+ ContractProject contractProject = contractProjectRepository.findById(resources.getId()).orElseGet(ContractProject::new);
+ ValidationUtil.isNull( contractProject.getId(),"ContractProject","id",resources.getId());
+ // 新增修改校验
+ createOrUpdateCheck(contractProject, resources);
+ contractProject.copy(resources);
+ contractProjectRepository.save(contractProject);
+ }
+
+ @Override
+ public void deleteAll(Long[] ids) {
+ for (Long id : ids) {
+ contractProjectRepository.deleteById(id);
+ }
+ }
+
+ @Override
+ public void download(List<ContractProjectDto> all, HttpServletResponse response) throws IOException {
+ List<Map<String, Object>> list = new ArrayList<>();
+ for (ContractProjectDto contractProject : all) {
+ ContractDto contractDto = contractServiceImpl.findById(contractProject.getContractId());
+ ProjectDto projectDto = projectServiceImpl.findById(contractProject.getProjectId());
+ String fundType = contractProject.getFundType() != null ? dictDetailRepository.findByDictNameAndValue(Constant.FUND_TYPE, contractProject.getFundType()).getLabel() : "";
+ Map<String,Object> map = new LinkedHashMap<>();
+ map.put("所属合同", contractDto.getContractName());
+ map.put("所属项目", projectDto.getName());
+ map.put("款项类型", fundType);
+ map.put("分配金额", contractProject.getAllocatedAmount());
+ map.put("备注信息", contractProject.getRemarks());
+ map.put("创建者", contractProject.getCreateBy());
+ map.put("创建时间", contractProject.getCreateTime());
+ list.add(map);
+ }
+ FileUtil.downloadExcel(list, response);
+ }
+
+ /**
+ * 新增修改校验
+ * @param oldContractProject
+ * @param newContractProject
+ */
+ private void createOrUpdateCheck(ContractProject oldContractProject, ContractProject newContractProject) {
+ // 根据合同ID、项目ID、款项类型查询合同项目数据
+ List<ContractProject> contractProjectList = contractProjectRepository.findByContractIdAndProjectIdAndFundType(newContractProject.getContractId(), newContractProject.getProjectId(), newContractProject.getFundType());
+ // 判断合同项目数据是否为空
+ if (contractProjectList.size() != 0 && contractProjectList.get(0).getId() != newContractProject.getId()) {
+ throw new BadRequestException("合同任务已存在,无法重复分配!");
+ }
+ // 分配金额总和
+ BigDecimal sumAllocatedAmount = contractProjectRepository.sumAllocatedAmountByContractIdAndFundType(newContractProject.getContractId(), newContractProject.getFundType());
+ // 判断是新增还是修改
+ if (oldContractProject == null) {
+ // 分配金额总和
+ sumAllocatedAmount = sumAllocatedAmount.add(newContractProject.getAllocatedAmount());
+ } else {
+ // 判断新旧合同项目付款类型是否一致
+ if (oldContractProject.getFundType().equals(newContractProject.getFundType())) {
+ // 分配金额总和
+ sumAllocatedAmount = sumAllocatedAmount.subtract(oldContractProject.getAllocatedAmount()).add(newContractProject.getAllocatedAmount());
+ } else {
+ // 分配金额总和
+ sumAllocatedAmount = sumAllocatedAmount.add(newContractProject.getAllocatedAmount());
+ }
+ }
+ // 根据合同ID查询合同数据
+ ContractDto contractDto = contractServiceImpl.findById(newContractProject.getContractId());
+ // 判断合同项目款项类型
+ if (Constant.FUND_CONTRACT.equals(newContractProject.getFundType())) {
+ // 判断分配金额是否超出合同金额
+ if (contractDto.getContractAmount() == null || sumAllocatedAmount.compareTo(contractDto.getContractAmount()) == 1) {
+ throw new BadRequestException("合同分配总金额超出合同费金额!");
+ }
+ } else if (Constant.FUND_SERVICE.equals(newContractProject.getFundType())) {
+ // 判断分配金额是否超出合同金额
+ if (contractDto.getServiceAmount() == null || sumAllocatedAmount.compareTo(contractDto.getServiceAmount()) == 1) {
+ throw new BadRequestException("合同分配总金额超出服务费金额!");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/mapstruct/ContractProjectMapper.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/mapstruct/ContractProjectMapper.java
new file mode 100644
index 0000000..0a210b2
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/contract/service/mapstruct/ContractProjectMapper.java
@@ -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.contract.service.mapstruct;
+
+import me.zhengjie.base.BaseMapper;
+import me.zhengjie.modules.contract.domain.ContractProject;
+import me.zhengjie.modules.contract.service.dto.ContractProjectDto;
+import org.mapstruct.Mapper;
+import org.mapstruct.ReportingPolicy;
+
+/**
+* @website https://eladmin.vip
+* @author 赵士淞
+* @date 2023-02-10
+**/
+@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
+public interface ContractProjectMapper extends BaseMapper<ContractProjectDto, ContractProject> {
+
+}
\ No newline at end of file
diff --git a/eladmin-web-master/src/api/contract/contractProject.js b/eladmin-web-master/src/api/contract/contractProject.js
new file mode 100644
index 0000000..9765142
--- /dev/null
+++ b/eladmin-web-master/src/api/contract/contractProject.js
@@ -0,0 +1,35 @@
+import request from '@/utils/request'
+
+export function getAll(params) {
+ return request({
+ url: 'api/contractProject',
+ method: 'get',
+ params
+ })
+}
+
+export function add(data) {
+ return request({
+ url: 'api/contractProject',
+ method: 'post',
+ data
+ })
+}
+
+export function del(ids) {
+ return request({
+ url: 'api/contractProject/',
+ method: 'delete',
+ data: ids
+ })
+}
+
+export function edit(data) {
+ return request({
+ url: 'api/contractProject',
+ method: 'put',
+ data
+ })
+}
+
+export default { getAll, add, edit, del }
diff --git a/eladmin-web-master/src/views/contract/contractProject/index.vue b/eladmin-web-master/src/views/contract/contractProject/index.vue
new file mode 100644
index 0000000..eb6f2b3
--- /dev/null
+++ b/eladmin-web-master/src/views/contract/contractProject/index.vue
@@ -0,0 +1,222 @@
+<template>
+ <div class="app-container">
+ <!--工具栏-->
+ <div class="head-container">
+ <div v-if="crud.props.searchToggle">
+ <!-- 搜索 -->
+ <el-select v-model="query.contractId" filterable clearable placeholder="所属合同" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
+ <el-option
+ v-for="item in contracts"
+ :key="item.contractId"
+ :label="item.contractName"
+ :value="item.contractId"
+ />
+ </el-select>
+ <el-select v-model="query.projectId" filterable clearable placeholder="所属项目" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
+ <el-option
+ v-for="item in projects"
+ :key="item.id"
+ :label="item.name"
+ :value="item.id"
+ />
+ </el-select>
+ <el-select v-model="query.fundType" filterable clearable placeholder="款项类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
+ <el-option
+ v-for="item in dict[fundType]"
+ :key="item.id"
+ :label="item.label"
+ :value="item.value"
+ />
+ </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="80px">
+ <el-form-item label="所属合同" prop="contractId">
+ <el-select v-model="form.contractId" filterable clearable placeholder="请选择" style="width: 370px;">
+ <el-option
+ v-for="item in contracts"
+ :key="item.contractId"
+ :label="item.contractName"
+ :value="item.contractId"
+ />
+ </el-select>
+ </el-form-item>
+ <el-form-item label="所属项目" prop="projectId">
+ <el-select v-model="form.projectId" filterable clearable placeholder="请选择" style="width: 370px;">
+ <el-option
+ v-for="item in projects"
+ :key="item.id"
+ :label="item.name"
+ :value="item.id"
+ />
+ </el-select>
+ </el-form-item>
+ <el-form-item label="款项类型" prop="fundType">
+ <el-select v-model="form.fundType" filterable placeholder="请选择" style="width: 370px;">
+ <el-option
+ v-for="item in dict[fundType]"
+ :key="item.id"
+ :label="item.label"
+ :value="item.value"
+ />
+ </el-select>
+ </el-form-item>
+ <el-form-item label="分配金额" prop="allocatedAmount">
+ <money-input :key="random" v-model="form.allocatedAmount" :width="370" />
+ </el-form-item>
+ <el-form-item label="备注信息">
+ <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 370px;" />
+ </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 :show-overflow-tooltip="true" prop="contractName" label="所属合同" />
+ <el-table-column :show-overflow-tooltip="true" prop="projectName" label="所属项目" />
+ <el-table-column :show-overflow-tooltip="true" prop="fundType" label="款项类型">
+ <template slot-scope="scope">
+ {{ dict.label[fundType][scope.row.fundType] }}
+ </template>
+ </el-table-column>
+ <el-table-column :show-overflow-tooltip="true" prop="allocatedAmount" label="分配金额">
+ <template slot-scope="scope">
+ {{ crud.toMoney(scope.row.allocatedAmount) }}
+ </template>
+ </el-table-column>
+ <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注信息" />
+ <el-table-column :show-overflow-tooltip="true" prop="createTime" label="创建时间" />
+ <el-table-column v-if="checkPer(['admin','contractProject:edit','contractProject: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 crudContractProject from '@/api/contract/contractProject'
+import CRUD, { presenter, header, form, crud } from '@crud/crud'
+import rrOperation from '@crud/RR.operation'
+import crudOperation from '@crud/CRUD.operation'
+import udOperation from '@crud/UD.operation'
+import pagination from '@crud/Pagination'
+import crudContract from '@/api/contract/contract'
+import crudProject from '@/api/project/project'
+import moneyInput from '../../assembly/moneyInput/index.vue'
+import constant from '../../../utils/constant'
+
+const defaultForm = { id: null, contractId: null, projectId: null, fundType: null, allocatedAmount: null, remarks: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
+export default {
+ name: 'ContractProject',
+ components: { pagination, crudOperation, rrOperation, udOperation, moneyInput },
+ mixins: [presenter(), header(), form(defaultForm), crud()],
+ dicts: [constant.FUND_TYPE],
+ cruds() {
+ return CRUD({ title: '合同项目关联', url: 'api/contractProject', idField: 'id', sort: 'id,desc', crudMethod: { ...crudContractProject }})
+ },
+ data() {
+ // 分配金额校验规则
+ var validateAllocatedAmount = (rule, value, callback) => {
+ if (value !== null) {
+ if (isNaN(Number(value))) {
+ callback(new Error('请输入数字值'))
+ } else {
+ if (value < 0 || value > 1000000000) {
+ callback(new Error('分配金额不能超过10亿'))
+ } else {
+ callback()
+ }
+ }
+ } else {
+ callback(new Error('分配金额不能为空'))
+ }
+ }
+ return {
+ permission: {
+ add: ['admin', 'contractProject:add'],
+ edit: ['admin', 'contractProject:edit'],
+ del: ['admin', 'contractProject:del'],
+ download: ['admin', 'contractProject:download']
+ },
+ rules: {
+ contractId: [
+ { required: true, message: '所属合同不能为空', trigger: 'change' }
+ ],
+ projectId: [
+ { required: true, message: '所属项目不能为空', trigger: 'change' }
+ ],
+ fundType: [
+ { required: true, message: '请选择款项类型', trigger: 'change' }
+ ],
+ allocatedAmount: [
+ { required: true, validator: validateAllocatedAmount, trigger: 'blur' }
+ ]
+ },
+ queryTypeOptions: [
+ { key: 'contractId', display_name: '所属合同' },
+ { key: 'projectId', display_name: '所属项目' },
+ { key: 'fundType', display_name: '款项类型' }
+ ],
+ // 字典:款项类型
+ fundType: constant.FUND_TYPE,
+ // 合同列表
+ contracts: [],
+ // 项目列表
+ projects: [],
+ // 随机数
+ random: 0
+ }
+ },
+ methods: {
+ // 钩子:在获取表格数据之前执行,false 则代表不获取数据
+ [CRUD.HOOK.beforeRefresh]() {
+ // 获取合同列表
+ this.getContracts()
+ // 获取项目列表
+ this.getProjects()
+ return true
+ },
+ // 获取合同列表
+ getContracts() {
+ // 获取合同列表
+ crudContract.getAll().then(res => {
+ // 合同列表
+ this.contracts = res
+ })
+ },
+ // 获取项目列表
+ getProjects() {
+ // 获取项目列表
+ crudProject.getAll().then(res => {
+ // 项目列表
+ this.projects = res
+ })
+ },
+ // 钩子:开始 "新建/编辑" - 之前
+ [CRUD.HOOK.beforeToCU]() {
+ // 随机数
+ this.random = Math.random()
+ }
+ }
+}
+</script>
+
+<style scoped>
+
+</style>
--
Gitblit v1.9.3