209ce8e4854b0476bcbd530578b196de507315a6.svn-base 13.6 KB
/**
 * Copyright &copy; 2015-2018 <a href="#">J-Site</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.reg.web.bus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBasePerson;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusHisBdcqzsdjxx;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusHisHouseBdcqzsdjxx;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusHisHouseQlr;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusHisHouseYwr;
import com.thinkgem.jeesite.modules.reg.service.base.RegBasePersonService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusHisBdcqzsdjxxService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusHisHouseBdcqzsdjxxService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusHisHouseYwrService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;

/**
 * 房屋历史数据录入义务人添加Controller
 * @author wb
 * @version 2016-04-17
 */
@Controller
@RequestMapping(value = "${adminPath}/reg/bus/regBusHisHouseYwr")
public class RegBusHisHouseYwrController extends BaseController {

	@Autowired
	private RegBusHisHouseYwrService regBusHisHouseYwrService;
	@Autowired
	private RegBasePersonService regBasePersonService;
	@Autowired
	private RegBusHisHouseBdcqzsdjxxService regBusHisHouseBdcqzsdjxxService;
	@Autowired
	private RegBusHisBdcqzsdjxxService regBusHisBdcqzsdjxxService;
	
	@ModelAttribute
	public RegBusHisHouseYwr get(@RequestParam(required=false) String id) {
		RegBusHisHouseYwr entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = regBusHisHouseYwrService.get(id);
		}
		if (entity == null){
			entity = new RegBusHisHouseYwr();
		}
		return entity;
	}
	
	@RequiresPermissions("reg:bus:regBusHisHouseYwr:view")
	@RequestMapping(value = {"list", ""})
	public String list(RegBusHisHouseYwr regBusHisHouseYwr, HttpServletRequest request, HttpServletResponse response, Model model) {
		System.out.println(request.getParameter("YWH"));
		if(StringUtils.isNotBlank(request.getParameter("YWH"))){
			regBusHisHouseYwr.setYwh(request.getParameter("YWH"));
			model.addAttribute("LSH",regBusHisHouseYwr.getYwh().substring(2));
		}
		//WinOpen标示
		if(StringUtils.isNotBlank(request.getParameter("WO"))){
			model.addAttribute("WO", "1");
		}
		if(StringUtils.isNotBlank(request.getParameter("td"))){
			model.addAttribute("WO", "");
			model.addAttribute("WWO", "1");
			model.addAttribute("td", "1");
			model.addAttribute("H", "1");
		}
		if(StringUtils.isNotBlank(request.getParameter("xg"))){
			model.addAttribute("xg", "1");
		}
		if(StringUtils.isNotBlank(request.getParameter("LISTVIEWS"))){
			model.addAttribute("LISTVIEWS", "1");
		}
		if(StringUtils.isNotBlank(request.getParameter("H"))){
			model.addAttribute("H", "1");
		}
		Page<RegBusHisHouseYwr> page = regBusHisHouseYwrService.findPage(new Page<RegBusHisHouseYwr>(request, response), regBusHisHouseYwr); 
		model.addAttribute("page", page);
		return "modules/reg/bus/regBusHisHouseYwrList";
	}

	/**
	 * 中间库列表
	 * @param regBusHisHouseYwr
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("reg:bus:regBusHisHouseYwr:view")
	@RequestMapping(value = "zjklist")
	public String zjklist(RegBusHisHouseYwr regBusHisHouseYwr, HttpServletRequest request, HttpServletResponse response, Model model) {
		if(StringUtils.isNotBlank(request.getParameter("YWH"))){
			regBusHisHouseYwr.setYwh(request.getParameter("YWH"));
		}
		Page<RegBusHisHouseYwr> page = regBusHisHouseYwrService.findywrzjkPage(new Page<RegBusHisHouseYwr>(request, response), regBusHisHouseYwr); 
		//WinOpen标示
		if(StringUtils.isNotBlank(request.getParameter("WO"))){
			model.addAttribute("WO", "1");
		}
		if(StringUtils.isNotBlank(request.getParameter("xg"))){
			model.addAttribute("xg", "1");
		}
		if(StringUtils.isNotBlank(request.getParameter("zjk"))){
			model.addAttribute("zjk", "1");
		}
		if(StringUtils.isNotBlank(request.getParameter("LISTVIEWS"))){
			model.addAttribute("LISTVIEWS", "1");
		}
		model.addAttribute("page", page);
		return "modules/reg/bus/regBusHisHouseYwrList";
	}
	
	
	@RequiresPermissions("reg:bus:regBusHisHouseYwr:view")
	@RequestMapping(value = "form")
	public String form(RegBusHisHouseYwr regBusHisHouseYwr, Model model, HttpServletRequest request) {
		if(StringUtils.isBlank(request.getParameter("optype"))){
			model.addAttribute("SXH", getQlrmcOrderNumber(request.getParameter("YWH")));
		}
		if(StringUtils.isNotBlank(request.getParameter("YWH"))){
			String ywh = request.getParameter("YWH");
			regBusHisHouseYwr.setYwh(ywh);
		}
		if(StringUtils.isNotBlank(request.getParameter("ids"))){
			model.addAttribute("idss",request.getParameter("ids"));
		}
		System.out.println(request.getParameter("H"));
		if(StringUtils.isNotBlank(request.getParameter("H"))){
			model.addAttribute("H",request.getParameter("H"));
		}
		String qxdm = DictUtils.getDictLabel(Global.getAreaCode(), "reg_bus_xq","");
		model.addAttribute("regBusHisHouseYwr", regBusHisHouseYwr);
		return "modules/reg/bus/regBusHisHouseYwrForm";
	}

	@RequiresPermissions("reg:bus:regBusHisHouseYwr:view")
	@RequestMapping(value = "showform")
	public String showform(RegBusHisHouseYwr regBusHisHouseYwr, Model model, HttpServletRequest request) {
		if(StringUtils.isNotBlank(request.getParameter("YWH"))){
			String ywh = request.getParameter("YWH");
			regBusHisHouseYwr.setYwh(ywh);
		}
		if(StringUtils.isNotBlank(request.getParameter("ids"))){
			model.addAttribute("idss",request.getParameter("ids"));
			regBusHisHouseYwr = regBusHisHouseYwrService.get(request.getParameter("ids"));
		}
		System.out.println(request.getParameter("H"));
		if(StringUtils.isNotBlank(request.getParameter("H"))){
			model.addAttribute("H",request.getParameter("H"));
		}
		model.addAttribute("show","1");
		model.addAttribute("regBusHisHouseYwr", regBusHisHouseYwr);
		return "modules/reg/bus/regBusHisHouseYwrForm";
	}
	
	
	@RequiresPermissions("reg:bus:regBusHisHouseYwr:view")
	@RequestMapping(value = "ywrform")
	public String ywrform(RegBusHisHouseYwr regBusHisHouseYwr, Model model, HttpServletRequest request) {
		Map<String,String> map = new HashMap<String,String>();
		//计算当前顺序号【注意:只有新增时才需要这个值】
		if(StringUtils.isBlank(request.getParameter("optype"))){
			model.addAttribute("SXH", getQlrmcOrderNumber(request.getParameter("YWH")));
		}
		if(StringUtils.isNotBlank(request.getParameter("YWH"))){
			String ywh = request.getParameter("YWH");
			regBusHisHouseYwr.setYwh(ywh);
		}
		if(StringUtils.isNotBlank(request.getParameter("H"))){
			model.addAttribute("H",request.getParameter("H"));
		}
		if(StringUtils.isNotBlank(request.getParameter("idss"))){
			model.addAttribute("idss",request.getParameter("idss"));
		}
		String ids = request.getParameter("ids");
		RegBasePerson person = new RegBasePerson();
		person = regBasePersonService.get(ids);
		regBusHisHouseYwr.setZjzl(person.getZjzl());
		regBusHisHouseYwr.setZjh(person.getZjh());
		regBusHisHouseYwr.setQlrmc(person.getRymc());
		regBusHisHouseYwr.setDz(person.getDz());
		regBusHisHouseYwr.setHjszss(person.getHjszss());
		regBusHisHouseYwr.setXb(person.getXb());
		regBusHisHouseYwr.setDh(person.getDh());
		regBusHisHouseYwr.setSshy(person.getSshy());
		regBusHisHouseYwr.setYb(person.getYb());
		regBusHisHouseYwr.setGzdw(person.getGzdw());
		regBusHisHouseYwr.setDzyj(person.getDzyj());
		regBusHisHouseYwr.setDlrmc(person.getDlrymc());
		regBusHisHouseYwr.setDljgmc(person.getDljg());
		regBusHisHouseYwr.setDlrdh(person.getDlrydh());
		regBusHisHouseYwr.setBz(person.getBz());
		regBusHisHouseYwr.setQlrlx(person.getRylx());
		regBusHisHouseYwr.setHjszss(person.getHjszss());
		regBusHisHouseYwr.setPcode(person.getPcode());
		regBusHisHouseYwr.setFzjg(person.getFzjg());
		regBusHisHouseYwr.setSfczr(DictUtils.getDictValue("是", "yes_no",""));
		regBusHisHouseYwr.setId("");
		model.addAttribute("pcode", person.getPcode());
		model.addAttribute("maps", map);
		model.addAttribute("regBusHisHouseYwr", regBusHisHouseYwr);
		return "modules/reg/bus/regBusHisHouseYwrForm";
	}
	
	@RequiresPermissions("reg:bus:regBusHisHouseYwr:edit")
	@RequestMapping(value = "save")
	public String save(RegBusHisHouseYwr regBusHisHouseYwr, Model model,HttpServletRequest request, RedirectAttributes redirectAttributes) {
		String tz = "";
		if(StringUtils.isNotBlank(request.getParameter("H"))){
			tz = request.getParameter("H");
		}
		String LSH = regBusHisHouseYwr.getYwh();
		//通过id获取房屋大表和权利人表数据如果存在数据直接更新
		RegBusHisHouseYwr ywr = new RegBusHisHouseYwr();
		ywr.setYwh(regBusHisHouseYwr.getYwh());
		ywr.setZjh(regBusHisHouseYwr.getZjh());
		List<RegBusHisHouseYwr> ywrlist = regBusHisHouseYwrService.findList(ywr);//获取权利人子表数据
		if(ywrlist.size()>0){
			ywr = ywrlist.get(0);
			regBusHisHouseYwr.setSxh(ywrlist.get(0).getSxh());
			regBusHisHouseYwr.setId(ywrlist.get(0).getId());
		}
		if(tz.equals("1")){
			//预告登记反写大表义务人
			RegBusHisHouseBdcqzsdjxx djxx = new RegBusHisHouseBdcqzsdjxx();
			djxx.setYwh(LSH);
			List<RegBusHisHouseBdcqzsdjxx> list =  regBusHisHouseBdcqzsdjxxService.findList(djxx);
			if(list.size() > 0){
				djxx = list.get(0);
				djxx.setYwr(regBusHisHouseYwr.getQlrmc());
				djxx.setYwrzjh(regBusHisHouseYwr.getZjh());
				djxx.setYwrzjzl(regBusHisHouseYwr.getZjzl());
				regBusHisHouseBdcqzsdjxxService.save(djxx);
			}
			regBusHisHouseYwrService.save(regBusHisHouseYwr);
		}
		//抵押
		if(tz.equals("2")){
			String ids = request.getParameter("idss");
			String[] idList = ids.split(";");
			for(String hisId : idList){
				RegBusHisHouseBdcqzsdjxx hisdjxx = regBusHisHouseBdcqzsdjxxService.get(hisId);
				RegBusHisHouseYwr newYwr = new RegBusHisHouseYwr();
				newYwr = regBusHisHouseYwr;
				newYwr.setBdcdyh(hisdjxx.getBdcdyh());
				newYwr.setId("");
				//首先获取权利人 ID个数
				int ywrmcOrderNumber = 1;
				RegBusHisHouseYwr ywr2 = new RegBusHisHouseYwr();
				ywr2.setYwh(LSH);
				ywr2.setBdcdyh(hisdjxx.getBdcdyh());
				List<RegBusHisHouseYwr> ywrlist_1 = regBusHisHouseYwrService.findList(ywr2);
				int count = ywrlist_1.size();
				if(count > 0){
					ywrmcOrderNumber = ywrlist_1.size() + 1;
				}
				newYwr.setSxh(String.valueOf(ywrmcOrderNumber));
				RegBusHisHouseYwr newYwr_1 = new RegBusHisHouseYwr();
				newYwr_1.setBdcdyh(hisdjxx.getBdcdyh());
				newYwr_1.setYwh(LSH);
				newYwr_1.setPcode(regBusHisHouseYwr.getPcode());
				List<RegBusHisHouseYwr> listywr =  regBusHisHouseYwrService.findList(newYwr_1);
				if(listywr.size() > 0){
					newYwr.setId(listywr.get(0).getId());
				}
				regBusHisHouseYwrService.save(newYwr);
			}
		}
		if(tz.equals("3")){
			regBusHisHouseYwrService.save(regBusHisHouseYwr);
		}
		//土地历史入口抵押
		String td = "";
		if(tz.equals("4")){
			regBusHisHouseYwrService.save(regBusHisHouseYwr);
			td = "1";
		}
		System.out.println(regBusHisHouseYwr.getYwh()+"****"+LSH);
		addMessage(redirectAttributes, "保存历史数据录入义务人添加成功");
		return "redirect:"+Global.getAdminPath()+"/reg/bus/regBusHisHouseYwr/list?WO=1&LISTVIEWS=1&YWH="+regBusHisHouseYwr.getYwh()+"&td="+td;
	}
	
	@RequiresPermissions("reg:bus:regBusHisHouseYwr:edit")
	@RequestMapping(value = "delete")
	public String delete(RegBusHisHouseYwr regBusHisHouseYwr, RedirectAttributes redirectAttributes) {
		
		RegBusHisHouseYwr regBushishouseywr1 = new RegBusHisHouseYwr();
		regBushishouseywr1.setYwh(regBusHisHouseYwr.getYwh());
		List<RegBusHisHouseYwr> regBusywrlist = regBusHisHouseYwrService.findList(regBushishouseywr1);
		if(regBusywrlist.size() > 0){
			regBushishouseywr1 = regBusywrlist.get(regBusywrlist.size()-1);
			if(Integer.parseInt(regBushishouseywr1.getSxh()) > Integer.parseInt(regBusHisHouseYwr.getSxh())){//判断当前顺序号是否是最大顺序号
				addMessage(redirectAttributes, "请先删除最大顺序号权利人!");
			}else{
				if(StringUtils.isNotBlank(regBusHisHouseYwr.getId())){
					regBusHisHouseYwrService.delete(regBusHisHouseYwr);
					addMessage(redirectAttributes, "删除房屋历史数据录入义务人添加成功");;
				}
			}
		}
		
		return "redirect:"+Global.getAdminPath()+"/reg/bus/regBusHisHouseYwr/?YWH="+regBusHisHouseYwr.getYwh();
	}
	/***
	* @Title: getQlrmcOrderNumber 
	* @Description: 通过业务号获取当前权利人在此业务中的顺序号 
	* @param @param ywhStr
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws
	 */
	public int getQlrmcOrderNumber(String ywhStr){
		int ywrmcOrderNumber = 1;//默认为001
		if(StringUtils.isBlank(ywhStr)){
			return ywrmcOrderNumber;
		}
		//首先获取权利人 ID个数
		RegBusHisHouseYwr qlr = new RegBusHisHouseYwr();
		qlr.setYwh(ywhStr);
		List<RegBusHisHouseYwr> qlrlist = regBusHisHouseYwrService.findList(qlr);
		int count = qlrlist.size();
		if(count > 0){
			ywrmcOrderNumber = qlrlist.size() + 1;
		}
		return ywrmcOrderNumber;
	}
}