zxl
2026-03-25 0b39edb68acc67ed01fbfe5d31bfa776a1b17de1
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
package com.tievd.jyz.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tievd.cube.commons.annotations.AutoLog;
import com.tievd.cube.commons.base.CubeController;
import com.tievd.cube.commons.base.Result;
import com.tievd.jyz.entity.DepartLabel;
import com.tievd.jyz.service.IDepartLabelService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
@Slf4j
@RestController
@RequestMapping("/jyz/departLabel")
public class DepartLabelController extends CubeController<DepartLabel, IDepartLabelService> {
 
    @Autowired
    private IDepartLabelService departLabelService;
 
    @GetMapping("/list")
    @Operation(summary = "分页查询机构标签")
    public Result<?> queryPageList(@RequestParam(required = false) String labelName,
                                    @RequestParam(required = false) String parentCode,
                                    @RequestParam(required = false) String parentId,
                                    @RequestParam(defaultValue = "1") Integer pageNo,
                                    @RequestParam(defaultValue = "10") Integer pageSize) {
        List<Map<String, Object>> list = departLabelService.queryDepartLabelList(labelName, parentCode, parentId);
        int total = list.size();
        int start = (pageNo - 1) * pageSize;
        int end = Math.min(start + pageSize, total);
        
        Page<Map<String, Object>> page = new Page<>(pageNo, pageSize, total);
        if (start < total) {
            page.setRecords(list.subList(start, end));
        } else {
            page.setRecords(Collections.emptyList());
        }
        
        return Result.ok(page);
    }
 
    @GetMapping("/listLabels")
    @Operation(summary = "获取所有标签名称")
    public Result<?> listLabels(@RequestParam(required = false) String parentCode,
                                  @RequestParam(required = false) String parentId) {
        List<String> labels = departLabelService.queryAllLabelNames(parentCode, parentId);
        return Result.ok(labels);
    }
 
    @AutoLog("机构标签-添加")
    @PostMapping("/add")
    @Operation(summary = "添加机构标签")
    public Result<?> add(@RequestBody DepartLabel departLabel) {
        LambdaQueryWrapper<DepartLabel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DepartLabel::getDepartId, departLabel.getDepartId());
        queryWrapper.eq(DepartLabel::getLabelName, departLabel.getLabelName());
        if (departLabelService.count(queryWrapper) > 0) {
            return Result.error("该机构已存在此标签");
        }
        departLabelService.save(departLabel);
        return Result.ok();
    }
 
    @AutoLog("机构标签-删除")
    @DeleteMapping("/delete")
    @Operation(summary = "删除机构标签")
    public Result<?> delete(@RequestBody Map<String, String> params) {
        String departId = params.get("departId");
        String labelName = params.get("labelName");
        LambdaQueryWrapper<DepartLabel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DepartLabel::getDepartId, departId);
        if (labelName != null && !labelName.isEmpty()) {
            queryWrapper.eq(DepartLabel::getLabelName, labelName);
        }
        departLabelService.remove(queryWrapper);
        return Result.ok();
    }
 
    @AutoLog("机构标签-更新")
    @PutMapping("/update")
    @Operation(summary = "更新机构标签")
    public Result<?> update(@RequestBody Map<String, String> params) {
        String departId = params.get("departId");
        String labelName = params.get("labelName");
        LambdaQueryWrapper<DepartLabel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DepartLabel::getDepartId, departId);
        List<DepartLabel> labels = departLabelService.list(queryWrapper);
        
        if (labels.isEmpty()) {
            return Result.ok();
        }
        
        departLabelService.remove(queryWrapper);
        
        if (labelName != null && !labelName.isEmpty()) {
            String[] labelArray = labelName.split(",");
            for (String label : labelArray) {
                if (!label.trim().isEmpty()) {
                    DepartLabel departLabel = new DepartLabel();
                    departLabel.setDepartId(departId);
                    departLabel.setLabelName(label.trim());
                    departLabelService.save(departLabel);
                }
            }
        }
        
        return Result.ok();
    }
 
    @PostMapping("/queryOrgOilCount")
    @Operation(summary = "查询站点加油数")
    public Result<?> queryOrgOilCount(@RequestBody Map<String, String> params) {
        String orgCode = params.get("orgCode");
        String startTime = params.get("startTime");
        String endTime = params.get("endTime");
        List<Map<String, Object>> oilCountList = departLabelService.queryOrgOilCount(orgCode, startTime, endTime);
        return Result.ok(oilCountList);
    }
}