You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.5 KiB
74 lines
2.5 KiB
package com.iflytop.gd.app.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.iflytop.gd.app.model.entity.Ores;
|
|
import com.iflytop.gd.app.model.vo.OresCraftsListVO;
|
|
import com.iflytop.gd.app.service.OresService;
|
|
import com.iflytop.gd.common.base.BasePageQuery;
|
|
import com.iflytop.gd.common.result.PageResult;
|
|
import com.iflytop.gd.common.result.Result;
|
|
import com.iflytop.gd.common.result.ResultCode;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@Tag(name = "矿石管理")
|
|
@RestController
|
|
@RequestMapping("/api/ores")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class OresController {
|
|
private final OresService oresService;
|
|
|
|
@Operation(summary = "矿石工艺列表")
|
|
@GetMapping("/list")
|
|
public PageResult<OresCraftsListVO> getList(BasePageQuery pageQuery) {
|
|
IPage<OresCraftsListVO> result = oresService.getPage(pageQuery);
|
|
return PageResult.success(result);
|
|
}
|
|
|
|
@Operation(summary = "添加新矿石")
|
|
@PostMapping("")
|
|
public Result<String> add(@Valid @RequestBody Ores ores) {
|
|
Ores existingOres = oresService.findByName(ores.getName());
|
|
if (existingOres == null) {
|
|
boolean isSuccess = oresService.addOres(ores);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
} else {
|
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
@Operation(summary = "更新矿石")
|
|
@PutMapping("")
|
|
public Result<String> update(@Valid @RequestBody Ores ores) {
|
|
Ores existingOres = oresService.findByName(ores.getName());
|
|
if (existingOres == null) {
|
|
boolean isSuccess = oresService.updateOres(ores);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
} else {
|
|
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
@Operation(summary = "删除矿石")
|
|
@DeleteMapping("/{ids}")
|
|
public Result<String> delete(@Parameter(description = "矿石ID,多个以英文逗号(,)分割") @PathVariable String ids) {
|
|
boolean isSuccess = oresService.deleteOres(ids);
|
|
if (isSuccess) {
|
|
return Result.success();
|
|
}
|
|
return Result.failed();
|
|
}
|
|
|
|
}
|