cigs4/ym-packing/src/main/java/com/cnbm/packing/controller/ScenesController.java
2023-12-28 15:33:05 +08:00

156 lines
5.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.cnbm.packing.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.cnbm.packing.dto.IdVo;
import com.cnbm.packing.dto.ScenesDTO;
import com.cnbm.packing.entity.Scenes;
import com.cnbm.packing.excel.ScenesExcel;
import com.cnbm.packing.mapper.ScenesMapper;
import com.cnbm.packing.service.ScenesServiceBiz;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 场景 表 前端控制器
*
* @author codeGenerator
* @since 2023-12-21
*/
@RestController
@RequestMapping("/basic/scenes")
@Api(tags="场景 表")
public class ScenesController {
@Autowired
private ScenesServiceBiz scenesService;
@Autowired
private ScenesMapper scenesMapper;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class),
@ApiImplicitParam(name = "name", value = "场景名", paramType = "query", dataTypeClass = String.class)
})
// @PreAuthorize("@ex.hasAuthority('basic:scenes:page')")
public Result<PageData<ScenesDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<ScenesDTO> page = scenesService.page(params);
return new Result<PageData<ScenesDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
// @PreAuthorize("@ex.hasAuthority('basic:scenes:info')")
public Result<ScenesDTO> get(@PathVariable("id") Long id){
ScenesDTO data = scenesService.get(id);
return new Result<ScenesDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
// @PreAuthorize("@ex.hasAuthority('basic:scenes:save')")
public Result<IdVo> save(@RequestBody ScenesDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
//验证编码是否重名
QueryWrapper<Scenes> wrapper1 = new QueryWrapper<>();
wrapper1.eq(Scenes.CODE, dto.getCode());
if(scenesMapper.selectCount(wrapper1)!= 0){
return new Result().error(1,"编码重复");
}
//验证名称是否重名
QueryWrapper<Scenes> wrapper2 = new QueryWrapper<>();
wrapper2.eq(Scenes.SCENES_NAME, dto.getScenesName());
System.out.println(scenesMapper.selectCount(wrapper2));
if(scenesMapper.selectCount(wrapper2)!= 0){
return new Result().error(1,"名称重复");
}
else {
return new Result<IdVo>().ok(scenesService.add(dto));
}
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
// @PreAuthorize("@ex.hasAuthority('basic:scenes:update')")
public Result<IdVo> update(@RequestBody ScenesDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
//验证编码是否重名
ScenesDTO entity = scenesService.get(dto.getId());
QueryWrapper<Scenes> wrapper1 = new QueryWrapper<>();
wrapper1.eq(Scenes.CODE, dto.getCode());
if(entity.getCode()!=dto.getCode() && scenesMapper.selectCount(wrapper1)!= 0){
return new Result().error(1,"编码重复");
}
//验证名称是否重名
QueryWrapper<Scenes> wrapper2 = new QueryWrapper<>();
wrapper2.eq(Scenes.SCENES_NAME, dto.getScenesName());
System.out.println(scenesMapper.selectCount(wrapper2));
if(entity.getScenesName()!=dto.getScenesName() && scenesMapper.selectCount(wrapper2)!= 0){
return new Result().error(1,"名称重复");
}
else {
return new Result<IdVo>().ok(scenesService.edit(dto));
}
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
// @PreAuthorize("@ex.hasAuthority('basic:scenes:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
scenesService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
// @PreAuthorize("@ex.hasAuthority('basic:scenes:export')")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<ScenesDTO> list = scenesService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, ScenesExcel.class);
}
@PostMapping(value = "list")
@ApiOperation(value = "获取场景列表")
public List<ScenesDTO> list(){
return scenesService.list();
}
}