Files
tuanwei-java/src/main/java/com/gxwebsoft/tower/controller/TowerPartStockController.java
2024-02-27 20:29:16 +08:00

137 lines
4.7 KiB
Java

package com.gxwebsoft.tower.controller;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.tower.service.TowerPartStockService;
import com.gxwebsoft.tower.entity.TowerPartStock;
import com.gxwebsoft.tower.param.TowerPartStockParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 产品库存控制器
*
* @author 科技小王子
* @since 2024-02-27 19:41:23
*/
@Api(tags = "产品库存管理")
@RestController
@RequestMapping("/api/tower/tower-part-stock")
public class TowerPartStockController extends BaseController {
@Resource
private TowerPartStockService towerPartStockService;
@PreAuthorize("hasAuthority('tower:towerPartStock:list')")
@OperationLog
@ApiOperation("分页查询产品库存")
@GetMapping("/page")
public ApiResult<PageResult<TowerPartStock>> page(TowerPartStockParam param) {
// 使用关联查询
return success(towerPartStockService.pageRel(param));
}
@PreAuthorize("hasAuthority('tower:towerPartStock:list')")
@OperationLog
@ApiOperation("查询全部产品库存")
@GetMapping()
public ApiResult<List<TowerPartStock>> list(TowerPartStockParam param) {
PageParam<TowerPartStock, TowerPartStockParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(towerPartStockService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(towerPartStockService.listRel(param));
}
@PreAuthorize("hasAuthority('tower:towerPartStock:list')")
@OperationLog
@ApiOperation("根据id查询产品库存")
@GetMapping("/{id}")
public ApiResult<TowerPartStock> get(@PathVariable("id") Integer id) {
return success(towerPartStockService.getById(id));
// 使用关联查询
//return success(towerPartStockService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('tower:towerPartStock:save')")
@OperationLog
@ApiOperation("添加产品库存")
@PostMapping()
public ApiResult<?> save(@RequestBody TowerPartStock towerPartStock) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
towerPartStock.setUserId(loginUser.getUserId());
}
if (towerPartStockService.save(towerPartStock)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('tower:towerPartStock:update')")
@OperationLog
@ApiOperation("修改产品库存")
@PutMapping()
public ApiResult<?> update(@RequestBody TowerPartStock towerPartStock) {
if (towerPartStockService.updateById(towerPartStock)) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('tower:towerPartStock:remove')")
@OperationLog
@ApiOperation("删除产品库存")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (towerPartStockService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@PreAuthorize("hasAuthority('tower:towerPartStock:save')")
@OperationLog
@ApiOperation("批量添加产品库存")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<TowerPartStock> list) {
if (towerPartStockService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('tower:towerPartStock:update')")
@OperationLog
@ApiOperation("批量修改产品库存")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<TowerPartStock> batchParam) {
if (batchParam.update(towerPartStockService, "part_id")) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('tower:towerPartStock:remove')")
@OperationLog
@ApiOperation("批量删除产品库存")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (towerPartStockService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}