package cn.superdesk.uniorder.controller._patch.accounting;

import cn.superdesk.uniorder.common.pagination.PageQueryParam;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dubbo.consumer.accounting.supplier.AccountingUnifiedSupplierDubboConsumerService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2021/2/5 下午5:59
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/2/5 下午5:59
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/patch/accounting/unified/supplier/dim/order2goods")
public class AccountingUnifiedSupplierDimOrder2DimGoodsController {


	@Autowired
	private AccountingUnifiedSupplierDubboConsumerService accountingUnifiedSupplierDubboConsumerService;
//--
//-- 表的结构 `accounting_unified_supplier`
//--
//
//CREATE TABLE `accounting_unified_supplier` (
//`id` bigint(20) NOT NULL,
//`accounting_order_sn` varchar(64) NOT NULL,
//`accounting_status` tinyint(3) NOT NULL,
//`invoice_status` tinyint(2) NOT NULL,
//`sale_id` bigint(20) DEFAULT NULL,
//`sale_name` varchar(100) DEFAULT NULL,
//`invoice_title` varchar(100) DEFAULT NULL,
//`tax_code` varchar(100) DEFAULT NULL,
//`invoice_type` tinyint(2) DEFAULT NULL,
//`address` varchar(200) DEFAULT NULL,
//`is_send_email` tinyint(3) DEFAULT NULL COMMENT '是否发邮件0-不发,1-发',
//`send_email_time` datetime DEFAULT NULL,
//`start_time` datetime DEFAULT NULL,
//`end_time` datetime DEFAULT NULL,
//`back_account_status` tinyint(2) NOT NULL COMMENT '0-未回款;1-部分回款;2-全部回款',
//`create_time` datetime DEFAULT NULL,
//`create_user_id` bigint(20) DEFAULT NULL,
//`update_time` datetime DEFAULT NULL,
//`update_user_id` bigint(20) DEFAULT NULL
//) ENGINE=InnoDB DEFAULT CHARSET=utf8;

//--
//-- 表的结构 `accounting_unified_supplier_order`
//--
//
//CREATE TABLE `accounting_unified_supplier_order` (
//`id` bigint(20) NOT NULL,
//`accounting_order_sn` varchar(50) NOT NULL,
//`order_sn` varchar(50) NOT NULL,
//`amount` decimal(10,4) NOT NULL,
//`cost_amount` decimal(10,4) DEFAULT '0.0000',
//`amount_with_freight` decimal(10,4) DEFAULT '0.0000',
//`cost_amount_with_freight` decimal(10,4) DEFAULT '0.0000'
//) ENGINE=InnoDB DEFAULT CHARSET=utf8;

//-- 添加表
//CREATE TABLE `accounting_unified_supplier_x_goods` (
//`id` bigint(20) NOT NULL,
//`accounting_order_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '对账单Id',
//`accounting_order_sn` varchar(32) NOT NULL COMMENT '对账单Sn',
//`unified_order_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '统一订单id',
//`order_sn` varchar(32) NOT NULL,
//`unified_order_goods_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '统一订单商品Id',
//`unified_order_credit_id` bigint(20) NULL DEFAULT '0' COMMENT '统一订单流水Id,目前维度是没有用的',
//`create_time` datetime DEFAULT NULL,
//`create_user_id` bigint(20) DEFAULT NULL,
//`update_time` datetime DEFAULT NULL,
//`update_user_id` bigint(20) DEFAULT NULL
//) ENGINE=InnoDB DEFAULT CHARSET=utf8;
//
//ALTER TABLE `accounting_unified_supplier_x_goods` ADD PRIMARY KEY(`id`);
//ALTER TABLE `accounting_unified_supplier_x_goods` CHANGE `id` `id` BIGINT(20) NOT NULL AUTO_INCREMENT;

	/**
	 * 超时不用管 能正常运行
	 * http://192.168.1.223:8089/web/patch/accounting/unified/supplier/dim/order2goods/run
	 *
	 * @param param
	 * @return
	 */
	@ApiOperation(value = "patch")
	@RequestMapping(value = "run", method = RequestMethod.POST)
	@ResponseBody
	public R<String> run(@RequestBody PageQueryParam param) {


		R<String> response = new R<>();

		// TODO 参数合法性判定

		String accountingOrderSn = null;

		if (null != param.getConditions().get("accountingOrderSn")) {
			accountingOrderSn = param.getConditions().get("accountingOrderSn").toString();
		}

		accountingUnifiedSupplierDubboConsumerService.patchXDimOrder2DimGoods(accountingOrderSn);

		return response;
	}
}
