package org.springblade.modules.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.entity.*;
import org.springblade.modules.service.*;
import org.springblade.modules.vo.BfshVO;
import org.springblade.modules.vo.TdryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@AllArgsConstructor
@RequestMapping("api")
public class TdryController {

	private CcxqService ccxqService;

	private HdcsService hdcsService;

	private JbxxService jbxxService;

	private ShgxService shgxService;

	private XsbxService xsbxService;

	private TdxwService tdxwService;

	private CzjlService czjlService;

	private GzzService gzzService;

	private GzzcyService gzzcyService;

	private HkblService hkblService;

	/**
	 * 人员列表
	 */
	@GetMapping("page")
	public R page(@RequestParam Map<String, Object> params, Query query) {
		IPage<JbxxEntity> page = jbxxService.selectRyPage(Condition.getPage(query), params);
		return R.data(page);
	}

	/**
	 * 人员信息录入
	 */
	@PostMapping("saveRy")
	public R saveRy(@RequestBody TdryVO tdryVO) {
		CcxqEntity ccxq = new CcxqEntity();
		BeanUtils.copyProperties(tdryVO, ccxq);
		HdcsEntity hdcs = new HdcsEntity();
		BeanUtils.copyProperties(tdryVO, hdcs);
		JbxxEntity jbxx = new JbxxEntity();
		BeanUtils.copyProperties(tdryVO, jbxx);
		ShgxEntity shgx = new ShgxEntity();
		BeanUtils.copyProperties(tdryVO, shgx);
		XsbxEntity xsbx = new XsbxEntity();
		BeanUtils.copyProperties(tdryVO, xsbx);
		ccxqService.save(ccxq);
		hdcsService.save(hdcs);
		jbxxService.save(jbxx);
		shgxService.save(shgx);
		xsbxService.save(xsbx);
		if (!tdryVO.getScjm().equals("") && tdryVO.getScjm() != null) {
			// 建立档案
			// 政治教育谈话
		}
		if (!tdryVO.getSfxy().equals("") && tdryVO.getSfxy() != null) {
			CzjlEntity czjl = new CzjlEntity();
			BeanUtils.copyProperties(tdryVO, czjl);
			czjlService.save(czjl);
		}
		if (!tdryVO.getSfyhk().equals("") && tdryVO.getSfyhk() != null) {
			HkblEntity hkbl = new HkblEntity();
			BeanUtils.copyProperties(tdryVO, hkbl);
			hkblService.save(hkbl);
		}
		return R.data("录入成功");
	}

	/**
	 * 特定行为录入
	 */
	@PostMapping("saveTdxw")
	public R saveTdxw(@RequestBody TdxwEntity tdxwEntity) {
		return R.data(tdxwService.save(tdxwEntity));
	}

	/**
	 * 扬言报复社会他人的人员工作措施展开
	 */
	@PostMapping("bfshrygzzk")
	public R bfshrygzzk(@RequestBody BfshVO bfshVO) {
		if (bfshVO.getRyfxdj().equals("一般")) {
			CzjlEntity czjl = new CzjlEntity();
			BeanUtils.copyProperties(bfshVO, czjl);
			czjlService.save(czjl);
		} else if (bfshVO.getRyfxdj().equals("中") || bfshVO.getRyfxdj().equals("高")) {
			GzzEntity tdry = gzzService.selectTdryId(bfshVO.getTdryId());
			if (tdry == null) {
				GzzEntity gzz = new GzzEntity();
				BeanUtils.copyProperties(bfshVO, gzz);
				gzzService.save(gzz);
				for (GzzcyEntity gzzcy : bfshVO.getGzzcyList()) {
					gzzcy.setGzzId(gzz.getId());
					gzzcyService.save(gzzcy);
				}
			}
			CzjlEntity czjl = new CzjlEntity();
			BeanUtils.copyProperties(bfshVO, czjl);
			czjlService.save(czjl);
		}
		return R.data("操作成功");
	}

	/**
	 * 建立帮教小组
	 */
	@PostMapping("saveBjxz")
	public R saveBjxz(@RequestBody BfshVO bfshVO) {
		GzzEntity tdry = gzzService.selectTdryId(bfshVO.getTdryId());
		if (tdry == null) {
			GzzEntity gzz = new GzzEntity();
			BeanUtils.copyProperties(bfshVO, gzz);
			gzzService.save(gzz);
			for (GzzcyEntity gzzcy : bfshVO.getGzzcyList()) {
				gzzcy.setGzzId(gzz.getId());
				gzzcyService.save(gzzcy);
			}
		}
		return R.data("操作成功");
	}

	/**
	 * 帮交工作记录
	 */
	@PostMapping("saveBjgzjl")
	public R saveBjgzjl(@RequestBody CzjlEntity czjlEntity) {
		return R.data(czjlService.save(czjlEntity));
	}
}
