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

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.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.bind.annotation.ResponseBody;
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.RegBaseFdcqxm;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseH;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZrz;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseFdcqxmService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseHService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseZrzService;

/**
 * 项目内多幢房屋Controller
 * @author lj
 * @version 2018-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/reg/base/regBaseFdcqxm")
public class RegBaseFdcqxmController extends BaseController {

	@Autowired
	private RegBaseFdcqxmService regBaseFdcqxmService;
	@Autowired
	private RegBaseZrzService regBaseZrzService;
	@Autowired
	private RegBaseHService regBaseHService;
	
	@ModelAttribute
	public RegBaseFdcqxm get(@RequestParam(required=false) String id) {
		RegBaseFdcqxm entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = regBaseFdcqxmService.get(id);
		}
		if (entity == null){
			entity = new RegBaseFdcqxm();
		}
		return entity;
	}
	
	@RequiresPermissions("reg:base:regBaseFdcqxm:view")
	@RequestMapping(value = {"list", ""})
	public String list(RegBaseFdcqxm regBaseFdcqxm, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<RegBaseFdcqxm> page = regBaseFdcqxmService.findPage(new Page<RegBaseFdcqxm>(request, response), regBaseFdcqxm); 
		model.addAttribute("page", page);
		return "modules/reg/base/regBaseFdcqxmList";
	}
	
	//项目多幢添加导航页
	@RequestMapping(value = {"guideList"})
	public String guideList(RegBaseFdcqxm regBaseFdcqxm, HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("YWH", request.getParameter("YWH"));
		model.addAttribute("DJLX", request.getParameter("DJLX"));
		regBaseFdcqxm.setIsaudit("1");
		Page<RegBaseFdcqxm> page = regBaseFdcqxmService.findPage(new Page<RegBaseFdcqxm>(request, response), regBaseFdcqxm); 
		model.addAttribute("page", page);
		return "modules/reg/base/regBaseFdcqxmGuideList";
	}

	@RequiresPermissions("reg:base:regBaseFdcqxm:view")
	@RequestMapping(value = "form")
	public String form(RegBaseFdcqxm regBaseFdcqxm, Model model,HttpServletRequest request) {
		model.addAttribute("regBaseFdcqxm", regBaseFdcqxm);
		model.addAttribute("views", request.getParameter("views"));
		return "modules/reg/base/regBaseFdcqxmForm";
	}

	@RequiresPermissions("reg:base:regBaseFdcqxm:edit")
	@RequestMapping(value = "save")
	public String save(RegBaseFdcqxm regBaseFdcqxm, Model model, RedirectAttributes redirectAttributes) {
		regBaseFdcqxm.setIsaudit("0");
		regBaseFdcqxmService.save(regBaseFdcqxm);
		addMessage(redirectAttributes, "保存项目内多幢房屋成功");
		return "redirect:"+Global.getAdminPath()+"/reg/base/regBaseFdcqxm/?repage";
	}
	
	@RequiresPermissions("reg:base:regBaseFdcqxm:edit")
	@RequestMapping(value = "delete")
	public String delete(RegBaseFdcqxm regBaseFdcqxm, RedirectAttributes redirectAttributes) {
		regBaseFdcqxmService.delete(regBaseFdcqxm);
		addMessage(redirectAttributes, "删除项目内多幢房屋成功");
		return "redirect:"+Global.getAdminPath()+"/reg/base/regBaseFdcqxm/?repage";
	}
	
	@RequestMapping(value = "audit")
	public String audit(RegBaseFdcqxm regBaseFdcqxm, RedirectAttributes redirectAttributes) {
		regBaseFdcqxm.setIsaudit("1");
		regBaseFdcqxmService.save(regBaseFdcqxm);
		addMessage(redirectAttributes, "审核项目内多幢房屋成功");
		return "redirect:"+Global.getAdminPath()+"/reg/base/regBaseFdcqxm/?repage";
	}
	
	@RequestMapping(value = "unaudit")
	public String unaudit(RegBaseFdcqxm regBaseFdcqxm, RedirectAttributes redirectAttributes) {
		regBaseFdcqxm.setIsaudit("0");
		regBaseFdcqxmService.save(regBaseFdcqxm);
		addMessage(redirectAttributes, "审核项目内多幢房屋成功");
		return "redirect:"+Global.getAdminPath()+"/reg/base/regBaseFdcqxm/?repage";
	}
	
	/**
	 * 选择fdcqxm后验证是否可用
	 * @param regBaseFdcqxm
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "canbeused")
	@ResponseBody
	public Map<String, String> canbeused(RegBaseFdcqxm regBaseFdcqxm , String id) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("result", "0");//默认0,满足条件;1不满足条件
		RegBaseZrz regBaseZrz = new RegBaseZrz();
		regBaseZrz.setXmid(id);
		List<RegBaseZrz> zrzList = regBaseZrzService.findList(regBaseZrz);
		if(zrzList.size()>0){
			for(int i=0;i<zrzList.size();i++){
				regBaseZrz = zrzList.get(i);
				if(!("1".equals(regBaseZrz.getIsaudit()))){
					map.put("msg", "幢("+regBaseZrz.getGzwmc()+")信息未审核或已被引用,请核实。");
					map.put("result", "1");
				}else{
					RegBaseH regBaseH = new RegBaseH();
					regBaseH.setBdcdyh(regBaseZrz.getBdcdyh().substring(0, 24));
					List<RegBaseH> hlistemp = regBaseHService.findAllList(regBaseH);
					regBaseH.setRights("0");
					regBaseH.setIsaudit("1");
					List<RegBaseH> hlistemp1 = regBaseHService.findAllList(regBaseH);
					if(hlistemp.size()>0){
						if(hlistemp.size()!=hlistemp1.size()){
							map.put("msg", "存在未审核或已引用户信息,请核实。");
							map.put("result", "1");
						}
					}else{
						map.put("msg", "请添加户信息。");
						map.put("result", "1");
					}
					
				}
			}
		}else{
			map.put("msg", "请添加幢信息!");
			map.put("result", "1");
		}
		return map;
	}
		

}