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

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import com.jeeplus.common.utils.IdGen;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.act.utils.ActUtils;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.service.OfficeService;
import com.jeeplus.modules.sys.service.WorkattachmentService;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workactivity.entity.Activity;
import com.jeeplus.modules.workactivity.service.ActivityService;
import com.jeeplus.modules.workfullmanage.service.WorkFullManageService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
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 com.jeeplus.modules.workfullmanage.entity.WorkFullManage;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.workaskcheckprice.entity.WorkAskCheckPrice;
import com.jeeplus.modules.workaskcheckprice.service.WorkAskCheckPriceService;

/**
 * 询价与核价Controller
 * @author liuw
 * @version 2017-11-06
 */
@Controller
@RequestMapping(value = "${adminPath}/workaskcheckprice/workAskCheckPrice")
public class WorkAskCheckPriceController extends BaseController {

	@Autowired
	private WorkAskCheckPriceService workAskCheckPriceService;
	@Autowired
	private WorkFullManageService workFullManageService;
	@Autowired
	private WorkattachmentService workattachmentService;
	@Autowired
	private ActivityService activityService;

	@Autowired
	private ActTaskService actTaskService;
	@Autowired
	private OfficeService officeService;
	@Autowired
	private HistoryService historyService;
	@Autowired
	private RepositoryService repositoryService;
	@Autowired
	private RuntimeService runtimeService;
	@ModelAttribute
	public WorkAskCheckPrice get(@RequestParam(required=false) String id) {
		WorkAskCheckPrice entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workAskCheckPriceService.get(id);
		}
		if (entity == null){
			entity = new WorkAskCheckPrice();
		}
		return entity;
	}
	
	/**
	 * 询价与核价列表页面
	 */
	//@RequiresPermissions("workaskcheckprice:workAskCheckPrice:list")
	@RequestMapping(value = {"list", ""})
	public String list(WorkAskCheckPrice workAskCheckPrice, HttpServletRequest request, HttpServletResponse response, Model model) {
		workAskCheckPrice.setCompanyId(UserUtils.getSelectCompany().getId());
		Page<WorkAskCheckPrice> page = workAskCheckPriceService.findPage(new Page<WorkAskCheckPrice>(request, response), workAskCheckPrice);
		List<WorkAskCheckPrice> list = page.getList();
		for (WorkAskCheckPrice entity :list){
			boolean state = true;
			if(StringUtils.isNotBlank(entity.getProcessInstanceId())){
				state = actTaskService.isProcessEnd(entity.getProcessInstanceId());
			}else{
				state = false;
			}
			entity.setProcessEnded(state);
		}
		model.addAttribute("page", page);
		return "modules/workaskcheckprice/workAskCheckPriceList";
	}
	/**
	 * 工单执行（完成任务）
	 * @param
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "saveAudit")
	public String saveAudit(WorkAskCheckPrice workAskCheckPrice, Map<String, Object> vars, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
		/*if (org.apache.commons.lang3.StringUtils.isBlank(workAskCheckPrice.getAct().getComment())){
			addMessage(model, "请填写审核意见。");
			return form(workAskCheckPrice, model,request);
		}*/
		String str = workAskCheckPriceService.auditSave(workAskCheckPrice);
		WorkFullManage w = workAskCheckPrice.getFullManage();
		model.addAttribute("workFullManage", w);
		addMessage(redirectAttributes, str);
		return "redirect:"+Global.getAdminPath()+"/workaskcheckpricemg/workAskCheckPriceMg/?repage";
	}
	/**
	 * 查看，增加，编辑询价与核价表单页面
	 */
	//@RequiresPermissions(value={"workaskcheckprice:workAskCheckPrice:view","workaskcheckprice:workAskCheckPrice:add","workaskcheckprice:workAskCheckPrice:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(WorkAskCheckPrice workAskCheckPrice, Model model,HttpServletRequest request) {

		String wf=request.getParameter("wf");
		if(wf!=null){
			WorkFullManage workF = workFullManageService.getWF(wf);
			model.addAttribute("workFullManage", workF);
		}
		model.addAttribute("workAskCheckPrice", workAskCheckPrice);
		if (workAskCheckPrice.getAct()!=null && StringUtils.isNotBlank(workAskCheckPrice.getAct().getTaskId())){
			return "modules/workaskcheckprice/workAskCheckPriceAudit";
		}
		if(StringUtils.isNotBlank(workAskCheckPrice.getName()) && workAskCheckPrice.getName().equals("view")){
			return "modules/workaskcheckprice/workAskCheckPriceView";
		}
		if (StringUtils.isBlank(workAskCheckPrice.getId())){
			workAskCheckPrice.setCheckNum( IdGen.uuid());
		}
		return "modules/workaskcheckprice/workAskCheckPriceForm";
	}

	/**
	 * 保存询价与核价
	 */
	//@RequiresPermissions(value={"workaskcheckprice:workAskCheckPrice:add","workaskcheckprice:workAskCheckPrice:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(WorkAskCheckPrice workAskCheckPrice, Model model, RedirectAttributes redirectAttributes,HttpServletRequest request) throws Exception{
		if (!beanValidator(model, workAskCheckPrice)){
			return form(workAskCheckPrice, model,request);
		}
		if(!workAskCheckPrice.getIsNewRecord()){//编辑表单保存
			WorkAskCheckPrice t = workAskCheckPriceService.get(workAskCheckPrice.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(workAskCheckPrice, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			t.setCompanyId(UserUtils.getSelectCompany().getId());
			String remarks = t.getRemarks();
			if(StringUtils.isNotBlank(remarks) && remarks.equals("重新申请")){
			//if (StringUtils.isNotBlank(t.getStatus()) &&t.getStatus().equals("3")){
				String processInstanceId = t.getProcessInstanceId();
				HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
				if(historicProcessInstance!=null) {
					t.setHistoricProcessInstance(historicProcessInstance);
					t.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult());
				} else {
					ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).active().singleResult();
					if (processInstance != null){
						t.setProcessInstance(processInstance);
						t.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult());
					}
				}
				ProcessInstance processInstance = actTaskService.getProcIns(t.getProcessInstanceId());
				if (processInstance!=null) {
					Task taskInfok = actTaskService.getCurrentTaskInfo(processInstance);
					Act act = new Act();
					act.setTaskId(taskInfok.getId());
					act.setTaskName(taskInfok.getName());
					act.setTaskDefKey(taskInfok.getTaskDefinitionKey());
					act.setProcDefId(taskInfok.getProcessDefinitionId());
					act.setProcInsId(taskInfok.getProcessInstanceId());
					act.setTask(taskInfok);
					act.setFlag("yes");
					t.setAct(act);
				}
				t.setRemarks("");
				workAskCheckPriceService.auditSave(t);
				workAskCheckPriceService.save(t);//保存
				addMessage(redirectAttributes, "询价与核价已重新申请!");
			}else {
				workAskCheckPriceService.save(t);//保存
				addMessage(redirectAttributes, "修改询价与核价成功");
			}

		}else{//新增表单保存
			workAskCheckPrice.setStatus("2");
			workAskCheckPrice.setCompanyId(UserUtils.getSelectCompany().getId());
			workAskCheckPrice.setOfficeId(UserUtils.getSelectOffice().getId());
			workAskCheckPriceService.save(workAskCheckPrice);//保存
			Map<String, Object> variables = new HashMap<String, Object>();
			workAskCheckPriceService.startProcess(workAskCheckPrice,variables);
			addMessage(redirectAttributes, "保存询价与核价成功");
		}
		return "redirect:"+Global.getAdminPath()+"/workaskcheckpricemg/workAskCheckPriceMg/?repage";
	}

	/**
	 * 保存
	 */
	@RequestMapping(value = "store")
	public String store(WorkAskCheckPrice workAskCheckPrice, Model model, RedirectAttributes redirectAttributes,HttpServletRequest request) throws Exception{
		if (!beanValidator(model, workAskCheckPrice)){
			return form(workAskCheckPrice, model,request);
		}
		if(!workAskCheckPrice.getIsNewRecord()){//编辑表单保存
			WorkAskCheckPrice t = workAskCheckPriceService.get(workAskCheckPrice.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(workAskCheckPrice, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			t.setCompanyId(UserUtils.getSelectCompany().getId());

			if (StringUtils.isNotBlank(t.getStatus()) &&t.getStatus().equals("3")){
				String processInstanceId = t.getProcessInstanceId();
				HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
				if(historicProcessInstance!=null) {
					t.setHistoricProcessInstance(historicProcessInstance);
					t.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult());
				} else {
					ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).active().singleResult();
					if (processInstance != null){
						t.setProcessInstance(processInstance);
						t.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult());
					}
				}
				ProcessInstance processInstance = actTaskService.getProcIns(t.getProcessInstanceId());
				if (processInstance!=null) {
					Task taskInfok = actTaskService.getCurrentTaskInfo(processInstance);
					Act act = new Act();
					act.setTaskId(taskInfok.getId());
					act.setTaskName(taskInfok.getName());
					act.setTaskDefKey(taskInfok.getTaskDefinitionKey());
					act.setProcDefId(taskInfok.getProcessDefinitionId());
					act.setProcInsId(taskInfok.getProcessInstanceId());
					act.setTask(taskInfok);
					act.setFlag("no");
					t.setAct(act);
				}
				workAskCheckPriceService.auditSave(t);
				workAskCheckPriceService.save(t);//保存
				addMessage(redirectAttributes, "询价与核价已撤销!");
			}else {
				workAskCheckPriceService.save(t);//保存
				addMessage(redirectAttributes, "修改询价与核价成功");
			}
		}else{//新增表单保存
			workAskCheckPrice.setStatus("1");
			workAskCheckPrice.setCompanyId(UserUtils.getSelectCompany().getId());
			workAskCheckPrice.setOfficeId(UserUtils.getSelectOffice().getId());
			workAskCheckPriceService.save(workAskCheckPrice);//保存
			addMessage(redirectAttributes, "暂存询价与核价成功");
		}
		return "redirect:"+Global.getAdminPath()+"/workaskcheckpricemg/workAskCheckPriceMg/?repage";
	}
	/**
	 * 删除询价与核价
	 */
	//@RequiresPermissions("workaskcheckprice:workAskCheckPrice:del")
	@RequestMapping(value = "delete")
	public String delete(WorkAskCheckPrice workAskCheckPrice, RedirectAttributes redirectAttributes) {
		workAskCheckPriceService.delete(workAskCheckPrice);
		addMessage(redirectAttributes, "删除询价与核价成功");
		//return "redirect:"+Global.getAdminPath()+"/workaskcheckprice/workAskCheckPrice/?repage";
		return "redirect:"+Global.getAdminPath()+"/workaskcheckpricemg/workAskCheckPriceMg/workAskCheckPriceMgList";
	}
	
	/**
	 * 批量删除询价与核价
	 */
	@RequiresPermissions("workaskcheckprice:workAskCheckPrice:del")
	@RequestMapping(value = "deleteAll")
	public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
		String idArray[] =ids.split(",");
		for(String id : idArray){
			workAskCheckPriceService.delete(workAskCheckPriceService.get(id));
		}
		addMessage(redirectAttributes, "删除询价与核价成功");
		return "redirect:"+Global.getAdminPath()+"/workaskcheckprice/workAskCheckPrice/?repage";
	}
	
	/**
	 * 导出excel文件
	 */
	@RequiresPermissions("workaskcheckprice:workAskCheckPrice:export")
    @RequestMapping(value = "export", method=RequestMethod.POST)
    public String exportFile(WorkAskCheckPrice workAskCheckPrice, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "询价与核价"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            Page<WorkAskCheckPrice> page = workAskCheckPriceService.findPage(new Page<WorkAskCheckPrice>(request, response, -1), workAskCheckPrice);
    		new ExportExcel("询价与核价", WorkAskCheckPrice.class).setDataList(page.getList()).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导出询价与核价记录失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workaskcheckprice/workAskCheckPrice/?repage";
    }

	/**
	 * 导入Excel数据

	 */
	@RequiresPermissions("workaskcheckprice:workAskCheckPrice:import")
    @RequestMapping(value = "import", method=RequestMethod.POST)
    public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
		try {
			int successNum = 0;
			int failureNum = 0;
			StringBuilder failureMsg = new StringBuilder();
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<WorkAskCheckPrice> list = ei.getDataList(WorkAskCheckPrice.class);
			for (WorkAskCheckPrice workAskCheckPrice : list){
				try{
					workAskCheckPriceService.save(workAskCheckPrice);
					successNum++;
				}catch(ConstraintViolationException ex){
					failureNum++;
				}catch (Exception ex) {
					failureNum++;
				}
			}
			if (failureNum>0){
				failureMsg.insert(0, "，失败 "+failureNum+" 条询价与核价记录。");
			}
			addMessage(redirectAttributes, "已成功导入 "+successNum+" 条询价与核价记录"+failureMsg);
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入询价与核价失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workaskcheckprice/workAskCheckPrice/?repage";
    }
	
	/**
	 * 下载导入询价与核价数据模板
	 */
	@RequiresPermissions("workaskcheckprice:workAskCheckPrice:import")
    @RequestMapping(value = "import/template")
    public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "询价与核价数据导入模板.xlsx";
    		List<WorkAskCheckPrice> list = Lists.newArrayList(); 
    		new ExportExcel("询价与核价数据", WorkAskCheckPrice.class, 1).setDataList(list).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入模板下载失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workaskcheckprice/workAskCheckPrice/?repage";
    }
	
	
	/**
	 * 选择全过程管理项目
	 */
	@RequestMapping(value = "selectfullManage")
	public String selectfullManage(WorkFullManage fullManage, String url, String fieldLabels, String fieldKeys, String searchLabel, String searchKey, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<WorkFullManage> page = workAskCheckPriceService.findPageByfullManage(new Page<WorkFullManage>(request, response),  fullManage);
		try {
			fieldLabels = URLDecoder.decode(fieldLabels, "UTF-8");
			fieldKeys = URLDecoder.decode(fieldKeys, "UTF-8");
			searchLabel = URLDecoder.decode(searchLabel, "UTF-8");
			searchKey = URLDecoder.decode(searchKey, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		model.addAttribute("labelNames", fieldLabels.split("\\|"));
		model.addAttribute("labelValues", fieldKeys.split("\\|"));
		model.addAttribute("fieldLabels", fieldLabels);
		model.addAttribute("fieldKeys", fieldKeys);
		model.addAttribute("url", url);
		model.addAttribute("searchLabel", searchLabel);
		model.addAttribute("searchKey", searchKey);
		model.addAttribute("obj", fullManage);
		model.addAttribute("page", page);
		return "modules/sys/gridselect";
	}


	/**
	 * 待办任务列表页面
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"workAskCheckPriceTodoList"})
	public String workAskCheckPriceTodoList(Act act, HttpServletRequest request, HttpServletResponse response, Model model) {
		act.setProcDefKey("workaskcheckprice");
		List<Act> list = new ArrayList<>();
		list.addAll(actTaskService.todoList(act));
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();
		List<Activity> activities = activityService.groupByActivityMenu("9574872f45b84acd893010e66a3dyyy7",companyId);  // 默认父id
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(actTaskService.todoList(act));
		}
		List<WorkAskCheckPrice> lists = new ArrayList<WorkAskCheckPrice>();
		String officeId = "";
		if(!UserUtils.getSelectRoleInfo()){
			User user = UserUtils.getUser();
			officeId = user.getOffice().getId();
		}
		for (Act a : list) {
			WorkAskCheckPrice workAskCheckPrice = workAskCheckPriceService.getByProcessInstanceId(a.getTask().getProcessInstanceId());
			if (workAskCheckPrice != null && workAskCheckPrice.getCompanyId().equals(companyId) && workAskCheckPrice.getStatus() !=null && workAskCheckPrice.getStatus().equals("2")) {
				User createBy = UserUtils.get(workAskCheckPrice.getCreateBy().getId());
				if (StringUtils.isNotBlank(officeId)){
					if (officeId.equals(createBy.getOffice().getId())){
						if (a.getVars().getMap().get("applyUserId")!=null) {
							User user = UserUtils.get(a.getVars().getMap().get("applyUserId").toString());
							if (user != null) {
								a.getVars().getMap().put("applyUserId", UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
							}
						}
						workAskCheckPrice.setAct(a);
						/*if (com.jeeplus.common.utils.StringUtils.isNotBlank(workEngineeringProject.getId())){
							workEngineeringProject.setName(officeService.get(companyId).getName());
						}*/
						lists.add(workAskCheckPrice);
					}
				}else {
					if (a.getVars().getMap().get("applyUserId")!=null) {
						User user = UserUtils.get(a.getVars().getMap().get("applyUserId").toString());
						if (user != null) {
							a.getVars().getMap().put("applyUserId", UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
						}
					}
					workAskCheckPrice.setAct(a);
					/*if (com.jeeplus.common.utils.StringUtils.isNotBlank(workEngineeringProject.getId())){
						workEngineeringProject.setName(officeService.get(companyId).getName());
					}*/
					lists.add(workAskCheckPrice);
				}
			}
		}
		model.addAttribute("list", lists);
		return "modules/workaskcheckprice/workAskCheckPriceTodoList";
	}

	/**
	 * 已办任务
	 * @param act
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"workAskCheckPriceHistoricList"})
	public String workAskCheckPriceHistoricList (Act act, HttpServletRequest request, HttpServletResponse response, Model model){
		act.setProcDefKey("workaskcheckprice");
		List<Act> list = actTaskService.historicList(act);
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();
		List<Activity> activities = activityService.groupByActivityMenu("9574872f45b84acd893010e66a3dyyy7",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(actTaskService.historicList(act));
		}
		List<WorkAskCheckPrice> lists = new ArrayList<WorkAskCheckPrice>();
		for (Act a : list) {
			try {
				WorkAskCheckPrice workAskCheckPrice = workAskCheckPriceService.getByProcessInstanceId(a.getHistTask().getProcessInstanceId());
				if (workAskCheckPrice != null && workAskCheckPrice.getCompanyId().equals(companyId)) {
					if (a.getVars().getMap().get("applyUserId")!=null){
						a.getVars().getMap().put("applyUserId",UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
					}
					workAskCheckPrice.setAct(a);
					/*if (com.jeeplus.common.utils.StringUtils.isNotBlank(workEngineeringProject.getId())){
						workEngineeringProject.setName(officeService.get(companyId).getName());
					}*/
					lists.add(workAskCheckPrice);
				}
			}catch (Exception e){
				logger.info("Exception e"+e);
			}

		}
		model.addAttribute("list", lists);

		return "modules/workaskcheckprice/workAskCheckPriceHistoricList";
	}

	/**
	 * 审核信息
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "applyOnWorkBidProject")
	public String applyOnWorkBidProject(Act act, HttpServletResponse response, Model model) {
		// 获取流程XML上的表单KEY
		String formKey = "/workaskcheckprice/workAskCheckPrice/form";
		//logger.info("------formKeys:"+formKeys);
		// 获取流程实例对象
		if (act.getProcInsId() != null){
			if(actTaskService.getProcIns(act.getProcInsId())!=null){
				act.setProcIns(actTaskService.getProcIns(act.getProcInsId()));
			}else{
				act.setFinishedProcIns(actTaskService.getFinishedProcIns(act.getProcInsId()));
			}
		}
		return "redirect:" + ActUtils.getFormUrl(formKey, act);
	}

	/**
	 * 读取所有流程
	 * @return
	 */
	@RequestMapping(value = "getProcess")
	public String getProcess(WorkAskCheckPrice workAskCheckPrice, HttpServletRequest request, HttpServletResponse response, Model model) {
		//admin 可以查看所有流程  展示注释
//        User user = UserUtils.getUser();
//        if (!user.isAdmin()){
////            leave.setCompanyId(user.getComId());
//            if (!UserUtils.isManager()){
//                workReimbursement.setCreateBy(user);
//            }
//        }
		WorkAskCheckPrice workAskCheckPrice1 = workAskCheckPriceService.get(workAskCheckPrice.getId());
		model.addAttribute("processInstanceId", workAskCheckPrice1.getProcessInstanceId());
		return "modules/workaskcheckprice/workAskCheckPriceTask";
	}

	/**
	 * 启动流程
	 * @return
	 */
	@RequestMapping(value = "startposs")
	public String startposs(WorkAskCheckPrice workAskCheckPrice, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes)throws Exception {
		Map<String, Object> variables = new HashMap<String, Object>();
		WorkAskCheckPrice t = workAskCheckPriceService.get(workAskCheckPrice.getId());//从数据库取出记录的值
		MyBeanUtils.copyBeanNotNull2Bean(workAskCheckPrice, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
		t.setStatus("2");
		t.preUpdate();
		workAskCheckPriceService.update(t);
		workAskCheckPriceService.startProcess(t,variables);
		addMessage(redirectAttributes, "启动流程成功");
			//return "redirect:"+Global.getAdminPath()+"/workaskcheckpricemg/workAskCheckPriceMg/?repage";
		return "redirect:"+Global.getAdminPath()+"/workaskcheckpricemg/workAskCheckPriceMg/workAskCheckPriceMgList";
	}
}