/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.smartapplication.carenterrecord.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.community.agency.service.IAgencyService;
import org.springblade.community.residential.entity.Residential;
import org.springblade.community.residential.service.IResidentialService;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.smartapplication.carenterrecord.dto.QueryDto;
import org.springblade.smartapplication.carenterrecord.vo.QueryVO;
import org.springblade.smartapplication.caroutrecord.entity.CarOutRecord;
import org.springblade.smartapplication.caroutrecord.service.ICarOutRecordService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.smartapplication.carenterrecord.entity.CarEnterRecord;
import org.springblade.smartapplication.carenterrecord.vo.CarEnterRecordVO;
import org.springblade.smartapplication.carenterrecord.wrapper.CarEnterRecordWrapper;
import org.springblade.smartapplication.carenterrecord.service.ICarEnterRecordService;
import org.springblade.core.boot.ctrl.BladeController;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Random;

/**
 *  控制器
 *
 * @author BladeX
 * @since 2021-01-04
 */
@RestController
@AllArgsConstructor
@RequestMapping("carenterrecord/carenterrecord")
@Api(value = "", tags = "安快车辆入场记录")
public class CarEnterRecordController extends BladeController {

	private ICarEnterRecordService carEnterRecordService;
	private ICarOutRecordService carOutRecordService;
	private IResidentialService residentialService;
	private IAgencyService agencyService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入carEnterRecord")
	public R<CarEnterRecordVO> detail(CarEnterRecord carEnterRecord) {
		CarEnterRecord detail = carEnterRecordService.getOne(Condition.getQueryWrapper(carEnterRecord));
		return R.data(CarEnterRecordWrapper.build().entityVO(detail));
	}

	/**
	 * 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入carEnterRecord")
	public R<IPage<CarEnterRecordVO>> list(CarEnterRecord carEnterRecord, Query query, BladeUser bladeUser) {
		String timeRange = null;
		LambdaQueryWrapper<CarEnterRecord> wrapper = null;
		if(carEnterRecord.getTimeRange() != null){
			timeRange = carEnterRecord.getTimeRange();
			carEnterRecord.setTimeRange(null);
			String[] timeRangeArray = timeRange.split(",");
			wrapper = Condition.getQueryWrapper(carEnterRecord).lambda().gt(CarEnterRecord::getEnterTime,timeRangeArray[0]).lt(CarEnterRecord::getEnterTime,timeRangeArray[1]);
		}else{
			wrapper = Condition.getQueryWrapper(carEnterRecord).lambda();
		}
		IPage<CarEnterRecord> pages = carEnterRecordService.page(Condition.getPage(query), wrapper.eq(CarEnterRecord::getTenantId,bladeUser.getTenantId()).orderByDesc(CarEnterRecord::getEnterTime));
		return R.data(CarEnterRecordWrapper.build().pageVO(pages));
	}


	/**
	 * 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入carEnterRecord")
	public R<IPage<CarEnterRecordVO>> page(CarEnterRecordVO carEnterRecord, Query query) {
		IPage<CarEnterRecordVO> pages = carEnterRecordService.selectCarEnterRecordPage(Condition.getPage(query), carEnterRecord);
		return R.data(pages);
	}

	/**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入carEnterRecord")
	public R save(@Valid @RequestBody CarEnterRecord carEnterRecord) {
		return R.status(carEnterRecordService.save(carEnterRecord));
	}

	/**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入carEnterRecord")
	public R update(@Valid @RequestBody CarEnterRecord carEnterRecord) {
		return R.status(carEnterRecordService.updateById(carEnterRecord));
	}

	/**
	 * 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入carEnterRecord")
	public R submit(@Valid @RequestBody CarEnterRecord carEnterRecord) {
		return R.status(carEnterRecordService.saveOrUpdate(carEnterRecord));
	}


	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(carEnterRecordService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * 	筛选车辆记录
	 * */
	@GetMapping("/queryRecord")
	@ApiOperation("筛选车辆记录")
	public  R<QueryVO> queryRecord(QueryDto queryDto){
		return R.data(new QueryVO.QueryVOBuilder()
		.withEnterList(
			carEnterRecordService.getBaseMapper().selectPage(new Page<>(queryDto.getCurrent(),queryDto.getSize()),new QueryWrapper<>(new CarEnterRecord())
				.lambda()
				.eq(queryDto.getTid()!=null,CarEnterRecord::getTenantId,queryDto.getTid())
				.eq(queryDto.getCarNnm()!=null,CarEnterRecord::getCarNo,queryDto.getCarNnm())
				.like(queryDto.getDateOfEnter()!=null,CarEnterRecord::getEnterTime,queryDto.getDateOfEnter())
		))
		.withOutList(
			carOutRecordService.getBaseMapper().selectPage(new Page<>(queryDto.getCurrent(),queryDto.getSize()),new QueryWrapper<>(new CarOutRecord())
				.lambda()
				.eq(queryDto.getTid()!=null,CarOutRecord::getTenantId,queryDto.getTid())
				.eq(queryDto.getCarNnm()!=null,CarOutRecord::getCarNo,queryDto.getCarNnm())
				.like(queryDto.getDateOfOut()!=null,CarOutRecord::getOutTime,queryDto.getDateOfOut())

		))
		.build()
		);
	}



	/**
	 * 生成记录
	 */
	@PostMapping("/initRecord")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "生成记录", notes = "传入carEnterRecord")
	public R initRecord(@Valid @RequestBody CarEnterRecord carEnterRecord) {

		String carNoArr[] = {"宁AY118N","宁AU671C","宁A009B5","宁EJ3576","宁AR797N","宁A7JM56","宁AH184Y","宁AK264Z","皖AD79089","陕A8GR79","宁A38713","陕D1L979","宁A3CS29","宁AH896J","宁A14L84","陕VCJ611","宁EJ3576","宁A7061C","宁AA266J","宁A14L84","宁A6KR73","宁AT0801","豫CSL333","宁ANB900","甘MN5283","宁A88888","宁AF625A","宁A22A77","宁AAE999","浙B2R18P"};
		String personName[] = {"贺佳伟","宋有平","张旭伟","鲁少华","董静","朱金萍","冉艳丽","刘树虎","秦自洪","杨琴","杨宁","杜喜路","董晓勇","李俊杰","邓爱波","找全新","李三乃","张华伟","牟国华","黄建华","聂相玲","马玉春","马文贵","王志千","孙亚茹","蔡伟","王振雷","蔡伟","仝晓龙","刘洋"};
		String enterImage[] = {"http://sfm-image.oss-cn-shenzhen.aliyuncs.com/c6d0979a-3d15-43e9-a846-0b417f31cb4320210611074111c宁AY118N?Expires=2570053273&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=4Mnz5ENBKLrzFbdStONsnEnL4kY%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/0d482f16-fe14-415a-8174-5a27f7a81a3920210611073732c宁AU671C?Expires=2570053056&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=H5Uf076zyH%2F%2BqNIncoBLjkvIJXQ%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/f0454a24-cdb0-4319-8940-57b1df794abf20210610095642c宁A009B5?Expires=2569975007&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=BZwMY37oJTUDBx9DApm8h75nX90%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/c0ab7894-c0b8-448c-a6f2-035b753b53ce20210610095252c宁EJ3576?Expires=2569974782&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=c9dEDZpsEDOIWoPVC4EBenfrevw%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/d5a67df8-6b64-48ab-b76d-a20ea367b7df20210610095137c宁AR797N?Expires=2569974705&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=rszkm5xzElJGIuABNrDiqk6uJgg%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/fab34c90-79eb-4ec5-8810-997d2bc4045c20210610095044c宁A7JM56?Expires=2569974653&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=VIkh40cpR4KJumybRaZVQ07D%2FYo%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/9a61e570-2deb-486c-a7ea-ef65fe3f701a20210610094506c宁AH184Y?Expires=2569974313&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=7WiWsgDu%2FNVo1rgj8ePkFIo8204%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/c690ab3d-2e93-45ff-8009-dcbb3016933b20210610094412c宁AK264Z?Expires=2569974256&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=TH0aC3o64xOSou4OJr2yJZAA5Mg%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/cdd3b4a5-04ab-4f4a-886e-1e0a2bde254020210610093933c皖AD79089?Expires=2569973979&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=bwiOnrhaj35yLskusWq4AuT0d3I%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/a07461e5-299e-4407-9763-51af16b5d7ee20210610093740c陕A8GR79?Expires=2569973866&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=ko8z4suSzVtktepqbZb5G3OCG7k%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/9286d35e-475b-4d12-b248-c3f3c122d86a20210610093120c宁A38713?Expires=2569973488&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=xhXOMk9vqmY6BaaffS8J5LL37LI%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/251faa26-f913-4c4c-818a-da0e40afde8a20210610093003c陕D1L979?Expires=2569973411&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=h5Gc9j5unoUKerg4qcGEvTG44dk%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/37fa16e6-4b74-4d0d-9ac8-dc61789fcf1c20210610092808c宁A3CS29?Expires=2569973294&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=jzhPy6afZYfTuekTJuVpS%2FXQwMU%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/3bbe41a9-de40-43bf-902b-7e9ad3355ec520210610092608c宁AH896J?Expires=2569973174&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=I7g1zt30f6LFXTA%2B83d0mfTMitE%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/9256fe44-88a2-41f2-ac69-f391ded0efd220210610092535c宁A14L84?Expires=2569973141&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=cZAq7kjuH5IkYWQR%2BiFUQKAVNyo%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/be6c06e8-2f2c-4968-9ce5-c0eb724a061f20210610092344c陕VCJ611?Expires=2569973032&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=1yKgbhwGCSuPsM%2F%2F7tSHe81OOlc%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/3b21ae11-cea5-454b-ba71-2e1887e45b8320210610091958c宁EJ3576?Expires=2569972807&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=Kzy0diA2uGVqZspzXeCC4Rxze3M%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/39157cca-3b27-4778-82f3-d04ebd19327520210610091847c宁A7061C?Expires=2569972730&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=wq9H0atSx%2Fuhy3gvawD1nwNp4PI%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/514f4b3f-25b8-4625-9805-256d7ee0dd3a20210610090534c宁AA266J?Expires=2569971945&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=IoV8tEmBohUU8i5TdjMFawDkoQE%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/62319626-fda6-40e4-b9b5-da44f08fe0d720210610090519c宁A14L84?Expires=2569971924&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=bwqvEPHO0NRk%2F59R9nqq2ShbrRg%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/7804bdbd-c916-4734-892a-cc3f190d530620210610090504c宁A6KR73?Expires=2569971908&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=qozt4QmoDTsSwn17QpZhGdZeqNM%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/13ec6d10-98f8-4523-a367-a946e03ff8f020210610090329c宁AT0801?Expires=2569971819&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=Jj9OUUcrUchBaDslc2R%2Bo3oTaB0%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/a361882a-088d-49a6-b74c-ae7b1156bdab20210610090158c豫CSL333?Expires=2569971722&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=bQJN4OcN9Qr5%2F%2FXUxcuzK0MJF6Y%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/83882b2f-8ab7-48b1-bb73-556a26481acf20210610090140c宁ANB900?Expires=2569971705&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=1eIH4zlge2oeA7ZaYqYhcWfyLqw%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/3f01e7c1-9097-4798-8362-9d1e0e822ed320210610090104c甘MN5283?Expires=2569971668&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=A9KzvJYasDssbBiFjNu1AdjMga8%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/23bc0198-31ce-42a0-9964-8e5b7dcdafb020210610085911c宁A88888?Expires=2569971555&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=LIgR19USNw3ZlAdO5%2FyMsRvlHZE%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/0b993f02-aa65-49fc-8d9f-b06984e3e9ed20210610085853c宁AF625A?Expires=2569971534&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=L%2FX5PFYq6Ejkcau62bh3RC%2Bbvao%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/be8738b2-a5b6-4d8f-8aba-b6be8c4ec6eb20210610085630c宁A22A77?Expires=2569971392&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=KQ1CKrcCEefreYT6OllyCdHZsEI%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/e731e7d9-0ecf-4fe9-a8bc-13f2391797ee20210610085610c宁AAE999?Expires=2569971372&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=nS7zKwYW5rUMpDheDPB8Xgq%2BLx4%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/837a2944-3899-4e4f-b405-fe6d3a44d05520210610085501c浙B2R18P?Expires=2569971303&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=4kQcDAwDels5zOE%2BcYsUyxfWf60%3D"};
		String outImage[] = {"http://sfm-image.oss-cn-shenzhen.aliyuncs.com/26400ef8-78b5-47b4-bff1-9ec703cdbadd20210610095716c皖AD79089?Expires=2569975043&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=oYdhddykk6usH%2Br3NduX3wLtiWk%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/2726f23c-3f8f-48d4-98c5-8f2d4e585dbf20210610095433c宁ANB900?Expires=2569974886&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=aKohnoBHJJbq6Eh0kXkOQlhVA2c%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/4a770f80-6517-4308-825d-c9dff79b83a320210610095056c宁A38713?Expires=2569974665&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=p8Vq%2BTMsp6elXUwvvJR%2BxPpfhWM%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/183a1f93-b0c3-4ff9-badb-078e6c8fa26720210610095044c宁AK264Z?Expires=2569974660&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=oHiGD6mEkfNcIXWTw1Vvna3t1Vw%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/3464892d-5c93-4bf2-b615-94a15efde2a320210610094454c甘M1H287?Expires=2569974305&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=4k6ojhvWcSix92hx88Tcs6b%2BBTU%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/5d145b4a-aec9-4ae2-8564-3cc7f57f25ea20210610094140c陕A1C4S8?Expires=2569974108&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=0Bmlo7Kif5pWPNIyxw0X%2BtI9D2g%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/77b54326-b91a-4cd9-b18b-01ba521df37e20210610093642c甘MN5283?Expires=2569973810&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=so%2FtLIyI6es7Mo4LZ7DqNa%2FOOHg%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/236db3ba-8284-4d47-b317-6eb7b596764a20210610093613c宁EJ3576?Expires=2569973781&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=OOLIdRO8ozmWxQmYciSWXUdu2Nc%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/21c9a17d-c709-4e91-b2a0-05aec0dfb9ca20210610093336c陕D1L979?Expires=2569973621&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=BLr4OgYMws0BZKo19wWmFg9O5rs%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/f0cd98b5-17d0-41c2-9a9d-ae12935ea37720210610093137c宁A6KR73?Expires=2569973504&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=N5vOSb4JncJonHxEe%2FXyh%2FxXAMI%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/6acd9c86-e1c4-4f08-b5ec-a90e4f962c5520210610092453c陕VCJ611?Expires=2569973101&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=Q2VNYo8NGIPXoAfosHg9XgKGAts%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/146477df-a99b-4756-ae2c-98f8b645e31420210610091946c豫AH19Q9?Expires=2569972795&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=Bns8k4GOQ0tljuvM24eK33hHHTs%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/52c69c58-1c73-47b5-a3fc-a9c3b5240d7a20210610091701c宁A009B5?Expires=2569972630&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=8eZ%2BQib9w%2F5pKp5HHwIIz5KVQbk%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/3056466f-b996-409d-82f4-526f56024c2720210610091606c宁A2001C?Expires=2569972573&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=36YyQPxV2SSHZ%2FbX9aHTJQGhVnQ%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/88add16e-2c2d-46b3-a84e-c5e4be3fd4e120210610091457c宁A14L84?Expires=2569972505&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=At25qlZMZgX12LW3or2grmrBRcc%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/5bdc1f8a-bb2b-4b38-9414-d6ad917b19b520210610091357c宁AA266J?Expires=2569972444&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=JyTk9C2vlwcagj4c0AzMTZNDhdM%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/c79b9db6-6c6d-40f2-bd55-aa57339644b320210610090613c宁A6189E?Expires=2569971979&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=yOzYQQlU0lsSmUDIdFCiz7e%2FvRY%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/b9bce2d9-d1a8-4ca5-961e-45b6254d9ad620210610090556c宁A88888?Expires=2569971970&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=pZvRSfHDg8xvfOzInGWyNf2usRA%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/6d0412ea-08ea-4bdf-9a66-a2b777754b2c20210610090548c宁AT0801?Expires=2569971958&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=H5GLmiGhGtlL7dGHyumE%2F9K61NQ%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/341fbcee-e9c2-4c82-a95c-ad322a1d788320210610090420c宁A22A77?Expires=2569971871&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=cN%2B%2BRy5NEOzGgjQcKcgbQSE5sfA%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/266fb841-050f-4ebe-a841-c4a7e3f8dd9820210610090319c浙B2R18P?Expires=2569971806&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=pmsUf%2BQ3FAci0qfkBT%2BMLq8oZ8M%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/241f7fa7-68e5-4f8e-bf13-a96eb0cfd73520210610090019c宁AP181Q?Expires=2569971624&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=IEUfCx6bcAPupv%2B%2F7xnJL%2B%2BDJY0%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/ba04131a-5c33-4852-9868-1c124d641c3020210610085908c宁A5370D?Expires=2569971555&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=RKQykGhNpBZ3lEPs3z1D8RBe32c%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/7f1938d3-197a-45e1-bce3-63ab9f77b63520210610085811c宁AHZ035?Expires=2569971494&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=25E58lY1%2Bnt3xZYK8VjX8ZyGKCE%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/8c2a4d5f-6d0d-4af8-9680-cc64b3b4d33e20210610085758c宁AP126G?Expires=2569971485&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=JYl%2BZZgo14sCzwW9kTWhI%2BghwWY%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/d03a4d6d-f307-4f4b-9ba8-08a835d0211820210610085644c宁A3DW73?Expires=2569971409&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=TyXX%2B0UtWrhSMGIQBupG76ta%2Fh8%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/ff2ec259-42f4-41fb-b2ca-2a4abbd3e88220210610085216c陕CWZ676?Expires=2569971141&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=JErCYCTdESikYyvA%2BnSw6V9V4Co%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/300efddd-221f-465b-88d3-346efb29322220210610083756c宁A22A77?Expires=2569970283&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=v%2FQnxqjwDPE79cPk%2FPZQ8tNPCik%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/83b3ea7d-d88e-47e0-be1b-dcd9968a2a3a20210610083351c陕VCJ611?Expires=2569970038&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=BBhl8doPc208R7iYvRgmNJqcTiQ%3D","http://sfm-image.oss-cn-shenzhen.aliyuncs.com/1171bad1-8bea-4676-bde0-a0f8c95fb90320210610083338c宁A3CS29?Expires=2569970021&OSSAccessKeyId=LTAImO0B1h7uYZZY&Signature=0lynfKMnDyL2w6QpmUMvNH%2BT4zQ%3D"};
		String carType[] = {"3648","3649","3650","3651","3652","3653","3654","3655","3656","3657"};

		Random rand = new Random();
		Integer ran15_30 = rand.nextInt(15) + 15; // 记录条数

		if(carEnterRecord.getTimeRange() != null){
			String timeRange = carEnterRecord.getTimeRange();
			carEnterRecord.setTimeRange(null);
			String[] timeRangeArray = timeRange.split(",");
			String beginTime = timeRangeArray[0];
//			String endTime = timeRangeArray[1];

			Residential residential = residentialService.getById(carEnterRecord.getResidentialId());
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			for (int i = 0; i < ran15_30; i++) {
				Integer ran30 = rand.nextInt(29) + 1; // 车牌、车主下标
				Integer ran12h = (rand.nextInt(12) + 8);  // 小时
				String hour = (ran12h >= 10 )? ran12h + "" : "0" + ran12h;
				Integer ran59m = rand.nextInt(59) + 1; //
				String min = (ran59m >= 10 )? ran59m + "" : "0" + ran59m;
				Integer ran59s = rand.nextInt(59) + 1; // 秒
				String second = (ran59s >= 10 )? ran59s + "" : "0" + ran59s;
				Integer ranCar = rand.nextInt(9) + 1; // 车辆类型
				Integer ran999 = rand.nextInt(999) + 1; // 随机数

				CarEnterRecord record = new CarEnterRecord();
				record.setCarNo(carNoArr[ran30]);
				record.setEnterImgPath(enterImage[ran30]);
				String enterTime = beginTime + " " + hour + ":" + min + ":" + second;

				String orderNo = beginTime.replaceAll("-", "") + ran12h + ran59m + ran59s + ran999 + "-" + record.getCarNo().substring(1, record.getCarNo().length() - 1);
				record.setOrderNo(orderNo);

				try{
					record.setEnterTime(sdf.parse(enterTime));
				}catch (Exception e){
					System.out.println(e.getMessage());
				}

				record.setAgencyId(residential.getAgencyId());
				record.setResidentialId(residential.getId());
				record.setOrgPosition(residential.getOrgPosition());
				record.setParkKey("9bm8k59f");
				record.setEnterGateName("入口车道3");
				record.setEnterOperatorName("管理员");
				record.setCarTypeNo(carType[ranCar]);

				carEnterRecordService.save(record);
			}



		}
		return R.status(true);
	}
}
