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

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

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

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
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.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
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.web.BaseController;
import com.thinkgem.jeesite.common.utils.JsonUtil;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.jy.entity.fw.JyFw;
import com.thinkgem.jeesite.modules.jy.service.fw.JyFwService;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseC;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseH;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZrz;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusBdcqzsdjxx;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseCService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseHService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseZrzService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusBdcqzsdjxxService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusRightsService;
import com.thinkgem.jeesite.modules.reg.web.base.RegBaseCController;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
import com.thinkgem.jeesite.modules.title.buss.RemoteBuss;
import com.thinkgem.jeesite.modules.title.po.ZdjbxxDto;

/**
 * 交易房屋基础信息表Controller
 * 
 * @author lw
 * @version 2020-10-27
 */
@Controller
@RequestMapping(value = "${adminPath}/jy/fw/jyFw")
public class JyFwController extends BaseController {

	@Autowired
	private JyFwService jyFwService;
	@Autowired
	private RegBaseHService regBaseHService;
	@Autowired
	private RegBaseZrzService regBaseZrzService;
	@Autowired
	private RegBusBdcqzsdjxxService regBusBdcqzsdjxxService;
	@Autowired
	private RegBaseCService regBaseCService;
	@Autowired
	private RegBaseCController regBaseCController;

	@Autowired
	private RemoteBuss buss;

	@ModelAttribute
	public JyFw get(@RequestParam(required = false) String id) {
		JyFw entity = null;
		if (StringUtils.isNotBlank(id)) {
			entity = jyFwService.get(id);
		}
		if (entity == null) {
			entity = new JyFw();
		}
		return entity;
	}

	@RequiresPermissions("jy:fw:jyFw:view")
	@RequestMapping(value = { "list", "" })
	public String list(JyFw jyFw, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<JyFw> page = jyFwService.findPage(new Page<JyFw>(request, response), jyFw);
		model.addAttribute("page", page);
		return "modules/jy/fw/jyFwList";
	}

	@RequiresPermissions("jy:fw:jyFw:view")
	@RequestMapping(value = "form")
	public String form(JyFw jyFw, Model model) {
		model.addAttribute("jyFw", jyFw);
		return "modules/jy/fw/jyFwForm";
	}

	@RequiresPermissions("jy:fw:jyFw:edit")
	@RequestMapping(value = "save")
	public String save(JyFw jyFw, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, jyFw)) {
			return form(jyFw, model);
		}
		jyFwService.save(jyFw);
		addMessage(redirectAttributes, "保存交易房屋基础信息成功");
		return "redirect:" + Global.getAdminPath() + "/jy/fw/jyFw/?repage";
	}

	@RequiresPermissions("jy:fw:jyFw:edit")
	@RequestMapping(value = "delete")
	public String delete(JyFw jyFw, RedirectAttributes redirectAttributes) {
		jyFwService.delete(jyFw);
		addMessage(redirectAttributes, "删除交易房屋基础信息成功");
		return "redirect:" + Global.getAdminPath() + "/jy/fw/jyFw/?repage";
	}

	@RequestMapping(value = "fcfht")
	public String fcfhtform(JyFw jyFw, RegBaseZrz regBaseZrz, Model model, HttpServletRequest request,
			HttpServletResponse response) {
		Page<RegBaseZrz> page = regBaseZrzService.findPage(new Page<RegBaseZrz>(request, response), regBaseZrz);
		model.addAttribute("page", page);
		model.addAttribute("jyFw", jyFw);
		model.addAttribute("regBaseZrz", regBaseZrz);
		return "modules/jy/fw/fcfhtXmForm";
	}
	
	@RequestMapping(value = "fcfhtsc")
	public String fcfhtsc(JyFw jyFw, RegBaseZrz regBaseZrz, Model model, HttpServletRequest request,
			HttpServletResponse response) {
		Page<RegBaseZrz> page = regBaseZrzService.findPage(new Page<RegBaseZrz>(request, response), regBaseZrz);
		model.addAttribute("page", page);
		model.addAttribute("jyFw", jyFw);
		model.addAttribute("regBaseZrz", regBaseZrz);
		return "modules/jy/fw/fcfhtScCADForm";
	}
	
	@RequestMapping(value = "hbfht")
	public String hbfhtform (HttpServletRequest request,
			HttpServletResponse response,Model model,RedirectAttributes redirectAttributes) {  
		return "modules/jy/fw/hbfhtForm";
	}

	
	
	
	@RequestMapping(value = "batchUploadFhhct")
	public String batchUploadFhhct(  @RequestParam("fileinp") MultipartFile[] files,RedirectAttributes redirectAttributes,
			Model model, HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException {
		String hs = "";
		for (MultipartFile file : files) {
			String fileName = file.getOriginalFilename();
			int gnum = fileName.substring(0, fileName.length() - 1).lastIndexOf(".");
			String hz = fileName.substring(gnum,fileName.length());
			String bdcdyh = fileName.substring(0, gnum);
			String path = Global.getUserfilesBaseDir() + "\\" + Global.USERFILES_BASE_URL + "ht\\" + bdcdyh; 
			RegBaseH h = regBaseHService.getIslogout(bdcdyh);
			if(h == null || h.getId() == null) {
				hs  = hs+(StringUtils.isEmpty(hs)?"":"、")+bdcdyh;
				continue;
			}
			File dir = new File(path);
			if (!dir.exists()) {
				dir.mkdirs();
			}
			String uuid = UUID.randomUUID().toString();

			String image_path = path + "\\" + uuid+hz;
			logger.info("保存原文件信息:" + image_path);
			File source = new File(image_path);
			file.transferTo(source); 
			h.setFhtImage( "ht\\" + bdcdyh + "\\" + uuid+hz);
			regBaseHService.save(h);
		}  
		addMessage(redirectAttributes, "批量上传合成分户图成功"+(StringUtils.isEmpty(hs)?"":"未找到"+hs+"户信息"));
		return "redirect:"+Global.getAdminPath()+"/jy/fw/jyFw/hbfht";
	}
	
	@RequestMapping(value = "deleteFht")
	public String deleteFht(  RedirectAttributes redirectAttributes,
			Model model, HttpServletRequest request, HttpServletResponse response) {
		String hid = request.getParameter("hid");
		System.out.println("Hid ========"+hid);
		RegBaseH h = regBaseHService.get(hid);
		String iscad = request.getParameter("iscad");
		if("1".equals(iscad)) {
			h.setFhtCad("");
		}
		h.setFhtImage("");
		regBaseHService.save(h);
		addMessage(model, "删除分户图成功");  
		return openHouseView(redirectAttributes, new RegBaseC(), request, response, model);
	}
	
	
	/**
	 * 上传房屋分户图
	 * 
	 * @param jyFw
	 * @param regBaseZrz
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 * @throws IllegalStateException
	 */
	@RequestMapping(value = "uploadFht")
	public String uploadFht(@RequestParam("fileinp") MultipartFile file, RedirectAttributes redirectAttributes,
			Model model, HttpServletRequest request, HttpServletResponse response)
			throws IllegalStateException, IOException {
		String ids = request.getParameter("hids");
		String bdcdyh = request.getParameter("bdcdyh");
		String fileName = file.getOriginalFilename();
		List<String> h_ids = JsonUtil.ObjectToList(ids);

		String path = Global.getUserfilesBaseDir() + "\\" + Global.USERFILES_BASE_URL + "fht\\" + bdcdyh;
		File dir = new File(path);
		if (!dir.exists()) {
			dir.mkdirs();
		}
		String cad_path = path + "\\" + fileName;
		logger.info("保存原文件信息:" + cad_path);
		File source = new File(cad_path);
		file.transferTo(source);

		List<Map> filelst = Lists.newArrayList();

		for (String hid : h_ids) {
			Map<String, String> map = Maps.newHashMap();
			MultipartFile new_file = file;
			RegBaseH h = regBaseHService.get(hid);
			String uuid = UUID.randomUUID().toString();

			String destination = path + "\\" + uuid;
			logger.info("保存文件信息:" + destination);
			File dest = new File(destination);
			Files.copy(source.toPath(), dest.toPath());

			map.put("name", fileName);
			map.put("bdcdyh", h.getBdcdyh());
			map.put("path", "fht\\" + bdcdyh + "\\" + uuid);
			map.put("hid", hid);

			filelst.add(map);
		}

		if (Global.isTitle()) {
			String url = Global.getTitleUrl() + "/accept/fht";
			Map params = Maps.newHashMap();
			params.put("jsonData", JsonUtil.toJsonString(filelst));
			
			try {
				String content = buss.posturl(params, url);
				Map resMap = JsonUtil.jsonToMap(content);
				if (resMap == null || resMap.size() > 0) {
					addMessage(model, "房屋分户图文件上传到权籍系统失败");
					return openHouseView(redirectAttributes, new RegBaseC(), request, response, model);
				}
			} catch (Exception e) {
				addMessage(model, "房屋分户图文件上传到权籍系统失败:" + e.getMessage());
				e.printStackTrace();
				return openHouseView(redirectAttributes, new RegBaseC(), request, response, model);
			}

		}

		for (Map<String, String> hobj : filelst) {
			String hid = hobj.get("hid");
			String cadpath = hobj.get("path");
			RegBaseH h = regBaseHService.get(hid);
			h.setFhtCad(cadpath);
			regBaseHService.save(h);
		}

		addMessage(model, "房屋分户图文件上传成功");
		return openHouseView(redirectAttributes, new RegBaseC(), request, response, model);
	}

	/***
	 * @Title: openHouseView @Description: 楼盘信息表 @param @param
	 *         regBaseC @param @param request @param @param response @param @param
	 *         model @param @return 设定文件 @return String 返回类型 @throws
	 */
	@RequestMapping(value = "openHouseView")
	public String openHouseView(RedirectAttributes redirectAttributes, RegBaseC regBaseC, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		RegBaseZrz regBaseZrz = null;
		
		String bdcdyh = request.getParameter("bdcdyh");
		model.addAttribute("cbdcdyh", bdcdyh);
		
		String iscad = request.getParameter("iscad");
		model.addAttribute("iscad", iscad);
		
		String ywh = request.getParameter("ywh");
		RegBusBdcqzsdjxx regBusBdcqzsdjxx = new RegBusBdcqzsdjxx();
		List<RegBusBdcqzsdjxx> findListDjxx = new ArrayList<RegBusBdcqzsdjxx>();
		if (StringUtils.isNotBlank(ywh)) {
			regBusBdcqzsdjxx.setYwh(ywh);
			regBusBdcqzsdjxx.setIslogout("13");
			findListDjxx = regBusBdcqzsdjxxService.findList(regBusBdcqzsdjxx);
		}
		if (StringUtils.isNotBlank(bdcdyh)) {
			String regBaseZrzdyh = bdcdyh.substring(0, 24) + "0000";
			regBaseZrz = regBaseZrzService.getRegBaseZrz(regBaseZrzdyh);
			model.addAttribute("XMMC", regBaseZrz.getXmmc());
			regBaseC.setZid(regBaseZrz.getId());
			model.addAttribute("ZH", regBaseZrz.getZrzh());
			model.addAttribute("JZWMC", regBaseZrz.getGzwmc());
		}
		// 构建自己的层户列表数据结构
		// 获取幢包含的层列表
		// regBaseC.setZid(request.getParameter("ZID"));
		List<RegBaseC> regBaseCList = regBaseCService.findList(regBaseC);
		model.addAttribute("regBaseCList", regBaseCList);
		model.addAttribute("cCount", regBaseCList.size());
		// 获取层包含的户列表
		List<RegBaseH> regBaseHList = new ArrayList<RegBaseH>();
		List<RegBaseH> regBaseAllHList = new ArrayList<RegBaseH>();
		RegBaseH regBaseH = new RegBaseH();
		// 幢包含所有的户数
		// int hCount = 0;
		int tmpMaxCount = 0;
		Double zchmjs = 0.0;
		DecimalFormat df = new DecimalFormat("0.00");
		for (int i = 0; i < regBaseCList.size(); i++) {
			logger.info("ch==={}", regBaseCList.get(i).getCh());
			// 设置获取户列表的层ID
			regBaseH.setCid(regBaseCList.get(i).getId());
			regBaseHList = regBaseHService.findList(regBaseH);
			// 计算本层所有户的实测面积
			Double chmjs = 0.0;
			for (int a = 0; a < regBaseHList.size(); a++) {
				RegBaseH regBaseHT = regBaseHList.get(a);
				chmjs += regBaseHT.getScjzmj();
				if (findListDjxx.size() > 0) {
					for (int j = 0; j < findListDjxx.size(); j++) {
						regBusBdcqzsdjxx = findListDjxx.get(j);
						if (regBaseHT.getBdcdyh().equals(regBusBdcqzsdjxx.getBdcdyh())) {
							regBaseHT.setStatus("bj");// 临时赋值为bj,表示当前业务中的房屋
							break;
						}
					}
				}
			}
			RegBaseC regBaseCT = new RegBaseC();
			regBaseCT = regBaseCList.get(i);
			regBaseCT.setChjzmj(chmjs);
			zchmjs += chmjs;
			// 添加页面户需要的model
			// 计算幢包含的所有户数
			// hCount += regBaseHList.size();
			// 获取最大的层中户数算法
			int maxNumbers = regBaseCController.getMaxColNumber(regBaseHList);
			if (tmpMaxCount < maxNumbers) {
				tmpMaxCount = maxNumbers;
			}
			regBaseAllHList.addAll(regBaseHList);
		}
		model.addAttribute("ZSCJZMJ", df.format(zchmjs));
		model.addAttribute("regBaseAllHList", regBaseAllHList);
		int hCount = regBaseAllHList.size();
		model.addAttribute("hCount", hCount);
		// 再构造一个表头
		List<Integer> intS = new ArrayList<Integer>();
		// 表头个数 【用最大的层中户数】
		for (int i = 0; i < tmpMaxCount; i++) {
			intS.add(i + 1);
		}
		model.addAttribute("intS", intS);
		if (StringUtils.isNotBlank(request.getParameter("cxfs"))) {
			model.addAttribute("cxfs", request.getParameter("cxfs"));// 查询统计--基础信息查询楼盘传入标记
		}
		if (StringUtils.isNotBlank(request.getParameter("DJLX"))) {
			model.addAttribute("DJLX", request.getParameter("DJLX"));
		}
		model.addAttribute("ZID", regBaseZrz.getId());
		return "modules/jy/fw/fwlpbView";
	}

}