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


import cn.superdesk.uniorder.common.constants.ResponseMsgConstants;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dto.param.accounting.AutoCreateScheduleTaskStatementOfAccountParam;
import cn.superdesk.uniorder.dto.param.accounting.AutoCreateScheduleTaskStatementOfAccountReportVo;
import cn.superdesk.uniorder.dto.param.accounting.unified.customer.DzMainAutoParam;
import cn.superdesk.uniorder.dubbo.consumer.accounting.customer.AccountingUnifiedCustomerDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.scheduler.SysQuartzScheduleTaskStatementOfAccountDubboConsumerService;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
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.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: 客户结算-自动创建-对账单-订单维度
 * @Author: linjinyu
 * @CreateDate: 2020/12/16 下午3:56
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020/12/16 下午3:56
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "客户结算-自动创建-对账单-订单维度", tags = {"客户结算-自动创建-对账单-订单维度"})
@Slf4j
@RestController
@RequestMapping("/accounting/unified/customer/auto/dim/order")
public class UnifiedCustomerAutoCreateAccountingDimOrderController extends BaseController {

	@Autowired
	private AccountingUnifiedCustomerDubboConsumerService accountingUnifiedCustomerDubboConsumerService;

	@Autowired
	private SysQuartzScheduleTaskStatementOfAccountDubboConsumerService sysQuartzScheduleTaskStatementOfAccountDubboConsumerService;


	/**
	 * http://192.168.1.223:8089/web//accounting/unified/customer/auto/dim/order/autoCreateScheduleTaskStatementOfAccount
	 *
	 * @param params
	 * @return
	 */
	@ApiOperation(value = "客户结算-自动-对账单 按条件 排列组合 生成任务-新版本 permutationAndCombinationAutoCreate")
	@RequestMapping(value = "/autoCreateScheduleTaskStatementOfAccount", method = RequestMethod.POST)
	@ResponseBody
	public R<AutoCreateScheduleTaskStatementOfAccountReportVo> autoCreateScheduleTaskStatementOfAccount(
			@RequestBody
//			@Valid
					AutoCreateScheduleTaskStatementOfAccountParam params) {

		log.info(AnJsonUtils.toJson(params));

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

		Integer hasError = 0;
		if (null == params.getStartTime()) {

			hasError = 1;
		}

		if (null == params.getEndTime()) {
			hasError = 1;
		}

		if (hasError.equals(1)) {
			response.setCode(500);
			response.setMessage("账单周期不能为空");

			return response;
		}


//		SysConfig sysConfigConditions = BeanUtils.mapToBean(conditions,SysConfig.class);


		AutoCreateScheduleTaskStatementOfAccountReportVo report = sysQuartzScheduleTaskStatementOfAccountDubboConsumerService.autoCreateScheduleTaskStatementOfAccountDimOrder(getToken(), params);

		response.setData(report);

		return response;


	}


	/**
	 * 数据管理-生成对账单
	 * 自动创建 客户结算 对账单
	 * TODO 看代码是已经屏蔽 202004328 18:10 发现 record by linjinyu
	 * <p>
	 * 自动生产对账单
	 *
	 * @param
	 * @return
	 */
	@ApiOperation(value = "数据管理-生成对账单(老版本) 自动创建 客户结算 对账单 (不能用)")
	@RequestMapping(value = "/autoCreateAccounting", method = RequestMethod.POST)
	@ResponseBody
	public R<Map<String, Object>> autoCreateAccounting(DzMainAutoParam model) {

		R<Map<String, Object>> result = new R<>();

		try {

			// 企业 ids
			String[] companys = model.getCompanys().split(",");

			if (companys.length == 0) {
				result.setSuccess(false);
				result.setMessage("您没有选择企业！");
				return result;
			}

			//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			//Map<String, Object> resMap =  mainDubboService.autoProduce(getToken(),companys,model.getDateType(),model.getStarTime(),model.getEndTime());

			result.setSuccess(true);
			result.setData(null);

		} catch (Exception e) {

			result.setSuccess(false);
			result.setMessage(ResponseMsgConstants.ERROR_UNKNOW);
			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}

		return result;
	}
}
