package org.springblade.modules.external;

import com.alibaba.fastjson.JSONObject;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.smartapplication.carocr.entity.CarOcr;
import org.springblade.smartapplication.carocr.service.ICarOcrService;
import org.springblade.smartapplication.carocrout.entity.CarOcrOut;
import org.springblade.smartapplication.carocrout.service.ICarOcrOutService;
import org.springblade.utils.AESPlus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Base64;

@RestController
@AllArgsConstructor
@RequestMapping("external")
@Api(value = "", tags = "接口")
public class External {

	private ICarOcrService carOcrService;

	private ICarOcrOutService carOcrOutService;

	/**
	 * 新增
	 */
	@PostMapping("carInRecord/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入carOcr")
	public Result carInRecordSave(@RequestParam String param) throws Exception{
		String carOcrJson = new String(Base64.getDecoder().decode(param));
		String decrypt = AESPlus.decrypt("123456789ABCDEFG", carOcrJson);

		CarOcr carOcr = JSONObject.parseObject(decrypt, CarOcr.class);
		boolean save = carOcrService.save(carOcr);
		Result result = new Result();
		if(save){

			result.setStatus(1);
			result.setCode("ok");
			result.setMessage("success");
			return result;
		}else{
			result.setStatus(0);
			return result;
		}


	}

	/**
	 * 第三方对接接口:新增
	 */
	@PostMapping("carOutRecord/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入carOcrOut")
	public Result carOutRecordSave(@RequestParam String param) throws Exception{
		String carOcrOutJson = new String(Base64.getDecoder().decode(param));
		String decrypt = AESPlus.decrypt("123456789ABCDEFG", carOcrOutJson);

		CarOcrOut carOcrOut = JSONObject.parseObject(decrypt, CarOcrOut.class);
		boolean save = carOcrOutService.save(carOcrOut);
		Result result = new Result();
		if(save){

			result.setStatus(1);
			result.setCode("ok");
			result.setMessage("success");
			return result;
		}else{
			result.setStatus(0);
			return result;
		}
	}
}
