package org.springblade.modules.mdjfdj.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.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xiaoleilu.hutool.util.NetUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.common.cache.DictBizCache;
import org.springblade.common.controller.vo.webService.YwxxVO;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
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.modules.gzInfo.vo.ZdVo;
import org.springblade.modules.log.sjSp.entity.SjSpEntity;
import org.springblade.modules.log.sjSp.service.ISjSpService;
import org.springblade.modules.mdjfdj.entity.JdrhApptj;
import org.springblade.modules.mdjfdj.entity.MdjfDjEntity;
import org.springblade.modules.mdjfdj.excel.MdjfDjExcel;
import org.springblade.modules.mdjfdj.service.IJdrhApptjService;
import org.springblade.modules.mdjfdj.service.IMdjfDjService;
import org.springblade.modules.mdjfdj.vo.JqVO;
import org.springblade.modules.mdjfdj.vo.MdXgVO;
import org.springblade.modules.mdjfdj.vo.MdjfDjVO;
import org.springblade.modules.mdjfdj.wrapper.MdjfDjWrapper;
import org.springblade.modules.mdjfhf.entity.HfEntity;
import org.springblade.modules.mdjfhf.service.IHfService;
import org.springblade.modules.mdjfpj.entity.PjEntity;
import org.springblade.modules.mdjfpj.service.IPjService;
import org.springblade.modules.mdjfry.entity.MdjfRyEntity;
import org.springblade.modules.mdjfry.service.IMdjfRyService;
import org.springblade.modules.mdjftj.entity.MdjfTjEntity;
import org.springblade.modules.mdjftj.service.IMdjfTjService;
import org.springblade.modules.mdjfxj.djXj.entity.DjXjEntity;
import org.springblade.modules.mdjfxj.djXj.service.IDjXjService;
import org.springblade.modules.mdjfxj.pjXj.entity.PjXjEntity;
import org.springblade.modules.mdjfxj.pjXj.service.IPjXjService;
import org.springblade.modules.mdjfxj.ryXj.entity.RyXjEntity;
import org.springblade.modules.mdjfxj.ryXj.service.IRyXjService;
import org.springblade.modules.mdjfxj.tjXj.entity.TjXjEntity;
import org.springblade.modules.mdjfxj.tjXj.service.ITjXjService;
import org.springblade.modules.rhzf.fwInfo.service.IFwInfoService;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.entity.DictBiz;
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.IUserService;
import org.springblade.modules.system.vo.DeptListVo;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.*;

/**
 * 矛盾纠纷登记表 控制器
 *
 * @author BladeX
 * @since 2023-08-02
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-mdjfdj/mdjfdj")
@Api(value = "矛盾纠纷登记表", tags = "矛盾纠纷登记表接口")
@Slf4j
public class MdjfDjController extends BladeController {

	private final IMdjfDjService mdjfdjService;
	private final IMdjfRyService mdjfryService;
	private final IMdjfTjService mdjftjService;
	private final IPjService pjService;
	private final IJdrhApptjService jdrhApptjService;
	private final IDictBizService dictBizService;
	private final IUserService userService;
	private final IDeptService deptService;
	private final IHfService hfService;
	private final ISjSpService sjSpService;
	private final IFwInfoService fwInfoService;
	private final IDjXjService djXjService;
	private final ITjXjService tjXjService;
	private final IRyXjService ryXjService;
	private final IPjXjService pjXjService;



	/**
	 * 矛盾纠纷登记表 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入mdjfdj")
	public R<MdjfDjEntity> detail(MdjfDjEntity mdjfdj) {
		//MdjfDjEntity detail = mdjfdjService.getOne(Condition.getQueryWrapper(mdjfdj));
		MdjfDjEntity detail = mdjfdjService.getDetail(mdjfdj);
		User user = userService.getById(detail.getCreateUser());
		detail.setCreateName(user.getName());
		return R.data(detail);
	}

	/**
	 * 矛盾纠纷登记表 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入mdjfdj")
	public R<IPage<MdjfDjVO>> list(@ApiIgnore @RequestParam Map<String, Object> mdjfdj, Query query) {
		IPage<MdjfDjEntity> pages = mdjfdjService.page(Condition.getPage(query), Condition.getQueryWrapper(mdjfdj, MdjfDjEntity.class));
		return R.data(MdjfDjWrapper.build().pageVO(pages));
	}

	/**
	 * 矛盾纠纷登记表 自定义分页
	 */
	@GetMapping("/page")
	public R page(@RequestParam Map<String, Object> params, Query query) {
		params.put("deptId", AuthUtil.getDeptId());
		IPage<MdjfDjVO> pages = mdjfdjService.selectmdjfDjPage(Condition.getPage(query), params);
		return R.data(pages);
	}

	/**
	 * 矛盾纠纷登记表 自定义分页
	 */
	@GetMapping("/page-app")
	public R pageToApp(@RequestParam Map<String, Object> params, Query query) {
		params.put("deptId", AuthUtil.getDeptId());
		params.put("userId", AuthUtil.getUserId());
		String[] mdIds = new String[0];
		if (params.get("mdId") != null) {
			String mdId = params.get("mdId").toString();
			mdIds = mdId.split(",");
		}
		IPage<MdjfDjVO> pages = mdjfdjService.pageToApp(Condition.getPage(query), params, mdIds);
		return R.data(pages);
	}

	/**
	 * 矛盾纠纷详情
	 */
	@GetMapping("/detailById")
	public R detailById(@RequestParam Long id) {
//		MdjfDjEntity mdjfDj = new MdjfDjEntity();
//		mdjfDj = mdjfdjService.getDetail(mdjfDj);
		MdjfDjEntity mdjfDj = mdjfdjService.getById(id);
		Dept sq = new Dept();
		if (mdjfDj.getJfsssq() != null) {
			sq = deptService.getById(mdjfDj.getJfsssq());
		}
		if (null != sq.getDeptName()) {
			mdjfDj.setSqName(sq.getDeptName());
		}
		List<MdjfRyEntity> mdjfRyList = mdjfryService.getRyByMdId(id);
		MdjfDjVO mdjfDetail = new MdjfDjVO(null, mdjfDj, mdjfRyList, new ArrayList<MdjfTjEntity>());
		return R.data(mdjfDetail);
	}

	/**
	 * 矛盾纠纷登记表 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入mdjfdj")
	public R save(@Valid @RequestBody MdjfDjEntity mdjfdj) {
		return R.status(mdjfdjService.save(mdjfdj));
	}

	/**
	 * 矛盾纠纷登记
	 */
	@DSTransactional
	@PostMapping("/mdjfDj")
	public R mdjfDj(@RequestBody MdjfDjVO mdjfdj) {
		MdjfDjEntity mdjf = mdjfdj.getMdjfDj();
		//添加矛盾已回访次数 默认0   回访状态 默认0   回访是否超时 0
		mdjf.setYhfcs(0);
		mdjf.setCscs(0);
		if (StringUtils.isNotBlank(mdjf.getMdjbV())) {
			String mdjbV = mdjf.getMdjbV();
			mdjf.setXhfcs(Integer.valueOf(DictBizCache.getValue("mdhfcs", mdjbV)));
		}

		// 矛盾纠纷登记
		mdjfdjService.save(mdjf);
		String deptId = AuthUtil.getDeptId().split(",")[0];
		Dept dept = deptService.getById(Long.valueOf(deptId));
		if (dept.getAncestors().contains("220200000000")) {
			mdjfdjService.saveToJl(mdjf);
		}
		// 人员登记
		if (null != mdjfdj.getMdjfRyList() && mdjfdj.getMdjfRyList().size() > 0) {
			List<MdjfRyEntity> mdjfRyList = mdjfdj.getMdjfRyList();
			for (int i = 0; i < mdjfRyList.size(); i++) {
				mdjfRyList.get(i).setJfId(mdjf.getId());
			}
			mdjfryService.saveBatch(mdjfRyList);
			if (dept.getAncestors().contains("220200000000")) {
				mdjfryService.saveBatchToJl(mdjfRyList);
			}
		}
		// 调解记录
		if (null != mdjfdj.getMdjfTjList() && mdjfdj.getMdjfTjList().size() > 0) {
			List<MdjfTjEntity> mdjfTjList = mdjfdj.getMdjfTjList();
			for (int i = 0; i < mdjfTjList.size(); i++) {
				mdjfTjList.get(i).setJfId(mdjf.getId());
			}
			mdjftjService.saveBatch(mdjfTjList);
		}

		if (null != mdjfdj.getFwId()) {
			fwInfoService.updateMdId(mdjfdj.getFwId(), mdjf.getId());
		}
		return R.data(mdjf.getId());
	}

	/**
	 * 矛盾纠纷登记表 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入mdjfdj")
	public R update(@Valid @RequestBody MdjfDjEntity mdjfdj) {
		if (null == mdjfdj.getId()) {
			return R.fail("请重试");
		}
		return R.status(mdjfdjService.updateById(mdjfdj));
	}

	/**
	 * 矛盾纠纷修改 - APP
	 */
	@PostMapping("/updateByApp")
	public R updateByApp(@RequestBody MdXgVO mdXgVO) {
		if (sjSpService.getIsExist(3, String.valueOf(mdXgVO.getMdjfDj().getId())) > 0) {
			return R.fail("等待分局审批中，请不要重复提交");
		}
		SjSpEntity sjSpEntity = new SjSpEntity();
		sjSpEntity.setYwlb(3);
		sjSpEntity.setYwid(mdXgVO.getMdjfDj().getId());
		sjSpEntity.setParams(JSONObject.toJSONString(mdXgVO));
		sjSpEntity.setQqyy(mdXgVO.getQqyy());
		return R.status(sjSpService.save(sjSpEntity));
	}

	/**
	 * 矛盾纠纷回访
	 */
	@PostMapping("/addHuiFang")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入mdjfdj")
	public R addHuiFang(@Valid @RequestBody MdjfDjEntity mdjfdj) {
		mdjfdjService.addHuiFang(mdjfdj);
		return R.status(true);
	}

	/**
	 * 矛盾纠纷登记表 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入mdjfdj")
	public R submit(@Valid @RequestBody MdjfDjEntity mdjfdj) {
		if (StringUtils.isNotBlank(mdjfdj.getPj()) && mdjfdj.getPjsj() == null) {
			mdjfdj.setPjsj(new Date());
			mdjfdj.setPjr(AuthUtil.getUserName());
		}
		if (StringUtils.isNotBlank(mdjfdj.getFknr()) && mdjfdj.getFksj() == null) {
			mdjfdj.setFksj(new Date());
			mdjfdj.setFkr(AuthUtil.getUserName());
			mdjfdj.setFkdw(Long.parseLong(AuthUtil.getUser().getDeptId()));
		}
		mdjfdj.setYhfcs(0);
		mdjfdj.setCscs(0);
		if(StringUtils.isNotBlank(mdjfdj.getMdjbV())){
			String mdjbV = mdjfdj.getMdjbV();
			mdjfdj.setXhfcs(Integer.valueOf(DictBizCache.getValue("mdhfcs",mdjbV)));
		}
		return R.status(mdjfdjService.saveOrUpdate(mdjfdj));
	}

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

	/**
	 * 导出数据
	 */
	@GetMapping("/export-mdjfdj")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "导出数据", notes = "传入mdjfdj")
	public void exportmdjfDj(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) {
		params.put("deptId", AuthUtil.getDeptId());
		List<MdjfDjExcel> list = mdjfdjService.exportmdjfDj(params);
		ExcelUtil.export(response, "矛盾纠纷数据" + DateUtil.time(), "矛盾纠纷数据", list, MdjfDjExcel.class);
	}

	@GetMapping("/selectJflx")
	public R selectJflx(@RequestParam Map<String, Object> params) {
		// params : parentId 一级字典固定传 1686566442075504641 二级字典传一级字典的id
		List<ZdVo> list = dictBizService.selectJflx(params);
		if (null == list || list.size() == 0) {
			list = dictBizService.selectJflx2(params);
		}
		System.out.println("selectJflx :: " + list);
		return R.data(list);
	}

	@GetMapping("/getMddjzd")
	public R getMddjzd(@RequestParam Map<String, Object> params) {
		Mddjzd mddjzd = new Mddjzd();
		// params : parentId 一级字典固定传 1686566442075504641 二级字典传一级字典的id
		List<ZdVo> list = dictBizService.selectJflx(params);
		if (null == list || list.size() == 0) {
			list = dictBizService.selectJflx2(params);
		}
		List<DeptListVo> deptListVos = deptService.getDeptList(AuthUtil.getUserId());
		List<DictBiz> dictBizs = dictBizService.getListPC(params.get("code").toString());
		mddjzd.setJflxvos(list);
		mddjzd.setDeptListVos(deptListVos);
		mddjzd.setMddjvos(dictBizs);

		return R.data(mddjzd);
	}
	@Data
	class Mddjzd{
		private List<ZdVo> jflxvos;
		private List<DeptListVo> deptListVos;
		private List<DictBiz> mddjvos;

	}

	//@Scheduled(cron = "0 0 0/1 * * ?")
	public void getHfcscs() {
		//查询未回访和回访中、矛盾级别不为null，第一次回访截止时间不是null（已调解） 的的矛盾
		QueryWrapper<MdjfDjEntity> qe = new QueryWrapper<>();
		qe.in("hfzt_new","0","1");
		qe.isNotNull("hfjzsj");
		qe.isNotNull("mdjb_v");
		qe.eq("is_deleted",0);
		List<MdjfDjEntity> list = mdjfdjService.list(qe);
		if(list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Date date = new Date();
				MdjfDjEntity mdjfDjEntity = list.get(i);

				/**
				 * 判断逻辑：前提：设置每次回访的状态是默认0   回访状态正常是1  超时是2
				 * 1、当前时间在第一次回访和第二次回访之间时，判断第一次回访状态：查询第一次回访截止时间之前的所有回访次数
				 * 		如果回访次数等于0，则dychf设置为2，,并且该矛盾存在超时，设置矛盾的超时状态为1。
				 * 		如果回访次数大于0，则dychf设置为1.
				 */
				if (date.compareTo(mdjfDjEntity.getHfjzsj()) > 0 && date.compareTo(mdjfDjEntity.getHfjzsj2()) < 0) {
					if (mdjfDjEntity.getDychf() == 0) {
						List<HfEntity> num1 = hfService.getCountsHfcsByMdId(mdjfDjEntity.getId(), mdjfDjEntity.getHfjzsj());
						if (num1.size() > 0) {
							mdjfDjEntity.setDychf(1);
						} else {
							mdjfDjEntity.setDychf(2);
							mdjfDjEntity.setCszt("1");
						}
					}
				}
				/**
				 * 1、当前时间在第2次回访和第三次回访之间时，判断第2次回访状态：
				 * 		A或B等级的矛盾，第二次回访截止时间之前，需回访两次，所以判断第二次回访截止时间之前的回访次数即可
				 * 		回访次数小于2时，dechf状态一定是超时的
				 * 		回访次数大于等于2时，需判断最有后一次回访的时间是否在第一次回访截止时间和第二次回访截止时间之内
				 * 		如果在期间，则dechf设置为1
				 * 		否则设置为2，该矛盾存在超时，设置矛盾的超时状态为1。
				 */
				if (date.compareTo(mdjfDjEntity.getHfjzsj2()) > 0 && date.compareTo(mdjfDjEntity.getHfjzsj3()) < 0) {
					if (mdjfDjEntity.getDechf() == 0 && (mdjfDjEntity.getMdjbV().contains("A") || mdjfDjEntity.getMdjbV().contains("B"))) {
						List<HfEntity> num2 = hfService.getCountsHfcsByMdId(mdjfDjEntity.getId(), mdjfDjEntity.getHfjzsj2());
						if (num2.size() >= 2) {
							HfEntity hfEntity = num2.get(num2.size() - 1);
							if (hfEntity.getCreateTime().compareTo(mdjfDjEntity.getHfjzsj()) > 0) {
								mdjfDjEntity.setDechf(1);
							} else {
								mdjfDjEntity.setDechf(2);
								mdjfDjEntity.setCszt("1");
							}
						} else {
							mdjfDjEntity.setDechf(2);
							mdjfDjEntity.setCszt("1");
						}
					}
				}
				/**
				 * 与第二次判断逻辑差不多，只是时间和矛盾等级有一些变化
				 */
				if (date.compareTo(mdjfDjEntity.getHfjzsj3()) > 0) {
					if (mdjfDjEntity.getDschf() == 0 && mdjfDjEntity.getMdjbV().contains("A")) {
						List<HfEntity> num3 = hfService.getCountsHfcsByMdId(mdjfDjEntity.getId(), mdjfDjEntity.getHfjzsj3());
						if (num3.size() >= 3) {
							HfEntity hfEntity = num3.get(num3.size() - 1);
							if (hfEntity.getCreateTime().compareTo(mdjfDjEntity.getHfjzsj2()) > 0 && hfEntity.getCreateTime().compareTo(mdjfDjEntity.getHfjzsj3()) < 0) {
								mdjfDjEntity.setDschf(1);
							} else {
								mdjfDjEntity.setDschf(2);
								mdjfDjEntity.setCszt("1");
							}
						} else {
							mdjfDjEntity.setDschf(2);
							mdjfDjEntity.setCszt("1");
						}
					}
				}
				mdjfdjService.updateById(mdjfDjEntity);

			}
		}
	}
	//添加apptj（app统计）定时任务
	@Scheduled(cron = "0 0 3 * * ?")
//	@GetMapping("/getAppTj")
	public void getAppTj() {
		LinkedHashSet<String> strings = NetUtil.localIpv4s();
		for (String s : strings) {
			if ("10.106.55.38".equals(s)) {
				log.error("执行定时任务的IP："+s);
				List<JdrhApptj> appTjList = jdrhApptjService.getAppTj();
				for (int j = 0; j < appTjList.size(); j++) {
					//昨日统计
					JdrhApptj jdrhApptj = appTjList.get(j);
					Long bmid = jdrhApptj.getBmid();
					//前日统计
					List<JdrhApptj> daysAgoTj = jdrhApptjService.get2DaysAgoTj(bmid);
					if (daysAgoTj.size() > 0) {
						jdrhApptj.setZrjxcj(jdrhApptj.getCssl() - daysAgoTj.get(0).getCssl());
						jdrhApptj.setZrjxjc(jdrhApptj.getJccs() - daysAgoTj.get(0).getJccs());
						jdrhApptj.setZrzfl(jdrhApptj.getZfl() - daysAgoTj.get(0).getZfl());
					}
				}
				jdrhApptjService.saveBatch(appTjList);
			}else{
				log.error("未执行定时任务的IP："+s);
			}
		}
	}
//	@Scheduled(cron = "0 0 3 * * ?")
	@GetMapping("/getAppTj1")
	public void getAppTj1() {
		LinkedHashSet<String> strings = NetUtil.localIpv4s();
		for (String s : strings) {
			if ("10.106.55.12".equals(s)) {
				log.error("执行定时任务的IP："+s);
				List<JdrhApptj> appTjList = jdrhApptjService.getAppTj();
				for (int j = 0; j < appTjList.size(); j++) {
					//昨日统计
					JdrhApptj jdrhApptj = appTjList.get(j);
					Long bmid = jdrhApptj.getBmid();
					//前日统计
					List<JdrhApptj> daysAgoTj = jdrhApptjService.get2DaysAgoTj(bmid);
					if (daysAgoTj.size() > 0) {
						jdrhApptj.setZrjxcj(jdrhApptj.getCssl() - daysAgoTj.get(0).getCssl());
						jdrhApptj.setZrjxjc(jdrhApptj.getJccs() - daysAgoTj.get(0).getJccs());
						jdrhApptj.setZrzfl(jdrhApptj.getZfl() - daysAgoTj.get(0).getZfl());
					}
				}
				jdrhApptjService.saveBatch(appTjList);
			}else{
				log.error("未执行定时任务的IP："+s);
			}
		}
	}

	/**
	 * 查询jfly=110警情的矛盾列表
	 */
	@GetMapping("/getMdList")
	public R getMdList(@RequestParam Map<String, Object> params, Query query) {
		params.put("deptId", AuthUtil.getDeptId());
		IPage<MdjfDjVO> pages = mdjfdjService.getMdList(Condition.getPage(query), params);
		return R.data(pages);
	}

	/**
	 * 根据报警人联系电话，查询警情
	 */
	@GetMapping("/getJqByLxdh")
	public R getJqByLxdh(@RequestParam Map<String, String> params) {
		String deptId = "";
		Dept deptCategory = deptService.getDeptCategory(AuthUtil.getDeptId().split(",")[0]);
		if (deptCategory.getDeptCategory() == 4 || deptCategory.getDeptCategory() == 14) {
			deptId = AuthUtil.getDeptId();
		} else {
			Dept dept = deptService.getSjByAccount(AuthUtil.getDeptId().split(",")[0]);
			if (null == dept) {
				return R.fail("用户所属部门不正确");
			} else {
				deptId = String.valueOf(dept.getId());
			}
		}
		switch (deptId) {
			case "220100000000":
				params.put("xzqh", "长春市");
				break;
			case "220200000000":
				params.put("xzqh", "吉林市");
				break;
			case "220300000000":
				params.put("xzqh", "四平市");
				break;
			case "220400000000":
				params.put("xzqh", "辽源市");
				break;
			case "220500000000":
				params.put("xzqh", "通化市");
				break;
			case "220581000000":
				params.put("xzqh", "梅河口市");
				break;
			case "220600000000":
				params.put("xzqh", "白山市");
				break;
			case "220700000000":
				params.put("xzqh", "松原市");
				break;
			case "220800000000":
				params.put("xzqh", "白城市");
				break;
			case "222400000000":
				params.put("xzqh", "延边州");
				break;
			case "229000000000":
				params.put("xzqh", "长白山市");
				break;
		}
		List<JqVO> jqList = mdjfdjService.getJqByLxdh(params);
		return R.data(jqList);
	}

	/**
	 * 查询警情分母
	 */
	@GetMapping("/getJqFm")
	public R getJqFm(@RequestParam Map<String, String> params, Query query) {
		String deptId = "";
		Dept deptCategory = deptService.getDeptCategory(AuthUtil.getDeptId().split(",")[0]);
		if (deptCategory.getDeptCategory() == 4 || deptCategory.getDeptCategory() == 14) {
			deptId = AuthUtil.getDeptId();
		} else {
			Dept dept = deptService.getSjByAccount(AuthUtil.getDeptId().split(",")[0]);
			if (null == dept) {
				return R.fail("用户所属部门不正确");
			} else {
				deptId = String.valueOf(dept.getId());
			}
		}
		switch (deptId) {
			case "220000000000":
				params.put("xzqh", "吉林省");
				break;
			case "220100000000":
				params.put("xzqh", "长春市");
				break;
			case "220200000000":
				params.put("xzqh", "吉林市");
				break;
			case "220300000000":
				params.put("xzqh", "四平市");
				break;
			case "220400000000":
				params.put("xzqh", "辽源市");
				break;
			case "220500000000":
				params.put("xzqh", "通化市");
				break;
			case "220581000000":
				params.put("xzqh", "梅河口市");
				break;
			case "220600000000":
				params.put("xzqh", "白山市");
				break;
			case "220700000000":
				params.put("xzqh", "松原市");
				break;
			case "220800000000":
				params.put("xzqh", "白城市");
				break;
			case "222400000000":
				params.put("xzqh", "延边州");
				break;
			case "229000000000":
				params.put("xzqh", "长白山市");
				break;
		}
		IPage<JqVO> jqList = mdjfdjService.getJqFm(Condition.getPage(query), params);
		return R.data(jqList);
	}

	/**
	 * 没有反馈的警情提醒
	 */
	@GetMapping("/getJqTx")
	public R getJqTx() {
		List<JqVO> jqList = new ArrayList<>();
		YwxxVO ywxxVO = fwInfoService.getYwxxParams(AuthUtil.getUserId());
		if (null != ywxxVO && StringUtils.isNotBlank(ywxxVO.getGajgdm())) {
			jqList = mdjfdjService.getJqTx(ywxxVO.getGajgdm());
		}
		return R.data(jqList);
	}
	/**
	 * 将其他警种录入的矛盾纠纷转至mdjf_dj表
	 */
	@PostMapping("getMdjfdj")
	public R getMdjfdj(@RequestBody DjXjEntity djXjEntity) {
		djXjService.updateById(djXjEntity);
		DjXjEntity djXj = djXjService.getById(djXjEntity.getId());
		MdjfDjEntity mdjfDjEntity = new MdjfDjEntity();
		BeanUtil.copy(djXj, mdjfDjEntity);
		mdjfdjService.save(mdjfDjEntity);
		QueryWrapper<TjXjEntity> tjxj = new QueryWrapper<>();
		tjxj.eq("jf_id", djXjEntity.getId());
		List<TjXjEntity> tjxjList = tjXjService.list(tjxj);
		for (TjXjEntity tj:tjxjList) {
			MdjfTjEntity mdjfTjEntity = new MdjfTjEntity();
			BeanUtil.copy(tj, mdjfTjEntity);
			mdjftjService.save(mdjfTjEntity);
		}
		QueryWrapper<RyXjEntity> ryxj = new QueryWrapper<>();
		ryxj.eq("jf_id", djXjEntity.getId());
		List<RyXjEntity> ryxjList = ryXjService.list(ryxj);
		for (RyXjEntity ry:ryxjList) {
			MdjfRyEntity mdjfRyEntity = new MdjfRyEntity();
			BeanUtil.copy(ry, mdjfRyEntity);
			mdjfryService.save(mdjfRyEntity);
		}
		QueryWrapper<PjXjEntity> pjxj = new QueryWrapper<>();
		pjxj.eq("jf_id", djXjEntity.getId());
		List<PjXjEntity> pjxjList = pjXjService.list(pjxj);
		for (PjXjEntity pj:pjxjList) {
			PjEntity pjEntity = new PjEntity();
			BeanUtil.copy(pj, pjEntity);
			pjService.save(pjEntity);
		}
		return R.success("操作成功");
	}
}
