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 3b9335a..a477d1a 100644 --- a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java +++ b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java @@ -470,6 +470,16 @@ public class ProjectController extends BaseController { return ResponseMsg.buildSuccessMsg("成功"); } + + /** + * 删除草稿状态下的概算项目 + */ + @GetMapping("/deleteProject/{id}") + @ResponseBody + public ResponseMsg deleteProject(@PathVariable int id) { + return projectService.deleteProject(id); + } + @InitBinder public void initBinder(WebDataBinder webDataBinder) { webDataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd")); diff --git a/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java b/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java index d9bbe0b..d002349 100644 --- a/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectEstimateCostManageRepository.java @@ -6,4 +6,6 @@ import java.util.List; public interface ProjectEstimateCostManageRepository extends JpaRepository { List findAllByProjectIdEquals(int id); + + int deleteByProjectId(int pId); } diff --git a/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java b/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java index 7af11be..f9711d5 100644 --- a/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectEstimateCostRepository.java @@ -6,4 +6,6 @@ import java.util.List; public interface ProjectEstimateCostRepository extends JpaRepository { List findAllByProjectIdEquals(int id); + + int deleteByProjectId(int pId); } diff --git a/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java b/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java index 2b51c2b..30d5b23 100644 --- a/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java +++ b/src/main/java/cn/palmte/work/model/ProjectEstimateIncomeRepository.java @@ -6,4 +6,6 @@ import java.util.List; public interface ProjectEstimateIncomeRepository extends JpaRepository { List findAllByProjectIdEquals(int id); + + int deleteByProjectId(int piId); } diff --git a/src/main/java/cn/palmte/work/service/ProjectEstimateService.java b/src/main/java/cn/palmte/work/service/ProjectEstimateService.java index 9487a1a..2cae490 100644 --- a/src/main/java/cn/palmte/work/service/ProjectEstimateService.java +++ b/src/main/java/cn/palmte/work/service/ProjectEstimateService.java @@ -63,6 +63,15 @@ public class ProjectEstimateService { costManage(project, estimateBean); } + public void deleteEstimate(int projectId){ + //删除收入记录 + projectEstimateIncomeRepository.deleteByProjectId(projectId); + //删除成本记录 + projectEstimateCostRepository.deleteByProjectId(projectId); + //删除管理记录 + projectEstimateCostManageRepository.deleteByProjectId(projectId); + } + private void cost(Project project, EstimateBean estimateBean) { ProjectEstimateCost projectEstimateCostDevice = new ProjectEstimateCost(); projectEstimateCostDevice.setProjectId(project.getId()); diff --git a/src/main/java/cn/palmte/work/service/ProjectService.java b/src/main/java/cn/palmte/work/service/ProjectService.java index cc7bacd..5390fa5 100644 --- a/src/main/java/cn/palmte/work/service/ProjectService.java +++ b/src/main/java/cn/palmte/work/service/ProjectService.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; 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; @@ -39,6 +40,8 @@ public class ProjectService { private SysRoleRepository sysRoleRepository; @Autowired private AdminRepository adminRepository; + @Autowired + private ProjectEstimateService projectEstimateService; private QueryHelper getQueryHelper(Map searchInfo) { @@ -300,4 +303,23 @@ public class ProjectService { } projectVisibleRepository.save(pvs); } + + @Transactional(rollbackFor = Exception.class) + public ResponseMsg deleteProject(int id) { + Project one = projectRepository.findOne(id); + if (one == null) { + return ResponseMsg.buildFailedMsg("项目不存在"); + } + + if (one.getStatus() != StatusEnum.ESTIMATE_ACCOUNTS.getStatus() + || one.getApproveStatusEstimate() != ApproveStatusEnum.APPROVAL_UNCOMMIT.getApproveStatus()) { + return ResponseMsg.buildFailedMsg("项目当前状态下不能删除"); + } + + projectRepository.delete(id); + + projectEstimateService.deleteEstimate(id); + + return ResponseMsg.buildSuccessMsg("删除成功"); + } } diff --git a/src/main/resources/templates/admin/project_list.ftl b/src/main/resources/templates/admin/project_list.ftl index 75bf09d..a26a8ab 100644 --- a/src/main/resources/templates/admin/project_list.ftl +++ b/src/main/resources/templates/admin/project_list.ftl @@ -216,6 +216,15 @@ + <#-- 项目等于概算状态、概算审核为草稿状态--> + <#if list.creatorId==adminId && list.status==1 && list.approveStatusEstimate==0> + + + <#-- <@shiro.hasPermission name="PROJECT_EDIT">--> <#-- 概算审核等于通过状态、预算审核不等于待审核状态、 决算审核不等于通过状态--> @@ -401,4 +410,23 @@ }); + + var deleteProject = function (id) { + if (window.confirm('确定要删除此项目吗?')) { + $.ajax({ + url: '${base}/project/deleteProject/' + id, + dataType: "json", + async: false, + success: function (data) { + if (data.status == 0) { + alert(data.msg); + window.location.href = window.location.href; + } else if (data.status == 1) { + alert(data.msg); + } + } + }); + } + } +