package com.tievd.jyz.controller; import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.tievd.cube.commons.base.Result; import com.tievd.cube.commons.mybatisplus.QueryGenerator; import com.tievd.cube.commons.annotations.DictApi; import com.tievd.cube.commons.annotations.AutoLog; import com.tievd.jyz.entity.LabelCar; import com.tievd.jyz.service.ILabelCarService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.tievd.jyz.service.ILabelService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import com.tievd.cube.commons.base.CubeController; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.IOException; /** * LabelCar * * @author cube * @since 2023-02-27 * @version V2.0.0 */ @Slf4j @DictApi @RestController @RequestMapping("/jyz/labelCar") @Tag(name = "打标签相关接口") public class LabelCarController extends CubeController { @Autowired private ILabelCarService labelCarService; @Autowired ILabelService labelService; /** * 分页列表查询 */ @GetMapping("/list") public Result queryPageList(LabelCar labelCar, @RequestParam(defaultValue="1") Integer pageNo, @RequestParam(defaultValue="10") Integer pageSize, HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(labelCar, req.getParameterMap()); Page page = new Page<>(pageNo, pageSize); IPage pageList = labelCarService.page(page, queryWrapper); return Result.ok(pageList); } /** * 添加 */ @AutoLog("打标签") @PostMapping("/add") @Operation(summary = "打标签接口") @io.swagger.v3.oas.annotations.parameters.RequestBody(description="参数: {licenseNums:[], labelNames:[]}") public Result add(@RequestBody JSONObject param) { List licenseNums = param.getObject("licenseNums", List.class); List labelNames = param.getObject("labelNames", List.class); if (CollectionUtils.isEmpty(licenseNums)) { return Result.error("未选择车辆"); } labelCarService.remove(new LambdaQueryWrapper().in(LabelCar::getLicenseNum, licenseNums)); List labelCarList = new ArrayList<>(); for (String licenseNum : licenseNums) { int n = 1; for (String labelName : labelNames) { LabelCar labelCar = new LabelCar().setLabelName(labelName).setLabelId(n++).setLicenseNum(licenseNum); labelCarList.add(labelCar); } } labelCarService.saveBatch(labelCarList); return Result.ok(); } /** * 编辑 */ @AutoLog("LabelCar-编辑") @PutMapping("/edit") public Result edit(@RequestBody LabelCar labelCar) { labelCarService.updateById(labelCar); return Result.ok(); } /** * 通过id删除 */ @AutoLog("LabelCar-通过id删除") @DeleteMapping("/delete") public Result delete(@RequestParam String id) { labelCarService.removeById(id); return Result.ok(); } /** * 批量删除 */ @AutoLog("LabelCar-批量删除") @DeleteMapping("/deleteBatch") public Result deleteBatch(@RequestParam String ids) { this.labelCarService.removeByIds(Arrays.asList(ids.split(","))); return Result.ok(); } /** * 通过id查询 */ @GetMapping("/queryById") public Result queryById(@RequestParam String id) { LabelCar labelCar = labelCarService.getById(id); return Result.ok(labelCar); } /** * 导出excel */ @RequestMapping("/exportXls") public void exportXls(HttpServletRequest request, HttpServletResponse response, LabelCar labelCar) throws IOException { super.exportXls(request, response, labelCar, "LabelCar"); } /** * 通过excel导入数据 */ @PostMapping("/importExcel") public Result importExcel(HttpServletRequest request) throws Exception { return super.importExcel(request, LabelCar.class); } }