package org.springblade.modules.rhzf.fwInfo.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springblade.common.controller.vo.webService.WebServiceVO;
import org.springblade.common.controller.vo.webService.YwxxVO;
import org.springblade.common.utils.ExportWordUtil;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.jwt.JwtUtil;
import org.springblade.core.jwt.props.JwtProperties;
import org.springblade.core.launch.constant.TokenConstant;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.modules.externalLog.entity.ExternalLogEntity;
import org.springblade.modules.externalLog.service.IExternalLogService;
import org.springblade.modules.fjInfo.service.IFjInfoService;
import org.springblade.modules.jgInfo.service.IJgInfoService;
import org.springblade.modules.log.rhzfCzrk.entity.RhzfCzrkEntity;
import org.springblade.modules.log.rhzfCzrk.service.IRhzfCzrkService;
import org.springblade.modules.log.rhzfFw.entity.RhzfFwEntity;
import org.springblade.modules.log.rhzfFw.service.IRhzfFwService;
import org.springblade.modules.log.rhzfFz.entity.RhzfFzEntity;
import org.springblade.modules.log.rhzfFz.service.IRhzfFzService;
import org.springblade.modules.log.rhzfJwrk.entity.RhzfJwrkEntity;
import org.springblade.modules.log.rhzfJwrk.service.IRhzfJwrkService;
import org.springblade.modules.log.rhzfJzrk.entity.RhzfJzrkEntity;
import org.springblade.modules.log.rhzfJzrk.service.IRhzfJzrkService;
import org.springblade.modules.log.rhzfWlrk.entity.RhzfWlrkEntity;
import org.springblade.modules.log.rhzfWlrk.service.IRhzfWlrkService;
import org.springblade.modules.log.rhzfZzrk.entity.RhzfZzrkEntity;
import org.springblade.modules.log.rhzfZzrk.service.IRhzfZzrkService;
import org.springblade.modules.mdjfdj.entity.MdjfDjEntity;
import org.springblade.modules.mdjfdj.service.IMdjfDjService;
import org.springblade.modules.mdjfry.entity.MdjfRyEntity;
import org.springblade.modules.mdjfry.service.IMdjfRyService;
import org.springblade.modules.rhzf.aqxcff.pojo.entity.RhzfAqxcffEntity;
import org.springblade.modules.rhzf.aqxcff.service.IRhzfAqxcffService;
import org.springblade.modules.rhzf.fwFz.entity.FwFzEntity;
import org.springblade.modules.rhzf.fwFz.service.IFwFzService;
import org.springblade.modules.rhzf.fwInfo.entity.FwInfoEntity;
import org.springblade.modules.rhzf.fwInfo.entity.Fwccjgb;
import org.springblade.modules.rhzf.fwInfo.entity.HcbdEntity;
import org.springblade.modules.rhzf.fwInfo.excel.FwInfoExcel;
import org.springblade.modules.rhzf.fwInfo.excel.HcbdExcel;
import org.springblade.modules.rhzf.fwInfo.excel.HcbdsExcel;
import org.springblade.modules.rhzf.fwInfo.service.HcbdService;
import org.springblade.modules.rhzf.fwInfo.service.IFwInfoService;
import org.springblade.modules.rhzf.fwInfo.util.GsonUtil;
import org.springblade.modules.rhzf.fwInfo.util.GsonUtils;
import org.springblade.modules.rhzf.fwInfo.vo.FjVO;
import org.springblade.modules.rhzf.fwInfo.vo.*;
import org.springblade.modules.rhzf.fwInfo.wrapper.FwInfoWrapper;
import org.springblade.modules.rhzf.fwRy.entity.FwRyEntity;
import org.springblade.modules.rhzf.fwRy.service.IFwRyService;
import org.springblade.modules.rhzf.fwRy.vo.FwRyVO;
import org.springblade.modules.rhzf.fwqz.pojo.entity.RhzfFwqzEntity;
import org.springblade.modules.rhzf.fwqz.service.IRhzfFwqzService;
import org.springblade.modules.rhzf.gzyj.pojo.entity.RhzfGzyjEntity;
import org.springblade.modules.rhzf.gzyj.service.IRhzfGzyjService;
import org.springblade.modules.rhzf.jxcs.entity.JxcsEntity;
import org.springblade.modules.rhzf.jxcs.service.IJxcsService;
import org.springblade.modules.rhzf.jxcs.vo.JxcsVO;
import org.springblade.modules.rhzf.ryCzrk.entity.RyCzrkEntity;
import org.springblade.modules.rhzf.ryCzrk.service.IRyCzrkService;
import org.springblade.modules.rhzf.ryJwrk.entity.RyJwrkEntity;
import org.springblade.modules.rhzf.ryJwrk.service.IRyJwrkService;
import org.springblade.modules.rhzf.ryJzrk.entity.RyJzrkEntity;
import org.springblade.modules.rhzf.ryJzrk.service.IRyJzrkService;
import org.springblade.modules.rhzf.ryWlrk.entity.RyWlrkEntity;
import org.springblade.modules.rhzf.ryWlrk.service.IRyWlrkService;
import org.springblade.modules.rhzf.ryZzrk.entity.RyZzrkEntity;
import org.springblade.modules.rhzf.ryZzrk.service.IRyZzrkService;
import org.springblade.modules.rhzf.wtfy.pojo.entity.RhzfWtfyEntity;
import org.springblade.modules.rhzf.wtfy.service.IRhzfWtfyService;
import org.springblade.modules.sqjw.sydw.pojo.entity.SydwEntity;
import org.springblade.modules.sqjw.sydw.pojo.vo.HylxVO;
import org.springblade.modules.sqjw.sydw.service.SydwService;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IDeptService;
import org.springblade.modules.system.service.IDictBizService;
import org.springblade.modules.system.service.IRegionService;
import org.springblade.modules.system.service.IUserService;
import org.springblade.modules.system.vo.*;
import org.springblade.modules.zdb.entity.ZdbEntity;
import org.springblade.modules.zdb.service.IZdbService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 入户走访_房屋_基本信息 控制器
 *
 * @author BladeX
 * @since 2023-11-14
 */
@RestController
@AllArgsConstructor
@Slf4j
@RequestMapping("blade-fwInfo/fwInfo")
@Api(value = "入户走访_房屋_基本信息", tags = "入户走访_房屋_基本信息接口")
public class FwInfoController extends BladeController {

	private final IFwInfoService fwInfoService;

	private final IFwFzService fwFzService;

	private final IFwRyService fwRyService;

	private final IRyCzrkService czrkService;

	private final IRyJwrkService jwrkService;

	private final IRyJzrkService jzrkService;

	private final IRyWlrkService wlrkService;

	private final IRyZzrkService zzrkService;

	private final IJxcsService jxcsService;

	private final IRhzfFwqzService fwqzService;

	private final IRhzfGzyjService gzyjService;

	private final IRhzfWtfyService wtfyService;

	private final IRhzfAqxcffService aqxcffService;

	private final IDictBizService dictService;

	private final IRegionService regionService;

	private final IUserService userService;

	private final IMdjfDjService mdjfDjService;

	private final IMdjfRyService mdjfRyService;

	private final IDeptService deptService;

	private final IZdbService zdbService;

	private final IExternalLogService logService;

	private final IRhzfFwService fwLogService;

	private final IRhzfFzService fzLogService;

	private final IRhzfCzrkService czrkLogService;

	private final IRhzfZzrkService zzrkLogService;

	private final IRhzfWlrkService wlrkLogService;

	private final IRhzfJwrkService jwrkLogService;

	private final IRhzfJzrkService jzrkLogService;

	private final IFjInfoService fjInfoService;

	private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	private final JwtProperties jwtProperties;

	private final IJgInfoService jgInfoService;

	private final HcbdService hcbdService;

	private final SydwService sydwService;

	/**
	 * 入户走访_房屋_基本信息 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入fwInfo")
	public R<FwInfoVO> detail(FwInfoEntity fwInfo) {
		FwInfoEntity detail = fwInfoService.getOne(Condition.getQueryWrapper(fwInfo));
		return R.data(FwInfoWrapper.build().entityVO(detail));
	}

	/**
	 * 入户走访_房屋_基本信息 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入fwInfo")
	public R<IPage<FwInfoVO>> list(@ApiIgnore @RequestParam Map<String, Object> fwInfo, Query query) {
		IPage<FwInfoEntity> pages = fwInfoService.page(Condition.getPage(query), Condition.getQueryWrapper(fwInfo, FwInfoEntity.class));
		return R.data(FwInfoWrapper.build().pageVO(pages));
	}

	/**
	 * 入户走访_房屋_基本信息 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入fwInfo")
	public R<IPage<FwInfoVO>> page(FwInfoVO fwInfo, Query query) {
		fwInfo.setDeptId(AuthUtil.getDeptId());
		List<FwInfoVO> list = fwInfoService.getMphxlhByLdphxlh(fwInfo.getLdphxlh());
		if (list.size() > 0) {
			IPage<FwInfoVO> page = new Page<>();
			List<FwInfoVO> fwList = new ArrayList<>();
			for (FwInfoVO fwInfoVO:list) {
				FwInfoVO fw = fwInfoService.selectFwInfo(fwInfo, fwInfoVO.getDzbm());
				if (fw != null) {
					fwList.add(fw);
				}
			}
			List<FwInfoVO> subList = fwList.stream().skip((query.getCurrent() - 1) * query.getSize()).limit(query.getSize()).collect(Collectors.toList());
			page.setRecords(subList).setTotal(fwList.size()).setSize(query.getSize()).setCurrent(query.getCurrent());
			return R.data(page);
		}
		IPage<FwInfoVO> pages = fwInfoService.selectFwInfoPage(Condition.getPage(query), fwInfo);
		return R.data(pages);
	}

	/**
	 * 入户走访_走访历史
	 */
	@GetMapping("/history")
	public R history(@RequestParam Map<String, Object> params, Query query) {
		params.put("deptId", AuthUtil.getDeptId());
		IPage<RhzfHistoryVO> pages = fwInfoService.history(Condition.getPage(query), params);
		return R.data(pages);
	}

	/**
	 * 入户走访_房屋_基本信息 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入fwInfo")
	public R save(@Valid @RequestBody FwInfoEntity fwInfo) {
		if (fwInfo.getDzType() == 2) {
			fwInfo.setDyh("平房");
			fwInfo.setLch(1);
		}
		int fjExist = fwInfoService.getFjNum(fwInfo);
		if (fjExist >= 1) {
			return R.fail("房间重复，添加失败");
		}
		return R.status(fwInfoService.save(fwInfo));
	}

	/**
	 * 查询全国人口信息
	 */
	@GetMapping("/getRyxxBySfzh")
	public R getRyxxBySfzh (@RequestParam Map<String, Object> params) {
		WebServiceVO webServiceVO = getParams("rkxx", "查询全国人口信息");
		webServiceVO.getYWXX().setRksfzh(params.get("rksfzh").toString());
		String result = fwInfoService.getCzrkInfo(webServiceVO);
//		String result = "{\"message\":\"操作成功\",\"data\":{\"rkxxList\":[{\"cym\":\"\",\"cyzk_dwmc\":\"\",\"xm\":\"魏斌\",\"sjgsdwdm\":\"220106663000\",\"hjdz_qhnxxdz\":\"正阳街道和平大街委88组\",\"hh\":\"012653237\",\"sjgsdwmc\":\"长春市和平大街派出所\",\"sg\":\"176\",\"hjdz_ssxqdm\":\"220106\",\"rk_jbxxly\":\"2\",\"cyzk_zy\":\"\",\"zjxydm\":\"00\",\"xbdm\":\"1\",\"hyzkdm\":\"20\",\"gmsfhm\":\"220105198510200016\",\"lxdh\":\"15604300035\",\"xldm\":\"70\",\"byzkdm\":\"0\",\"csrq\":\"19851020\",\"mzdm\":\"01\",\"jrbz\":\"0\",\"xxdm\":\"\"}],\"RecordCount\":1},\"code\":\"200\"}";
		saveExternalLog("getRyxxBySfzh", JSONObject.toJSONString(webServiceVO, false), result);

		List<RkxxVO> rkxxList = new ArrayList<>();
		try {
			JSONObject resultJson = JSONObject.parseObject(result);
			String data = resultJson.getString("data");
			JSONObject dataJson = JSONObject.parseObject(data);
			String rkxxListStr = dataJson.getString("rkxxList");
			rkxxList = JSONObject.parseArray(rkxxListStr, RkxxVO.class);
			for (RkxxVO rkxx : rkxxList) {
				rkxx.setZjxy(dictService.getValue("zjxy", rkxx.getZjxydm()));
				rkxx.setHyzk(dictService.getValue("hyzk", rkxx.getHyzkdm()));
				rkxx.setXl(dictService.getValue("whcd", rkxx.getXldm()));
				rkxx.setByzk(dictService.getValue("byzk", rkxx.getByzkdm()));
				rkxx.setMz(dictService.getValue("mz", rkxx.getMzdm()));
				rkxx.setXx(dictService.getValue("xx", rkxx.getXxdm()));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return R.data(rkxxList);
	}

	public WebServiceVO getParams (String ywlb, String ywmc) {
		WebServiceVO webServiceVO = new WebServiceVO();
		try {
			YwxxVO ywxxVO = fwInfoService.getYwxxParams(AuthUtil.getUserId());
			webServiceVO.getUSERINFO().setORG_CODE(ywxxVO.getGajgdm());
			webServiceVO.getUSERINFO().setORG_NAME(ywxxVO.getGajgmc());
			webServiceVO.getUSERINFO().setACCOUNT_ID(AuthUtil.getUserAccount());
			webServiceVO.getUSERINFO().setIp(InetAddress.getLocalHost().getHostAddress());
			webServiceVO.getYWXX().setYwlb(ywlb); // 业务类别，jzw查询民警名下建筑物、dzxx查询建筑物下地址及房屋、jzcs查询房屋已装户人员信息
			webServiceVO.getYWXX().setYwmc(ywmc); // 业务类别名称 jzw查询建筑物、dzxx查询地址及房屋、jzcs查询实有人口
			webServiceVO.getYWXX().setDqm(ywxxVO.getDqm().equals("220581") ? "220500" : ywxxVO.getDqm()); // 地区码 (市局代码截取前6位)
			webServiceVO.getYWXX().setGajgdm(ywxxVO.getGajgdm()); // 数据归属单位代码 (12位)
			webServiceVO.getYWXX().setPcsdm(""); // 数据归属派出所代码 (9位)
			webServiceVO.getYWXX().setGajgmc(ywxxVO.getGajgmc()); // 数据归属单位名称
			webServiceVO.getYWXX().setYhjh(AuthUtil.getUserAccount()); // 数据管理民警警号
			webServiceVO.getYWXX().setYhmc(AuthUtil.getNickName()); // 数据管理民警姓名
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return webServiceVO;
	}

	public void saveExternalLog(String method, String requestParams, String responseBody) {
		ExternalLogEntity externalLog = new ExternalLogEntity();
		externalLog.setMethod(method);
		externalLog.setRequestParams(requestParams);
		externalLog.setResponseBody(responseBody);
		logService.save(externalLog);
	}

	/**
	 * 查询在逃人员
	 */
	@GetMapping("/getZtry")
	public R getZtry(String rksfzh) {
		WebServiceVO webServiceVO = getParams("ztry", "查询在逃人员信息");
		webServiceVO.getYWXX().setRksfzh(rksfzh);
		String result = fwInfoService.getCzrkInfo(webServiceVO);
//		String result = "{\"code\":\"200\",\"data\":{\"ztryList\":[{\"xssxqmc\":\"吉林省洮南市\",\"bm\":\"\",\"hjdzxz\":\"万宝镇前进村雷振廷屯\",\"hjssxqmc\":\"吉林省洮南市\",\"gmsfhm\":\"220881196207026014\",\"xm\":\"曹振海\",\"xbmc\":\"男\",\"qscsrq\":\"19620702\",\"jzcsrq\":\"19620702\",\"xzzxz\":\"万宝镇前进村雷振廷屯\",\"mzmc\":\"蒙古族\",\"rybh\":\"T2102020419992002100090\"}],\"RecordCount\":0},\"message\":\"操作成功\"}\n";
		saveExternalLog("getZtry", JSONObject.toJSONString(webServiceVO, false), result);
		String recordCount = "";
		try {
			JSONObject resultJson = JSONObject.parseObject(result);
			String data = resultJson.getString("data");
			JSONObject dataJson = JSONObject.parseObject(data);
			recordCount = dataJson.getString("RecordCount");
		} catch (Exception e) {
			log.error("rksfzh==" + rksfzh + "，在逃人员无数据");
		}
		return R.data(recordCount);
//		return R.data("");
	}

	/**
	 * 入户走访_列表
	 */
	@GetMapping("/getLdList-app")
	public R getLdListApp(@RequestParam Map<String, Object> params, Query query) {
		YwxxVO ywxxVO = fwInfoService.getYwxxParams(AuthUtil.getUserId());
		if (!AuthUtil.getDeptId().equals(ywxxVO.getDeptId())) {
			// 踢出
			BladeUser user = AuthUtil.getUser();
			if (user != null && jwtProperties.getState()) {
				String token = JwtUtil.getToken(WebUtil.getRequest().getHeader(TokenConstant.HEADER));
				JwtUtil.removeAccessToken(user.getTenantId(), String.valueOf(user.getUserId()), token);
			}
			return R.fail("用户所属部门有变动，请重新登录");
		}
		String gajgdm = ywxxVO.getGajgdm();
		if (StringUtils.isBlank(gajgdm)) {
			return R.fail("当前账号所属部门不正确");
		}
		List<LdBzdzVO> ldList = new ArrayList<>();
		if (StringUtils.isBlank(ywxxVO.getJh())) {
			return R.fail("该警号在三实平台中非社区民警，无法进行入户走访");
		}
		if (gajgdm.startsWith("2202")) {
			// 根据警号获取警格
			List<String> jgIdList = jgInfoService.getJgByJh(AuthUtil.getUserAccount());
			if (null != jgIdList && jgIdList.size() > 0) {
				// 根据警格获取楼栋列表
				ldList = fwInfoService.getLdByJg(jgIdList);
				return R.data(GsonUtil.toGsonStr(ldList));
			}
		}
		if (gajgdm.equals("2296911130000")) {
			gajgdm = "22969A130000"; // 天桥岭森林公安局青松派出所
		} else if (gajgdm.equals("2296911140000")) {
			gajgdm = "22969A140000"; // 天桥岭森林公安局内河派出所
		} else if (gajgdm.equals("2296911150000")) {
			gajgdm = "22969A150000"; // 天桥岭森林公安分局响水派出所
		} else if (gajgdm.equals("2296911160000")) {
			gajgdm = "22969A160000"; // 天桥岭森林公安分局张家店派出所
		} else if (gajgdm.equals("2296911170000")) {
			gajgdm = "22969A170000"; // 天桥岭森林公安局上河派出所
		} else if (gajgdm.equals("2296911180000")) {
			gajgdm = "22969A180000"; // 天桥岭森林公安局响水派出所
		} else if (gajgdm.equals("220409026000")) {
			gajgdm = "220409010000"; // 天桥岭森林公安局响水派出所
		} else if (gajgdm.equals("220203660000")) {
			gajgdm = "220299630000"; // 吉林市公安局龙潭分局靠山派出所
		}
		params.put("gajgdm", gajgdm);
//		String targetDm = fwInfoService.getTargetDm(gajgdm);
//		if (StringUtils.isNotBlank(targetDm)) {
//			params.put("gajgdm", targetDm);
//		}
		String userRole = AuthUtil.getUserRole();
		if (userRole.equals("社区民警")) {
			params.put("yhjh", ywxxVO.getYhjh());
			String targetJh = fwInfoService.getTarget(AuthUtil.getUserAccount());
			if (StringUtils.isNotBlank(targetJh)) {
				params.put("yhjh", targetJh);
			}
			ldList = fwInfoService.getJzwList(params);
		} else if (userRole.equals("辅警") || userRole.equals("网格员")) {
			// 获取归属民警的警号
			User mjUser = fjInfoService.getMjId(AuthUtil.getUserId());
			if (null == mjUser) {
				return R.fail("辅警需要绑定民警后，才能进行入户走访");
			}
			params.put("yhjh", mjUser.getJh());
			ldList = fwInfoService.getJzwList(params);
		} else {
			return R.fail("用户角色不正确");
		}
		return R.data(GsonUtil.toGsonStr(ldList));
	}

	/**
	 * 入户走访_列表_平台
	 */
	@GetMapping("/getLdList-pt")
	public R getLdListPt(@RequestParam Map<String, Object> params) {
		String userRole = AuthUtil.getUserRole();
		String gajgdm = "";
		if (userRole.equals("派出所管理员")) {
			gajgdm = AuthUtil.getDeptId();
		} else if (userRole.equals("社区民警")) {
			int index;
			if (AuthUtil.getDeptId().contains(",")) {
				index = AuthUtil.getDeptId().indexOf(",");
				gajgdm = AuthUtil.getDeptId().substring(0, index);
			} else {
				gajgdm = AuthUtil.getDeptId();
			}
			Dept byId = deptService.getById(Long.valueOf(gajgdm));
			gajgdm = byId.getParentId().toString();
		}
		if (gajgdm.equals("2296911130000")) {
			gajgdm = "22969A130000"; // 天桥岭森林公安局青松派出所
		} else if (gajgdm.equals("2296911140000")) {
			gajgdm = "22969A140000"; // 天桥岭森林公安局内河派出所
		} else if (gajgdm.equals("2296911150000")) {
			gajgdm = "22969A150000"; // 天桥岭森林公安分局响水派出所
		} else if (gajgdm.equals("2296911160000")) {
			gajgdm = "22969A160000"; // 天桥岭森林公安分局张家店派出所
		} else if (gajgdm.equals("2296911170000")) {
			gajgdm = "22969A170000"; // 天桥岭森林公安局上河派出所
		} else if (gajgdm.equals("2296911180000")) {
			gajgdm = "22969A180000"; // 天桥岭森林公安局响水派出所
		} else if (gajgdm.equals("220409026000")) {
			gajgdm = "220409010000"; // 天桥岭森林公安局响水派出所
		} else if (gajgdm.equals("220203660000")) {
			gajgdm = "220299630000"; // 吉林市公安局龙潭分局靠山派出所
		}
		params.put("gajgdm", gajgdm);
		List<LdBzdzVO> ldList = fwInfoService.getJzwList(params);
		return R.data(GsonUtils.toGsonStr(ldList));
	}

	/**
	 * 楼栋详情
	 * params ldphxlh
	 */
	@GetMapping("/getLdDetail")
	public R getLdDetail(@RequestParam Map<String, Object> params) {
		// 查有几个单元
		List<DyVO> dyList = fwInfoService.getDyList(params);
		for (DyVO dyVO : dyList) {
			params.put("dyh", dyVO.getDyh());
			List<LcVO> lcList = fwInfoService.getLcList(params);
			for (LcVO lcVO : lcList) {
				params.put("lch", lcVO.getLch());
				List<FjVO> fjList = fwInfoService.getFjList(params);
				lcVO.setFjList(fjList);
			}
			dyVO.setLcList(lcList);
		}
		return R.data(dyList);
	}

	/**
	 * 房间详情
	 * params ldphxlh dzbm
	 */
	@GetMapping("/getFjDetail")
	public R getFjDetail(@RequestParam Map<String, Object> params) {
		// 房间详情
		RhzfSaveVO rhzfSaveVO = fwInfoService.getFjDetail(params);
		if (null != rhzfSaveVO && null != rhzfSaveVO.getId()) {
			params.put("fwId", rhzfSaveVO.getId());
			// 房主列表
			FwFzEntity fz = fwFzService.getFzList(params);
			rhzfSaveVO.setFzInfo(fz);
			// 实有人口列表
			List<SyjzryVO> syjzryList = new ArrayList<>();
			List<FwRyVO> ryList = fwInfoService.getRyList(params);
			for (FwRyVO fwRyVO : ryList) {
				SyjzryVO syjzryVO = new SyjzryVO();
				params.put("ryId", fwRyVO.getRyId());
				if (fwRyVO.getRyType().equals("czrk")) {
					syjzryVO = fwInfoService.getCzrk(params);
				} else if (fwRyVO.getRyType().equals("jwrk")) {
					syjzryVO = fwInfoService.getJwrk(params);
					syjzryVO.setRyYwm(syjzryVO.getRyMz());
				} else if (fwRyVO.getRyType().equals("jzrk")) {
					syjzryVO = fwInfoService.getJzrk(params);
				} else if (fwRyVO.getRyType().equals("wlrk")) {
					syjzryVO = fwInfoService.getWlrk(params);
				} else if (fwRyVO.getRyType().equals("zzrk")) {
					syjzryVO = fwInfoService.getZzrk(params);
				}
				// 根据身份证号查询户籍接口，补充照片等信息
				String zp = "HttpRequest.post().";
				syjzryVO.setZp(zp);
				syjzryList.add(syjzryVO);
			}
			rhzfSaveVO.setSyjzryList(syjzryList);
			// 九小场所列表
			List<JxcsVO> jxcsList = jxcsService.getJxcsList(params);
			rhzfSaveVO.setJxcsList(jxcsList);
			// 工作意见
			List<RhzfGzyjEntity> gzyjHistory = gzyjService.getByDzbm(params);
			rhzfSaveVO.setGzyjHistory(gzyjHistory);
			// 问题反映
			List<RhzfWtfyEntity> wtfyHistory = wtfyService.getByDzbm(params);
			rhzfSaveVO.setWtfyHistory(wtfyHistory);
			// 服务群众
			List<RhzfFwqzEntity> fwqzHistory = fwqzService.getByDzbm(params);
			rhzfSaveVO.setFwqzHistory(fwqzHistory);
			// 安全宣传防范
			List<RhzfAqxcffEntity> aqxcffHistory = aqxcffService.getByDzbm(params);
			rhzfSaveVO.setAqxcffHistory(aqxcffHistory);
			// 实有单位
			SydwEntity sydwEntity = sydwService.getByDzbm(params);
			rhzfSaveVO.setSydw(sydwEntity);
		} else {
			rhzfSaveVO = new RhzfSaveVO();
		}
		return R.data(rhzfSaveVO);
	}

	@GetMapping("/getRhzfCs")
	public R getRhzfCs() {
		try {
			RhzfCsVO rhzfCsVO = new RhzfCsVO();
			int total = dictService.getZfcs();
			// 总队要求每人每日最多入户走访30次 次数
			Long userId = AuthUtil.getUserId();
			if (userId.equals(1678286861087535105L)) {
				total = 99;
			}
			if (userId.equals(1813462445587435522L)) {
				total = 99;
			}
			int rhzfCs = total;
			if (null != userId) {
				rhzfCs = fwInfoService.getRhzfCs(userId);
			}
			rhzfCsVO.setRhzfCs(rhzfCs);
			rhzfCsVO.setTotal(total);
			// 总队要求每人每日最多入户走访20次
			int kfTotal = dictService.getKfsl();
			int kfsl = fwInfoService.getKfsl(AuthUtil.getUserId());
			Dept sq = deptService.getById(Long.valueOf(AuthUtil.getDeptId().split(",")[0]));
			if (sq.getAncestors().contains("220105290000") || sq.getAncestors().contains("220105330000")) {
				kfTotal = 25;
			}
			if (userId.equals(1678286861087535105L)) {
				kfTotal = 99;
			}
			rhzfCsVO.setKfTotal(kfTotal);
			rhzfCsVO.setKfsl(kfsl);
			return R.data(rhzfCsVO);
		} catch (Exception e) {
			return R.data(e.getMessage());
		}
	}

	/**
	 * 入户走访_房屋_基本信息 新增
	 */
	@DSTransactional
	@PostMapping("/saveFwAndRy")
	public R saveFwAndRy(@RequestBody RhzfSaveVO rhzfSaveVO) {
		if (null != rhzfSaveVO.getFzInfo()) {
			FwFzEntity fzEntity = rhzfSaveVO.getFzInfo();
			if (StringUtils.isBlank(fzEntity.getTsqk())
				&& (StringUtils.isBlank(fzEntity.getFzXm()) || StringUtils.isBlank(fzEntity.getFzSfzh()) || StringUtils.isBlank(fzEntity.getFzDh()))) {
				return R.fail("上传失败，提交的数据中不能只有空格");
			}
		}
		if (null != rhzfSaveVO.getFwSyyt() && rhzfSaveVO.getFwSyyt().equals("空房")) {
			int kfTotal = dictService.getKfsl();
			int kfsl = fwInfoService.getKfsl(AuthUtil.getUserId());
			if (kfsl >= kfTotal) {
				return R.fail("今日空房登记户数已达上限（" + kfTotal + "户），辛苦了！");
			}
		} else {
			// 正常房 每日上限次数
			int total = dictService.getZfcs();
			// 正常房 今日登记次数
			int rhzfCs = fwInfoService.getRhzfCs(AuthUtil.getUserId());
			if (rhzfCs >= total) {
				return R.fail("今日非空房登记户数已达上限（" + total + "户），辛苦了！");
			}
		}
		// 保存房屋信息
		FwInfoEntity fwInfo = new FwInfoEntity();
		BeanUtil.copy(rhzfSaveVO, fwInfo);
		Long mjId = rhzfSaveVO.getMjId();
		// 根据dzbm 查rhzf_fw_info是否已有数据
		FwInfoEntity oldRecord = fwInfoService.getFwIsExist(fwInfo);
		if (StringUtils.isNotBlank(rhzfSaveVO.getFwSyyt()) || StringUtils.isNotBlank(fwInfo.getQzzp())) {
			if (null == oldRecord) {
				fwInfo.setTimes(1);
				fwInfo.setMjId(mjId);
				fwInfoService.save(fwInfo);
			} else {
				// 先更新
				fwInfo.setId(oldRecord.getId());
				fwInfo.setTimes(oldRecord.getTimes() + 1);
				fwInfoService.updateById(fwInfo);
			}
			// 保存房屋操作记录
			RhzfFwEntity fwLogEntity = new RhzfFwEntity();
			BeanUtil.copy(fwInfo, fwLogEntity);
			fwLogEntity.setMjId(mjId);
			fwLogService.save(fwLogEntity);
		}
		// 保存房主信息
		if (null != rhzfSaveVO.getFzInfo()) {
			if (null == oldRecord) {
				rhzfSaveVO.getFzInfo().setFwId(fwInfo.getId());
				rhzfSaveVO.getFzInfo().setMjId(mjId);
				fwFzService.save(rhzfSaveVO.getFzInfo());
			} else if (null != rhzfSaveVO.getFzInfo()) {
				rhzfSaveVO.getFzInfo().setFwId(fwInfo.getId());
				fwFzService.updateFzByFwId(rhzfSaveVO.getFzInfo());
			}
			// 保存房主操作记录
			RhzfFzEntity fzLogEntity = new RhzfFzEntity();
			BeanUtil.copy(rhzfSaveVO.getFzInfo(), fzLogEntity);
			fzLogEntity.setMjId(mjId);
			fzLogService.save(fzLogEntity);
		}
		// 保存九小场所信息
		if (null != rhzfSaveVO.getJxcsList() && !rhzfSaveVO.getJxcsList().isEmpty()) {
			List<JxcsEntity> jxcsList = new ArrayList<>();
			for (JxcsVO jxcs : rhzfSaveVO.getJxcsList()) {
				JxcsEntity cs = new JxcsEntity();
				BeanUtil.copy(jxcs, cs);
				cs.setFwId(rhzfSaveVO.getId());
				if (null == cs.getId()) {
					// 新增
					jxcsList.add(cs);
				} else if (cs.getIsDeleted() == 0) {
					// 更新
					jxcsService.updateById(cs);
				} else if (cs.getIsDeleted() == 1) {
					// 删除
					jxcsService.deleteLogic(Func.toLongList(cs.getId().toString()));
				}
			}
			jxcsService.saveBatch(jxcsList);
		}
		// 工作意见
		if (null != rhzfSaveVO.getGzyj()) {
			rhzfSaveVO.getGzyj().setFwId(rhzfSaveVO.getId());
			rhzfSaveVO.getGzyj().setDzbm(rhzfSaveVO.getDzbm());
			// 保存
			gzyjService.saveOrUpdate(rhzfSaveVO.getGzyj());
		}
		// 问题反映
		if (null != rhzfSaveVO.getWtfy()) {
			rhzfSaveVO.getWtfy().setFwId(rhzfSaveVO.getId());
			rhzfSaveVO.getWtfy().setDzbm(rhzfSaveVO.getDzbm());
			// 保存
			wtfyService.saveOrUpdate(rhzfSaveVO.getWtfy());
		}
		// 服务群众
//		if (null != rhzfSaveVO.getFwqz()) {
//			rhzfSaveVO.getFwqz().setFwId(fwInfo.getId());
//			rhzfSaveVO.getFwqz().setDzbm(rhzfSaveVO.getDzbm());
//			// 保存
//			fwqzService.saveOrUpdate(rhzfSaveVO.getFwqz());
//		}
		// 安全宣传防范
		if (null != rhzfSaveVO.getAqxcff()) {
			rhzfSaveVO.getAqxcff().setFwId(rhzfSaveVO.getId());
			rhzfSaveVO.getAqxcff().setDzbm(rhzfSaveVO.getDzbm());
			// 保存
			aqxcffService.saveOrUpdate(rhzfSaveVO.getAqxcff());
		}
		return R.data(fwInfo);
	}

	/**
	 * 根据dzbm获取房间人员历史
	 * fwId
	 */
	@GetMapping("/getRyls")
	public R getRyls(@RequestParam Map<String, String> params) {
		List<SyjzryVO> data = fwRyService.getRyls(params);
		return R.data(data);
	}

	/**
	 * 入户走访_人员_基本信息 新增/修改/删除
	 */
	@DSTransactional
	@PostMapping("/updateRy-app")
	public R updateRy(@RequestBody SyjzryVO syjzry) {
		Dept sq = deptService.getById(Long.valueOf(AuthUtil.getDeptId().split(",")[0]));
		Long mjId = syjzry.getMjId();
		int type = 0;
		Long ryId = 0L;
		if (syjzry.getRyType().equals("czrk")) {
			// 常住人口
			RyCzrkEntity czrkEntity = new RyCzrkEntity();
			BeanUtil.copy(syjzry, czrkEntity);
			czrkEntity.setMjId(mjId);
			if (null == czrkEntity.getId()) {
				czrkService.save(czrkEntity);
				// 向吉林数据库插入
				if (sq.getAncestors().contains("220200000000")) {
					czrkService.saveToJl(czrkEntity);
				}
				type = 1;
				ryId = czrkEntity.getId();
			} else if (czrkEntity.getIsDeleted() == 0) {
				czrkService.updateById(czrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					czrkService.updateByIdToJl(czrkEntity);
				}
			} else {
				czrkEntity.setZxrq(sdf.format(new Date()));
				czrkService.czrkZx(czrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					czrkService.czrkZxToJl(czrkEntity);
				}
				Map<String, Object> params = new HashMap<>();
				params.put("ryId", czrkEntity.getId());
				params.put("ryType", syjzry.getRyType());
				fwRyService.deleteByRyidAndType(params);
				// 向吉林数据库删除
				if (sq.getAncestors().contains("220200000000")) {
					fwRyService.deleteByRyidAndTypeToJl(params);
				}
				type = 3;
			}
			RhzfCzrkEntity czrkLogEntity = new RhzfCzrkEntity();
			BeanUtil.copy(czrkEntity, czrkLogEntity);
			czrkLogService.save(czrkLogEntity);
		} else if (syjzry.getRyType().equals("jwrk")) {
			// 境外人口
			RyJwrkEntity jwrkEntity = new RyJwrkEntity();
			BeanUtil.copy(syjzry, jwrkEntity);
			jwrkEntity.setRyMz(syjzry.getRyYwm());
			jwrkEntity.setMjId(mjId);
			if (null == jwrkEntity.getId()) {
				jwrkService.save(jwrkEntity);
				// 向吉林数据库插入
				if (sq.getAncestors().contains("220200000000")) {
					jwrkService.saveToJl(jwrkEntity);
				}
				type = 1;
				ryId = jwrkEntity.getId();
			} else if (jwrkEntity.getIsDeleted() == 0) {
				jwrkService.updateById(jwrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					jwrkService.updateByIdToJl(jwrkEntity);
				}
			} else {
				jwrkEntity.setZxrq(sdf.format(new Date()));
				jwrkService.jwrkZx(jwrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					jwrkService.jwrkZxToJl(jwrkEntity);
				}
				Map<String, Object> params = new HashMap<>();
				params.put("ryId", jwrkEntity.getId());
				params.put("ryType", syjzry.getRyType());
				fwRyService.deleteByRyidAndType(params);
				// 向吉林数据库删除
				if (sq.getAncestors().contains("220200000000")) {
					fwRyService.deleteByRyidAndTypeToJl(params);
				}
				type = 3;
			}
			RhzfJwrkEntity jwrkLogEntity = new RhzfJwrkEntity();
			BeanUtil.copy(jwrkEntity, jwrkLogEntity);
			jwrkLogService.save(jwrkLogEntity);
		} else if (syjzry.getRyType().equals("jzrk")) {
			// 寄住人口
			RyJzrkEntity jzrkEntity = new RyJzrkEntity();
			BeanUtil.copy(syjzry, jzrkEntity);
			jzrkEntity.setMjId(mjId);
			if (null == jzrkEntity.getId()) {
				jzrkService.save(jzrkEntity);
				// 向吉林数据库插入
				if (sq.getAncestors().contains("220200000000")) {
					jzrkService.saveToJl(jzrkEntity);
				}
				type = 1;
				ryId = jzrkEntity.getId();
			} else if (jzrkEntity.getIsDeleted() == 0) {
				jzrkService.updateById(jzrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					jzrkService.updateByIdToJl(jzrkEntity);
				}
			} else {
				jzrkEntity.setZxrq(sdf.format(new Date()));
				jzrkService.jzrkZx(jzrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					jzrkService.jzrkZxToJl(jzrkEntity);
				}
				Map<String, Object> params = new HashMap<>();
				params.put("ryId", jzrkEntity.getId());
				params.put("ryType", syjzry.getRyType());
				fwRyService.deleteByRyidAndType(params);
				// 向吉林数据库删除
				if (sq.getAncestors().contains("220200000000")) {
					fwRyService.deleteByRyidAndTypeToJl(params);
				}
				type = 3;
			}
			RhzfJzrkEntity jzrkLogEntity = new RhzfJzrkEntity();
			BeanUtil.copy(jzrkEntity, jzrkLogEntity);
			jzrkLogService.save(jzrkLogEntity);
		} else if (syjzry.getRyType().equals("wlrk")) {
			// 未落常口
			RyWlrkEntity wlrkEntity = new RyWlrkEntity();
			BeanUtil.copy(syjzry, wlrkEntity);
			wlrkEntity.setMjId(mjId);
			if (null == wlrkEntity.getId()) {
				wlrkService.save(wlrkEntity);
				// 向吉林数据库插入
				if (sq.getAncestors().contains("220200000000")) {
					wlrkService.saveToJl(wlrkEntity);
				}
				type = 1;
				ryId = wlrkEntity.getId();
			} else if (wlrkEntity.getIsDeleted() == 0) {
				wlrkService.updateById(wlrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					wlrkService.updateByIdToJl(wlrkEntity);
				}
			} else {
				wlrkEntity.setZxrq(sdf.format(new Date()));
				wlrkService.wlrkZx(wlrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					wlrkService.wlrkZxToJl(wlrkEntity);
				}
				Map<String, Object> params = new HashMap<>();
				params.put("ryId", wlrkEntity.getId());
				params.put("ryType", syjzry.getRyType());
				fwRyService.deleteByRyidAndType(params);
				// 向吉林数据库删除
				if (sq.getAncestors().contains("220200000000")) {
					fwRyService.deleteByRyidAndTypeToJl(params);
				}
				type = 3;
			}
			RhzfWlrkEntity wlrkLogEntity = new RhzfWlrkEntity();
			BeanUtil.copy(wlrkEntity, wlrkLogEntity);
			wlrkLogService.save(wlrkLogEntity);
		} else if (syjzry.getRyType().equals("zzrk")) {
			// 暂住人口
			RyZzrkEntity zzrkEntity = new RyZzrkEntity();
			BeanUtil.copy(syjzry, zzrkEntity);
			zzrkEntity.setMjId(mjId);
			if (null == zzrkEntity.getId()) {
				zzrkService.save(zzrkEntity);
				// 向吉林数据库插入
				if (sq.getAncestors().contains("220200000000")) {
					zzrkService.saveToJl(zzrkEntity);
				}
				type = 1;
				ryId = zzrkEntity.getId();
			} else if (zzrkEntity.getIsDeleted() == 0) {
				zzrkService.updateById(zzrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					zzrkService.updateByIdToJl(zzrkEntity);
				}
			} else {
				zzrkEntity.setZxrq(sdf.format(new Date()));
				zzrkService.zzrkZx(zzrkEntity);
				// 向吉林数据库更新
				if (sq.getAncestors().contains("220200000000")) {
					zzrkService.zzrkZxToJl(zzrkEntity);
				}
				Map<String, Object> params = new HashMap<>();
				params.put("ryId", zzrkEntity.getId());
				params.put("ryType", syjzry.getRyType());
				fwRyService.deleteByRyidAndType(params);
				// 向吉林数据库删除
				if (sq.getAncestors().contains("220200000000")) {
					fwRyService.deleteByRyidAndTypeToJl(params);
				}
				type = 3;
			}
			RhzfZzrkEntity zzrkLogEntity = new RhzfZzrkEntity();
			BeanUtil.copy(zzrkEntity, zzrkLogEntity);
			zzrkLogService.save(zzrkLogEntity);
		}
		// 新增人员 需要 保存房屋_人员关系
		if (type == 1) {
			FwRyEntity fwRyEntity = new FwRyEntity();
			fwRyEntity.setFwId(syjzry.getFwId());
			fwRyEntity.setRyId(ryId);
			fwRyEntity.setRyType(syjzry.getRyType());
			fwRyEntity.setDzbm(syjzry.getDzbm());
			fwRyEntity.setMjId(mjId);
			fwRyService.save(fwRyEntity);
			// 向吉林数据库插入
			if (sq.getAncestors().contains("220200000000")) {
				fwRyService.saveToJl(fwRyEntity);
			}
		} else if (type == 3) {
			Map<String, Object> params = new HashMap<>();
			params.put("ryId", syjzry.getId());
			params.put("ryType", syjzry.getRyType());
			fwRyService.deleteByRyidAndType(params);
			// 向吉林数据库删除
			if (sq.getAncestors().contains("220200000000")) {
				fwRyService.deleteByRyidAndTypeToJl(params);
			}
		}
		fwInfoService.gxUpdateTime(syjzry.getFwId());
		return R.success("更新成功");
	}

	/**
	 * 二次走访，只更新房屋照片和update_time
	 */
	@DSTransactional
	@PostMapping("/secondRhzf")
	public R secondRhzf(@RequestBody RhzfSaveVO rhzfSaveVO) {
		if (null != rhzfSaveVO.getFzInfo()) {
			FwFzEntity fzEntity = rhzfSaveVO.getFzInfo();
			if (StringUtils.isBlank(fzEntity.getTsqk())
				&& (StringUtils.isBlank(fzEntity.getFzXm()) || StringUtils.isBlank(fzEntity.getFzSfzh()) || StringUtils.isBlank(fzEntity.getFzDh()))) {
				return R.fail("上传失败，提交的数据中不能只有空格");
			}
		}
		Dept sq = deptService.getById(Long.valueOf(AuthUtil.getDeptId().split(",")[0]));
		// 更新房屋信息
		FwInfoEntity fwInfo = new FwInfoEntity();
		BeanUtil.copy(rhzfSaveVO, fwInfo);
		FwInfoEntity oldRecord = fwInfoService.getFwIsExist(fwInfo);
		fwInfo.setId(oldRecord.getId());
		fwInfo.setTimes(oldRecord.getTimes() + 1);
		fwInfoService.updateById(fwInfo);
		// 向吉林数据库更新
		if (sq.getAncestors().contains("220200000000")) {
			fwInfoService.updateByIdToJl(fwInfo);
		}
		// 保存房屋操作记录
		RhzfFwEntity fwLogEntity = new RhzfFwEntity();
		BeanUtil.copy(fwInfo, fwLogEntity);
		fwLogService.save(fwLogEntity);
		// 更新房主信息
		if (null != rhzfSaveVO.getFzInfo()) {
			rhzfSaveVO.getFzInfo().setFwId(fwInfo.getId());
			fwFzService.updateFzByFwId(rhzfSaveVO.getFzInfo());
			// 向吉林数据库更新
			if (sq.getAncestors().contains("220200000000")) {
				fwFzService.updateFzByFwIdToJl(rhzfSaveVO.getFzInfo());
			}
			// 保存房主操作记录
			RhzfFzEntity fzLogEntity = new RhzfFzEntity();
			BeanUtil.copy(rhzfSaveVO.getFzInfo(), fzLogEntity);
			fzLogService.save(fzLogEntity);
		}
		return R.status(true);
	}

	/**
	 * 入户走访_房屋_基本信息 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入fwInfo")
	public R update(@Valid @RequestBody FwInfoEntity fwInfo) {
		return R.status(fwInfoService.updateById(fwInfo));
	}

	/**
	 * 入户走访_房屋_基本信息 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入fwInfo")
	public R submit(@Valid @RequestBody FwInfoEntity fwInfo) {
		return R.status(fwInfoService.saveOrUpdate(fwInfo));
	}

	/**
	 * 入户走访_房屋_基本信息 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(fwInfoService.deleteLogic(Func.toLongList(ids)));
	}


	/**
	 * 导出数据
	 */
	@GetMapping("/export-fwInfo")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "导出数据", notes = "传入fwInfo")
	public void exportFwInfo(FwInfoVO fwInfo, BladeUser bladeUser, HttpServletResponse response) {
		//QueryWrapper<FwInfoEntity> queryWrapper = Condition.getQueryWrapper(fwInfo, FwInfoEntity.class);
		//if (!AuthUtil.isAdministrator()) {
		//	queryWrapper.lambda().eq(FwInfo::getTenantId, bladeUser.getTenantId());
		//}
		//queryWrapper.lambda().eq(FwInfoEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
		//获取派出所代码
		fwInfo.setDeptId(AuthUtil.getDeptId());
		List<FwInfoExcel> list = fwInfoService.exportFwInfo(fwInfo);
		ExcelUtil.export(response, "入户走访_房屋_基本信息数据" + DateUtil.time(), "入户走访_房屋_基本信息数据表", list, FwInfoExcel.class);
	}

	/**
	 * 导出数据
	 */
	@GetMapping("/export-fwInfory")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "导出数据", notes = "传入fwInfo")
	public void exportFwInfory(FwInfoVO fwInfo, BladeUser bladeUser, HttpServletResponse response) {
		//根据条件查询房屋信息
		fwInfo.setDeptId(AuthUtil.getDeptId());
		List<FwInfoExcel> list = fwInfoService.exportFwInfo(fwInfo);
		//根据房屋id查询房屋下的人员
		List<FwInfoExcel> exportRyList = fwInfoService.getExportRyList(list);
		ExcelUtil.export(response, "入户走访_房屋_基本信息数据" + DateUtil.time(), "入户走访_房屋_基本信息数据表", exportRyList, FwInfoExcel.class);
	}


	/**
	 * 获取字典
	 */
	@GetMapping("/dictionary")
	@Cacheable(cacheNames = "blade:getZd")
	public R dictionary() {
		RhzfZdVO data = new RhzfZdVO();

		String code = "";
		code = "jwrylb"; // 境外人员类别
		List<ZdVO> jwrylb = dictService.getDictList(code);
		data.setJwrylb(jwrylb);
		code = "sfzjzl"; // 身份证件种类
		List<ZdVO> sfzjzl = dictService.getDictList(code);
		data.setSfzjzl(sfzjzl);
		code = "lhtjlsy"; // 来华停居留事由
		List<ZdVO> lhtjlsy = dictService.getDictList(code);
		data.setLhtjlsy(lhtjlsy);
		code = "yfzgx"; // 与房主关系
		List<ZdVO> yfzgx = dictService.getDictList(code);
		data.setYfzgx(yfzgx);
		code = "hyzk"; // 婚姻状况
		List<ZdVO> hyzk = dictService.getDictList(code);
		data.setHyzk(hyzk);
		code = "whcd"; // 文化程度
		List<ZdVO> whcd = dictService.getDictList(code);
		data.setWhcd(whcd);
		code = "zzmm"; // 政治面貌
		List<ZdVO> zzmm = dictService.getDictList(code);
		data.setZzmm(zzmm);
		code = "byzk"; // 兵役状况
		List<ZdVO> byzk = dictService.getDictList(code);
		data.setByzk(byzk);
		code = "dwlb"; // 单位类别
		List<ZdVO> dwlb = dictService.getDictList(code);
		data.setDwlb(dwlb);
		code = "gllb"; // 管理类别
		List<ZdVO> gllb = dictService.getDictList(code);
		data.setGllb(gllb);
		code = "glxl"; // 管理细类
		List<ZdVO> glxl = dictService.getDictList(code);
		data.setGlxl(glxl);
		code = "wlhrylb"; // 未落户人员类别
		List<ZdVO> wlhrylb = dictService.getDictList(code);
		data.setWlhrylb(wlhrylb);
		code = "hjdcxflsx"; // 户籍地城乡分类属性
		List<ZdVO> hjdcxflsx = dictService.getDictList(code);
		data.setHjdcxflsx(hjdcxflsx);
		code = "zzdcxflsx"; // 暂住地城乡分类属性
		List<ZdVO> zzdcxflsx = dictService.getDictList(code);
		data.setZzdcxflsx(zzdcxflsx);
		code = "gjdq"; // 国家地区
		List<ZdVO> gjdq = dictService.getDictList(code);
		data.setGjdq(gjdq);
		code = "tjlzjzl"; // 停居留证件种类
		List<ZdVO> tjlzjzl = dictService.getDictList(code);
		data.setTjlzjzl(tjlzjzl);
		code = "fwlb"; // 房屋类别
		List<ZdVO> fwlb = dictService.getDictList(code);
		data.setFwlb(fwlb);
		code = "fwxz"; // 房屋性质
		List<ZdVO> fwxz = dictService.getDictList(code);
		data.setFwxz(fwxz);
		code = "fwyt"; // 房屋用途
		List<ZdVO> fwyt = dictService.getDictList(code);
		data.setFwyt(fwyt);
		code = "syyt"; // 使用用途
		List<ZdVO> syyt = dictService.getDictList(code);
		data.setSyyt(syyt);
		code = "tsrq"; // 特殊人群
		List<ZdVO> tsrq = dictService.getDictList(code);
		data.setTsrq(tsrq);
		code = "zjxy"; // 宗教信仰
		List<ZdVO> zjxy = dictService.getDictList(code);
		data.setZjxy(zjxy);
		code = "mz"; // 民族
		List<ZdVO> mz = dictService.getDictList(code);
		data.setMz(mz);
		code = "zzsy"; // 暂住事由
		List<ZdVO> zzsy = dictService.getDictList(code);
		data.setZzsy(zzsy);
		code = "ldphhz"; // 楼栋牌号后缀
		List<ZdVO> ldphhz = dictService.getDictList(code);
		data.setLdphhz(ldphhz);

		code = "zzrkzxyy"; // 暂住人口注销原因
		List<ZdVO> zzrkzxyy = dictService.getDictList(code);
		data.setZzrkzxyy(zzrkzxyy);
		code = "czrkzxyy"; // 常住人口注销原因
		List<ZdVO> czrkzxyy = dictService.getDictList(code);
		data.setCzrkzxyy(czrkzxyy);
		code = "wcyy"; // 外出原因
		List<ZdVO> wcyy = dictService.getDictList(code);
		data.setWcyy(wcyy);
		code = "hzrbzyy"; // 户在人不在原因
		List<ZdVO> hzrbzyy = dictService.getDictList(code);
		data.setHzrbzyy(hzrbzyy);
		code = "gsjyms"; // 公司经营模式
		List<ZdVO> gsjyms = dictService.getDictList(code);
		data.setGsjyms(gsjyms);
		code = "gsrcjyqk"; // 公司日常经营情况
		List<ZdVO> gsrcjyqk = dictService.getDictList(code);
		data.setGsrcjyqk(gsrcjyqk);

		code = "smfwlx"; // 上门服务类型
		List<ZdVO> smfwlx = dictService.getDictList(code);
		data.setSmfwlx(smfwlx);
		code = "wtfwlx"; // 委托服务类型
		List<ZdVO> wtfwlx = dictService.getDictList(code);
		data.setWtfwlx(wtfwlx);
		code = "yyfwlx"; // 预约服务类型
		List<ZdVO> yyfwlx = dictService.getDictList(code);
		data.setYyfwlx(yyfwlx);

		code = "jyfs"; // 经营方式
		List<ZdVO> jyfs = dictService.getDictList(code);
		data.setJyfs(jyfs);

		code = "zylb"; // 职业类别
		List<ZdVO> zylb = dictService.getDictList(code);
		data.setZylb(zylb);

		// 实有单位行业类型
		List<HylxVO> hylx = dictService.getHylx();
		for (HylxVO hylxVO : hylx) {
			List<ZdVO> dwlx = dictService.getDwlx(hylxVO.getId());
			hylxVO.setDwlxList(dwlx);
		}
		data.setHylx(hylx);

		code = "xslx"; // 职业类别
		List<ZdVO> xslx = dictService.getDictList(code);
		data.setXslx(xslx);

		List<XzqhVO> cityList = regionService.getCity("22");
		for (XzqhVO city : cityList) {
			String[] area = regionService.getArea(city.getCode());
			city.setArea(area);
		}
		data.setXzqh(cityList);
		return R.data(data);
	}

	/**
	 * 房间详情
	 * params dzbm
	 */
	@GetMapping("/getFjDetailZfd")
	public R getFjDetailZfd(@RequestParam Map<String, Object> params) {
		// 房间详情
		RhzfSaveVO rhzfSaveVO = fwInfoService.getFjDetail(params);
		if (null == rhzfSaveVO) {
			return R.data(new RhzfSaveVO());
		}
		params.put("fwId", rhzfSaveVO.getId());
		// 房主列表
		FwFzEntity fz = fwFzService.getFzList(params);
		rhzfSaveVO.setFzInfo(fz);
		// 人员列表
		List<SyjzryVO> syjzryList = new ArrayList<>();
		List<FwRyVO> ryList = fwInfoService.getRyList(params);
		for (FwRyVO fwRyVO : ryList) {
			SyjzryVO syjzryVO = new SyjzryVO();
			params.put("ryId", fwRyVO.getRyId());
			if (fwRyVO.getRyType().equals("czrk")) {
				syjzryVO = fwInfoService.getCzrk(params);
			} else if (fwRyVO.getRyType().equals("jwrk")) {
				syjzryVO = fwInfoService.getJwrk(params);
				syjzryVO.setRyYwm(syjzryVO.getRyMz());
			} else if (fwRyVO.getRyType().equals("jzrk")) {
				syjzryVO = fwInfoService.getJzrk(params);
			} else if (fwRyVO.getRyType().equals("wlrk")) {
				syjzryVO = fwInfoService.getWlrk(params);
			} else if (fwRyVO.getRyType().equals("zzrk")) {
				syjzryVO = fwInfoService.getZzrk(params);
			}
			syjzryList.add(syjzryVO);
		}
		rhzfSaveVO.setSyjzryList(syjzryList);
		// 九小场所列表
		List<JxcsVO> jxcsList = jxcsService.getJxcsList(params);
		rhzfSaveVO.setJxcsList(jxcsList);
		return R.data(rhzfSaveVO);
	}


	@RequestMapping("/generaWord")
	public void genera(HttpServletResponse response, String dzbm) {
		Map<String, Object> params = new HashMap<>();
		params.put("dzbm",dzbm);
		//通过id，获取房屋的具体信息
		R fjDetail = getFjDetailZfd(params);
		RhzfSaveVO rhzfSaveVO = (RhzfSaveVO)fjDetail.getData();
		Map<String, Object> paramfw = new HashMap<>();

		paramfw.put("fwrq",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( rhzfSaveVO.getUpdateTime()));
		//采集人基本信息
		User userInfo = userService.getById(rhzfSaveVO.getUpdateUser());
		String deptId = userInfo.getDeptId();
		if (deptId.indexOf(",") >= 0){
			int index = deptId.indexOf(",");
			deptId = deptId.substring(0, index);
		}
		//社区民警☑   辅警□   警务助理□    网格长□    楼栋长□    单元长□    一村一警□
		if( "社区民警".equals(AuthUtil.getUserRole())){
			paramfw.put("cjrlb", "社区民警☑   辅警□   警务助理□    网格长□    楼栋长□    单元长□    一村一警□");
		}
		if( "辅警".equals(AuthUtil.getUserRole())){
			paramfw.put("cjrlb", "社区民警□   辅警☑   警务助理□    网格长□    楼栋长□    单元长□    一村一警□");
		}
		if( "警务助理".equals(AuthUtil.getUserRole())){
			paramfw.put("cjrlb", "社区民警□   辅警□   警务助理☑    网格长□    楼栋长□    单元长□    一村一警□");
		}
		if( "网格长".equals(AuthUtil.getUserRole())){
			paramfw.put("cjrlb", "社区民警□   辅警□   警务助理□    网格长☑    楼栋长□    单元长□    一村一警□");
		}
		if( "楼栋长".equals(AuthUtil.getUserRole())){
			paramfw.put("cjrlb", "社区民警□   辅警□   警务助理□    网格长□    楼栋长☑    单元长□    一村一警□");
		}
		if( "单元长".equals(AuthUtil.getUserRole())){
			paramfw.put("cjrlb", "社区民警□   辅警□   警务助理□    网格长□    楼栋长□    单元长☑    一村一警□");
		}
		if( "一村一警".equals(AuthUtil.getUserRole())){
			paramfw.put("cjrlb", "社区民警□   辅警□   警务助理□    网格长□    楼栋长□    单元长□    一村一警☑");
		}

		paramfw.put("cjrxm", userInfo.getName());
		paramfw.put("cjrlxdh", userInfo.getPhone());
		Dept depts = deptService.getById(Long.parseLong(deptId));
		Dept parentDept = deptService.getById(depts.getParentId());
		if(parentDept != null){
			paramfw.put("cjrdw", deptService.getById(depts.getParentId()).getDeptName()+depts.getDeptName());
		}else{
			paramfw.put("cjrdw", depts.getDeptName());
		}

		//房屋地址信息
		paramfw.put("fwdz", fwInfoService.getFwxzByRkDzxx(dzbm));
		if("单元(公寓)楼".equals(rhzfSaveVO.getFwLb())){
			paramfw.put("fwlb","单元(公寓)楼☑\n" +
				"筒子楼      □\n" +
				"平房        □\n" +
				"自建楼(房)  □\n" +
				"别墅        □\n" +
				"其他       □");
		}
		if("筒子楼".equals(rhzfSaveVO.getFwLb())){
			paramfw.put("fwlb","单元(公寓)楼□\n" +
				"筒子楼      ☑\n" +
				"平房        □\n" +
				"自建楼(房)  □\n" +
				"别墅        □\n" +
				"其他       □");
		}
		if("平房".equals(rhzfSaveVO.getFwLb())){
			paramfw.put("fwlb","单元(公寓)楼□\n" +
				"筒子楼      □\n" +
				"平房        ☑\n" +
				"自建楼(房)  □\n" +
				"别墅        □\n" +
				"其他       □");
		}
		if("自建楼(房)".equals(rhzfSaveVO.getFwLb())){
			paramfw.put("fwlb","单元(公寓)楼□\n" +
				"筒子楼      □\n" +
				"平房        □\n" +
				"自建楼(房)  ☑\n" +
				"别墅        □\n" +
				"其他       □");
		}
		if("别墅".equals(rhzfSaveVO.getFwLb())){
			paramfw.put("fwlb","单元(公寓)楼□\n" +
				"筒子楼      □\n" +
				"平房        □\n" +
				"自建楼(房)  □\n" +
				"别墅        ☑\n" +
				"其他       □");
		}
		if("其他".equals(rhzfSaveVO.getFwLb())){
			paramfw.put("fwlb","单元(公寓)楼□\n" +
				"筒子楼      □\n" +
				"平房        □\n" +
				"自建楼(房)  □\n" +
				"别墅        □\n" +
				"其他       ☑");
		}
		if("住宅".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅☑   工业□\n" +
				"商业□   办公□\n" +
				"教育□   军事□\n" +
				"体育□   其他□");
		}
		if("工业".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅□   工业☑\n" +
				"商业□   办公□\n" +
				"教育□   军事□\n" +
				"体育□   其他□");
		}
		if("商业".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅□   工业□\n" +
				"商业☑   办公□\n" +
				"教育□   军事□\n" +
				"体育□   其他□");
		}
		if("办公".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅□   工业□\n" +
				"商业□   办公☑\n" +
				"教育□   军事□\n" +
				"体育□   其他□");
		}
		if("教育".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅□   工业□\n" +
				"商业□   办公□\n" +
				"教育☑   军事□\n" +
				"体育□   其他□");
		}
		if("军事".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅□   工业□\n" +
				"商业□   办公□\n" +
				"教育□   军事☑\n" +
				"体育□   其他□");
		}
		if("体育".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅□   工业□\n" +
				"商业□   办公□\n" +
				"教育□   军事□\n" +
				"体育☑   其他□");
		}
		if("其他".equals(rhzfSaveVO.getFwYt())){
			paramfw.put("fwyt","住宅□   工业□\n" +
				"商业□   办公□\n" +
				"教育□   军事□\n" +
				"体育□   其他☑");
		}
		if("居民住宅".equals(rhzfSaveVO.getFwXz())){
			paramfw.put("fwxz","居民住宅 ☑\n" +
				"单位宿舍 □\n" +
				"工地工棚 □\n" +
				"商业门店 □\n" +
				"旅店    □\n" +
				"其他  □");
		}
		if("单位宿舍".equals(rhzfSaveVO.getFwXz())){
			paramfw.put("fwxz","居民住宅 □\n" +
				"单位宿舍 ☑\n" +
				"工地工棚 □\n" +
				"商业门店 □\n" +
				"旅店    □\n" +
				"其他  □");
		}
		if("工地工棚".equals(rhzfSaveVO.getFwXz())){
			paramfw.put("fwxz","居民住宅 □\n" +
				"单位宿舍 □\n" +
				"工地工棚 ☑\n" +
				"商业门店 □\n" +
				"旅店    □\n" +
				"其他  □");
		}
		if("商业门店".equals(rhzfSaveVO.getFwXz())){
			paramfw.put("fwxz","居民住宅 □\n" +
				"单位宿舍 □\n" +
				"工地工棚 □\n" +
				"商业门店 ☑\n" +
				"旅店    □\n" +
				"其他  □");
		}
		if("旅店".equals(rhzfSaveVO.getFwXz())){
			paramfw.put("fwxz","居民住宅 □\n" +
				"单位宿舍 □\n" +
				"工地工棚 □\n" +
				"商业门店 □\n" +
				"旅店    ☑\n" +
				"其他  □");
		}
		if("其他".equals(rhzfSaveVO.getFwXz())){
			paramfw.put("fwxz","居民住宅 □\n" +
				"单位宿舍 □\n" +
				"工地工棚 □\n" +
				"商业门店 □\n" +
				"旅店    □\n" +
				"其他  ☑");
		}

		if("自用".equals(rhzfSaveVO.getFwSyyt())){
			paramfw.put("fwsyyt","自用 ☑\n" +
				"出租 □\n" +
				"空房 □\n" +
				"混用 □\n" +
				"借用 □\n" +
				"其他 □");
		}
		if("出租".equals(rhzfSaveVO.getFwSyyt())){
			paramfw.put("fwsyyt","自用 □\n" +
				"出租 ☑\n" +
				"空房 □\n" +
				"混用 □\n" +
				"借用 □\n" +
				"其他 □");
		}
		if("空房".equals(rhzfSaveVO.getFwSyyt())){
			paramfw.put("fwsyyt","自用 □\n" +
				"出租 □\n" +
				"空房 ☑\n" +
				"混用 □\n" +
				"借用 □\n" +
				"其他 □");
		}
		if("混用".equals(rhzfSaveVO.getFwSyyt())){
			paramfw.put("fwsyyt","自用 □\n" +
				"出租 □\n" +
				"空房 □\n" +
				"混用 ☑\n" +
				"借用 □\n" +
				"其他 □");
		}
		if("借用".equals(rhzfSaveVO.getFwSyyt())){
			paramfw.put("fwsyyt","自用 □\n" +
				"出租 □\n" +
				"空房 □\n" +
				"混用 □\n" +
				"借用 ☑\n" +
				"其他 □");
		}
		if("其他".equals(rhzfSaveVO.getFwSyyt())){
			paramfw.put("fwsyyt","自用 □\n" +
				"出租 □\n" +
				"空房 □\n" +
				"混用 □\n" +
				"借用 □\n" +
				"其他 ☑");
		}
		String fwmj = rhzfSaveVO.getFwMj()!=null || rhzfSaveVO.getFwMj()!=""?"面积："+rhzfSaveVO.getFwMj()+"m²":"暂无";
		String fwfjs = rhzfSaveVO.getFwJs()!=null || rhzfSaveVO.getFwJs()!=""?"房间数："+rhzfSaveVO.getFwJs():"暂无";
		paramfw.put("hnmjjjs",fwmj+"\n"+fwfjs);
		//房主信息
		FwFzEntity fzInfo = rhzfSaveVO.getFzInfo();
		if(fzInfo !=null){
			paramfw.put("fzxm",fzInfo.getFzXm());
			paramfw.put("fzzjhm",fzInfo.getFzSfzh());
			paramfw.put("fzdh",fzInfo.getFzDh());
			paramfw.put("fzgzdw",fzInfo.getFzDw());
			paramfw.put("fzjzdz",fzInfo.getFzJzd());
		}
//		实有居住人员
		List<SyjzryVO> syjzryList = rhzfSaveVO.getSyjzryList();
		syjzryList.stream().peek(syjzryVO -> {
			if(StringUtils.isNotBlank(syjzryVO.getRyType())){
				syjzryVO.setRyType("jwrk".equals(syjzryVO.getRyType())?"是":"否");
			}
			syjzryVO.setRhyzValue(syjzryVO.getRhyz() == 0?"是":"否");
		}).collect(Collectors.toList());
		paramfw.put("syjzryList",syjzryList);
		//特殊人群信息
		String tsrq = "";
		String zjxy = "";
		StringBuilder stringBuilder = new StringBuilder();
		StringBuilder stringBuilderZjxy = new StringBuilder();
		if(syjzryList.size()>0){
			for (int i = 0; i < syjzryList.size(); i++) {
				SyjzryVO syjzryVO = syjzryList.get(i);
				String ryXm = syjzryVO.getRyXm();
				Integer ryIndex = i+1;
				if(StringUtils.isNotBlank(syjzryVO.getRyTsLb())){
					String ryTsLb = syjzryVO.getRyTsLb();
					stringBuilder.append(ryIndex + "、" + ryXm + "-" + ryTsLb + "。\n");
				}
				if(StringUtils.isNotBlank(syjzryVO.getZjxy())){
					String ryzjxy = syjzryVO.getZjxy();
					if(!ryzjxy.contains("无")){
						stringBuilderZjxy.append(ryIndex + "、" + ryXm + "-" + ryzjxy + "。\n");
					}
				}
			}
			if(StringUtils.isNotBlank(stringBuilder.toString())){
				tsrq = stringBuilder.toString();
			}else{
				tsrq = "无特殊人群信息";
			}
			zjxy = stringBuilderZjxy.toString();
		}
		paramfw.put("tsrq",tsrq);
		paramfw.put("zjxy",zjxy);
		paramfw.put("sfyzjxy",StringUtils.isNotBlank(zjxy)?"是":"否");

		//矛盾纠纷
		//获取矛盾纠纷id，多个逗号分割的
		List<MdjfDjEntity> mdjfDjEntities = new ArrayList<>();
		if(StringUtils.isNotBlank(rhzfSaveVO.getMdId())){
			if(rhzfSaveVO.getMdId().length()>0){
				//创建矛盾数据集合
				String[] split = rhzfSaveVO.getMdId().split(",");
				for (int i = 0; i < split.length; i++) {
					MdjfDjEntity mdjfDj = new MdjfDjEntity();
					mdjfDj.setId(Long.parseLong(split[i]));
					MdjfDjEntity mdjfDjEntity = mdjfDjService.getDetail(mdjfDj);
					mdjfDjEntity.setJffssjStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( mdjfDjEntity.getJffssj()));
					mdjfDjEntity.setSftj(StringUtils.isNotBlank(mdjfDjEntity.getTjzt())?"是":"否");
					//获取矛盾纠纷人员
					List<MdjfRyEntity> mdjfRyEntities = mdjfRyService.getRyByMdId(Long.parseLong(split[i]));
					if(mdjfRyEntities.size()>0){
						StringBuilder jfryArr = new StringBuilder();
						for (int j = 0; j < mdjfRyEntities.size(); j++) {
							MdjfRyEntity mdjfRyEntity = mdjfRyEntities.get(j);
							String lb =mdjfRyEntity.getLb();
							String xm =mdjfRyEntity.getXm();
							jfryArr.append(lb+":"+xm+"\n");
						}
						mdjfDjEntity.setJfryArr(jfryArr.toString());
					}
					mdjfDjEntities.add(mdjfDjEntity);
				}
			}
		}
		paramfw.put("mdjfDjEntities",mdjfDjEntities);

//		//九小场所登记
		List<JxcsVO> jxcsList = rhzfSaveVO.getJxcsList();
		if(jxcsList.size()>0){
			jxcsList.stream().peek(jxcsVO -> {
				jxcsVO.setSffrValue(jxcsVO.getSffr() == 0?"是":"否");
			}).collect(Collectors.toList());
		}
		paramfw.put("jxcsList",jxcsList);

		//服务类型
		if(StringUtils.isNotBlank(rhzfSaveVO.getFwlx())){
			rhzfSaveVO.setSfsmfw("☑有               □无");
		}else{
			rhzfSaveVO.setSfsmfw("□有               ☑无");
		}
		paramfw.put("sfsmfw",rhzfSaveVO.getSfsmfw());
		paramfw.put("fwlx",rhzfSaveVO.getFwlx());

		//问题反应
//		if(StringUtils.isNotBlank(rhzfSaveVO.getWtfy())){
//			paramfw.put("sfywtfy","有".equals(rhzfSaveVO.getWtfy())?"☑有               □无":"□有               ☑无");
//			paramfw.put("wtfy", rhzfSaveVO.getWtfyFj() );
//		}
		//工作建议
//		paramfw.put("gzyj",StringUtils.isNotBlank(rhzfSaveVO.getGzyj())?rhzfSaveVO.getGzyj():"暂无建议");
		//签名   http://192.168.50.93:9000/jdrh/upload/20231227/Signature_1703639042681.jpg
		String qzzp = new String();
		if (rhzfSaveVO.getQzzp() != null){
			qzzp = rhzfSaveVO.getQzzp().replace("192.168.50.93","10.106.38.18");
		}
		paramfw.put("qzzp",qzzp);
		LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
		Configure config =
			Configure.builder()
				.bind("syjzryList", hackLoopTableRenderPolicy)
				.bind("jxcsList", hackLoopTableRenderPolicy)
				.bind("mdjfDjEntities", hackLoopTableRenderPolicy)
				.build();

		//2.获取根目录，创建模板文件
		String path = copyTempFile("word/czrk.docx");
		String fileName = "入户走访工作登记表-" + rhzfSaveVO.getDzmc() + ".docx";
		String tmpPath = path + fileName;
		try {
			//3.将模板文件写入到根目录
			//4.编译模板，渲染数据
			XWPFTemplate template = XWPFTemplate.compile(path, config).render(paramfw);
			//5.写入到指定目录位置
			FileOutputStream fos = new FileOutputStream(tmpPath);
			template.write(fos);
			fos.flush();
			fos.close();
			template.close();
//			//6.提供前端下载
			ExportWordUtil.down(response, tmpPath, fileName);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			//7.删除临时文件
			File file = new File(tmpPath);
			file.delete();
			File copyFile = new File(path);
			copyFile.delete();
		}
	}

	public static void main(String[] args) {
		String str = "http://192.168.50.93:9000/jdrh/upload/20231227/Signature_1703639042681.jpg";
		str = str.replace("192.168.50.93","10.106.38.18");
		System.out.println(str);
	}

	/**
	 * 将项目中的模板文件拷贝到根目录下
	 *
	 * @return
	 */
	private String copyTempFile(String templeFilePath) {
		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(templeFilePath);
		String tempFileName = System.getProperty("user.home") + "/" + "czrk.docx";
		File tempFile = new File(tempFileName);
		try {
			FileUtils.copyInputStreamToFile(inputStream, tempFile);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		return tempFile.getPath();
	}

	/**
	 * 获取字典，楼栋牌号后缀
	 */
	@GetMapping("getLdphhz")
	public R getLdphhz(Map<String,String> params){
		ZdVOS zdVOS = new ZdVOS();
		List<ZdVO> ldphhz = dictService.getLdphhz(params);
		zdVOS.setLdphhz(ldphhz);
		List<ZdVOSS> dept = deptService.getDept(AuthUtil.getDeptId());
		zdVOS.setDept(dept);
		ZdbEntity deptByZddm = zdbService.getDeptByZddm(AuthUtil.getDeptId());
		if(deptByZddm != null && "5".equals(deptByZddm.getLb())){
			if(deptByZddm.getParents().split(",").length == 5 ){
				List<ZdbEntity> zdb = zdbService.getParentsBySqbm(AuthUtil.getDeptId());
				zdVOS.setZdb(zdb);
			}
		}
		return R.data(zdVOS);
	}

	/**
	 * 获取当前人的社区
	 */
	@GetMapping("getDept")
	public R getDept(){
		return R.data(deptService.getDept(AuthUtil.getDeptId()));
	}

	/**
	 * 根据id查寻房主
	 */
	@GetMapping("getFzById")
	public R getFzById(Long id){
		return R.data(fwFzService.getFzById(id));
	}

	/**
	 * 修改房屋人员
	 */
	@Transactional
	@PostMapping("getFwry")
	public R getFwry(@RequestBody SyjzryVO syjzryVO){
		fwInfoService.gxUpdateTime(syjzryVO.getFwId());
		syjzryVO.setUpdateUser(AuthUtil.getUserId());
		if (syjzryVO.getRyType().equals("czrk")){
			czrkService.updateRy(syjzryVO);
			// 保存房主操作记录
			RhzfCzrkEntity rhzfCzrkEntity = new RhzfCzrkEntity();
			BeanUtil.copy(syjzryVO, rhzfCzrkEntity);
			czrkLogService.save(rhzfCzrkEntity);
		} else if (syjzryVO.getRyType().equals("jwrk")){
			RyJwrkEntity ryJwrkEntity = new RyJwrkEntity();
			ryJwrkEntity.setRyMz(syjzryVO.getRyXm());
			ryJwrkEntity.setRyXb(syjzryVO.getRyXb());
			ryJwrkEntity.setRyCsrq(syjzryVO.getRyCsrq());
			ryJwrkEntity.setRyDh(syjzryVO.getRyDh());
			ryJwrkEntity.setVx(syjzryVO.getVx());
			ryJwrkEntity.setRyZjhm(syjzryVO.getRySfzh());
			ryJwrkEntity.setDwMc(syjzryVO.getDwMc());
			ryJwrkEntity.setDwXz(syjzryVO.getDwXz());
			ryJwrkEntity.setZjxy(syjzryVO.getZjxy());
			ryJwrkEntity.setZjxyDm(syjzryVO.getZjxyDm());
			ryJwrkEntity.setUpdateUser(AuthUtil.getUserId());
			jwrkService.updateRy(ryJwrkEntity);
			// 保存房主操作记录
			RhzfJwrkEntity rhzfJwrkEntity = new RhzfJwrkEntity();
			BeanUtil.copy(syjzryVO, rhzfJwrkEntity);
			jwrkLogService.save(rhzfJwrkEntity);
		} else if (syjzryVO.getRyType().equals("jzrk")){
			jzrkService.updateRy(syjzryVO);
			// 保存房主操作记录
			RhzfJzrkEntity rhzfJzrkEntity = new RhzfJzrkEntity();
			BeanUtil.copy(syjzryVO, rhzfJzrkEntity);
			jzrkLogService.save(rhzfJzrkEntity);
		} else if (syjzryVO.getRyType().equals("wlrk")){
			wlrkService.updateRy(syjzryVO);
			// 保存房主操作记录
			RhzfWlrkEntity rhzfWlrkEntity = new RhzfWlrkEntity();
			BeanUtil.copy(syjzryVO, rhzfWlrkEntity);
			wlrkLogService.save(rhzfWlrkEntity);
		} else if (syjzryVO.getRyType().equals("zzrk")){
			zzrkService.updateRy(syjzryVO);
			// 保存房主操作记录
			RhzfZzrkEntity rhzfZzrkEntity = new RhzfZzrkEntity();
			BeanUtil.copy(syjzryVO, rhzfZzrkEntity);
			zzrkLogService.save(rhzfZzrkEntity);
		}
		return R.success("修改成功");
	}


	//检查单导出

	@RequestMapping("/jcddc")
	public void jcddc(HttpServletResponse response, String pc) {
		//通过批次 获取要检查的房屋
		List<Fwccjgb> jcdList = fwInfoService.getJcdList(pc);
		List<String> filePathList = new ArrayList<>();
		if(jcdList.size()>0){
			for (int i = 0; i <jcdList.size() ; i++) {
				//创建检查单的参数
				Map<String, Object> paramfw = new HashMap<>();
				//根据房屋的id 获取房主信息
				Fwccjgb fwccjgb = jcdList.get(i);
				paramfw.put("sj", fwccjgb.getSjName());
				paramfw.put("fj", fwccjgb.getFjName());
				paramfw.put("pcs", fwccjgb.getPcsname());
				paramfw.put("mj", fwccjgb.getSqmj());
				paramfw.put("xz", fwccjgb.getXz());
				QueryWrapper<FwFzEntity> fzqe = new QueryWrapper<>();
				fzqe.eq("fw_id", fwccjgb.getId());
				fzqe.eq("is_deleted", 0);
				fzqe.orderByDesc("update_time");
				List<FwFzEntity> fzlist = fwFzService.list(fzqe);
				if (fzlist.size() > 0) {
//					fwccjgb.setFzxm(fzlist.get(0).getFzXm());
//					fwccjgb.setFzsfzh(fzlist.get(0).getFzSfzh());
//					fwccjgb.setFzdh(fzlist.get(0).getFzDh());
					paramfw.put("fzxm", fzlist.get(0).getFzXm());
					paramfw.put("fzsfzh", fzlist.get(0).getFzSfzh());
					paramfw.put("fzdh", fzlist.get(0).getFzDh());
				}
				//根据房屋的id 获取房间人员
				Map<String, Object> params = new HashMap<>();
				params.put("dzbm", fwccjgb.getDzbm());
				params.put("fwid", fwccjgb.getId());
				//通过id，获取房屋的具体信息
				R fjDetail = getFjDetailByFwIdAndDzbm(params);
				RhzfSaveVO rhzfSaveVO = (RhzfSaveVO)fjDetail.getData();
				List<SyjzryVO> syjzryList = rhzfSaveVO.getSyjzryList();
				paramfw.put("jzry", syjzryList);
				LoopRowTableRenderPolicy hackLoopTableRenderPolicy = new LoopRowTableRenderPolicy();
				Configure config =
					Configure.builder()
						.bind("jzry", hackLoopTableRenderPolicy)
						.build();
				//2.获取根目录，创建模板文件
				String path = copyTempFile("word/rhhcd.docx");
				String fileName = "入户走访工作核查表-" + fwccjgb.getXz() + ".docx";
				String tmpPath = path + fileName;
				filePathList.add(tmpPath);
				try {
					//3.将模板文件写入到根目录
					//4.编译模板，渲染数据
					XWPFTemplate template = XWPFTemplate.compile(path, config).render(paramfw);
					//5.写入到指定目录位置
					FileOutputStream fos = new FileOutputStream(tmpPath);
					template.write(fos);
//			//6.提供前端下载
					fos.flush();
					fos.close();
					template.close();

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			ExportWordUtil.zipAndDownload(response, filePathList, "rhzf.zip");
			for(String filePath: filePathList){
				//7.删除临时文件
				File file = new File(filePath);
				if(file.exists()){
					file.delete();
				}
			}
		}

	}

	/**
	 * 房间详情
	 * params ldphxlh dzbm
	 */
	@GetMapping("/getFjDetailByFwIdAndDzbm")
	public R getFjDetailByFwIdAndDzbm(@RequestParam Map<String, Object> params) {
		// 房间详情
		RhzfSaveVO rhzfSaveVO = fwInfoService.getFjDetailByFwIdAndDzbm(params);
		// 根据dzbm 查rhzf_fw_info是否已有数据
		FwInfoEntity fwInfo = new FwInfoEntity();
		fwInfo.setDzbm(params.get("dzbm").toString());
		List<SyjzryVO> syjzryList2 = new ArrayList<>();
//		if (null == params.get("id") || StringUtils.isBlank(params.get("id").toString())) {
		List<FwRyVO> ryList = fwInfoService.getRyList(params);
		for (FwRyVO fwRyVO : ryList) {
			SyjzryVO syjzryVO = new SyjzryVO();
			params.put("ryId", fwRyVO.getRyId());
			if (fwRyVO.getRyType().equals("czrk")) {
				syjzryVO = fwInfoService.getCzrk(params);
			} else if (fwRyVO.getRyType().equals("jwrk")) {
				syjzryVO = fwInfoService.getJwrk(params);
				syjzryVO.setRyYwm(syjzryVO.getRyMz());
			} else if (fwRyVO.getRyType().equals("jzrk")) {
				syjzryVO = fwInfoService.getJzrk(params);
			} else if (fwRyVO.getRyType().equals("wlrk")) {
				syjzryVO = fwInfoService.getWlrk(params);
			} else if (fwRyVO.getRyType().equals("zzrk")) {
				syjzryVO = fwInfoService.getZzrk(params);
			}
			syjzryList2.add(syjzryVO);
		}
		rhzfSaveVO.setSyjzryList(syjzryList2);
		return R.data(rhzfSaveVO);
	}

	/**
	 * 获取特殊人群列表
	 */
	@GetMapping("getTsrq")
	public R getTsrq(){
		return R.data(dictService.getTsrq());
	}

	/**
	 * 根据excel查询五类人口库是否存在
	 */
	@PostMapping("selectRkBySfzhExcel")
	public R<Boolean> selectRkBySfzhExcel(MultipartFile file) {
		List<HcbdEntity> hcbdlist = new ArrayList<>();
		List<HcbdExcel> list = ExcelUtil.read(file, HcbdExcel.class);
		if (list.size() > 1000) {
			return R.fail("只能上传1000条数据，请调整excel");
		}
		for (HcbdExcel hcbdExcel : list) {
			HcbdExcel sfcz = hcbdService.selectRkByExcel(hcbdExcel.getSfzh(), AuthUtil.getDeptId());
			HcbdEntity hcbd = BeanUtil.copy(hcbdExcel, HcbdEntity.class);
			if (sfcz != null) {
				hcbd.setSfcz("是");
			} else {
				hcbd.setSfcz("否");
			}
			hcbdlist.add(hcbd);
		}
		return R.data(hcbdService.saveBatch(hcbdlist));
	}

	/**
	 * 导出
	 */
	@GetMapping("/export-hcbd")
	public void exportHcbd(HttpServletResponse response) {
		List<HcbdExcel> list = hcbdService.exportHcbd(AuthUtil.getDeptId());
		ExcelUtil.export(response, "证件比对" + DateUtil.time(), "证件比对", list, HcbdExcel.class);
		hcbdService.deletedHcbd(AuthUtil.getUserId());
	}

	/**
	 * 核查比对列表
	 */
	@GetMapping("hcbdPage")
	public R hcbdPage(Map<String, Object> params, Query query) {
		params.put("userId", AuthUtil.getUserId());
		IPage<HcbdEntity> page = hcbdService.selectHcbdPage(Condition.getPage(query), params);
		return R.data(page);
	}

	/**
	 * 模板导出
	 */
	@PostMapping("exportTemplateHcbd")
	public void exportTemplateHcbd(HttpServletResponse response) {
		List<HcbdsExcel> list = new ArrayList<>();
		ExcelUtil.export(response, "比对模板", "证件比对", list, HcbdsExcel.class);
	}
}
