2022-06-30 15:28:19 +08:00
|
|
|
|
package com.cnbm.basic.controller;
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
|
|
|
|
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;
|
2022-06-30 15:28:19 +08:00
|
|
|
|
import com.cnbm.basic.dto.UnitDTO;
|
|
|
|
|
import com.cnbm.basic.excel.UnitExcel;
|
|
|
|
|
import com.cnbm.basic.service.IUnitService;
|
2022-06-22 09:14:03 +08:00
|
|
|
|
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;
|
2022-06-30 15:28:19 +08:00
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2022-06-22 09:14:03 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-30 15:28:19 +08:00
|
|
|
|
* 单位 表 前端控制器
|
2022-06-22 09:14:03 +08:00
|
|
|
|
*
|
|
|
|
|
* @author why
|
2022-06-30 15:28:19 +08:00
|
|
|
|
* @since 2022-06-30
|
2022-06-22 09:14:03 +08:00
|
|
|
|
*/
|
|
|
|
|
@RestController
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@RequestMapping("/code/unit")
|
|
|
|
|
@Api(tags="单位 表")
|
|
|
|
|
public class UnitController {
|
2022-06-22 09:14:03 +08:00
|
|
|
|
@Autowired
|
2022-06-30 15:28:19 +08:00
|
|
|
|
private IUnitService unitService;
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
|
|
|
|
@GetMapping("page")
|
|
|
|
|
@ApiOperation("分页")
|
|
|
|
|
@ApiImplicitParams({
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@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)
|
2022-06-22 09:14:03 +08:00
|
|
|
|
})
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@PreAuthorize("@ex.hasAuthority('code:unit:page')")
|
|
|
|
|
public Result<PageData<UnitDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
|
|
|
|
PageData<UnitDTO> page = unitService.page(params);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
2022-06-30 15:28:19 +08:00
|
|
|
|
return new Result<PageData<UnitDTO>>().ok(page);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("{id}")
|
|
|
|
|
@ApiOperation("信息")
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@PreAuthorize("@ex.hasAuthority('code:unit:info')")
|
|
|
|
|
public Result<UnitDTO> get(@PathVariable("id") Long id){
|
|
|
|
|
UnitDTO data = unitService.get(id);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
2022-06-30 15:28:19 +08:00
|
|
|
|
return new Result<UnitDTO>().ok(data);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping
|
|
|
|
|
@ApiOperation("保存")
|
|
|
|
|
@LogOperation("保存")
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@PreAuthorize("@ex.hasAuthority('code:unit:save')")
|
|
|
|
|
public Result save(@RequestBody UnitDTO dto){
|
2022-06-22 09:14:03 +08:00
|
|
|
|
//效验数据
|
|
|
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
|
|
|
|
2022-06-30 15:28:19 +08:00
|
|
|
|
unitService.save(dto);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
|
|
|
|
return new Result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping
|
|
|
|
|
@ApiOperation("修改")
|
|
|
|
|
@LogOperation("修改")
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@PreAuthorize("@ex.hasAuthority('code:unit:update')")
|
|
|
|
|
public Result update(@RequestBody UnitDTO dto){
|
2022-06-22 09:14:03 +08:00
|
|
|
|
//效验数据
|
|
|
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
|
|
|
|
2022-06-30 15:28:19 +08:00
|
|
|
|
unitService.update(dto);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
|
|
|
|
return new Result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DeleteMapping
|
|
|
|
|
@ApiOperation("删除")
|
|
|
|
|
@LogOperation("删除")
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@PreAuthorize("@ex.hasAuthority('code:unit:delete')")
|
2022-06-22 09:14:03 +08:00
|
|
|
|
public Result delete(@RequestBody Long[] ids){
|
|
|
|
|
//效验数据
|
|
|
|
|
AssertUtils.isArrayEmpty(ids, "id");
|
|
|
|
|
|
2022-06-30 15:28:19 +08:00
|
|
|
|
unitService.delete(ids);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
|
|
|
|
return new Result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("export")
|
|
|
|
|
@ApiOperation("导出")
|
|
|
|
|
@LogOperation("导出")
|
2022-06-30 15:28:19 +08:00
|
|
|
|
@PreAuthorize("@ex.hasAuthority('code:unit:export')")
|
2022-06-22 09:14:03 +08:00
|
|
|
|
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
2022-06-30 15:28:19 +08:00
|
|
|
|
List<UnitDTO> list = unitService.list(params);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
|
2022-06-30 15:28:19 +08:00
|
|
|
|
ExcelUtils.exportExcelToTarget(response, null, list, UnitExcel.class);
|
2022-06-22 09:14:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 09:47:38 +08:00
|
|
|
|
@GetMapping("{statusId}")
|
2022-07-20 15:29:54 +08:00
|
|
|
|
@ApiOperation("改变状态")
|
|
|
|
|
@LogOperation("改变状态")
|
|
|
|
|
public Result changeStatus(@PathVariable("id") Long id){
|
|
|
|
|
unitService.changeStatus(id);
|
|
|
|
|
|
|
|
|
|
return new Result();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-22 09:14:03 +08:00
|
|
|
|
}
|