/*
 *      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.community.houseuser.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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 net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils;
import org.springblade.common.Constants;
import org.springblade.community.agency.entity.Agency;
import org.springblade.community.agency.service.IAgencyService;
import org.springblade.community.building.entity.Building;
import org.springblade.community.building.service.IBuildingService;
import org.springblade.community.car.entity.Car;
import org.springblade.community.car.service.ICarService;
import org.springblade.community.floor.entity.Floor;
import org.springblade.community.floor.service.IFloorService;
import org.springblade.community.houseuser.dto.HouseuserDTO;
import org.springblade.community.houseuser.entity.Houseuser;
import org.springblade.community.houseuser.service.IHouseuserService;
import org.springblade.community.houseuser.vo.HouseuserVO;
import org.springblade.community.houseuser.wrapper.HouseuserWrapper;
import org.springblade.community.houseuserdetail.entity.HouseuserDetail;
import org.springblade.community.houseuserdetail.service.IHouseuserDetailService;
import org.springblade.community.houseuserthird.entity.ThirdHouseUser;
import org.springblade.community.houseuserthird.service.IThirdHouseUserService;
import org.springblade.community.residential.entity.Residential;
import org.springblade.community.residential.service.IResidentialService;
import org.springblade.community.room.entity.Room;
import org.springblade.community.room.service.IRoomService;
import org.springblade.community.unit.entity.Unit;
import org.springblade.community.unit.service.IUnitService;
import org.springblade.core.boot.ctrl.BladeController;
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.core.tool.utils.StringUtil;
import org.springblade.modules.system.entity.Dict;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.service.IDictBizService;
import org.springblade.modules.system.service.IDictService;
import org.springblade.system.orgposition.entity.OrgPosition;
import org.springblade.system.orgposition.service.IOrgPositionService;
import org.springblade.utils.AESPlus;
import org.springblade.utils.CustInfoVerifyUtil;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 住户表 控制器
 *
 * @author BladeX
 * @since 2020-10-18
 */
@RestController
@AllArgsConstructor
@RequestMapping("community/houseuser")
@Api(value = "住户表", tags = "住户表接口")
public class HouseuserController extends BladeController {

	private IHouseuserService houseuserService;
	private IThirdHouseUserService thirdHouseUserService;
	private IRoomService roomService;
	private IUnitService unitService;
	private IResidentialService residentialService;
	private IBuildingService buildingService;
	private IFloorService floorService;
	private IAgencyService agencyService;
	private IOrgPositionService orgPositionService;
	private CustInfoVerifyUtil custInfoVerifyUtil;
	private IDictService dictService;
	private IDictBizService dictBizService;
	private ICarService carService;
	private IHouseuserDetailService houseuserDetailService;

	/**
	 * 获取同一房间下所有住户
	 */
	@GetMapping("/getUsersByRoomId")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入houseuser")
	public R getUsersByRoomId(Long roomId) {
		Houseuser houseuser = new Houseuser();
		houseuser.setRoomId(roomId);
		List<Houseuser> list = houseuserService.list(Condition.getQueryWrapper(houseuser));
		return R.data(list);
	}

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入houseuser")
	public R<HouseuserVO> detail(HouseuserDTO houseuserDTO) {
		Houseuser detail = houseuserService.getOne(Condition.getQueryWrapper(houseuserDTO));
		if(houseuserDTO.getViewOrEdit().equals("view")){
			return R.data(HouseuserWrapper.build().entityVO(detail));
		}else{
			return R.data(HouseuserWrapper.build().editEntityVO(detail));
		}
	}

	/**
	 +	 * 详情未脱敏
	 +	 */
	@GetMapping("/getOne")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "详情", notes = "传入houseuser")
	public R<Houseuser> getOne(Houseuser houseuser) {
		Houseuser detail = houseuserService.getOne(Condition.getQueryWrapper(houseuser));
		return R.data(detail);
	}

	/**
	 * 分页 住户表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入houseuser")
	public R<IPage<HouseuserVO>> list(Houseuser houseuser, Query query) {
		IPage<Houseuser> pages = houseuserService.page(Condition.getPage(query), Condition.getQueryWrapper(houseuser));
		return R.data(HouseuserWrapper.build().pageVO(pages));
	}

	/**
	 * 分页 住户表--隐藏敏感信息
	 */
	@GetMapping("/desensitizeList")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "分页", notes = "传入houseuser")
	public R<IPage<HouseuserVO>> desensitizeList(@RequestParam Map<String,Object> houseuser, Query query, BladeUser bladeUser) {
		String deptId = bladeUser.getDeptId();
		String[] deptIds = deptId.split(",");
		LambdaQueryWrapper<Houseuser> wrapper = Condition.getQueryWrapper(houseuser,Houseuser.class).lambda();
		for(int i=0;i<deptIds.length;i++){
			OrgPosition orgPosition = orgPositionService.getOne(new QueryWrapper<>(new OrgPosition()).lambda().eq(OrgPosition::getOrgId,deptIds[i]));
			if(i ==0){
				wrapper.like(Houseuser::getOrgPosition,orgPosition.getOrgPosition());
			}else{
				wrapper.or().like(Houseuser::getOrgPosition,orgPosition.getOrgPosition());
			}
		}

		IPage<Houseuser> pages = houseuserService.page(Condition.getPage(query),wrapper);
		return R.data(HouseuserWrapper.build().pageVO(pages));
	}

	/**
	 * 自定义分页 住户表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入houseuser")
	public R<IPage<HouseuserVO>> page(HouseuserVO houseuser, Query query) {
		IPage<HouseuserVO> pages = houseuserService.selectHouseuserPage(Condition.getPage(query), houseuser);
		return R.data(pages);
	}

	/**
	 * 新增 住户表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入houseuser")
	@Transactional
	public R save(@Valid @RequestBody Houseuser houseuser) {
		String idCard = houseuser.getIdCard();
		if(StringUtil.isNotBlank(idCard)){
			Boolean verify = custInfoVerifyUtil.verify(houseuser.getIdCard(), houseuser.getName(), "1");
			if(!verify){
				return R.fail("身份证验证失败，请填写正确的身份证信息");
			}
		}
		Room room = this.roomService.getById(houseuser.getRoomId());
		room.setUserNumber(room.getUserNumber()+1);
		this.roomService.updateById(room);
		Residential residential = this.residentialService.getById(houseuser.getResidentialId());
		residential.setUserNumber(residential.getUserNumber()+1);
		this.residentialService.updateById(residential);
//		Agency agency = this.agencyService.getById(houseuser.getAgencyId());
//		agency.setPersonCount(agency.getPersonCount()+1);
//		this.agencyService.updateById(agency);
		return R.status(houseuserService.save(houseuser));
	}

	/**
	 * 修改 住户表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入houseuser")
	public R update(@Valid @RequestBody Houseuser houseuser) {
		return R.status(houseuserService.updateById(houseuser));
	}

	/**
	 * 新增或修改 住户表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入houseuser")
	public R submit(@Valid @RequestBody HouseuserVO houseuser) {

		HouseuserDetail detail = houseuser.getDetail();
		HouseuserDetail houseuserDetail = houseuserDetailService.getBaseMapper().selectOne(new QueryWrapper<>(new HouseuserDetail()).lambda().eq(HouseuserDetail::getPersonId, houseuser.getId()));
		if (houseuserDetail != null){
			detail.setId(houseuserDetail.getId());
		}
		if (houseuser.getId() == null){
			Residential residential = residentialService.getById(houseuser.getResidentialId());
			Agency agency = agencyService.getById(residential.getAgencyId());
			Building building = buildingService.getById(houseuser.getBuildingId());
			Unit unit = unitService.getById(houseuser.getUnitId());
			Room room = roomService.getById(houseuser.getRoomId());
			Floor floor = floorService.getById(room.getFloorId());

			houseuser.setAgencyId(agency.getId());
			houseuser.setAgencyName(agency.getAgencyName());
			houseuser.setResidentialName(residential.getName());
			houseuser.setBuildingName(building.getName());
			houseuser.setUnitName(unit.getName());
			houseuser.setFloorId(floor.getId());
			houseuser.setFloorName(floor.getName());
			houseuser.setRoomName(room.getName());

			houseuser.setRegionArea(residential.getRegionArea());
			houseuser.setRegionCity(residential.getRegionCity());
			houseuser.setRegionProvince(residential.getRegionProvince());

			houseuserService.save(houseuser);
			detail.setPersonId(houseuser.getId());
			houseuser.setOrgPosition(residential.getOrgPosition() + "/" + houseuser.getId());
		}
		houseuserService.updateById(houseuser);
		detail.setPersonId(houseuser.getId());
		return R.status(houseuserDetailService.saveOrUpdate(detail));
	}


	/**
	 * 删除 住户表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	@Transactional
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		Arrays.stream(ids.split(",")).forEach(id ->{
			Houseuser houseuser = this.houseuserService.getById(id);
			Room room = this.roomService.getById(houseuser.getRoomId());
			room.setUserNumber(room.getUserNumber()-1);
			this.roomService.updateById(room);
			Residential residential = this.residentialService.getById(houseuser.getResidentialId());
			residential.setUserNumber(residential.getUserNumber()-1);
			this.residentialService.updateById(residential);
			Agency agency = this.agencyService.getById(houseuser.getAgencyId());
			agency.setPersonCount(agency.getPersonCount()-1);
			this.agencyService.updateById(agency);
		});
		return R.status(houseuserService.deletePhysical(Func.toLongList(ids)));
	}

	/**
	 * 分页 老人
	 */
	@GetMapping("/elderlyList")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "分页", notes = "传入houseuser")
	public R<IPage<Houseuser>> elderlyList(Houseuser houseuser, Query query) {
		IPage<Houseuser> pages = houseuserService.page(Condition.getPage(query), Condition.getQueryWrapper(houseuser).lambda().notIn(Houseuser::getElderlyType,0));
		return R.data(pages);
	}

	/**
	 * 分页 老人
	 */
	@GetMapping("/desensitizeElderly")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "分页", notes = "传入houseuser")
	public R<IPage<HouseuserVO>> desensitizeElderly(Houseuser houseuser, Query query) {
		IPage<Houseuser> pages = houseuserService.page(Condition.getPage(query), Condition.getQueryWrapper(houseuser).lambda().notIn(Houseuser::getElderlyType,0));
		return R.data(HouseuserWrapper.build().pageVO(pages));
	}

	/**
	 * 设置orgPosition
	 */
	@GetMapping("/setOrgPosition")
	@ApiOperationSupport(order = 10)
	@ApiOperation(value = "设置orgPosition", notes = "传入houseuser")
	public R setOrgPosition() {
		List<Houseuser> houseusers = houseuserService.getBaseMapper().selectList(new QueryWrapper<>(new Houseuser()));
		houseusers.parallelStream().forEach(houseuser -> {
			Residential residential = residentialService.getById(houseuser.getResidentialId());
			houseuser.setOrgPosition(residential.getOrgPosition()+"/"+houseuser.getId());
			houseuserService.updateById(houseuser);

		});
		return new R();
	}

	@GetMapping("/convertToHouseUser")
	@ApiOperationSupport(order = 11)
	@ApiOperation(value = "转化成住户", notes = "")
	public R convertToHouseUser() {
		List<ThirdHouseUser> thirdHouseUsers = thirdHouseUserService.getBaseMapper().selectList(new QueryWrapper<>(new ThirdHouseUser()).lambda().eq(ThirdHouseUser::getProcessed, 0));

		List<ThirdHouseUser> list = new ArrayList<>();

		thirdHouseUsers.parallelStream().forEach(thirdHouseUser -> {
			String name = thirdHouseUser.getName();
			String idcard = thirdHouseUser.getIdcard();
//		String agencyName = thirdHouseUser.getAgencyName();
			String residentialName = thirdHouseUser.getResidentialName();
			String houseInfo = thirdHouseUser.getHouseInfo();
			if (houseInfo == null || !houseInfo.contains("-")){
				thirdHouseUser.setErrorMsg("找不到该用户的房屋信息或房屋信息异常");
//				添加到list，最后批量更新
				list.add(thirdHouseUser);
				thirdHouseUserService.updateById(thirdHouseUser);
				return;
			}
			String[] houseMsg = houseInfo.split("-");
			String buildingName;
			if (houseInfo.contains("52-") || houseInfo.contains("53-")){
				buildingName = "营业房" + houseMsg[houseMsg.length - 3] + "栋";
			}else{
				buildingName = houseMsg[houseMsg.length - 3] + "栋";
			}
			String unitName = houseMsg[houseMsg.length - 2] + "单元";
			String roomName = houseMsg[houseMsg.length - 1];
			String floorName = roomName.substring(0, roomName.length() - 2) + "层";

			Residential residential = residentialService.getBaseMapper().selectOne(new QueryWrapper<>(new Residential()).lambda().eq(Residential::getName, residentialName));
			if (residential == null){
				thirdHouseUser.setErrorMsg("找不到该小区-" + residentialName);
//			添加到list，最后批量更新
				list.add(thirdHouseUser);
				thirdHouseUserService.updateById(thirdHouseUser);
				return;
			}

			Agency agency = agencyService.getById(residential.getAgencyId());

			Building building = buildingService.getBaseMapper().selectOne(new QueryWrapper<>(new Building()).lambda().eq(Building::getName, buildingName)
				.eq(Building::getResidentialId, residential.getId()));
			if (building == null){
				thirdHouseUser.setErrorMsg("找不到该楼栋-" + buildingName);
//			添加到list，最后批量更新
				list.add(thirdHouseUser);
				thirdHouseUserService.updateById(thirdHouseUser);
				return;
			}
			Unit unit = unitService.getBaseMapper().selectOne(new QueryWrapper<>(new Unit()).lambda().eq(Unit::getResidentialId, residential.getId())
				.eq(Unit::getBuildingId, building.getId())
				.eq(Unit::getName, unitName));
			if (unit == null){
				thirdHouseUser.setErrorMsg("找不到该单元-" + houseInfo);
//			添加到list，最后批量更新
				list.add(thirdHouseUser);
				thirdHouseUserService.updateById(thirdHouseUser);
				return;
			}
			Floor floor = floorService.getBaseMapper().selectOne(new QueryWrapper<>(new Floor()).lambda().eq(Floor::getResidentialId, residential.getId())
				.eq(Floor::getBuildingId, building.getId()).eq(Floor::getUnitId, unit.getId()).eq(Floor::getName, floorName));
			if (floor == null){
				thirdHouseUser.setErrorMsg("找不到该楼层-" + houseInfo);
//			添加到list，最后批量更新
				list.add(thirdHouseUser);
				thirdHouseUserService.updateById(thirdHouseUser);
				return;
			}
			Room room = roomService.getBaseMapper().selectOne(new QueryWrapper<>(new Room()).lambda().eq(Room::getResidentialId, residential.getId())
				.eq(Room::getBuildingId, building.getId()).eq(Room::getUnitId, unit.getId()).eq(Room::getFloorId, floor.getId())
				.eq(Room::getName, roomName));
			if (room == null){
				thirdHouseUser.setErrorMsg("找不到该房屋-" + houseInfo);
//			添加到list，最后批量更新
				list.add(thirdHouseUser);
				thirdHouseUserService.updateById(thirdHouseUser);
				return;
			}

			Houseuser houseuser = houseuserService.getBaseMapper().selectOne(new QueryWrapper<>(new Houseuser()).lambda().eq(Houseuser::getName, name)
				.eq(Houseuser::getIdCard, idcard).eq(Houseuser::getResidentialId, residential.getId())
				.eq(Houseuser::getBuildingId, building.getId()).eq(Houseuser::getUnitId, unit.getId())
				.eq(Houseuser::getFloorId, floor.getId()).eq(Houseuser::getRoomId, room.getId()));
			if (houseuser == null){
				houseuser = new Houseuser();
				houseuser.setName(thirdHouseUser.getName());
				houseuser.setIdCard(thirdHouseUser.getIdcard());
				houseuser.setAgencyId(agency.getId());
				houseuser.setResidentialId(residential.getId());
				houseuser.setBuildingId(building.getId());
				houseuser.setUnitId(unit.getId());
				houseuser.setFloorId(floor.getId());
				houseuser.setRoomId(room.getId());
				houseuser.setRegionProvince(residential.getRegionProvince());
				houseuser.setRegionCity(residential.getRegionCity());
				houseuser.setRegionArea(residential.getRegionArea());
				houseuser.setType(1);//常住人员
			}
			houseuser.setAgencyName(agency.getAgencyName());
			houseuser.setResidentialName(residential.getName());
			houseuser.setBuildingName(building.getName());
			houseuser.setUnitName(unit.getName());
			houseuser.setFloorName(floor.getName());
			houseuser.setRoomName(room.getName());
			houseuser.setTel(thirdHouseUser.getTel());
			houseuser.setPersonType(1); // 常住

			Dict sexDict = dictService.getBaseMapper().selectOne(new QueryWrapper<>(new Dict()).lambda().eq(Dict::getCode, "sex").eq(Dict::getDictValue, thirdHouseUser.getSex().trim()));
			if (sexDict != null){
				houseuser.setSex(Integer.valueOf(sexDict.getDictKey()));
			}

			if ("户主".equals(thirdHouseUser.getRelationship())){
				houseuser.setType(1); // 业主
			}

			if (houseuser.getId() == null){
				houseuserService.save(houseuser);
			}
			houseuser.setOrgPosition(residential.getOrgPosition() + "/" + houseuser.getId());
			houseuserService.updateById(houseuser);

			houseuser = thirdToUser(thirdHouseUser, houseuser);

			thirdHouseUser.setProcessed(1);
			list.add(thirdHouseUser);
			thirdHouseUserService.updateById(thirdHouseUser);
		});

		if (list.size() > 0){
			thirdHouseUserService.updateBatchById(list);
		}

		return R.status(true);
	}

	private Houseuser thirdToUser(ThirdHouseUser thirdHouseUser, Houseuser houseuser) {

		HouseuserDetail detail = houseuserDetailService.getBaseMapper().selectOne(new QueryWrapper<>(new HouseuserDetail()).lambda().eq(HouseuserDetail::getPersonId, houseuser.getId()));
		if (detail == null){
			detail = new HouseuserDetail();
		}

		detail.setPersonId(houseuser.getId());
		try {
			//民族
			String nation = thirdHouseUser.getNation();
			nation= nation.contains("族") ? nation : nation + "族";
			Dict nationDict = dictService.getBaseMapper().selectOne(new QueryWrapper<>(new Dict()).lambda().eq(Dict::getCode, "nation").eq(Dict::getDictValue, nation));
			if (nationDict != null){
				detail.setNation(Integer.valueOf(nationDict.getDictKey()));
			}
//文化程度
			Dict educationDict = dictService.getBaseMapper().selectOne(new QueryWrapper<>(new Dict()).lambda().eq(Dict::getCode, "education").like(Dict::getDictValue, thirdHouseUser.getEducation()));
			if (nationDict != null){
				detail.setEducation(Integer.valueOf(educationDict.getDictKey()));
			}
//政治面貌
			Dict politicalDict = dictService.getBaseMapper().selectOne(new QueryWrapper<>(new Dict()).lambda().eq(Dict::getCode, "political").eq(Dict::getDictValue, thirdHouseUser.getPolitical()));
			if (nationDict != null){
				detail.setPolitical(Integer.valueOf(politicalDict.getDictKey()));
			}
//国籍
			DictBiz nationalityDict = dictBizService.getBaseMapper().selectOne(new QueryWrapper<>(new DictBiz()).lambda().eq(DictBiz::getCode, "nationality").eq(DictBiz::getDictValue, thirdHouseUser.getNationality()));
			if (nationDict != null){
				detail.setNationality(Integer.valueOf(nationalityDict.getDictKey()));
			}
//婚姻状况
			DictBiz maritalDict = dictBizService.getBaseMapper().selectOne(new QueryWrapper<>(new DictBiz()).lambda().eq(DictBiz::getCode, "marital").eq(DictBiz::getDictValue, thirdHouseUser.getMaritalStatus()));
			if (nationDict != null){
				detail.setMaritalStatus(Integer.valueOf(maritalDict.getDictKey()));
			}
		}catch (Exception e){
			System.out.println("报错" + e.getMessage());
		}


		detail.setOccupation(thirdHouseUser.getOccupation());
		detail.setRelationship(thirdHouseUser.getRelationship());
		detail.setNativePlace(thirdHouseUser.getNativePlace());
		detail.setAddress(thirdHouseUser.getAddress());
		detail.setWorkplace(thirdHouseUser.getWorkplace());

		detail.setIsFile("是".equals(thirdHouseUser.getIsFile()) ? 1 : 0);
		detail.setWubao("是".equals(thirdHouseUser.getWubao()) ? 1 : 0);
		detail.setDibao("是".equals(thirdHouseUser.getDibao()) ? 1 : 0);
		detail.setCanji("是".equals(thirdHouseUser.getCanji()) ? 1 : 0);
		detail.setGuer("是".equals(thirdHouseUser.getGuer()) ? 1 : 0);
		detail.setYoufu("是".equals(thirdHouseUser.getYoufu()) ? 1 : 0);

		detail.setRemark(thirdHouseUser.getRemark());

		houseuserDetailService.saveOrUpdate(detail);

		if (thirdHouseUser.getCarNo() != null && StringUtils.isNotBlank(thirdHouseUser.getCarNo())){
			Car car = carService.getBaseMapper().selectOne(new QueryWrapper<>(new Car()).lambda().eq(Car::getNumber, thirdHouseUser.getCarNo()));
			if (car == null){
				car = new Car();
			}
			car.setNumber(thirdHouseUser.getCarNo());
			car.setPersonId(houseuser.getId());
			car.setPersonName(thirdHouseUser.getName());
			car.setPersonPhone(thirdHouseUser.getTel());
			car.setType(0);// 轿车
			carService.saveOrUpdate(car);
		}
		if (thirdHouseUser.getCarNoTruck() != null && StringUtils.isNotBlank(thirdHouseUser.getCarNoTruck())){
			Car car = carService.getBaseMapper().selectOne(new QueryWrapper<>(new Car()).lambda().eq(Car::getNumber, thirdHouseUser.getCarNo()));
			if (car == null){
				car = new Car();
			}
			car.setNumber(thirdHouseUser.getCarNoTruck());
			car.setPersonId(houseuser.getId());
			car.setPersonName(thirdHouseUser.getName());
			car.setPersonPhone(thirdHouseUser.getTel());
			car.setType(1);// 货车
			carService.saveOrUpdate(car);
		}

		return houseuser;
	}

	/**
	 * 分页 住户表
	 */
	@GetMapping("/searchList")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入houseuser")
	public R<IPage<Houseuser>> searchList(Houseuser houseuser, Query query) {
		try {
			if(StringUtil.isNotBlank(houseuser.getName())){
				houseuser.setName(AESPlus.encrypt(Constants.encryptKey, houseuser.getName()));
			}
		}catch (Exception e){

		}
		IPage<Houseuser> pages = houseuserService.page(Condition.getPage(query), Condition.getQueryWrapper(houseuser));
		return R.data(pages);
	}

	public static void main(String[] params){
		try {
//			enterpriseStaff.setRealName(AESPlus.encrypt(Constants.encryptKey, enterpriseStaff.getRealName()));
//			enterpriseStaff.setPhone(AESPlus.encrypt(Constants.encryptKey, enterpriseStaff.getPhone()));
//			enterpriseStaff.setEmail(AESPlus.encrypt(Constants.encryptKey, enterpriseStaff.getEmail()));
//			enterpriseStaff.setIdcard(AESPlus.encrypt(Constants.encryptKey, enterpriseStaff.getIdcard()));
		} catch (Exception e) {
			e.printStackTrace();
//			log.error(e.getMessage());
		}
	}

}
