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

import java.util.ArrayList;
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.transaction.annotation.Transactional;
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.base.entity.RegBaseZsglbSub;
import com.thinkgem.jeesite.modules.reg.base.service.RegBaseZsglbSubService;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseZsglb;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusBdcqzsdjxx;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSz;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseZsglbService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusBdcqzsdjxxService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusSzService;
import com.thinkgem.jeesite.modules.reg.web.bus.RegBusSlsqController;

/**
 * 证书基础子表管理Controller
 * @author jiangdb
 * @version 2018-01-09
 */
@Controller
@RequestMapping(value = "${adminPath}/reg/base/regBaseZsglbSub")
public class RegBaseZsglbSubController extends BaseController {

	@Autowired
	private RegBaseZsglbSubService regBaseZsglbSubService;
	@Autowired
	private RegBaseZsglbService regBaseZsglbService;
	@Autowired
	private RegBusSzService regBusSzService;
	@Autowired
	private RegBusSlsqController regBusSlsqController;
	@Autowired
	private RegBusBdcqzsdjxxService regBusBdcqzsdjxxService;
	@ModelAttribute
	public RegBaseZsglbSub get(@RequestParam(required=false) String id) {
		RegBaseZsglbSub entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = regBaseZsglbSubService.get(id);
		}
		if (entity == null){
			entity = new RegBaseZsglbSub();
		}
		return entity;
	}
	
	@RequiresPermissions("reg.base:regBaseZsglbSub:view")
	@RequestMapping(value = {"list", ""})
	public String list(RegBaseZsglbSub regBaseZsglbSub, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<RegBaseZsglbSub> page = regBaseZsglbSubService.findPage(new Page<RegBaseZsglbSub>(request, response), regBaseZsglbSub); 
		model.addAttribute("page", page);
		return "modules/reg.base/regBaseZsglbSubList";
	}

	@RequiresPermissions("reg.base:regBaseZsglbSub:view")
	@RequestMapping(value = "form")
	public String form(RegBaseZsglbSub regBaseZsglbSub, Model model) {
		model.addAttribute("regBaseZsglbSub", regBaseZsglbSub);
		return "modules/reg.base/regBaseZsglbSubForm";
	}

	@RequiresPermissions("reg.base:regBaseZsglbSub:edit")
	@RequestMapping(value = "save")
	public String save(RegBaseZsglbSub regBaseZsglbSub, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, regBaseZsglbSub)){
			return form(regBaseZsglbSub, model);
		}
		regBaseZsglbSubService.save(regBaseZsglbSub);
		addMessage(redirectAttributes, "保存证书基础子表成功");
		return "redirect:"+Global.getAdminPath()+"/reg.base/regBaseZsglbSub/?repage";
	}
	
	@RequiresPermissions("reg.base:regBaseZsglbSub:edit")
	@RequestMapping(value = "delete")
	public String delete(RegBaseZsglbSub regBaseZsglbSub, RedirectAttributes redirectAttributes) {
		regBaseZsglbSubService.delete(regBaseZsglbSub);
		addMessage(redirectAttributes, "删除证书基础子表成功");
		return "redirect:"+Global.getAdminPath()+"/reg.base/regBaseZsglbSub/?repage";
	}
	
	
	@RequestMapping(value = "checkData")
	@ResponseBody
	@Transactional
	public ModelMap checkData(HttpServletRequest request,HttpServletResponse response) {
		ModelMap model1 = new ModelMap();
		String newbm = request.getParameter("newbm");//new:修改后
		String oldbm = request.getParameter("oldbm");//old:修改前编
		String oldqlsx = request.getParameter("oldqlsx");
		String newqlsx = request.getParameter("newqlsx");
		String ywh = request.getParameter("ywh");
		String newmainid = "";
		String oldmainid = "";
		
		String newszzh = "";
		String newbdcqzh = "";
		RegBaseZsglb newzsglb = new RegBaseZsglb();
		
		RegBaseZsglbSub newzsglbSub = new RegBaseZsglbSub();
		newzsglb.setZsbm(Long.valueOf(newbm));
		newzsglb.setIsdj("jc");
		newzsglb.setIsbf("1");
		List<RegBaseZsglb> zsglblist = regBaseZsglbService.findList(newzsglb);
		if(zsglblist.size()>0){
			newzsglb = zsglblist.get(0);
			newmainid = newzsglb.getId();
			newszzh = newzsglb.getSzzh();
			newbdcqzh = newzsglb.getBdcqzh();
		}
		
		if(StringUtils.isNotBlank(newmainid)){
			newzsglbSub.setMainId(newmainid);
			newzsglbSub.setBdcqlsx(newqlsx);
			List<RegBaseZsglbSub> newsubs =  regBaseZsglbSubService.findList(newzsglbSub);
			if(Integer.valueOf(newqlsx)>1){
				newzsglbSub.setBdcqlsx(String.valueOf(Integer.valueOf(newqlsx)-1));
				List<RegBaseZsglbSub> newsubs1 =  regBaseZsglbSubService.findList(newzsglbSub);	
				
				if(newsubs.size()>0){//大于0说明当前证书页已经有信息,返回false
					model1.addAttribute("successbj","1");
					model1.addAttribute("msg", "所选证书权利页已被占用,请确定。");
				}else if(newsubs1.size()==0){
					model1.addAttribute("successbj","1");
					model1.addAttribute("msg", "所选证书上一权利页为空,请选择。");
				}else{//查询原始证书数据,更新到新证书
					model1.addAttribute("successbj","0");
					RegBaseZsglb oldzsglb = new RegBaseZsglb();
					oldzsglb.setZsbm(Long.valueOf(oldbm));
					oldzsglb.setIsdj("jc");
					oldzsglb.setIsbf("1");
					List<RegBaseZsglb> ozsglblist = regBaseZsglbService.findList(oldzsglb);
					if(ozsglblist.size()>0){
						oldzsglb = ozsglblist.get(0);
						oldmainid = oldzsglb.getId();
						RegBaseZsglbSub zsglbsub = new RegBaseZsglbSub();
						zsglbsub.setMainId(oldmainid);
						zsglbsub.setBdcqlsx(oldqlsx);
						List<RegBaseZsglbSub> subs =  regBaseZsglbSubService.findList(zsglbsub);
						RegBusBdcqzsdjxx djxx = new RegBusBdcqzsdjxx();
						for(int i=0;i<subs.size();i++){
							newzsglbSub = subs.get(i);
							newzsglbSub.setMainId(newmainid);
							newzsglbSub.setBdcqlsx(newqlsx);
							regBaseZsglbSubService.save(newzsglbSub);
							
							djxx.setBdcdyh(newzsglbSub.getBdcdyh());
							djxx.setYwh(ywh);
							djxx.setDbsj("NOTNULL");
							djxx.setIslogout("0");
							List<RegBusBdcqzsdjxx> djxxlist = regBusBdcqzsdjxxService.findList(djxx);//ywh+bdcdyh+有效标记,确定唯一一条信息
							djxx = djxxlist.get(0);
							djxx.setBdcqzbh(newszzh);
							djxx.setBdcqzh(newbdcqzh);
							djxx.setYsxlh(newbm);
							regBusBdcqzsdjxxService.save(djxx);
							//更新对应权属中的证号或者证明号
							regBusSlsqController.updateRightsOnSz(ywh, djxx.getBdcdyh(),
									djxx.getDjlx(), newbdcqzh);
						}
						String idtmp = "";
						RegBusSz sz = new RegBusSz();
						sz.setYwh(ywh);
						sz.setYsxlh(Long.valueOf(oldbm));
						List<RegBusSz> szlist = regBusSzService.findList(sz);
						if(szlist.size()>0){//逻辑上应该是一条数据
							sz = szlist.get(0);
							idtmp = sz.getId();
							sz.setId("");
							sz.setSzzh(newszzh);
							sz.setYsxlh(Long.valueOf(newbm));
							regBusSzService.save(sz);
						}
						List<RegBaseZsglbSub> Sublisttmp = regBaseZsglbSubService.findbymainid(oldmainid);
						if(Sublisttmp.size()==0){
							oldzsglb.setSzr(null);
							oldzsglb.setSzzh(null);
							oldzsglb.setYwh(null);
							oldzsglb.setBdcdyh(null);
							oldzsglb.setIsbf("0");
							regBaseZsglbService.save(oldzsglb);
							sz = new RegBusSz();
							sz.setId(idtmp);
							regBusSzService.delete(sz);
						}
					}
				}
			}
		}
		return model1;
	}

}