package cn.iocoder.yudao.module.trade.controller.admin.foreign;
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.module.trade.controller.admin.foreign.vo.TradePortBatchPageReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.foreign.vo.TradePortBatchRespVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.foreign.vo.TradePortBatchSaveReqVO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.foreign.TradePortBatchDO;
|
import cn.iocoder.yudao.module.trade.service.foreign.TradePortBatchService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import jakarta.annotation.Resource;
|
import jakarta.validation.Valid;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.math.BigDecimal;
|
import java.util.List;
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
@Tag(name = "管理后台 - 港口入库批次")
|
@RestController
|
@RequestMapping("/trade/port-batch")
|
@Validated
|
public class TradePortBatchController {
|
|
@Resource
|
private TradePortBatchService batchService;
|
|
@PostMapping("/create")
|
@Operation(summary = "创建港口入库批次")
|
@PreAuthorize("@ss.hasPermission('trade:port-batch:create')")
|
public CommonResult<Long> createBatch(@Valid @RequestBody TradePortBatchSaveReqVO reqVO) {
|
return success(batchService.createBatch(reqVO));
|
}
|
|
@PutMapping("/update")
|
@Operation(summary = "更新港口入库批次")
|
@PreAuthorize("@ss.hasPermission('trade:port-batch:update')")
|
public CommonResult<Boolean> updateBatch(@Valid @RequestBody TradePortBatchSaveReqVO reqVO) {
|
batchService.updateBatch(reqVO);
|
return success(true);
|
}
|
|
@DeleteMapping("/delete")
|
@Operation(summary = "删除港口入库批次")
|
@PreAuthorize("@ss.hasPermission('trade:port-batch:delete')")
|
public CommonResult<Boolean> deleteBatch(@RequestParam("id") Long id) {
|
batchService.deleteBatch(id);
|
return success(true);
|
}
|
|
@GetMapping("/get")
|
@Operation(summary = "获得港口入库批次")
|
@PreAuthorize("@ss.hasPermission('trade:port-batch:query')")
|
public CommonResult<TradePortBatchRespVO> getBatch(@RequestParam("id") Long id) {
|
return success(convert(batchService.getBatch(id)));
|
}
|
|
@GetMapping("/page")
|
@Operation(summary = "获得港口入库批次分页")
|
@PreAuthorize("@ss.hasPermission('trade:port-batch:query')")
|
public CommonResult<PageResult<TradePortBatchRespVO>> getBatchPage(@Valid TradePortBatchPageReqVO reqVO) {
|
PageResult<TradePortBatchDO> page = batchService.getBatchPage(reqVO);
|
return success(BeanUtils.toBean(page, TradePortBatchRespVO.class, this::fillRemaining));
|
}
|
|
@GetMapping("/simple-list")
|
@Operation(summary = "获得港口入库批次精简列表(供外贸订单选择)")
|
public CommonResult<List<TradePortBatchRespVO>> getBatchSimpleList() {
|
return success(convertList(batchService.getBatchList(),
|
b -> fillRemaining(BeanUtils.toBean(b, TradePortBatchRespVO.class))));
|
}
|
|
private TradePortBatchRespVO convert(TradePortBatchDO batch) {
|
return batch == null ? null : fillRemaining(BeanUtils.toBean(batch, TradePortBatchRespVO.class));
|
}
|
|
private TradePortBatchRespVO fillRemaining(TradePortBatchRespVO vo) {
|
BigDecimal total = vo.getTotalCount() == null ? BigDecimal.ZERO : vo.getTotalCount();
|
BigDecimal matched = vo.getMatchedCount() == null ? BigDecimal.ZERO : vo.getMatchedCount();
|
vo.setRemainingCount(total.subtract(matched));
|
return vo;
|
}
|
|
}
|