/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workaftermath.web;

import com.google.common.collect.Lists;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workbidingproject.entity.WorkBidingProject;
import com.jeeplus.modules.workbidingproject.service.WorkBidingProjectService;
import org.apache.shiro.authz.annotation.Logical;
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.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import java.util.List;

/**
 * 招标项目Controller
 * @author
 * @version
 */
@Controller
@RequestMapping(value = "${adminPath}/workbidingprojectmg/workBidingProjectmg")
public class WorkBidingProjectMgController extends BaseController {

	@Autowired
	private WorkBidingProjectService workBidingProjectService;

	@ModelAttribute
	public WorkBidingProject get(@RequestParam(required=false) String id) {
		WorkBidingProject entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workBidingProjectService.get(id);
		}
		if (entity == null){
			entity = new WorkBidingProject();
		}
		return entity;
	}

	/**
	 * 招标项目信息列表页面
	 */
	@RequiresPermissions("workbidingprojectmg:workBidingProjectmg:list")
	@RequestMapping(value = {"list", ""})
	public String list(WorkBidingProject workBidingProject, HttpServletRequest request, HttpServletResponse response, Model model) {
		if(!UserUtils.getSelectOffice().getName().contains("招标")){
			workBidingProject.setBiddingType("-1");
			model.addAttribute("status", "1");
		}else {
			model.addAttribute("status", "2");
		}
		if(!UserUtils.getSelectRoleInfo()){
			String id = UserUtils.getUser().getId();
			workBidingProject.setQueryCon(id);
		}
		Page<WorkBidingProject> page = workBidingProjectService.findPage(new Page<WorkBidingProject>(request, response), workBidingProject);
		model.addAttribute("page", page);
		return "modules/workaftermath/workAftermathmgList";
	}

	/**
	 * 查看，增加，编辑招标项目信息表单页面
	 */
	//@RequiresPermissions(value={"workbidingproject:workBidingProject:view","workbidingproject:workBidingProject:add","workbidingproject:workBidingProject:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(WorkBidingProject workBidingProject, Model model) {
		model.addAttribute("workBidingProject", workBidingProject);
		return "modules/workbidingproject/workBidingProjectForm";
	}
}