12bfaa8485c7078038a832d4eddfecf3bb4f0e7a.svn-base 7.81 KB
/**
 * Copyright © 2015-2018 ODM All rights reserved.
 */
package com.thinkgem.jeesite.modules.act.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.activiti.engine.ActivitiTaskAlreadyClaimedException;
import org.activiti.engine.task.Task;
import org.activiti.tracelog.ActivitiLog;
import org.apache.commons.lang3.StringUtils;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.act.entity.Act;
import com.thinkgem.jeesite.modules.act.service.ActTaskService;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseH;
import com.thinkgem.jeesite.modules.reg.entity.base.RegBaseHbhqk;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusBdcqzsdjxx;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSlsq;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseHService;
import com.thinkgem.jeesite.modules.reg.service.base.RegBaseHbhqkService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusBdcqzsdjxxService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusSlsqService;
import com.thinkgem.jeesite.modules.reg.web.bus.RegBusFzController;
import com.thinkgem.jeesite.modules.reg.web.bus.RegBusSlsqController;
import com.thinkgem.jeesite.modules.reg.web.httprest.utils.DatatypeUtil;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.thinkgem.jeesite.modules.ycsl.entity.ywzt.YcslYwzt;
import com.thinkgem.jeesite.modules.ycsl.service.ywzt.YcslYwztService;

/**
 * 流程批量处理Controller
 * 
 * @author winner pan
 * @version 2018-5-09
 */
@Controller
@RequestMapping(value = "${adminPath}/act/batchProcess")
public class ActBatchProcesssController extends BaseController {

	@Autowired
	private ActTaskService actTaskService;
	@Autowired
	private RegBusSlsqService regBusSlsqService;
	@Autowired
	private RegBusFzController RegBusFz;
	@Autowired
	private RegBusSlsqController regBusSlsqController;
	@Autowired
	private RegBusBdcqzsdjxxService regBusBdcqzsdjxxService;
	@Autowired
	private RegBaseHbhqkService regBaseHbhqkService;
	@Autowired
	private RegBaseHService regBaseHService;
	
	@Autowired
	private YcslYwztService ycslYwztService;
	/**
	 * 签收任务
	 * 
	 * @param taskId
	 *            任务ID
	 */
	@RequestMapping(value = "exec")
	@ResponseBody
	public String exec(String taskIds, Model model, HttpServletRequest request) {
		if(StringUtils.isEmpty(taskIds)){
			return "请至少选择一条要审核的数据.";
		}
		//获取县区代码
		String areaCode = Global.getAreaCode();
		String ids[] = taskIds.split(",");
		StringBuffer errorInfo = new StringBuffer();
		//add point for trace the claim operation issue.
		ActivitiLog.batchProcessThread.set(true);
		for (String id : ids) {
			// 读取regBusSlsq.act.taskDefKey
			Task task = actTaskService.getTask(id);
			if(task==null){
				continue;
			}
			try {
				String userId = UserUtils.getUser().getLoginName();// ObjectUtils.toString(UserUtils.getUser().getId());
				 
				
				// 如果被其他用户签收则报异常
				// 第一步先签收
				try{
				actTaskService.claim(task.getId(), userId);
				}catch(ActivitiTaskAlreadyClaimedException e){
					errorInfo.append(task.getName()).append(":").append("已被他人签收.").append("\n");
					continue;
				}
				
				task = actTaskService.getTask(id);
				// reg_bus_sqsl:id
				RegBusSlsq regBusSlsq = regBusSlsqService.getByProcInsId(task.getProcessInstanceId());
				String audits = regBusSlsq.getTaskdefkey();
				String YWH = regBusSlsq.getYwh();
				ModelMap modelMap = RegBusFz.taskSubmit(YWH, audits);
				if (!modelMap.get("success").toString().equals("1")) {
					// 中断处理
					errorInfo.append(task.getName()).append(":").append("流程提交失败.").append("\n");
					continue;
				}
				Act act = regBusSlsq.getAct();
				if (act == null) {
					act = new Act();
					regBusSlsq.setAct(act);
				}
				act.setFlag("yes");
				act.setTaskId(task.getId());
				act.setTaskName(task.getName());
				act.setTaskDefKey(task.getTaskDefinitionKey());
				act.setProcInsId(task.getProcessInstanceId());
				act.setProcDefId(task.getProcessDefinitionId());
				String commentText = "";
				String reg_audits = task.getTaskDefinitionKey(); 
				if ("reg_audit".equalsIgnoreCase(reg_audits)) {
					if("610702".equals(areaCode) || "610725".equals(areaCode) || "610721".equals(areaCode) || "610727".equals(areaCode)  || "610728".equals(areaCode)){
						if(!regBusSlsq.getYwh().contains("X")){
							commentText = "审核合格";
						}else{
							commentText = "初审合格";
						}
					}else{
						commentText = "初审合格";
					}
				} else if ("reg_audit2".equals(reg_audits)) {
					commentText = "复审合格";
				} else if ("reg_audit3".equals(reg_audits)) {
					commentText = "核定通过";
					if("429".equals(regBusSlsq.getDjxl())){
						qzx_429(regBusSlsq);
					}
				} else if ("reg_audit5".equals(reg_audits)) {
					commentText = "缮证到收费";
				} else if ("reg_audit56".equals(reg_audits)) {
					commentText = "已收费";
				} else if ("reg_audit6".equals(reg_audits)) {
					commentText = "已发证";
				} else if ("reg_end".equals(reg_audits)) {
					commentText = "已归档";
				}
				act.setComment(commentText);
				String returnStr = regBusSlsqController.saveAudit(regBusSlsq, model, request, regBusSlsq.getDjxl());
				if(returnStr.indexOf("/act/task/todo/")<0){
					errorInfo.append(task.getName()).append(":").append("保存审核失败").append("\n");
				}
				 
				
			} catch (Exception e) {
				if (super.logger.isDebugEnabled()) {
					e.printStackTrace();
				} else {
					super.logger.error(e.getMessage());
				}
				errorInfo.append(task.getName()).append(":").append(e.getMessage())
						.append("\n");
			}
		}
		//add point for trace the claim operation issue.
		ActivitiLog.batchProcessThread.set(false);
		// 返回列表界面
		return errorInfo.toString();
	}

	/**
	 * 期转现楼盘变更,批量审核提交才处理业务
	 * @param regBusSlsq
	 */
	public void qzx_429(RegBusSlsq regBusSlsq) {
		String currentywh = regBusSlsq.getYwh();
		RegBusBdcqzsdjxx regBusBdcqzsdjxx = new RegBusBdcqzsdjxx();
		regBusBdcqzsdjxx.setYwh(currentywh);
		List<RegBusBdcqzsdjxx> regBusBdcqzsdjxxList = regBusBdcqzsdjxxService.findList(regBusBdcqzsdjxx);
		int count = regBusBdcqzsdjxxList.size();
		if (count > 0) {
			for (int j = 0; j < count; j++) {
				RegBusBdcqzsdjxx regBusBdcqzsdjxxTemp = regBusBdcqzsdjxxList.get(j);
				RegBaseHbhqk regBaseHbhqkT = new RegBaseHbhqk();
				regBaseHbhqkT.setYwh(currentywh);
				regBaseHbhqkT.setBdcdyh(regBusBdcqzsdjxxTemp.getBdcdyh());
				List<RegBaseHbhqk> findHbhqkList = regBaseHbhqkService.findList(regBaseHbhqkT);
				if (findHbhqkList.size() > 0) {
					regBaseHbhqkT = findHbhqkList.get(0);
					RegBaseH regBaseOldT = regBaseHService.get(regBaseHbhqkT.getOldhid());
					String oldRights = regBaseOldT.getRights();
					RegBaseH regBaseNewT = regBaseHService.get(regBaseHbhqkT.getHid());
					regBaseNewT.setRights(oldRights);
					regBaseNewT.setIsaudit(regBaseOldT.getIsaudit());
					regBaseNewT.setIsdiya(regBaseOldT.getIsdiya());
					regBaseNewT.setIschafeng(regBaseOldT.getIschafeng());
					regBaseNewT.setIsyiyi(regBaseOldT.getIsyiyi());
					regBaseHService.save(regBaseNewT);
					regBaseOldT.setRights("3");
					regBaseHService.save(regBaseOldT);
				}
				regBusBdcqzsdjxxTemp.setFzsj(DateUtils.getDate("yyyy-MM-dd"));
				regBusBdcqzsdjxxService.save(regBusBdcqzsdjxxTemp);// 更新发证时间是为了核定状态后解除业务占用
			}
		}
	}
	
}