package com.prolog.rdc.tms.controller;

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.product.core.tools.util.JsonMapper;
import com.prolog.rdc.tms.model.dto.ContractLogQueryDTO;
import com.prolog.rdc.tms.model.dto.LogisticsContractDTO;
import com.prolog.rdc.tms.model.dto.LogisticsContractQuery;
import com.prolog.rdc.tms.model.dto.ShipBillDTO;
import com.prolog.rdc.tms.model.entity.BmsLogOperationModel;
import com.prolog.rdc.tms.model.vo.ContractLogQueryVO;
import com.prolog.rdc.tms.model.vo.LogisticsContractVO;
import com.prolog.rdc.tms.model.vo.StatusUpdate;
import com.prolog.rdc.tms.service.LogisticsContractService;
import com.prolog.rdc.tms.service.ShipBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@RestController
@Api(tags = "物流合同")
@RequestMapping("/logisticsContract")
public class LogisticsContractController {

    private final Logger logger = LoggerFactory.getLogger(LogisticsContractController.class);

    @Autowired
    private LogisticsContractService service;
    @Autowired
    private ShipBillService shipBillService;

    @UserLog("物流合同-新增")
    @ApiOperation(value = "物流合同-新增", notes = "物流合同-新增")
    @PostMapping("/save")
    public RestMessage<Object> save(@RequestBody @Valid LogisticsContractVO vo) {
        logger.info("- > save vo={}", JsonMapper.toJsonString(vo));
        service.save(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("物流合同-列表查询")
    @ApiOperation(value = "物流合同-列表查询", notes = "物流合同-列表查询")
    @PostMapping("/findList")
    public RestMessage<Page<LogisticsContractDTO>> findList(@RequestBody LogisticsContractQuery vo) {
        logger.info("- > findList vo={}", JsonMapper.toJsonString(vo));
        Page<LogisticsContractDTO> list = service.findList(vo);
        return RestMessage.newInstance(true, "操作成功", list);
    }

    @UserLog("物流合同-详情")
    @ApiOperation(value = "物流合同-详情", notes = "物流合同-详情")
    @PostMapping("/detail")
    public RestMessage<LogisticsContractDTO> detail(@RequestParam("id") Long id) {
        logger.info("- > detail vo={}", JsonMapper.toJsonString(id));
        LogisticsContractDTO detail = service.detail(id);
        return RestMessage.newInstance(true, "操作成功", detail);
    }

    @UserLog("物流合同-修改")
    @ApiOperation(value = "物流合同-修改", notes = "物流合同-修改")
    @PostMapping("/update")
    public RestMessage<Object> update(@RequestBody @Valid LogisticsContractVO vo) {
        logger.info("- > update vo={}", JsonMapper.toJsonString(vo));
        service.update(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("物流合同-复制")
    @ApiOperation(value = "物流合同-复制", notes = "物流合同-复制")
    @PostMapping("/copy")
    public RestMessage<Object> copy(@RequestBody @Valid LogisticsContractVO vo) {
        logger.info("- > copy vo={}", JsonMapper.toJsonString(vo));
        service.copy(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("物流合同-启用/停用")
    @ApiOperation(value = "物流合同-复制", notes = "物流合同-复制")
    @PostMapping("/updateStatus")
    public RestMessage<Object> updateStatus(@RequestBody List<StatusUpdate> list) {
        logger.info("- > updateStatus vo={}", JsonMapper.toJsonString(list));
        service.updateStatus(list);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("物流合同-日志")
    @ApiOperation(value = "物流合同-日志", notes = "物流合同-日志")
    @PostMapping("/findListForLog")
    public RestMessage<List<BmsLogOperationModel>> findListForLog(@RequestParam("id") Long id) {
        logger.info("- > findListForLog vo={}", JsonMapper.toJsonString(id));
        List<BmsLogOperationModel> page = service.findListForLog(id);
        return RestMessage.newInstance(true, "操作成功", page);
    }

    @UserLog("物流合同-试算实验")
    @ApiOperation(value = "物流合同-试算实验", notes = "物流合同-试算实验")
    @PostMapping("/trialTest")
    public RestMessage<Object> trialTest(@RequestParam("id") Long id) {
        logger.info("- > trialTest vo={}", JsonMapper.toJsonString(id));
        service.trialTest(id);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("试算结果详情")
    @ApiOperation(value = "试算结果详情", notes = "试算结果详情-")
    @PostMapping("/shipBilldetail")
    public RestMessage<Object> shipBilldetail(@RequestParam("id") Long id) {
        logger.info("- > trialTest vo={}", JsonMapper.toJsonString(id));
        ShipBillDTO detail = shipBillService.detail(id);
        return RestMessage.newInstance(true, "操作成功", detail);
    }

    @UserLog("物流合同-日志信息")
    @ApiOperation(value = "物流合同-日志信息", notes = "物流合同-日志信息")
    @PostMapping("/log")
    public RestMessage<List<ContractLogQueryDTO>> logQuery(@RequestBody ContractLogQueryVO vo) {
        logger.info("- > findList vo={}", JsonMapper.toJsonString(vo));
        List<ContractLogQueryDTO> list = service.logQuery(vo);
        return RestMessage.newInstance(true, "操作成功", list);
    }

}