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

import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
import com.jeeplus.modules.workcontractinfo.service.WorkContractInfoService;
import com.jeeplus.modules.workfullmanage.entity.WorkFullRecord;
import com.jeeplus.modules.workfullmanage.service.WorkFullRecordService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
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.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全过程管理项目归档Controller
 * @author mapengbo
 * @version 2017-11-01
 */
@Controller
@RequestMapping(value = "${adminPath}/workFullRecordContractController/workFullRecordContractController")
public class WorkFullRecordContractController extends BaseController {

	@Autowired
	private WorkFullRecordService workFullRecordService;
	@Autowired
	protected RuntimeService runtimeService;
	@Autowired
	protected TaskService taskService;
	@Autowired
	private WorkContractInfoService workContractInfoService;

	@ModelAttribute
	public WorkFullRecord get(@RequestParam(required=false) String id) {
		WorkFullRecord entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workFullRecordService.get(id);
		}
		if (entity == null){
			entity = new WorkFullRecord();
	}
		return entity;
	}
	
	/**
	 * 合同列表
	 */
	@RequiresPermissions("workFullRecordContractController:workFullRecordContractController:list")
	@RequestMapping("/list")
	public String list(WorkContractInfo workContractInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		User user = UserUtils.getUser();
		Role role = UserUtils.getSelectRole().get(0);
		if (org.apache.commons.lang3.StringUtils.isNotBlank(role.getEnname()) && role.getEnname().endsWith("gly")) {
			model.addAttribute("flag", true);
		} else {
			model.addAttribute("flag", false);
		}
		workContractInfo.setCurrentUser(user);
		workContractInfo.setOfficeId(UserUtils.getSelectOffice().getId());
		Page<WorkContractInfo> page = workContractInfoService.findPage(new Page<WorkContractInfo>(request, response), workContractInfo);
		model.addAttribute("page", page);
		return "modules/workcontractinfo/workRecordContractInfoList";
	}

	/**
	 * 归档信息
	 */
	@RequestMapping("/form")
	public String form(WorkFullRecord workFullRecord,Model model) {
		model.addAttribute("workFullRecord", workFullRecord);
		return "modules/workcontractinfo/workContractRecordDetail";
	}
}