| package com.mzl.flower.web.payment; | 
|   | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.mzl.flower.base.BaseController; | 
| import com.mzl.flower.base.R; | 
| import com.mzl.flower.base.ReturnDataDTO; | 
| import com.mzl.flower.config.exception.ValidationException; | 
| import com.mzl.flower.constant.Constants; | 
| import com.mzl.flower.dto.request.payment.*; | 
| import com.mzl.flower.dto.response.flower.StationStatisticDTO; | 
| import com.mzl.flower.dto.response.payment.*; | 
| import com.mzl.flower.service.payment.DeliveryOrderService; | 
| import io.micrometer.core.instrument.util.StringUtils; | 
| import io.swagger.annotations.Api; | 
| import io.swagger.annotations.ApiImplicitParam; | 
| import io.swagger.annotations.ApiImplicitParams; | 
| import io.swagger.annotations.ApiOperation; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.http.ResponseEntity; | 
| import org.springframework.validation.annotation.Validated; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.time.LocalDate; | 
| import java.time.LocalDateTime; | 
| import java.util.List; | 
|   | 
| @RestController | 
| @RequestMapping("/api/delivery") | 
| @Api(value = "配送质检管理-运营人员", tags = "配送质检管理-运营人员") | 
| @Validated | 
| @Slf4j | 
| public class DeliveryOrderController extends BaseController { | 
|   | 
|     @Autowired | 
|     private DeliveryOrderService deliveryOrderService; | 
|   | 
|     @GetMapping("/station/list") | 
|     @ApiOperation(value = "查询我的集货站列表") | 
|     public ResponseEntity<ReturnDataDTO<List<StationStatisticDTO>>> statisticStationList(String name | 
|             , String status, String date){ | 
|         /*if(StringUtils.isEmpty(date)){ | 
|             throw new ValidationException("请选择日期"); | 
|         }*/ | 
|         LocalDateTime startDate; | 
|         LocalDateTime endDate; | 
|         LocalDate localDate = deliveryOrderService.parseLocalDate(date); | 
|         if(localDate != null){ | 
|             endDate = localDate.atTime(17, 0, 0); | 
|             startDate = endDate.plusDays(-1); | 
|         } else { | 
|             LocalDateTime now = LocalDateTime.now(); | 
|             LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|             LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|             if(now.isAfter(towAm)){ | 
|                 startDate = fivePm.plusDays(-1); | 
|                 endDate = fivePm; | 
|             } else { | 
|                 startDate = fivePm.plusDays(-2); | 
|                 endDate = fivePm.plusDays(-1); | 
|             } | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.statisticStationList(name, startDate, endDate, status)); | 
|     } | 
|   | 
|   | 
|     /*@GetMapping("/list") | 
|     @ApiOperation(value = "查询配送单列表") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrderStationListDTO>>> selectDoStationList(Page page | 
|             , DeliveryOrderStationQueryDTO dto){ | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectDoStationList(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/list/today") | 
|     @ApiOperation(value = "查询今日配送单列表") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrderStationListDTO>>> selectDoStationTodayList(Page page | 
|             , DeliveryOrderStationQueryDTO dto){ | 
|         LocalDateTime now = LocalDateTime.now(); | 
|         LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|         LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|         if(now.isAfter(towAm)){ | 
|             dto.setStartDate(fivePm.plusDays(-1)); | 
|             dto.setEndDate(fivePm); | 
|         } else { | 
|             dto.setStartDate(fivePm.plusDays(-2)); | 
|             dto.setEndDate(fivePm.plusDays(-1)); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectDoStationList(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/list/yesterday") | 
|     @ApiOperation(value = "查询昨日配送单列表") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrderStationListDTO>>> selectDoStationYesterdayList(Page page | 
|             , DeliveryOrderStationQueryDTO dto){ | 
|         LocalDateTime now = LocalDateTime.now(); | 
|         LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|         LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|         if(now.isAfter(towAm)){ | 
|             dto.setStartDate(fivePm.plusDays(-2)); | 
|             dto.setEndDate(fivePm.plusDays(-1)); | 
|         } else { | 
|             dto.setStartDate(fivePm.plusDays(-3)); | 
|             dto.setEndDate(fivePm.plusDays(-2)); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectDoStationList(page, dto)); | 
|     }*/ | 
|   | 
|     @GetMapping("/list/view") | 
|     @ApiOperation(value = "配送单详情") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "配送单id", required = true, dataType = "String", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<DeliveryOrderCheckDTO>> getDeliverOrderInfo(String id){ | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.getDeliverOrderInfo(id)); | 
|     } | 
|   | 
|     /*@PostMapping("/list/view/check") | 
|     @ApiOperation(value = "质检操作") | 
|     public ResponseEntity<ReturnDataDTO> doCheck(@RequestBody OrderItemCheckDTO dto) { | 
|         deliveryOrderService.doCheck(dto); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     }*/ | 
|   | 
|     /*@GetMapping("/list/view/complete") | 
|     @ApiOperation(value = "质检完成") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "配送单id", required = true, dataType = "String", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO> completeCheck(String id) { | 
|         String orderId = deliveryOrderService.completeCheck(id); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     }*/ | 
|   | 
|     @GetMapping("/list/items/view") | 
|     @ApiOperation(value = "获取商品详情") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "配送物品id", required = true, dataType = "String", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<DeliveryOrderItemDTO>> getDeliveryOrderItem(String id){ | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.getDeliveryOrderItem(id)); | 
|     } | 
|   | 
|     @PostMapping("/list/items/views") | 
|     @ApiOperation(value = "获取商品详情列表") | 
|     public ResponseEntity<ReturnDataDTO<List<DeliveryOrderItemDTO>>> getDeliveryOrderItem(@RequestBody PostQueryDTO dto){ | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.getDeliveryOrderItems(dto)); | 
|     } | 
|   | 
|     //////////////////////////////////////////////////////////新接口 | 
|     @GetMapping("/check/list") | 
|     @ApiOperation(value = "查询集货站供应商配送列表") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrderList4CheckDTO>>> selectSupplierDoList4Check(Page page | 
|             , DeliveryOrderStationQueryDTO dto){ | 
|         String date = dto.getDate(); | 
|         if(StringUtils.isEmpty(date)){ | 
|             throw new ValidationException("请选择日期"); | 
|         } | 
|         LocalDate localDate = deliveryOrderService.parseLocalDate(date); | 
|         if(localDate != null){ | 
|             LocalDateTime end = localDate.atTime(17, 0, 0); | 
|             LocalDateTime begin = end.plusDays(-1); | 
|             dto.setStartDate(begin); | 
|             dto.setEndDate(end); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectSupplierDoList4Check(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/check/list/today") | 
|     @ApiOperation(value = "查询集货站供应商配送列表(今日)") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrderList4CheckDTO>>> selectSupplierDoList4CheckToday(Page page | 
|             , DeliveryOrderStationQueryDTO dto){ | 
|         LocalDateTime now = LocalDateTime.now(); | 
|         LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|         LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|         if(now.isAfter(towAm)){ | 
|             dto.setStartDate(fivePm.plusDays(-1)); | 
|             dto.setEndDate(fivePm); | 
|         } else { | 
|             dto.setStartDate(fivePm.plusDays(-2)); | 
|             dto.setEndDate(fivePm.plusDays(-1)); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectSupplierDoList4Check(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/check/list/yesterday") | 
|     @ApiOperation(value = "查询集货站供应商配送列表(昨日)") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrderList4CheckDTO>>> selectSupplierDoList4CheckYesterday(Page page | 
|             , DeliveryOrderStationQueryDTO dto){ | 
|         LocalDateTime now = LocalDateTime.now(); | 
|         LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|         LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|         if(now.isAfter(towAm)){ | 
|             dto.setStartDate(fivePm.plusDays(-2)); | 
|             dto.setEndDate(fivePm.plusDays(-1)); | 
|         } else { | 
|             dto.setStartDate(fivePm.plusDays(-3)); | 
|             dto.setEndDate(fivePm.plusDays(-2)); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectSupplierDoList4Check(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/check/info/list") | 
|     @ApiOperation(value = "查询供应商配送单列表") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrder4CheckDTO>>> selectSupplierDoInfo4Check(Page page | 
|             , DeliveryOrderInfoSpQueryDTO dto){ | 
|         String date = dto.getDate(); | 
|         if(StringUtils.isEmpty(date)){ | 
|             throw new ValidationException("请选择日期"); | 
|         } | 
|         LocalDate localDate = deliveryOrderService.parseLocalDate(date); | 
|         if(localDate != null){ | 
|             LocalDateTime end = localDate.atTime(17, 0, 0); | 
|             LocalDateTime begin = end.plusDays(-1); | 
|             dto.setStartDate(begin); | 
|             dto.setEndDate(end); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectSupplierDoInfo4Check(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/check/info/list/today") | 
|     @ApiOperation(value = "查询供应商配送单列表(今日)") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrder4CheckDTO>>> selectSupplierDoInfo4CheckToday(Page page | 
|             , DeliveryOrderInfoSpQueryDTO dto){ | 
|         LocalDateTime now = LocalDateTime.now(); | 
|         LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|         LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|         if(now.isAfter(towAm)){ | 
|             dto.setStartDate(fivePm.plusDays(-1)); | 
|             dto.setEndDate(fivePm); | 
|         } else { | 
|             dto.setStartDate(fivePm.plusDays(-2)); | 
|             dto.setEndDate(fivePm.plusDays(-1)); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectSupplierDoInfo4Check(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/check/info/list/yesterday") | 
|     @ApiOperation(value = "查询供应商配送单列表(昨日)") | 
|     public ResponseEntity<ReturnDataDTO<Page<DeliveryOrder4CheckDTO>>> selectSupplierDoInfo4CheckYesterday(Page page | 
|             , DeliveryOrderInfoSpQueryDTO dto){ | 
|         LocalDateTime now = LocalDateTime.now(); | 
|         LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|         LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|         if(now.isAfter(towAm)){ | 
|             dto.setStartDate(fivePm.plusDays(-2)); | 
|             dto.setEndDate(fivePm.plusDays(-1)); | 
|         } else { | 
|             dto.setStartDate(fivePm.plusDays(-3)); | 
|             dto.setEndDate(fivePm.plusDays(-2)); | 
|         } | 
|   | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.selectSupplierDoInfo4Check(page, dto)); | 
|     } | 
|   | 
|     @GetMapping("/check/info/reduce") | 
|     @ApiOperation(value = "降级操作详情") | 
|     public ResponseEntity<ReturnDataDTO<OrderItemCheckReduceDTO>> getReduceCheck(String orderItemId){ | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.getReduceCheck(orderItemId)); | 
|     } | 
|   | 
|     @GetMapping("/check/info/replace") | 
|     @ApiOperation(value = "补货操作详情") | 
|     public ResponseEntity<ReturnDataDTO<OrderItemCheckNumDTO>> getReplaceCheck(String orderItemId){ | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.getOtherCheck(orderItemId | 
|                 , Constants.CHECK_TYPE.replace.name(), false)); | 
|     } | 
|   | 
|     @GetMapping("/check/info/lack") | 
|     @ApiOperation(value = "缺货操作详情") | 
|     public ResponseEntity<ReturnDataDTO<OrderItemCheckNumDTO>> getLackCheck(String orderItemId){ | 
|         return returnData(R.SUCCESS.getCode(), deliveryOrderService.getOtherCheck(orderItemId | 
|                 , Constants.CHECK_TYPE.lack.name(), false)); | 
|     } | 
|   | 
|     @PostMapping("/check/info/do/reduce") | 
|     @ApiOperation(value = "降级操作") | 
|     public ResponseEntity<ReturnDataDTO> doReduceCheck(@RequestBody OrderItemCheckCommitReduceDTO dto) { | 
|         deliveryOrderService.doReduceCheck(dto); | 
|         String orderId = deliveryOrderService.checkOrderItemStatus(dto.getOrderItemId()); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @PostMapping("/check/info/do/replace") | 
|     @ApiOperation(value = "补货操作") | 
|     public ResponseEntity<ReturnDataDTO> doReplaceCheck(@RequestBody OrderItemCheckCommitDTO dto) { | 
|         dto.setType(Constants.CHECK_TYPE.replace.name()); | 
|         deliveryOrderService.doCheck(dto, null, null, null); | 
|         String orderId = deliveryOrderService.checkOrderItemStatus(dto.getOrderItemId()); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @PostMapping("/check/info/do/lack") | 
|     @ApiOperation(value = "缺货操作") | 
|     public ResponseEntity<ReturnDataDTO> doLackCheck(@RequestBody OrderItemCheckCommitDTO dto) { | 
|         dto.setType(Constants.CHECK_TYPE.lack.name()); | 
|         deliveryOrderService.doCheck(dto, null, null, null); | 
|         String orderId = deliveryOrderService.checkOrderItemStatus(dto.getOrderItemId()); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/check/info/delete/reduce") | 
|     @ApiOperation(value = "删除降级信息") | 
|     public ResponseEntity<ReturnDataDTO> deleteReduce(String orderItemId){ | 
|         deliveryOrderService.deleteCheckInfo(orderItemId, Constants.CHECK_TYPE.reduce.name()); | 
|         String orderId = deliveryOrderService.checkOrderItemStatus(orderItemId); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/check/info/delete/replace") | 
|     @ApiOperation(value = "删除补货信息") | 
|     public ResponseEntity<ReturnDataDTO> deleteReplace(String orderItemId){ | 
|         deliveryOrderService.deleteCheckInfo(orderItemId, Constants.CHECK_TYPE.replace.name()); | 
|         String orderId = deliveryOrderService.checkOrderItemStatus(orderItemId); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/check/info/delete/lack") | 
|     @ApiOperation(value = "删除缺货信息") | 
|     public ResponseEntity<ReturnDataDTO> deleteLack(String orderItemId){ | 
|         deliveryOrderService.deleteCheckInfo(orderItemId, Constants.CHECK_TYPE.lack.name()); | 
|         String orderId = deliveryOrderService.checkOrderItemStatus(orderItemId); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/check/info/ok") | 
|     @ApiOperation(value = "完成商品质检") | 
|     public ResponseEntity<ReturnDataDTO> setCheckOk(String orderItemId){ | 
|         deliveryOrderService.setCheckOk(orderItemId); | 
|         String orderId = deliveryOrderService.checkOrderItemStatus(orderItemId); | 
|         deliveryOrderService.checkOrderStatus(orderId); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/check/list/complete") | 
|     @ApiOperation(value = "一键质检") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "供应商id", required = true, dataType = "Long", paramType = "query"), | 
|             @ApiImplicitParam(name = "date", value = "日期(yyyy-MM-dd)", required = true, dataType = "String", paramType = "query"), | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO> completeCheck(Long id, String date) { | 
|         if(StringUtils.isEmpty(date)){ | 
|             throw new ValidationException("请选择日期"); | 
|         } | 
|         LocalDateTime startDate = null; | 
|         LocalDateTime endDate = null; | 
|         LocalDate localDate = deliveryOrderService.parseLocalDate(date); | 
|         if(localDate != null){ | 
|             endDate = localDate.atTime(17, 0, 0); | 
|             startDate = endDate.plusDays(-1); | 
|         } | 
|   | 
|         List<String> orderIds = deliveryOrderService.completeSupplierCheck(id, startDate, endDate); | 
|         deliveryOrderService.checkOrdersStatus(orderIds); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/check/list/complete/today") | 
|     @ApiOperation(value = "一键质检(今日)") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "供应商id", required = true, dataType = "Long", paramType = "query"), | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO> completeCheckToday(Long id) { | 
|         LocalDateTime now = LocalDateTime.now(); | 
|         LocalDateTime towAm = LocalDate.now().atTime(2, 0, 0); | 
|         LocalDateTime fivePm = LocalDate.now().atTime(17, 0, 0); | 
|         LocalDateTime startDate; | 
|         LocalDateTime endDate; | 
|         if(now.isAfter(towAm)){ | 
|             startDate = fivePm.plusDays(-1); | 
|             endDate = fivePm; | 
|         } else { | 
|             startDate = fivePm.plusDays(-2); | 
|             endDate = fivePm.plusDays(-1); | 
|         } | 
|         List<String> orderIds = deliveryOrderService.completeSupplierCheck(id, startDate, endDate); | 
|         deliveryOrderService.checkOrdersStatus(orderIds); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
| } |