mitao
3 天以前 d058d56898cbaa185e5f5ac9294804975084fabf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.model.ContractTemplate;
import com.ruoyi.system.model.ProjectInvestment;
import com.ruoyi.system.model.ProjectMain;
import com.ruoyi.system.model.ProjectSettleItem;
import com.ruoyi.system.query.ContractTemplateListQuery;
import com.ruoyi.system.query.ProjectMainListQuery;
import com.ruoyi.system.query.ProjectPhaseListQuery;
import com.ruoyi.system.service.ProjectInventoryService;
import com.ruoyi.system.service.ProjectInvestmentService;
import com.ruoyi.system.service.ProjectMainService;
import com.ruoyi.system.service.ProjectSettleItemService;
import com.ruoyi.system.vo.ProjectMainListVO;
import com.ruoyi.system.vo.ProjectPhaseListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Arrays;
 
/**
 * <p>
 * 项目主表 前端控制器
 * </p>
 *
 * @author WuGuanFengYue
 * @since 2025-10-16
 */
@RestController
@Api(tags = "项目管理")
@RequestMapping("/project-main")
public class ProjectMainController {
    @Resource
    private ProjectMainService projectMainService;
    @Resource
    private ProjectInvestmentService projectInvestmentService;
    @Resource
    private ProjectSettleItemService projectSettleItemService;
    @ApiOperation(value = "储备项目分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<ProjectMainListVO>> pageList(@RequestBody ProjectMainListQuery query) {
        return R.ok(projectMainService.pageList(query));
    }
    @ApiOperation(value = "添加")
    @Transactional
    @Log(title = "储备项目-添加", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public R<Boolean> save(@RequestBody ProjectMain entity) {
        projectMainService.save(entity);
        ProjectInvestment projectInvestment1 = entity.getProjectInvestment1();
        projectInvestment1.setInvestmentType(1);
        projectInvestment1.setProjectId(entity.getId());
        projectInvestmentService.save(projectInvestment1);
        if (entity.getProjectInvestment2() !=null){
            ProjectInvestment projectInvestment2 = entity.getProjectInvestment2();
            projectInvestment2.setProjectId(entity.getId());
            projectInvestment2.setInvestmentType(2);
            projectInvestmentService.save(projectInvestment2);
        }
        return R.ok();
    }
    @ApiOperation(value = "修改")
    @Transactional
    @Log(title = "储备项目-修改", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public R<Boolean> edit(@RequestBody ProjectMain entity) {
        projectMainService.updateById(entity);
        ProjectInvestment projectInvestment = entity.getProjectInvestment1();
        projectInvestment.setProjectId(entity.getId());
        projectInvestmentService.updateById(projectInvestment);
        if (entity.getProjectInvestment2() !=null){
            ProjectInvestment projectInvestment2 = entity.getProjectInvestment2();
            projectInvestment2.setProjectId(entity.getId());
            projectInvestment2.setInvestmentType(2);
            projectInvestmentService.updateById(projectInvestment2);
        }
        return R.ok();
    }
    @ApiOperation(value = "储备项目启动")
    @Log(title = "储备项目-启动", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/start")
    public R<Boolean> start(Integer id) {
        ProjectMain projectMain = projectMainService.getById(id);
        if (projectMain.getStatus()!=1){
            return R.fail("项目已经启动!");
        }
        projectMain.setStatus(3);
        projectMainService.updateById(projectMain);
        return R.ok();
    }
    @ApiOperation(value = "储备项目详情")
    @GetMapping(value = "/detail")
    public R<ProjectMain> detail(Integer id ) {
        ProjectMain projectMain = projectMainService.getById(id);
        ProjectInvestment projectInvestment1 = projectInvestmentService.lambdaQuery()
                .eq(ProjectInvestment::getProjectId, id)
                .eq(ProjectInvestment::getInvestmentType, 1)
                .last("limit 1").one();
        projectMain.setProjectInvestment1(projectInvestment1);
 
        ProjectInvestment projectInvestment2 = projectInvestmentService.lambdaQuery()
                .eq(ProjectInvestment::getProjectId, id)
                .eq(ProjectInvestment::getInvestmentType, 2)
                .last("limit 1").one();
        projectMain.setProjectInvestment1(projectInvestment2);
        return R.ok(projectMain);
    }
    @Log(title = "储备项目-删除", businessType = BusinessType.DELETE)
    @ApiOperation(value = "储备项目-删除")
    @Transactional
    @DeleteMapping(value = "/delete")
    public R delete(@RequestParam String ids) {
        projectInvestmentService.remove(new LambdaQueryWrapper<ProjectInvestment>()
                .in(ProjectInvestment::getProjectId, Arrays.asList(ids.split(","))));
        projectMainService.removeByIds(Arrays.asList(ids.split(",")));
        return R.ok();
    }
    @ApiOperation(value = "项目阶段分页列表")
    @PostMapping(value = "/pageListPhase")
    public R<PageInfo<ProjectPhaseListVO>> pageListPhase(@RequestBody ProjectPhaseListQuery query) {
        return R.ok(projectMainService.pageListPhase(query));
    }
    @ApiOperation(value = "项目阶段-添加事项")
    @Log(title = "项目阶段-添加事项", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addSettleItem")
    public R<Boolean> addSettleItem(@RequestBody ProjectSettleItem entity) {
        if (StringUtils.hasLength(entity.getFileUrl())){
            entity.setStatus(3);
        }else{
            if (entity.getSettleTime().isBefore(LocalDate.now())) {
                entity.setStatus(2);
            }
        }
        projectSettleItemService.save(entity);
        return R.ok();
    }
    @ApiOperation(value = "项目阶段-编辑事项")
    @Log(title = "项目阶段-编辑事项", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/editSettleItem")
    public R<Boolean> editSettleItem(@RequestBody ProjectSettleItem entity) {
        if (StringUtils.hasLength(entity.getFileUrl())){
            entity.setStatus(3);
        }else{
            if (entity.getSettleTime().isBefore(LocalDate.now())) {
                entity.setStatus(2);
            }
        }
        projectSettleItemService.updateById(entity);
        return R.ok();
    }
    @ApiOperation(value = "项目阶段-事项详情")
    @GetMapping(value = "/detailSettleItem")
    public R<ProjectSettleItem> detailSettleItem(Integer id) {
        return R.ok(projectSettleItemService.getById(id));
    }
    @Log(title = "项目阶段-删除事项", businessType = BusinessType.DELETE)
    @ApiOperation(value = "项目阶段-删除事项")
    @DeleteMapping(value = "/deleteSettleItem")
    public R deleteSettleItem(@RequestParam String ids) {
        projectSettleItemService.removeByIds(Arrays.asList(ids.split(",")));
        return R.ok();
    }
    @ApiOperation(value = "项目进入下一阶段")
    @Log(title = "项目进入下一阶段", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/next")
    public R<Boolean> next(Integer id) {
        ProjectMain projectMain = projectMainService.getById(id);
        if (projectMain.getStatus()==5){
            return R.fail("当前项目已到最后阶段!");
        }
        projectMain.setStatus(projectMain.getStatus()+1);
        projectMainService.updateById(projectMain);
        return R.ok();
    }
}