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

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.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.Dict;
import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.sys.entity.setdjxl.SysDjxlOffice;
import com.thinkgem.jeesite.modules.sys.service.DictService;
import com.thinkgem.jeesite.modules.sys.service.OfficeService;
import com.thinkgem.jeesite.modules.sys.service.setdjxl.SysDjxlOfficeService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;

/**
 * 初审机构设置业务登记类型Controller
 * @author xuyg
 * @version 2016-12-29
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/setdjxl/sysDjxlOffice")
public class SysDjxlOfficeController extends BaseController {

	@Autowired
	private SysDjxlOfficeService sysDjxlOfficeService;
	@Autowired
	private DictService dictService;
	@Autowired
	private OfficeService officeService;
	
	@ModelAttribute
	public SysDjxlOffice get(@RequestParam(required=false) String id) {
		SysDjxlOffice entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = sysDjxlOfficeService.get(id);
		}
		if (entity == null){
			entity = new SysDjxlOffice();
		}
		return entity;
	}
	
//	@RequiresPermissions("sys:setdjxl:sysDjxlOffice:view")
//	@RequestMapping(value = "listofdjxlquery")
//	public String listofdjxlquery(SysDjxlOffice sysDjxlOffice, HttpServletRequest request, HttpServletResponse response, Model model) {
//		List<String> djxlStrList = new ArrayList<String>();
//		//获取当前已经设置的机构登记小类;根据参数officeid
//		List<SysDjxlOffice> djxlOfficeList = sysDjxlOfficeService.findList(sysDjxlOffice);
//		int djxlcount = djxlOfficeList.size();
//		if(djxlcount > 0){
//			for(int i = 0; i < djxlcount; i++){
//				djxlStrList.add(djxlOfficeList.get(i).getValue());
//			}
//		}
//		model.addAttribute("djxlStrList", djxlStrList);
//		//获取所有的登记小类
//		List<Dict> djxlList = dictService.findDjxlList();
//		model.addAttribute("djxlList", djxlList);
//		model.addAttribute("officeid", sysDjxlOffice.getOfficeid());
//		return "modules/sys/dictOfDjxlList";
//	}
	
	@RequiresPermissions("sys:setdjxl:sysDjxlOffice:view")
	@RequestMapping(value = {"list", ""})
	public String list(SysDjxlOffice sysDjxlOffice, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SysDjxlOffice> page = sysDjxlOfficeService.findPage(new Page<SysDjxlOffice>(request, response), sysDjxlOffice); 
		model.addAttribute("page", page);
		return "modules/sys/setdjxl/sysDjxlOfficeList";
	}
	
	@RequiresPermissions("sys:dict:view")
	@RequestMapping(value = "listofdjxl")
	public String listofdjxl(SysDjxlOffice sysDjxlOffice, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<String> djxlStrList = new ArrayList<String>();
		//获取当前已经设置的机构登记小类;根据参数officeid
		List<SysDjxlOffice> djxlOfficeList = sysDjxlOfficeService.findList(sysDjxlOffice);
		int djxlcount = djxlOfficeList.size();
		if(djxlcount > 0){
			for(int i = 0; i < djxlcount; i++){
				djxlStrList.add(djxlOfficeList.get(i).getValue());
			}
		}
		model.addAttribute("djxlStrList", djxlStrList);
		//获取所有的登记小类
		List<Dict> djxlList = dictService.findDjxlList();
		model.addAttribute("djxlList", djxlList);
		model.addAttribute("officeid", sysDjxlOffice.getOfficeid());
		return "modules/sys/dictOfDjxlList";
	}

	@RequiresPermissions("sys:setdjxl:sysDjxlOffice:view")
	@RequestMapping(value = "form")
	public String form(SysDjxlOffice sysDjxlOffice, Model model) {
		model.addAttribute("sysDjxlOffice", sysDjxlOffice);
		return "modules/sys/setdjxl/sysDjxlOfficeForm";
	}

	@RequiresPermissions("sys:setdjxl:sysDjxlOffice:edit")
	@RequestMapping(value = "save")
	public String save(SysDjxlOffice sysDjxlOffice, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, sysDjxlOffice)){
			return form(sysDjxlOffice, model);
		}
		sysDjxlOfficeService.save(sysDjxlOffice);
		addMessage(redirectAttributes, "保存审核机构设置业务登记类型成功");
		return "redirect:"+Global.getAdminPath()+"/sys/setdjxl/sysDjxlOffice/?repage";
	}
	
	@RequestMapping(value = "savebat")
	@ResponseBody
	public ModelMap savebat(Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
		ModelMap modelMap = new ModelMap();
		String chk_value_str = request.getParameter("chk_value_str");
		String officeid = request.getParameter("officeid");
		//每次保存之前先清理之前的office id 相关信息
		SysDjxlOffice sysDjxlOfficeTmp = new SysDjxlOffice();
		sysDjxlOfficeTmp.setOfficeid(officeid);
		sysDjxlOfficeService.deleteByOfficeid(sysDjxlOfficeTmp);
		
		String[] chk_value_str_arr = chk_value_str.split("-");
		for(String chk_value_str_onearr : chk_value_str_arr){
			SysDjxlOffice sysDjxlOffice = new SysDjxlOffice();
			sysDjxlOffice.setOfficeid(officeid);
			sysDjxlOffice.setValue(chk_value_str_onearr);
			sysDjxlOffice.setLabel(DictUtils.getDictLabel(chk_value_str_onearr, "reg_bus_djxl", ""));
			sysDjxlOfficeService.save(sysDjxlOffice);
		}
		//addMessage(redirectAttributes, "批量保存当前机构所属的业务登记小类成功!");
		//return "redirect:"+Global.getAdminPath()+"/sys/setdjxl/sysDjxlOffice/?repage";
		Office office = officeService.get(officeid);
		model.addAttribute("office", office);
		modelMap.put("issucess", "1");
		return modelMap;
		//return "modules/sys/officeForm";
	}
	
	@RequiresPermissions("sys:setdjxl:sysDjxlOffice:edit")
	@RequestMapping(value = "delete")
	public String delete(SysDjxlOffice sysDjxlOffice, RedirectAttributes redirectAttributes) {
		sysDjxlOfficeService.delete(sysDjxlOffice);
		addMessage(redirectAttributes, "删除初审机构设置业务登记类型成功");
		return "redirect:"+Global.getAdminPath()+"/sys/setdjxl/sysDjxlOffice/?repage";
	}

}