package cn.superdesk.uniorder.controller.invoice.common;

import cn.superdesk.libs.common.json.JsonUtils;
import cn.superdesk.uniorder.common.pagination.PageQueryGenericParam;
import cn.superdesk.uniorder.common.pagination.PageQueryParam;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceTypeModeConfigSzhtxxPaperInvoice;
import cn.superdesk.uniorder.dto.param.invoice.common.InvoiceTypeModeConfigSzhtxxPaperInvoiceParam;
import cn.superdesk.uniorder.dto.param.invoice.common.InvoiceTypeModeConfigSzhtxxPaperInvoiceQueryCriteria;
import cn.superdesk.uniorder.dubbo.consumer.invoice.common.InvoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description:
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2022-04-22 10:22:57
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022-04-22 10:22:57
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "系统设置-发票种类-所属开票方式-深圳航信纸质发票", tags = {"系统设置-发票种类-所属开票方式-深圳航信纸质发票"})
@Slf4j
@Controller
@RequestMapping("/invoiceTypeModeConfigSzhtxxPaperInvoice")
public class InvoiceTypeModeConfigSzhtxxPaperInvoiceController extends BaseController {

    @Autowired
    private InvoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService;

    @ApiOperation(value = "分页查询 - 默认不用")
    @RequestMapping(value = "listByObscure", method = RequestMethod.POST)
    @ResponseBody
    public R<List<InvoiceTypeModeConfigSzhtxxPaperInvoice>> pageQueryInvoiceTypeModeConfigSzhtxxPaperInvoice(@RequestBody PageQueryParam param) {

        log.info("pageQueryInvoiceTypeModeConfigSzhtxxPaperInvoice:\n{}", JsonUtils.toJson(param));

        R<List<InvoiceTypeModeConfigSzhtxxPaperInvoice>> result = new R<>();

        // TODO 参数合法性判定

        result = invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService.pageQuery(param.getConditions(), param.getPageNo(), param.getPageSize());

        return result;
    }

    @ApiOperation(value = "分页查询")
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    public R<List<InvoiceTypeModeConfigSzhtxxPaperInvoice>> pageQueryGenericParamInvoiceTypeModeConfigSzhtxxPaperInvoice(@RequestBody PageQueryGenericParam<InvoiceTypeModeConfigSzhtxxPaperInvoiceQueryCriteria> param) {

        log.info("pageQueryInvoiceTypeModeConfigSzhtxxPaperInvoice:\n{}", JsonUtils.toJson(param));

        R<List<InvoiceTypeModeConfigSzhtxxPaperInvoice>> result = new R<>();

        // TODO 参数合法性判定

        result = invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService.pageQueryGenericParam(param.getConditions());

        return result;
    }

    @ApiOperation(value = "按id查询")
    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    @ResponseBody
    public R<List<InvoiceTypeModeConfigSzhtxxPaperInvoice>> getById(@PathVariable("id") long id) {

        R<List<InvoiceTypeModeConfigSzhtxxPaperInvoice>> result = new R<>();

        // TODO 参数合法性判定

        InvoiceTypeModeConfigSzhtxxPaperInvoice entity = invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService.findInvoiceTypeModeConfigSzhtxxPaperInvoiceById(id);

        List<InvoiceTypeModeConfigSzhtxxPaperInvoice> data = new ArrayList<>();
        data.add(entity);

        result.setData(data);

        return result;
    }

    @ApiOperation(value = "新增")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    @ResponseBody
    public R<String> addInvoiceTypeModeConfigSzhtxxPaperInvoice(@RequestBody InvoiceTypeModeConfigSzhtxxPaperInvoiceParam param) {

        log.info("addInvoiceTypeModeConfigSzhtxxPaperInvoice:\n{}", JsonUtils.toJson(param));


        // TODO 参数合法性判定

        invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService.addInvoiceTypeModeConfigSzhtxxPaperInvoice(param, getToken());

        return new R<>("200", "操作成功", true);
    }

    /**
     * 【1. 数据管理-1.2 发票种类【新增“深圳航信纸质发票”】-待整理-20220406】
     * https://www.tapd.cn/33003868/prong/stories/view/1133003868001004201
     * 1.2.2.2.2.1 【开通】
     * 1.2.2.2.2.5 【编辑】
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "编辑-成功会自动更新对映-模块X发票种类X发票方式[深圳航信纸质发票]-开通")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public R<String> updateInvoiceTypeModeConfigSzhtxxPaperInvoice(@RequestBody InvoiceTypeModeConfigSzhtxxPaperInvoiceParam param) {

        log.info("updateInvoiceTypeModeConfigSzhtxxPaperInvoice:\n{}", JsonUtils.toJson(param));

        invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService.updateInvoiceTypeModeConfigSzhtxxPaperInvoice(param, getToken());

        return new R<>("200", "操作成功", true);
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public R<String> deleteInvoiceTypeModeConfigSzhtxxPaperInvoice(@PathVariable("id") long id) {

        // TODO 参数合法性判定

        invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService.deleteInvoiceTypeModeConfigSzhtxxPaperInvoice(id, getToken());

        return new R<>("200", "操作成功", true);
    }

    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "delete_ids", method = RequestMethod.POST)
    @ResponseBody
    public R<String> deleteIdsInvoiceTypeModeConfigSzhtxxPaperInvoice(@RequestParam(value = "ids") long[] ids) {

        log.info(JsonUtils.toJson(ids));

        for (long id : ids) {
            invoiceTypeModeConfigSzhtxxPaperInvoiceDubboConsumerService.deleteInvoiceTypeModeConfigSzhtxxPaperInvoice(id, getToken());
        }

        return new R<>("200", "操作成功", true);

    }


}
