package com.prolog.rdc.tms.controller;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.lock.DistributedLock;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.product.core.tools.util.JsonMapper;
import com.prolog.rdc.tms.model.vo.BillDownloadVO;
import com.prolog.rdc.tms.service.BillDownloadService;
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.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;

@RestController
@Api(tags = "单据下传管理")
@RequestMapping("/bill_download")
public class BillDownloadController {

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

    @Autowired
    private BillDownloadService billDownloadService;

    @Autowired
    private DistributedLock distributedLock;

    @UserLog("单据管理-下传新增")
    @ApiOperation(value = "单据管理-新增", notes = "单据管理-新增")
    @PostMapping("/save/v1.0")
    public RestMessage<Object> downloadSave(@RequestBody @Valid List<BillDownloadVO> vos) {
        logger.info("- > save vo={}", JsonMapper.toJsonString(vos));
        try {
            billDownloadService.downloadSave(vos);
            return RestMessage.newInstance(true, "操作成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, "操作失败", null);
        }
    }

}