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);
|
}
|
}
|