YcslGxrController.java 7.41 KB
/**
 * Copyright &copy; 2015-2018 <a href="#">J-Site</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.ycsl.web;

import java.util.List;

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.ui.ModelMap;
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.RegBasePerson;
import com.thinkgem.jeesite.modules.reg.service.base.RegBasePersonService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
import com.thinkgem.jeesite.modules.ycsl.entity.YcslGxr;
import com.thinkgem.jeesite.modules.ycsl.service.YcslGxrService;

/**
 * 一窗受理-关系人Controller
 * @author lzj
 * @version 2020-12-24
 */
@Controller
@RequestMapping(value = "${adminPath}/ycsl/ycslGxr")
public class YcslGxrController extends BaseController {

	@Autowired
	private YcslGxrService ycslGxrService;
	@Autowired
	private RegBasePersonService regBasePersonService;
	
	@ModelAttribute
	public YcslGxr get(@RequestParam(required=false) String id) {
		YcslGxr entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = ycslGxrService.get(id);
		}
		if (entity == null){
			entity = new YcslGxr();
		}
		return entity;
	}
	
	@RequiresPermissions("ycsl:ycslGxr:view")
	@RequestMapping(value = {"list", ""})
	public String list(YcslGxr ycslGxr, HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("gxrlx", ycslGxr.getGxrlx());
		if(StringUtils.isNotBlank(request.getParameter("view"))) {
			model.addAttribute("view", request.getParameter("view"));
		}
		Page<YcslGxr> page = ycslGxrService.findPage(new Page<YcslGxr>(request, response), ycslGxr); 
		model.addAttribute("page", page);
		return "modules/ycsl/ycslGxrList";
	}

	@RequiresPermissions("ycsl:ycslGxr:view")
	@RequestMapping(value = "form")
	public String form(YcslGxr ycslGxr, Model model,HttpServletRequest request) {
		if(StringUtils.isNotBlank(request.getParameter("proid"))) {
			model.addAttribute("proid", request.getParameter("proid"));
			if(StringUtils.isBlank(request.getParameter("update"))) {//新增进入
				YcslGxr YcslGxr1 = new YcslGxr();
				YcslGxr1.setProid(request.getParameter("proid"));
				YcslGxr1.setGxrlx("qlr");
				List<YcslGxr> findList = ycslGxrService.findList(YcslGxr1);
				if(findList.size() > 0) {
					for (int i = 0; i < findList.size(); i++) {
						if("0".equals(findList.get(i).getGyfs())) {
							model.addAttribute("msg", "转入放信息共有方式存在单独所有,不符合多个共有人业务逻辑。");
							break;
						}
						ycslGxr.setGyfs(findList.get(i).getGyfs());
					}
				}
			}
			// 计算当前顺序号【注意:只有新增时才需要这个值】
			if (StringUtils.isBlank(ycslGxr.getId()) && StringUtils.isBlank(request.getParameter("SXH"))) {
					model.addAttribute("SXH", getQlrmcOrderNumber(request.getParameter("proid")));
				}else {
					model.addAttribute("SXH", ycslGxr.getSxh());
					model.addAttribute("gxrid", ycslGxr.getId());
				}
			if(StringUtils.isNotBlank(request.getParameter("SXH"))) {
				model.addAttribute("SXH", request.getParameter("SXH"));
				model.addAttribute("gxrid", request.getParameter("gxrid"));
			}
			if(StringUtils.isNotBlank(request.getParameter("ids"))) {
				String ids = request.getParameter("ids");
				RegBasePerson person = regBasePersonService.get(ids);
				ycslGxr.setGxrlx("qlr");
				ycslGxr.setGxrmc(person.getRymc());
				ycslGxr.setGxrsfzjzl(person.getZjzl());
				ycslGxr.setGxrzjh(person.getZjh());
				ycslGxr.setProid(request.getParameter("proid"));
				ycslGxr.setGxrlxdh(person.getDh());
				ycslGxr.setGxrtxdz(person.getDz());			
				ycslGxr.setGxrdlr(person.getDlrymc());
				ycslGxr.setRylx(person.getRylx());
				ycslGxr.setPcode(person.getPcode());
				ycslGxr.setGj(person.getGj());
			}
		}else {
			model.addAttribute("proid", ycslGxr.getProid());
		}
		if(StringUtils.isNotBlank(request.getParameter("view"))) {
			model.addAttribute("view", request.getParameter("view"));
		}
		model.addAttribute("ycslGxr", ycslGxr);
		return "modules/ycsl/ycslGxrForm";
	}

	@RequiresPermissions("ycsl:ycslGxr:edit")
	@RequestMapping(value = "save")
	@ResponseBody
	public ModelMap save(YcslGxr ycslGxr,HttpServletRequest request, Model model, RedirectAttributes redirectAttributes) {
		ModelMap modelmap = new ModelMap();
		ycslGxr.setGyqk(DictUtils.getDictLabel(ycslGxr.getGyfs(), "reg_bus_gyfs", ""));
		if(StringUtils.isNotBlank(request.getParameter("gxrid"))) {
			YcslGxr gxr = ycslGxrService.get(request.getParameter("gxrid"));
			ycslGxrService.delete(gxr);
		}
		ycslGxr.setId("");
		ycslGxrService.saveGxr(ycslGxr);
		return modelmap;
	}
	
	@RequiresPermissions("ycsl:ycslGxr:edit")
	@RequestMapping(value = "delete")
	public String delete(YcslGxr ycslGxr, RedirectAttributes redirectAttributes) {
		YcslGxr ycslGxr1 = new YcslGxr();
		ycslGxr1.setProid(ycslGxr.getProid());
		ycslGxr1.setGxrlx("qlr");
		List<YcslGxr> ycslGxrlist = ycslGxrService.findList(ycslGxr1);
		ycslGxr1 = ycslGxrService.get(ycslGxr.getId());
		if (ycslGxrlist.size() > 0) {
			ycslGxr1 = ycslGxrlist.get(ycslGxrlist.size() - 1);
			if (ycslGxr1.getSxh() > ycslGxr.getSxh()) {// 判断当前顺序号是否是最大顺序号
				addMessage(redirectAttributes, "请先删除最大顺序号关系人!");
			}else {
		     ycslGxrService.delete(ycslGxr);
			}
		}else {
			addMessage(redirectAttributes, "删除关系人信息失败!");
		}
		
		return "redirect:"+Global.getAdminPath()+"/ycsl/ycslGxr/list?id="+ycslGxr.getId();
	}

	/***
	* @Title: issjed 
	* @Description: 判断是否有权利人
	* @param @param request
	* @param @return    设定文件 
	* @return ModelMap    返回类型 
	* @throws
	 */
	@RequestMapping(value = "qlrinfoquery")
	@ResponseBody
	public ModelMap issjed(HttpServletRequest request) {
		String ywh = request.getParameter("proid");
		YcslGxr ycslGxr = new YcslGxr();
		ycslGxr.setProid(ywh);
		ycslGxr.setGxrlx("qlr");
		List<YcslGxr> findList = ycslGxrService.findList(ycslGxr);
		ModelMap modelMap = new ModelMap();
		if(findList.size()>0){
			modelMap.put("data", "1");//已经有权利人记录
		}else{
			modelMap.put("data", "0");
		}
        return modelMap;
	}
	
	/***
	 * @Title: getQlrmcOrderNumber @Description: 通过proid获取当前关系人的顺序号 @param @param
	 * ywhStr @param @return 设定文件 @return String 返回类型 @throws
	 */
	public int getQlrmcOrderNumber(String proid) {
		int qlrmcOrderNumber = 1;// 默认为001
		if (StringUtils.isBlank(proid)) {
			return qlrmcOrderNumber;
		}
		// 首先获取权利人 ID个数
		YcslGxr gxr = new YcslGxr();
		gxr.setProid(proid);
		gxr.setGxrlx("qlr");
		List<YcslGxr> gxrlist = ycslGxrService.findList(gxr);
		int count = gxrlist.size();
		if (count > 0) {
			qlrmcOrderNumber = gxrlist.size() + 1;
		}
		return qlrmcOrderNumber;
	}
	
	
}