f1fdb9ebcdccefa91d03ee0a42ca31465aaf7adb.svn-base 10.1 KB
/**
 * Copyright &copy; 2015-2018 <a href="#">J-Site</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.jy.web.qlr;

import java.io.IOException;
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.http.client.ClientProtocolException;
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.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.ServiceException;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.jy.entity.fw.JyFw;
import com.thinkgem.jeesite.modules.jy.entity.qlr.JyQlr;
import com.thinkgem.jeesite.modules.jy.service.fw.JyFwService;
import com.thinkgem.jeesite.modules.jy.service.qlr.JyQlrService;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseH;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseHService;
import com.thinkgem.jeesite.modules.reg.web.base.RegBaseCController;
import com.thinkgem.jeesite.modules.reg.web.httprest.httpRestService.HttpactivityService;
import com.thinkgem.jeesite.modules.reg.web.httprest.utils.DatatypeUtil;

/**
 * 交易房屋权利信息表Controller
 * @author lw
 * @version 2020-10-27
 */
@Controller
@RequestMapping(value = "${adminPath}/jy/qlr/jyQlr")
public class JyQlrController extends BaseController {

	@Autowired
	private JyQlrService jyQlrService;
	@Autowired
	private RegBaseHService regBaseHService;
	@Autowired
	private JyFwService jyFwService;
	@Autowired
	private HttpactivityService httpactivityService;
	

	
	@ModelAttribute
	public JyQlr get(@RequestParam(required=false) String id) {
		JyQlr entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = jyQlrService.get(id);
		}
		if (entity == null){
			entity = new JyQlr();
		}
		return entity;
	}
	 
	@RequestMapping(value = {"hook"})
	public String hook(RegBaseH regBaseH,JyQlr jyQlr, HttpServletRequest request, HttpServletResponse response, Model model) { 
		if (StringUtils.isBlank(regBaseH.getRights())) {
			regBaseH.setRights("012");// 只显示有效数据
		} else {
			regBaseH.setRights(regBaseH.getRights());// 只显示有效数据
		}
		
		Page<RegBaseH> page = regBaseHService.findAllPage(new Page<RegBaseH>(request, response), regBaseH);
 
		 
		page.setLength(5); 
		model.addAttribute("page", page); 
		model.addAttribute("regBaseH",regBaseH);
		return "modules/jy/qlr/jyQlrTodoHookList";
	}
	
	@RequestMapping(value = {"hookJy"})
	public String hookJy(JyQlr jyQlr, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) throws ClientProtocolException, IOException { 
		
		RegBaseH regBaseH = new RegBaseH();
		regBaseH.setBdcdyh(jyQlr.getBdcdyh());
		List<RegBaseH>  list = regBaseHService.findAllList(regBaseH);
		if(list== null || list.size()<=0) {
			throw new ServiceException("未找到需要挂接的不动产单元信息");
		}
		//Page page = jyQlrService.findFwDataPage(new Page<JyQlr>(request, response), jyQlr); 
		//model.addAttribute("page", page);
		//
		String hid = request.getParameter("hid");
		
		if(StringUtils.isNotBlank(hid)) {
			regBaseH = regBaseHService.get(hid);
		}else {
			regBaseH = list.get(0);
		}
		
		Page page  = new Page<>(request,response);  
		
		Map param_data = Maps.newHashMap();
		
		if(!StringUtils.isEmpty(jyQlr.getZl())) {
			param_data.put("zl", jyQlr.getZl()); 
		} 
		if(!StringUtils.isEmpty(jyQlr.getFybh())) { 
			param_data.put("fybh", jyQlr.getFybh() ); 
		} 
		if(!StringUtils.isEmpty(jyQlr.getXmmc())) {  
			param_data.put("xmmc", jyQlr.getXmmc() ); 
		} 
		if(!StringUtils.isEmpty(jyQlr.getShbw())) {   
			param_data.put("shbw", jyQlr.getShbw() ); 
		}
		if(!StringUtils.isEmpty(jyQlr.getLdjzmj())) {   
			param_data.put("ldjzmj", jyQlr.getLdjzmj() ); 
		} 
		if(!StringUtils.isEmpty(jyQlr.getJzwmc())) {    
			param_data.put("jzwmc", jyQlr.getJzwmc() ); 
		}
		if(!StringUtils.isEmpty(jyQlr.getCh())) {    
			param_data.put("ch", jyQlr.getCh()  ); 
		}
		if(!StringUtils.isEmpty(jyQlr.getZrzh())) {    
			param_data.put("zrzh", jyQlr.getZrzh());  
		}
		if(!StringUtils.isEmpty(jyQlr.getDy())) {    
			param_data.put("dy", jyQlr.getDy() ); 
		}
		if(!StringUtils.isEmpty(jyQlr.getQlrmc())) {    
			param_data.put("qlr", jyQlr.getQlrmc() ); 
		}
		if(!StringUtils.isEmpty(jyQlr.getQlrzjhm())) {    
			param_data.put("qlrzjh", jyQlr.getQlrzjhm() ); 
		}
		
		if(param_data.size() >0) {
			
			param_data.put("Page", page.getPageNo());
			param_data.put("rows", page.getPageSize());
		
			Map json = httpactivityService.postRequest(param_data,"queryTradeEstate"); 
			
			if(json == null) {
				return ""; 
			} 
			String code = json.get("code") == null?"0":json.get("code").toString();
			if(!"200".equals(code)){
				 throw new ServiceException("响应失败,错误信息:"+(json.get("message")) == null?"错误信息未返回":json.get("message").toString());
			}
			Map res_map = json.get("data") == null?Maps.newHashMap():(Map)json.get("data");
			List rows = res_map.get("rows") == null?Lists.newArrayList():(List)res_map.get("rows");
			
			logger.info("rows wwww==== {}",rows);
			if(rows.isEmpty()) {  
				model.addAttribute("data_msg","查询成功,未匹配到交易数据"); 
			}
//			else {
//				model.addAttribute("data_msg","查询成功,匹配到"+rows.size()+"条交易数据,请挂接"); 
//			}
			page.setCount(res_map.get("total") == null?0:Long.parseLong(res_map.get("total").toString()));
			page.setList( rows);
		}
		
		model.addAttribute("jyQlr",jyQlr); 
		model.addAttribute("page", page);
		model.addAttribute("regBaseH",regBaseH);
		return "modules/jy/qlr/hookJyPage";
	}
	
	  
	@RequestMapping(value = "hookSave")
	public String hookSave(JyQlr jyQlr, Model model,HttpServletResponse response, RedirectAttributes redirectAttributes) throws ClientProtocolException, IOException {
		Map map = new HashMap();
		RegBaseH regBaseH = new RegBaseH();
		regBaseH.setBdcdyh(jyQlr.getBdcdyh());
		regBaseH.setRights("012");
		List<RegBaseH>  list = regBaseHService.findAllList(regBaseH);
		if(list== null || list.size()<=0) {
			throw new ServiceException("未找到需要挂接的不动产单元信息");
		}
		regBaseH = list.get(0);
		RegBaseH h = regBaseHService.get(regBaseH.getId());
		
		
		Map param_data = Maps.newHashMap();
		param_data.put("fybh", jyQlr.getFybh());
		param_data.put("bdcdyh", jyQlr.getBdcdyh());
		Map json = httpactivityService.postRequest(param_data,"saveHookRelation"); 
		
		if(json == null) {
			return ""; 
		} 
		String code = json.get("code") == null?"0":json.get("code").toString();
		if(!"200".equals(code)){
			 throw new ServiceException("保存中间库房屋挂接关系失败:"+(json.get("message")) == null?"错误信息未返回":json.get("message").toString());
		}
		
		
		param_data = Maps.newHashMap(); 
		param_data.put("bdcdyh", jyQlr.getBdcdyh());
		param_data.put("sfcf", "0".equals(h.getIschafeng())?"否":"是");
		param_data.put("sfdy", "0".equals(h.getIsdiya())?"否":"是");
		param_data.put("sfyy", "0".equals(h.getIsyiyi())?"否":"是");
		param_data.put("sfyx", "3".equals(h.getRights())?"否":"是");
		
		
		json = httpactivityService.postRequest(param_data,"saveHouseStatus"); 
		code = json.get("code") == null?"0":json.get("code").toString();
		if(!"200".equals(code)){
			 throw new ServiceException("推送中间库房屋状态信息失败:"+(json.get("message")) == null?"错误信息未返回":json.get("message").toString());
		}
		
		if(!StringUtils.isEmpty(h.getFybh())){
			Map param1_data = Maps.newHashMap();
			param1_data.put("fybh", h.getFybh());
			param1_data.put("bdcdyh", h.getBdcdyh());
			Map json1 = httpactivityService.postRequest(param1_data,"removeHookRelation"); 
			if(json1 == null) {
				return ""; 
			} 
			String code1 = json1.get("code") == null?"0":json1.get("code").toString();
			if(!"200".equals(code1)){
				 throw new ServiceException("删除中间库房屋挂接关系失败:"+(json1.get("message")) == null?"错误信息未返回":json1.get("message").toString());
			}
		}
		
		h.setFybh(jyQlr.getFybh());
		h.setBtfwbm(jyQlr.getFybh());
		regBaseHService.save(h);
	  
		//addMessage(redirectAttributes, "不动产单元号【"+jyQlr.getBdcdyh()+"】与房源编号【"+jyQlr.getFybh()+"】挂接成功");
		
		map.put("state", true);
		return renderString(response, map);
	}
	
	@RequiresPermissions("jy:qlr:jyQlr:view")
	@RequestMapping(value = {"list", ""})
	public String list(JyQlr jyQlr, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<JyQlr> page = jyQlrService.findPage(new Page<JyQlr>(request, response), jyQlr); 
		model.addAttribute("page", page);
		return "modules/jy/qlr/jyQlrList";
	}

	@RequiresPermissions("jy:qlr:jyQlr:view")
	@RequestMapping(value = "form")
	public String form(JyQlr jyQlr, Model model) {
		model.addAttribute("jyQlr", jyQlr);
		return "modules/jy/qlr/jyQlrForm";
	}

	@RequiresPermissions("jy:qlr:jyQlr:edit")
	@RequestMapping(value = "save")
	public String save(JyQlr jyQlr, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, jyQlr)){
			return form(jyQlr, model);
		}
		jyQlrService.save(jyQlr);
		addMessage(redirectAttributes, "保存交易房屋权利信息成功");
		return "redirect:"+Global.getAdminPath()+"/jy/qlr/jyQlr/?repage";
	}
	
	@RequiresPermissions("jy:qlr:jyQlr:edit")
	@RequestMapping(value = "delete")
	public String delete(JyQlr jyQlr, RedirectAttributes redirectAttributes) {
		jyQlrService.delete(jyQlr);
		addMessage(redirectAttributes, "删除交易房屋权利信息成功");
		return "redirect:"+Global.getAdminPath()+"/jy/qlr/jyQlr/?repage";
	}

}