diff --git a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java index 75b28f2..6f97f96 100644 --- a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java +++ b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java @@ -57,14 +57,30 @@ public class ProjectController extends BaseController{ Dept one = deptRepository.findOne(1); model.put("dept",one); - return "admin/project_estimate_input"; + return "admin/project_estimate_add"; } - @RequestMapping("/estimateSave") - public String estimateSave(Project project, EstimateBean estimateBean, + @RequestMapping("/estimateAddSave") + public String estimateAddSave(Project project, EstimateBean estimateBean, Map model) { - projectService.estimateSave(project, estimateBean, InterfaceUtil.getAdmin()); + projectService.estimateAddSave(project, estimateBean, InterfaceUtil.getAdmin()); return "redirect:/project/list"; } + @RequestMapping("/edit") + public String edit(@RequestParam("id") int id,Map model) { + Project project = projectService.getProject(id); + model.put("project", project); + EstimateBean estimateBean = projectService.estimate(project); + model.put("estimateBean", estimateBean); + return "admin/project_estimate_edit"; + } + @RequestMapping("/estimateEditSave") + public String estimateEditSave(Project project, EstimateBean estimateBean, + Map model) { + projectService.estimateEditSave(project, estimateBean, InterfaceUtil.getAdmin()); + return "redirect:/project/list"; + } + + @RequestMapping("/estimateSaveAndApprove") public String estimateSaveAndApprove(Map model) { return "redirect:/project/list"; diff --git a/src/main/java/cn/palmte/work/model/ProjectEstimateCostManage.java b/src/main/java/cn/palmte/work/model/ProjectEstimateCostManage.java index 85e6068..ce4ca02 100644 --- a/src/main/java/cn/palmte/work/model/ProjectEstimateCostManage.java +++ b/src/main/java/cn/palmte/work/model/ProjectEstimateCostManage.java @@ -24,8 +24,8 @@ public class ProjectEstimateCostManage { private int type; - @Column(name = "income_tax_exclude") - private BigDecimal incomeTaxExclude; + @Column(name = "cost_tax_exclude") + private BigDecimal costTaxExclude; public Integer getId() { return id; @@ -51,11 +51,11 @@ public class ProjectEstimateCostManage { this.type = type; } - public BigDecimal getIncomeTaxExclude() { - return incomeTaxExclude; + public BigDecimal getCostTaxExclude() { + return costTaxExclude; } - public void setIncomeTaxExclude(BigDecimal incomeTaxExclude) { - this.incomeTaxExclude = incomeTaxExclude; + public void setCostTaxExclude(BigDecimal costTaxExclude) { + this.costTaxExclude = costTaxExclude; } } \ No newline at end of file diff --git a/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java b/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java index a584130..d9bbe0b 100644 --- a/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java @@ -2,5 +2,8 @@ package cn.palmte.work.model; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ProjectEstimateCostManageRepository extends JpaRepository { + List findAllByProjectIdEquals(int id); } diff --git a/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java b/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java index 1b17f43..7af11be 100644 --- a/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java @@ -2,5 +2,8 @@ package cn.palmte.work.model; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ProjectEstimateCostRepository extends JpaRepository { + List findAllByProjectIdEquals(int id); } diff --git a/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java b/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java index f60c5d5..2b51c2b 100644 --- a/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java @@ -2,5 +2,8 @@ package cn.palmte.work.model; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ProjectEstimateIncomeRepository extends JpaRepository { + List findAllByProjectIdEquals(int id); } diff --git a/src/main/java/cn/palmte/work/service/ProjectService.java b/src/main/java/cn/palmte/work/service/ProjectService.java index f49737e..ad0de33 100644 --- a/src/main/java/cn/palmte/work/service/ProjectService.java +++ b/src/main/java/cn/palmte/work/service/ProjectService.java @@ -7,13 +7,17 @@ import cn.palmte.work.bean.TypeEnum; import cn.palmte.work.model.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import top.jfunc.common.db.QueryHelper; import top.jfunc.common.db.bean.Page; import top.jfunc.common.db.utils.Pagination; +import top.jfunc.common.utils.CollectionUtil; import top.jfunc.common.utils.StrUtil; import java.util.Date; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @author xiongshiyan at 2021/10/29 , contact me with email yanshixiong@126.com or phone 15208384257 @@ -82,9 +86,10 @@ public class ProjectService { } /** - * 概算保存项目 + * 新增概算保存项目 */ - public Project estimateSave(Project project, EstimateBean estimateBean, Admin admin) { + @Transactional(rollbackFor = RuntimeException.class) + public Project estimateAddSave(Project project, EstimateBean estimateBean, Admin admin) { project.setTypeDesc(TypeEnum.parseType(project.getType()).getTypeDesc()); project.setStatusDesc(StatusEnum.parseStatus(project.getStatus()).getStatusDesc()); project.setApproveStatus(ApproveStatusEnum.APPROVAL_PENDING.getApproveStatus()); @@ -114,6 +119,36 @@ public class ProjectService { return project; } + private void clearEstimate(Project project){ + List incomes = projectEstimateIncomeRepository.findAllByProjectIdEquals(project.getId()); + if(CollectionUtil.isNotEmpty(incomes)){ + projectEstimateIncomeRepository.deleteInBatch(incomes); + } + + List costs = projectEstimateCostRepository.findAllByProjectIdEquals(project.getId()); + if(CollectionUtil.isNotEmpty(costs)){ + projectEstimateCostRepository.deleteInBatch(costs); + } + + List costManages = projectEstimateCostManageRepository.findAllByProjectIdEquals(project.getId()); + if(CollectionUtil.isNotEmpty(costManages)){ + projectEstimateCostManageRepository.deleteInBatch(costManages); + } + + } + /** + * 编辑概算保存项目 + */ + @Transactional(rollbackFor = RuntimeException.class) + public Project estimateEditSave(Project project, EstimateBean estimateBean, Admin admin) { + //删除原来的 + projectRepository.delete(project.getId()); + //清空概算信息 + clearEstimate(project); + + return estimateAddSave(project, estimateBean, admin); + } + private void cost(Project project, EstimateBean estimateBean) { ProjectEstimateCost projectEstimateCostDevice = new ProjectEstimateCost(); projectEstimateCostDevice.setProjectId(project.getId()); @@ -169,13 +204,13 @@ public class ProjectService { ProjectEstimateCostManage projectEstimateCostZijin = new ProjectEstimateCostManage(); projectEstimateCostZijin.setProjectId(project.getId()); projectEstimateCostZijin.setType(1); - projectEstimateCostZijin.setIncomeTaxExclude(estimateBean.getCostCompanyManageTaxExclude()); + projectEstimateCostZijin.setCostTaxExclude(estimateBean.getCostExpropriationTaxExclude()); projectEstimateCostManageRepository.saveAndFlush(projectEstimateCostZijin); ProjectEstimateCostManage projectEstimateCostManage = new ProjectEstimateCostManage(); projectEstimateCostManage.setProjectId(project.getId()); projectEstimateCostManage.setType(2); - projectEstimateCostManage.setIncomeTaxExclude(estimateBean.getCostCompanyManageTaxExclude()); + projectEstimateCostManage.setCostTaxExclude(estimateBean.getCostCompanyManageTaxExclude()); projectEstimateCostManageRepository.saveAndFlush(projectEstimateCostManage); } private void income(Project project, EstimateBean estimateBean) { @@ -200,4 +235,59 @@ public class ProjectService { projectEstimateIncomeService.setIncomeTaxExclude(estimateBean.getIncomeServiceTaxExclude()); projectEstimateIncomeRepository.saveAndFlush(projectEstimateIncomeService); } + + public Project getProject(int id) { + return projectRepository.findOne(id); + } + + public EstimateBean estimate(Project project) { + EstimateBean estimateBean = new EstimateBean(); + List incomes = projectEstimateIncomeRepository.findAllByProjectIdEquals(project.getId()); + + ProjectEstimateIncome projectEstimateIncomeDevice = incomes.stream().filter(d -> d.getType() == 1).collect(Collectors.toList()).get(0); + estimateBean.setIncomeDeviceTaxInclude(projectEstimateIncomeDevice.getIncomeTaxInclude()); + estimateBean.setIncomeDeviceTaxExclude(projectEstimateIncomeDevice.getIncomeTaxExclude()); + + ProjectEstimateIncome projectEstimateIncomeEngineer = incomes.stream().filter(d -> d.getType() == 2).collect(Collectors.toList()).get(0); + estimateBean.setIncomeEngineerTaxInclude(projectEstimateIncomeEngineer.getIncomeTaxInclude()); + estimateBean.setIncomeEngineerTaxExclude(projectEstimateIncomeEngineer.getIncomeTaxExclude()); + + ProjectEstimateIncome projectEstimateIncomeService = incomes.stream().filter(d -> d.getType() == 3).collect(Collectors.toList()).get(0); + estimateBean.setIncomeServiceTaxInclude(projectEstimateIncomeService.getIncomeTaxInclude()); + estimateBean.setIncomeServiceTaxExclude(projectEstimateIncomeService.getIncomeTaxExclude()); + + List costs = projectEstimateCostRepository.findAllByProjectIdEquals(project.getId()); + + ProjectEstimateCost projectEstimateCostDevice = costs.stream().filter(d -> d.getType() == 1).collect(Collectors.toList()).get(0); + estimateBean.setCostPurchaseDeviceTaxInclude(projectEstimateCostDevice.getCostTaxInclude()); + estimateBean.setCostPurchaseDeviceTaxExclude(projectEstimateCostDevice.getCostTaxExclude()); + + ProjectEstimateCost projectEstimateCostBuild = costs.stream().filter(d -> d.getType() == 2).collect(Collectors.toList()).get(0); + estimateBean.setCostPurchaseBuildTaxInclude(projectEstimateCostBuild.getCostTaxInclude()); + estimateBean.setCostPurchaseBuildTaxExclude(projectEstimateCostBuild.getCostTaxExclude()); + + ProjectEstimateCost projectEstimateCostService = costs.stream().filter(d -> d.getType() == 3).collect(Collectors.toList()).get(0); + estimateBean.setCostPurchaseServiceTaxInclude(projectEstimateCostService.getCostTaxInclude()); + estimateBean.setCostPurchaseServiceTaxExclude(projectEstimateCostService.getCostTaxExclude()); + + ProjectEstimateCost projectEstimateCostOther = costs.stream().filter(d -> d.getType() == 4).collect(Collectors.toList()).get(0); + estimateBean.setCostPurchaseOtherTaxInclude(projectEstimateCostOther.getCostTaxInclude()); + estimateBean.setCostPurchaseOtherTaxExclude(projectEstimateCostOther.getCostTaxExclude()); + + ProjectEstimateCost projectEstimateCostProjectManage = costs.stream().filter(d -> d.getType() == 5).collect(Collectors.toList()).get(0); + estimateBean.setCostProjectManageTaxInclude(projectEstimateCostProjectManage.getCostTaxInclude()); + estimateBean.setCostProjectManageTaxExclude(projectEstimateCostProjectManage.getCostTaxExclude()); + + ProjectEstimateCost projectEstimateCostOtherOther = costs.stream().filter(d -> d.getType() == 6).collect(Collectors.toList()).get(0); + estimateBean.setCostOtherOtherTaxInclude(projectEstimateCostOtherOther.getCostTaxInclude()); + estimateBean.setCostOtherOtherTaxExclude(projectEstimateCostOtherOther.getCostTaxExclude()); + + List manages = projectEstimateCostManageRepository.findAllByProjectIdEquals(project.getId()); + ProjectEstimateCostManage costManageExpropriation = manages.stream().filter(d -> d.getType() == 1).collect(Collectors.toList()).get(0); + estimateBean.setCostExpropriationTaxExclude(costManageExpropriation.getCostTaxExclude()); + ProjectEstimateCostManage costManageCompany = manages.stream().filter(d -> d.getType() == 2).collect(Collectors.toList()).get(0); + estimateBean.setCostCompanyManageTaxExclude(costManageCompany.getCostTaxExclude()); + + return estimateBean; + } } diff --git a/src/main/resources/templates/admin/project_estimate_input.ftl b/src/main/resources/templates/admin/project_estimate_add.ftl similarity index 99% rename from src/main/resources/templates/admin/project_estimate_input.ftl rename to src/main/resources/templates/admin/project_estimate_add.ftl index 806064e..5d5d5b1 100644 --- a/src/main/resources/templates/admin/project_estimate_input.ftl +++ b/src/main/resources/templates/admin/project_estimate_add.ftl @@ -8,7 +8,7 @@
项目概算表 /
-
+
    diff --git a/src/main/resources/templates/admin/project_estimate_edit.ftl b/src/main/resources/templates/admin/project_estimate_edit.ftl new file mode 100644 index 0000000..e6ee030 --- /dev/null +++ b/src/main/resources/templates/admin/project_estimate_edit.ftl @@ -0,0 +1,543 @@ +<#assign base=request.contextPath /> +<#import "../common/defaultLayout.ftl" as defaultLayout> +<@defaultLayout.layout> + +
    +
    +
    +
    项目概算表 / ${project.name}
    +
    + + + +
    + +
    +
    + + + +
    +
    *部门名称
    +
    + ${project.deptName} +
    +
    +
    + +
    +
    *项目计划开始时间
    +
    +
    + + +
    +
    +
    +
    +
    +
    *项目计划结束时间
    +
    +
    + + +
    +
    +
    +
    + + + +
    +
    *项目名称
    +
    + +
    +
    +
    + +
    +
    *项目类型
    +
    + +
    +
    +
    +
    +
    *垫资模式
    +
    + +
    +
    +
    + +
    +
    *客户名称
    +
    + +
    +
    +
    +
    +
    *终端客户名称
    +
    + +
    +
    +
    +
    +
    *垫资利息
    +
    + +
    +
    +
    +
    +
    *垫资峰值
    +
    + +
    +
    +
    +
    +
    *合同金额
    +
    + +
    +
    +
    +
    +
    *行业场景应用
    +
    + +
    +
    +
    +
    +
    *华智产品金额
    +
    + +
    +
    +
    +
    +
    *紫光其他产品金额
    +
    + +
    +
    +
    +
    +
    *主合同收款条款
    +
    + +
    +
    +
    + +
    + +
    +
    +
    + 收入 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    类别费用含税金额(元)不含税金额(元)
    收入设备类
    收入工程类
    收入服务类
    合计
    + 成本 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    类别费用费用项目含税金额(元)不含税金额(元)
    成本采购成本设备
    成本采购成本施工
    成本采购成本服务
    成本采购成本其他
    成本项目管理成本项目管理成本
    成本其他其他
    合计
    + 管理 + + + + + + + + + + + + + + + + + + +
    类别费用项目不含税金额(元)
    财务费用资金占用成本
    公司管理费用
    + + 利润率计算 + + + + + + + + + + + + + + + + + + +
    类别不含税金额(元)利润率(%)
    项目毛利
    项目贡献利润率
    +
    + +
    +
    +
    + +
    + + + +
    + + +
    +
+ + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/admin/project_list.ftl b/src/main/resources/templates/admin/project_list.ftl index fd5a1c1..546c7c3 100644 --- a/src/main/resources/templates/admin/project_list.ftl +++ b/src/main/resources/templates/admin/project_list.ftl @@ -171,7 +171,17 @@ ${list.deptName!} ${list.startDate?string("yyyy-MM")} ~ ${list.endDate?string("yyyy-MM")} - -- +
+
+ <@shiro.hasPermission name="PROJECT_EDIT"> + + +
+