67b0c3f05bb112fc2b36af0b78ca49ca72f5531a.svn-base 14.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
/**
 * 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.FTPUtil;
import com.thinkgem.jeesite.common.utils.JsonUtil;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.utils.ftp.Ftputil;
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());

			//上传到ftp
			FTPUtil ftp = new FTPUtil(Ftputil.IMAGE_FTP_IP, Ftputil.IMAGE_FTP_PORT,
					Ftputil.IMAGE_FTP_USERNAME, Ftputil.IMAGE_FTP_USERPWD,
					Ftputil.FILE_FTP_DEFAULTDIREECTORY);
			
			 String target = "/sjxm/ycdl/610702_fht/"+bdcdyh;
			ftp.upfile("/sjxm/ycdl/610702_fht/"+bdcdyh, destination);
			logger.debug(h.getBdcdyh());
		
			map.put("name", fileName);
			map.put("bdcdyh", h.getBdcdyh());
			
			map.put("path", target + "/" + 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";
	}

}