package com.prolog.rdc.tms.app.controller.business;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.app.model.dto.ShipbillManageDTO;
import com.prolog.rdc.tms.app.model.dto.ShipbillNodeTrackingDTO;
import com.prolog.rdc.tms.app.model.dto.business.ShipbillManageItemDTO;
import com.prolog.rdc.tms.app.model.dto.business.ShipbillManagePackDTO;
import com.prolog.rdc.tms.app.model.vo.ShipbillAdjustVO;
import com.prolog.rdc.tms.app.model.vo.ShipbillManageQueryVO;
import com.prolog.rdc.tms.app.service.business.ShipbillManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 业务APP——运单管理控制层
 *
 * @author xiaoyf
 * @since 2022-04-13 14:35:06
 */
@RestController
@Api(tags = "业务APP——运单管理控制层")
@RequestMapping("shipbillManage")
public class ShipbillManageController {

    @Autowired
    private ShipbillManageService service;

    @UserLog("运单分页查询")
    @ApiOperation(value = "运单分页查询", notes = "运单分页查询")
    @PostMapping("/queryPage")
    public RestMessage<Page<ShipbillManageDTO>> queryPage(@RequestBody ShipbillManageQueryVO vo) throws Exception {
        Page<ShipbillManageDTO> page = service.queryPage(vo);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    // STD-DEVELOP20220823 lhb 计算件重体 20220913 start
    @UserLog("运单调整分页查询")
    @ApiOperation(value = "运单调整分页查询", notes = "运单调整分页查询")
    @PostMapping("/adjust_queryPage")
    public RestMessage<Page<ShipbillManageDTO>> adjustQueryPage(@RequestBody ShipbillManageQueryVO vo) throws Exception {
        Page<ShipbillManageDTO> page = service.adjustQuery(vo);
        return RestMessage.newInstance(true, "查询成功！", page);
    }
    // STD-DEVELOP20220823 lhb 计算件重体 20220913 end

    @UserLog("运单详情查询")
    @ApiOperation(value = "运单详情查询", notes = "运单详情查询")
    @PostMapping("/queryDetail")
    public RestMessage<ShipbillManageDTO> queryDetail(@RequestBody ShipbillManageQueryVO vo)  throws Exception {
        ShipbillManageDTO page = service.queryDetail(vo);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("运单商品查询")
    @ApiOperation(value = "运单商品查询", notes = "运单商品查询")
    @PostMapping("/queryItem")
    public RestMessage<Page<ShipbillManageItemDTO>> queryItem(@RequestBody ShipbillManageQueryVO vo) throws Exception {
        Page<ShipbillManageItemDTO> page = service.queryItem(vo);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("运单包裹查询")
    @ApiOperation(value = "运单包裹查询", notes = "运单包裹查询")
    @PostMapping("/queryPack")
    public RestMessage<Page<ShipbillManagePackDTO>> queryPack(@RequestBody ShipbillManageQueryVO vo) throws Exception {
        Page<ShipbillManagePackDTO> page = service.queryPack(vo);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("运单节点查询")
    @ApiOperation(value = "运单节点查询", notes = "运单节点查询")
    @PostMapping("/queryShipbillNode")
    public RestMessage<List<ShipbillNodeTrackingDTO>> queryShipbillNode(@RequestBody @Valid ShipbillManageQueryVO vo) throws Exception {
        List<ShipbillNodeTrackingDTO> page = service.queryShipbillNode(vo);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @UserLog("调整运单")
    @ApiOperation(value = "调整运单", notes = "调整运单")
    @PostMapping("/adjust")
    public RestMessage<String> shipbillUpdate(@RequestBody List<ShipbillAdjustVO> adjustVOs) {
        try {
            service.shipbillUpdate(adjustVOs);
            return RestMessage.newInstance(true, "修改成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }
}
