刘光辉
昨天 bb638871a7fb692d80f1b7a758f991dc0879002c
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
package jnpf.limsController;
 
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.limsEntity.LimsSxtQushiDataVo;
import jnpf.limsEntity.LimsSxtQushiOptionsVo;
import jnpf.limsEntity.LimsSxtQushiParam;
import jnpf.limsService.LimsSxtQushiService;
import jnpf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
 
@Tag(name = "lims水系统趋势分析", description = "")
@RestController
@RequestMapping("/lims/biz/sxt/qushi")
public class LimsSxtQushiController {
 
    @Autowired
    private LimsSxtQushiService qushiService;
 
    @Operation(summary = "水系统趋势筛选选项")
    @GetMapping("/options")
    public R<LimsSxtQushiOptionsVo> options(
            @RequestParam(value = "yangpin_leixing_id", required = false) String yangpinLeixingId,
            @RequestParam(value = "chejian_id", required = false) String chejianId,
            @RequestParam(value = "quyangdian_ids", required = false) List<String> quyangdianIds) {
        return R.success(qushiService.listOptions(
                trimToNull(yangpinLeixingId), trimToNull(chejianId), normalizeIds(quyangdianIds)));
    }
 
    @Operation(summary = "水系统趋势分析数据")
    @PostMapping("/data")
    public R<LimsSxtQushiDataVo> data(@RequestBody LimsSxtQushiParam param) {
        if (param == null) {
            return R.error("请求参数不能为空");
        }
        if (!StringUtils.hasText(param.getYangpinLeixingId())) {
            return R.error("样品类型不能为空");
        }
        if (!StringUtils.hasText(param.getStartDate()) || !StringUtils.hasText(param.getEndDate())) {
            return R.error("日期范围不能为空");
        }
        List<String> itemIds = normalizeIds(param.getJianyanXiangmuIds());
        if (itemIds.isEmpty()) {
            return R.error("检验项目不能为空");
        }
 
        LocalDate startDate;
        LocalDate endDate;
        try {
            startDate = LocalDate.parse(param.getStartDate().trim());
            endDate = LocalDate.parse(param.getEndDate().trim());
        } catch (DateTimeParseException e) {
            return R.error("日期格式不正确");
        }
        if (startDate.isAfter(endDate)) {
            return R.error("开始日期不能大于结束日期");
        }
 
        param.setYangpinLeixingId(param.getYangpinLeixingId().trim());
        param.setChejianId(trimToNull(param.getChejianId()));
        param.setJianyanXiangmuIds(itemIds);
        param.setQuyangdianIds(normalizeIds(param.getQuyangdianIds()));
        return R.success(qushiService.listData(param, startDate, endDate));
    }
 
    private List<String> normalizeIds(List<String> ids) {
        LinkedHashSet<String> result = new LinkedHashSet<>();
        if (ids != null) {
            for (String id : ids) {
                if (StringUtils.hasText(id)) {
                    result.add(id.trim());
                }
            }
        }
        return new ArrayList<>(result);
    }
 
    private String trimToNull(String value) {
        return StringUtils.hasText(value) ? value.trim() : null;
    }
}