|
@@ -0,0 +1,118 @@
|
|
|
+package com.yc.ship.module.product.controller.admin.voyage;
|
|
|
+
|
|
|
+import com.yc.ship.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
+import com.yc.ship.framework.common.pojo.CommonResult;
|
|
|
+import com.yc.ship.framework.common.pojo.PageParam;
|
|
|
+import com.yc.ship.framework.common.pojo.PageResult;
|
|
|
+import com.yc.ship.framework.common.util.collection.CollectionUtils;
|
|
|
+import com.yc.ship.framework.common.util.object.BeanUtils;
|
|
|
+import com.yc.ship.framework.excel.core.util.ExcelUtils;
|
|
|
+import com.yc.ship.module.product.controller.admin.voyage.vo.VoyagePageReqVO;
|
|
|
+import com.yc.ship.module.product.controller.admin.voyage.vo.VoyageRespVO;
|
|
|
+import com.yc.ship.module.product.controller.admin.voyage.vo.VoyageSaveReqVO;
|
|
|
+import com.yc.ship.module.product.dal.dataobject.voyage.VoyageDO;
|
|
|
+import com.yc.ship.module.product.service.voyage.VoyageService;
|
|
|
+import com.yc.ship.module.resource.dal.dataobject.route.ResourceRouteDO;
|
|
|
+import com.yc.ship.module.resource.dal.dataobject.ship.ResourceShipDO;
|
|
|
+import com.yc.ship.module.resource.service.route.ResourceRouteService;
|
|
|
+import com.yc.ship.module.resource.service.ship.ResourceShipService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static com.yc.ship.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
+import static com.yc.ship.framework.common.pojo.CommonResult.success;
|
|
|
+
|
|
|
+@Tag(name = "管理后台 - 航次管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/product/voyage")
|
|
|
+@Validated
|
|
|
+public class VoyageController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private VoyageService voyageService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ResourceShipService shipService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ResourceRouteService routeService;
|
|
|
+
|
|
|
+ @PostMapping("/create")
|
|
|
+ @Operation(summary = "创建航次管理")
|
|
|
+ @PreAuthorize("@ss.hasPermission('product:voyage:create')")
|
|
|
+ public CommonResult<Long> createVoyage(@Valid @RequestBody VoyageSaveReqVO createReqVO) {
|
|
|
+ return success(voyageService.createVoyage(createReqVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/update")
|
|
|
+ @Operation(summary = "更新航次管理")
|
|
|
+ @PreAuthorize("@ss.hasPermission('product:voyage:update')")
|
|
|
+ public CommonResult<Boolean> updateVoyage(@Valid @RequestBody VoyageSaveReqVO updateReqVO) {
|
|
|
+ voyageService.updateVoyage(updateReqVO);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/delete")
|
|
|
+ @Operation(summary = "删除航次管理")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true)
|
|
|
+ @PreAuthorize("@ss.hasPermission('product:voyage:delete')")
|
|
|
+ public CommonResult<Boolean> deleteVoyage(@RequestParam("id") Long id) {
|
|
|
+ voyageService.deleteVoyage(id);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/get")
|
|
|
+ @Operation(summary = "获得航次管理")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
|
|
|
+ @PreAuthorize("@ss.hasPermission('product:voyage:query')")
|
|
|
+ public CommonResult<VoyageRespVO> getVoyage(@RequestParam("id") Long id) {
|
|
|
+ VoyageDO voyage = voyageService.getVoyage(id);
|
|
|
+ return success(BeanUtils.toBean(voyage, VoyageRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/page")
|
|
|
+ @Operation(summary = "获得航次管理分页")
|
|
|
+ @PreAuthorize("@ss.hasPermission('product:voyage:query')")
|
|
|
+ public CommonResult<PageResult<VoyageRespVO>> getVoyagePage(@Valid VoyagePageReqVO pageReqVO) {
|
|
|
+ PageResult<VoyageDO> pageResult = voyageService.getVoyagePage(pageReqVO);
|
|
|
+ PageResult<VoyageRespVO> page = BeanUtils.toBean(pageResult, VoyageRespVO.class);
|
|
|
+ List<VoyageRespVO> list = page.getList();
|
|
|
+ List<Long> shipIds = CollectionUtils.convertList(list, VoyageRespVO::getShipId);
|
|
|
+ List<ResourceShipDO> shipList = shipService.getList(shipIds);
|
|
|
+ Map<Long, ResourceShipDO> shipDOMap = CollectionUtils.convertMap(shipList, ResourceShipDO::getId);
|
|
|
+
|
|
|
+ List<Long> routeIds = CollectionUtils.convertList(list, VoyageRespVO::getRouteId);
|
|
|
+ List<ResourceRouteDO> routeList = routeService.getList(routeIds);
|
|
|
+ Map<Long, ResourceRouteDO> routeDOMap = CollectionUtils.convertMap(routeList, ResourceRouteDO::getId);
|
|
|
+ list.stream().forEach(item -> {
|
|
|
+ item.setShipName(shipDOMap.get(item.getShipId()).getName());
|
|
|
+ item.setRouteName(routeDOMap.get(item.getRouteId()).getName());
|
|
|
+ });
|
|
|
+ return success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/export-excel")
|
|
|
+ @Operation(summary = "导出航次管理 Excel")
|
|
|
+ @PreAuthorize("@ss.hasPermission('product:voyage:export')")
|
|
|
+ @ApiAccessLog(operateType = EXPORT)
|
|
|
+ public void exportVoyageExcel(@Valid VoyagePageReqVO pageReqVO,
|
|
|
+ HttpServletResponse response) throws IOException {
|
|
|
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ List<VoyageDO> list = voyageService.getVoyagePage(pageReqVO).getList();
|
|
|
+ // 导出 Excel
|
|
|
+ ExcelUtils.write(response, "航次管理.xls", "数据", VoyageRespVO.class,
|
|
|
+ BeanUtils.toBean(list, VoyageRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|