package org.springblade.openinterface.carbarrier.listener;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.community.carrecord.entity.CarRecord;
import org.springblade.community.carrecord.service.ICarRecordService;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.utils.Tools;
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 java.util.Map;

/**
 * @author zwx
 * @create 2020/12/28 10:56
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("openinterface/listen")
public class CarBarrierListenerController extends BladeController {

	private ICarRecordService carRecordService;
	/**
	 * 安快车辆道闸进出记录推送
	 * @param map
	 * @return
	 */
	@PostMapping("/car/ankuai/inOutRecord")
	public R iotDeviceDataReport(@RequestBody Map<String, Object> map) {
//		CarRecord carRecord = new CarRecord();
		log.info(JSONUtil.toJsonStr( "推送数据map = " + map));

		CarRecord carRecord = (CarRecord) Tools.map2Object(map, CarRecord.class);

		log.info(JSONUtil.toJsonStr( "carRecord = " + carRecord));

		return R.status(carRecordService.save(carRecord));
	}
}
