0d15cb51c4aa8a81746ba74b42249d49a13b6e41.svn-base 12.9 KB
/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.reg.web.base;

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.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.entity.base.RegBaseZsglb;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusBdcqzsdjxx;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseZsglbService;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.service.SystemService;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

/**
 * 证书信息维护Controller
 * @author xuyg
 * @version 2015-11-17
 */
@Controller
@RequestMapping(value = "${adminPath}/reg/base/regBaseZsglb")
public class RegBaseZsglbController extends BaseController {

	@Autowired
	private RegBaseZsglbService regBaseZsglbService;
	@Autowired
	private SystemService systemService;
	
	@ModelAttribute
	public RegBaseZsglb get(@RequestParam(required=false) String id) {
		RegBaseZsglb entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = regBaseZsglbService.get(id);
		}
		if (entity == null){
			entity = new RegBaseZsglb();
		}
		return entity;
	}
	
	@RequiresPermissions("reg:base:regBaseZsglb:view")
	@RequestMapping(value = {"list", ""})
	public String list(RegBaseZsglb regBaseZsglb, HttpServletRequest request, HttpServletResponse response, Model model) {
		String szwhrk = request.getParameter("szwhrk");
		String creater1 = "";
		String sqzsbs = request.getParameter("sqzsbs");
		String all = request.getParameter("all");
		if(StringUtils.isNotBlank(szwhrk)){
			User user = UserUtils.getUser();
			regBaseZsglb.setRemarks("1");//繕证维护入口选择编号
			regBaseZsglb.setId(user.getId());
			regBaseZsglb.setIsbf("0");
		}else {
			creater1 = regBaseZsglb.getCreater();
			User creater = UserUtils.getByName(regBaseZsglb.getCreater());
			if(creater != null){
				regBaseZsglb.setCreater(creater.getId());
			}
		}
		if(StringUtils.isNotBlank(all)){//全查标记,(D,J,NULL)
			regBaseZsglb.setIsdj("all");
		}
		if(StringUtils.isNotBlank(sqzsbs)){//证书版式0是单一版,1是集成版,筛选只集成版带参数,未带参数为单一版
			regBaseZsglb.setIsdj("jc");//jc集成
		}
		//-------------------------------记忆查询新增20180511
		if(StringUtils.isNotBlank(request.getParameter("parazsbh"))){
			regBaseZsglb.setZsbm(Long.parseLong(request.getParameter("parazsbh")));
		}
		if(StringUtils.isNotBlank(request.getParameter("parazslx"))){
			regBaseZsglb.setZslx(request.getParameter("parazslx"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paraywh"))){
			regBaseZsglb.setYwh(request.getParameter("paraywh"));
		}
		if(StringUtils.isNotBlank(request.getParameter("parazt"))){
			regBaseZsglb.setIsbf(request.getParameter("parazt"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paraszr"))){
			regBaseZsglb.setSzr(request.getParameter("paraszr"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paraszbh"))){
			regBaseZsglb.setSzzh(request.getParameter("paraszbh"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paracjz"))){
			regBaseZsglb.setCreater(request.getParameter("paracjz"));
		}
		//----------------------------------
		//------------------------------------
		Page<RegBaseZsglb> page = new Page<RegBaseZsglb>();
		if(StringUtils.isNotBlank(request.getParameter("pageNo"))){
			System.out.println(request.getParameter("pageNo"));		
			int no=Integer.parseInt(request.getParameter("pageNo"));
			int size=Integer.parseInt(request.getParameter("pageSize"));
			page = regBaseZsglbService.findPage(new Page<RegBaseZsglb>(no,size ), regBaseZsglb);		
		}
		//------------------------------------
		else{
			page = regBaseZsglbService.findPage(new Page<RegBaseZsglb>(request, response), regBaseZsglb);
		}
		List<RegBaseZsglb> listregBaseZsglb = page.getList();
		for(int i=0; i<listregBaseZsglb.size(); i++){
			RegBaseZsglb temp = listregBaseZsglb.get(i);
			User creater = systemService.getUser(temp.getCreateBy().getId());
			temp.setCreater(creater.getName());//该笔业务的操作人员名称
		}
		page.setList(listregBaseZsglb);
	
		model.addAttribute("page", page);
		//-------------------------------记忆查询新增20180511
		regBaseZsglb=new RegBaseZsglb();
		if(StringUtils.isNotBlank(request.getParameter("parazsbh"))){
			regBaseZsglb.setZsbm(Long.parseLong(request.getParameter("parazsbh")));
		}
		if(StringUtils.isNotBlank(request.getParameter("parazslx"))){
			regBaseZsglb.setZslx(request.getParameter("parazslx"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paraywh"))){
			regBaseZsglb.setYwh(request.getParameter("paraywh"));
		}
		if(StringUtils.isNotBlank(request.getParameter("parazt"))){
			regBaseZsglb.setIsbf(request.getParameter("parazt"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paraszr"))){
			regBaseZsglb.setSzr(request.getParameter("paraszr"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paraszbh"))){
			regBaseZsglb.setSzzh(request.getParameter("paraszbh"));
		}
		if(StringUtils.isNotBlank(request.getParameter("paracjz"))){
			regBaseZsglb.setCreater(request.getParameter("paracjz"));
		}
		model.addAttribute("regBaseZsglb", regBaseZsglb);
		//----------------------------------
		//繕证维护入口进入证书编码列表
		if(StringUtils.isNotBlank(szwhrk)){
			model.addAttribute("szwhrk", szwhrk);
			model.addAttribute("zslx", regBaseZsglb.getZslx());
			return "modules/reg/base/regBaseZsglbszwhList";
		}else {
			regBaseZsglb.setCreater(creater1);
			return "modules/reg/base/regBaseZsglbList";
		}
	}
	
	@RequiresPermissions("reg:base:regBaseZsglb:view")
	@RequestMapping(value = "alllist")
	public String alllist(RegBaseZsglb regBaseZsglb, HttpServletRequest request, HttpServletResponse response, Model model) {
		String creater1 = regBaseZsglb.getCreater();
		User creater = UserUtils.getByName(regBaseZsglb.getCreater());
		if(creater != null){
			regBaseZsglb.setCreater(creater.getId());
		}
		Page<RegBaseZsglb> page = regBaseZsglbService.findPage(new Page<RegBaseZsglb>(request, response), regBaseZsglb); 
		List<RegBaseZsglb> listregBaseZsglb = page.getList();
		for(int i=0; i<listregBaseZsglb.size(); i++){
			RegBaseZsglb temp = listregBaseZsglb.get(i);
			creater = systemService.getUser(temp.getCreateBy().getId());
			temp.setCreater(creater.getName());//该笔业务的操作人员名称
		}
		page.setList(listregBaseZsglb);
		model.addAttribute("page", page); 
		regBaseZsglb.setCreater(creater1);
		return "modules/reg/base/regBaseZsglbAllList";
	}

	@RequiresPermissions("reg:base:regBaseZsglb:view")
	@RequestMapping(value = "form")
	public String form(RegBaseZsglb regBaseZsglb, Model model, HttpServletRequest request) {
		String view = request.getParameter("VIEWS");
		if(StringUtils.isNotBlank(view)){
			model.addAttribute("VIEWS", view);
		}
		String update = request.getParameter("update");
		if(StringUtils.isNotBlank(update)){
			model.addAttribute("update", update);
		}else {
			regBaseZsglb.setZsbm((long)610000);
		}
		model.addAttribute("regBaseZsglb", regBaseZsglb);
		return "modules/reg/base/regBaseZsglbForm";
	}
	
	@RequiresPermissions("reg:base:regBaseZsglb:view")
	@RequestMapping(value = "formview")
	public String formview(RegBaseZsglb regBaseZsglb, Model model, HttpServletRequest request) {
		String view = request.getParameter("VIEWS");
		if(StringUtils.isNotBlank(view)){
			model.addAttribute("VIEWS", view);
		}
		String update = request.getParameter("update");
		if(StringUtils.isNotBlank(update)){
			model.addAttribute("update", update);
		}else {
			regBaseZsglb.setZsbm((long)610000);
		}
		model.addAttribute("regBaseZsglb", regBaseZsglb);
		return "modules/reg/base/regBaseZsglbFormView";
	}

	/**
	 * 证书保存
	 * reg_base_zsglb
	 * @param regBaseZsglb
	 * @param model
	 * @param redirectAttributes
	 * @param request
	 * @return
	 */
	@RequiresPermissions("reg:base:regBaseZsglb:edit")
	@RequestMapping(value = "save")
	public String save(RegBaseZsglb regBaseZsglb, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
		if (!beanValidator(model, regBaseZsglb)){
			return form(regBaseZsglb, model, request);
		}
		String view = "redirect:"+Global.getAdminPath()+"/reg/base/regBaseZsglb/?repage";
		if(StringUtils.isNotBlank(regBaseZsglb.getId())){
			regBaseZsglbService.save(regBaseZsglb);
		}else {
			RegBaseZsglb regBaseZsglbtemp = new RegBaseZsglb();
			regBaseZsglbtemp.setDelFlag("0");
			regBaseZsglbtemp.setRemarks("0");
			Long sl = regBaseZsglb.getZsbm()+regBaseZsglb.getZssl()-1;
			regBaseZsglbtemp.setZsbm(regBaseZsglb.getZsbm());
			regBaseZsglbtemp.setZssl(sl);
			regBaseZsglbtemp.setZslx(regBaseZsglb.getZslx());
			if("J".equals(regBaseZsglb.getIsdj())){
				regBaseZsglbtemp.setIsdj("jc");
			}
			List<RegBaseZsglb> regBaseZsglblist = regBaseZsglbService.findListSave(regBaseZsglbtemp);
			if(regBaseZsglblist.size() > 0){//数据库如果有本次添加的编码之一或者全部,不可以重复保存
				addMessage(redirectAttributes, "保存证书信息失败,已经添加过该类型证书编码,不能重复添加!");
			}else {
				for (Long i = regBaseZsglb.getZsbm(); i <= sl; i++) {
					regBaseZsglb.setZsbm(Long.valueOf(i));
					regBaseZsglb.setId("");
					regBaseZsglb.setIsbf("0");//未引用
					regBaseZsglbService.save(regBaseZsglb);
				}
				addMessage(redirectAttributes, "保存证书信息成功");
			}
		}
		return view;
	}
	
	@RequiresPermissions("reg:base:regBaseZsglb:edit")
	@RequestMapping(value = "delete")
	public String delete(RegBaseZsglb regBaseZsglb,RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response) {
		String no = request.getParameter("pageNo");
		String size = request.getParameter("pageSize");
		System.out.println(no);
		regBaseZsglbService.delete(regBaseZsglb);
		addMessage(redirectAttributes, "删除证书信息成功");
		//System.out.println("parazsbh="+request.getParameter("parazsbh")+"&parazslx="+request.getParameter("parazslx")+"&paraywh="+request.getParameter("paraywh")+"&parazt="+request.getParameter("parazt")+"&paraszr="+request.getParameter("paraszr")+"&paraszbh="+request.getParameter("paraszbh")+"&paracjz="+request.getParameter("paracjz")+"===="+no);
		return "redirect:"+Global.getAdminPath()+"/reg/base/regBaseZsglb/list?parazsbh="+request.getParameter("parazsbh")+"&parazslx="+request.getParameter("parazslx")+"&paraywh="+request.getParameter("paraywh")+"&parazt="+request.getParameter("parazt")+"&paraszr="+request.getParameter("paraszr")+"&paraszbh="+request.getParameter("paraszbh")+"&paracjz="+request.getParameter("paracjz")+"&pageNo="+no+"&pageSize="+size;		
	}
	
	/**
	 * 更新报废标记
	 * @param regBaseZsglb
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("reg:base:regBaseZsglb:edit")
	@RequestMapping(value = "update")
	public String update(RegBaseZsglb regBaseZsglb, RedirectAttributes redirectAttributes, HttpServletRequest request) {
		String iszf = request.getParameter("isZf");
		if(StringUtils.isNotBlank(iszf)){
			if(iszf.equals("1")){
				regBaseZsglb.setIsbf("2");//打报废标记
				regBaseZsglbService.save(regBaseZsglb);
				addMessage(redirectAttributes, "报废证书信息成功");
			}else if(iszf.equals("0")){
				regBaseZsglb.setSzr(null);
				regBaseZsglb.setSzzh(null);
				regBaseZsglb.setYwh(null);
				regBaseZsglb.setBdcdyh(null);
				regBaseZsglb.setIsbf("0");
				regBaseZsglbService.save(regBaseZsglb);
				addMessage(redirectAttributes, "恢复报废证书信息成功");
			}
		}
		return "redirect:"+Global.getAdminPath()+"/reg/base/regBaseZsglb/?repage";
	}
	
	@RequiresPermissions("reg:base:regBaseZsglb:edit")
	@RequestMapping("batchDeletes")
    @ResponseBody
    public ModelMap batchDeletes(HttpServletRequest request,HttpServletResponse response){
        ModelMap model1 = new ModelMap();
		String items = request.getParameter("delitems");
        List<String> delList = new ArrayList<String>();
        String[] strs = items.split(",");
        for (String str : strs) {
            delList.add(str);
        }
        model1.put("data", delList.size());
        regBaseZsglbService.batchDeletes(delList);
        return model1;
    }

}