jinlin
2023-11-13 639bc12e3fcca3b3290349fce00336a4dfae1c9d
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
package com.zt.life.modules.project.controller;
 
 
import com.zt.common.annotation.LogOperation;
import com.zt.common.constant.Constant;
import com.zt.common.annotation.QueryParam;
import com.zt.common.db.query.QueryFilter;
import com.zt.common.servlet.Result;
import com.zt.common.servlet.PageResult;
import com.zt.common.validator.AssertUtils;
import com.zt.common.validator.ValidatorUtils;
import com.zt.common.validator.group.AddGroup;
import com.zt.common.validator.group.DefaultGroup;
import com.zt.common.validator.group.UpdateGroup;
import com.zt.life.modules.project.dto.SoftwareTestOrderDto;
import com.zt.life.modules.project.model.SoftwareTestOrder;
import com.zt.life.modules.project.model.SoftwareTestOrderDeliverable;
import com.zt.life.modules.project.model.SoftwareTestOrderMeasured;
import com.zt.life.modules.project.service.ProjectService;
import com.zt.life.modules.project.service.SoftwareTestOrderDeliverableService;
import com.zt.life.modules.project.service.SoftwareTestOrderMeasuredService;
import com.zt.life.modules.project.service.SoftwareTestOrderService;
import com.zt.life.modules.sysBaseInfo.service.TestAgencyInfoService;
import com.zt.modules.coderule.service.SysCodeRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
 
/**
 * software_test_order
 *
 * @author zt generator
 * @since 1.0.0 2023-11-08
 */
@RestController
@RequestMapping("/project/SoftwareTestOrder/")
@Api(tags = "software_test_order")
public class SoftwareTestOrderController {
    @Autowired
    private SoftwareTestOrderService softwareTestOrderService;
 
    @Autowired
    private ProjectService projectService;
    @Autowired
    private SoftwareTestOrderDeliverableService softwareTestOrderDeliverableService;
    @Autowired
    private SoftwareTestOrderMeasuredService softwareTestOrderMeasuredService;
    @Autowired
    private TestAgencyInfoService testAgencyInfoService;
    @Autowired
    private SysCodeRuleService sysCodeRuleService;
 
    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.Q.PAGE, value = Constant.QV.PAGE, required = true, dataType = Constant.QT.INT),
            @ApiImplicitParam(name = Constant.Q.LIMIT, value = Constant.QV.LIMIT, required = true, dataType = Constant.QT.INT),
            @ApiImplicitParam(name = Constant.Q.ORDER_FIELD, value = Constant.QV.ORDER_FIELD, dataType = Constant.QT.STRING),
            @ApiImplicitParam(name = Constant.Q.ORDER, value = Constant.QV.ORDER, dataType = Constant.QT.STRING),
            @ApiImplicitParam(name = "testBasis", value = "测试依据", dataType = Constant.QT.STRING, format = "test_basis^EQ"),
            @ApiImplicitParam(name = "testType", value = "测试类型", dataType = Constant.QT.STRING, format = "test_type^EQ"),
            @ApiImplicitParam(name = "testStandard", value = "测试标准", dataType = Constant.QT.STRING, format = "test_standard^EQ"),
            @ApiImplicitParam(name = "articleNature", value = "物品性质", dataType = Constant.QT.STRING, format = "article_nature^EQ")})
    public PageResult<SoftwareTestOrder> page(@ApiIgnore @QueryParam QueryFilter queryFilter) {
        return PageResult.ok(softwareTestOrderService.page(queryFilter));
    }
 
    @GetMapping("getDto")
    @ApiOperation("信息")
    public Result<SoftwareTestOrderDto> getDto(Long orderId, Long projectId) {
        SoftwareTestOrderDto data = new SoftwareTestOrderDto();
 
        if (orderId != null) {
            data.setId(orderId);
            SoftwareTestOrder softwareTestOrder = softwareTestOrderService.get(orderId);
            data.setSoftwareTestOrder(softwareTestOrder);
 
            if (projectId == null)
                projectId = softwareTestOrder.getProjectId();
 
            data.setTestAgencyInfo(testAgencyInfoService.get(orderId));
            List<SoftwareTestOrderDeliverable> deliverableList = softwareTestOrderDeliverableService.childrenTables(orderId);
            if (deliverableList.isEmpty()) {
                deliverableList = softwareTestOrderService.deliverableDict();
                deliverableList = deliverableList.stream()
                        .peek(deliverable -> {
                            if (deliverable.getIdentify() == null) {
                                // 修改 identify 字段的值为新值
                                deliverable.setIdentify("1.0.0");
                            }
                        })
                        .collect(Collectors.toList());
            }
            data.setSoftwareTestOrderDeliverableList(deliverableList);
 
            List<SoftwareTestOrderMeasured> measuredList = softwareTestOrderMeasuredService.childrenTables(orderId);
            if (measuredList.isEmpty()) {
                measuredList = softwareTestOrderService.MeasuredDict();
                measuredList = measuredList.stream()
                        .peek(measured -> {
                            if (measured.getIdentify() == null) {
                                // 修改 identify 字段的值为新值
                                measured.setIdentify("1.0.0");
                            }
                        })
                        .collect(Collectors.toList());
            }
            data.setSoftwareTestOrderMeasuredList(measuredList);} else {
            data.setTestAgencyInfo(testAgencyInfoService.get(10000L));
        }
        if (projectId != null) {
            data.setProjectId(projectId);
            data.setProject(projectService.get(projectId));
        }
 
 
        return Result.ok(data);
    }
 
 
    @PostMapping
    @ApiOperation("新增")
    @LogOperation("新增")
    public Result insert(@RequestBody SoftwareTestOrderDto softwareTestOrderDto) {
        //效验数据
 
        ValidatorUtils.validateEntity(softwareTestOrderDto.getSoftwareTestOrder(), AddGroup.class, DefaultGroup.class);
        Map<String,String> map = new HashMap<>();
        map.put("funCode","software_test_order");
        softwareTestOrderDto.getSoftwareTestOrder().setCode(sysCodeRuleService.getNewCode(map));
        Boolean result = softwareTestOrderService.save(softwareTestOrderDto);
        return Result.ok();
    }
 
    @PutMapping
    @ApiOperation("修改")
    @LogOperation("修改")
    public Result update(@RequestBody SoftwareTestOrderDto softwareTestOrderDtor) {
        //效验数据
        ValidatorUtils.validateEntity(softwareTestOrderDtor.getSoftwareTestOrder(), UpdateGroup.class, DefaultGroup.class);
        Boolean result = softwareTestOrderService.save(softwareTestOrderDtor);
        return Result.ok();
    }
 
    @DeleteMapping
    @ApiOperation("删除")
    @LogOperation("删除")
    public Result delete(@RequestBody Long[] ids) {
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        softwareTestOrderService.delete(ids);
 
        return Result.ok();
    }
 
}