衣服的入库出库

旧巷老猫 提交于 2020-03-11 10:59:41

package com.ztesoft.zsmartcity.spcp.biz.eventc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.StringUtil;
import com.ztesoft.zsmartcity.spcp.biz.admin.entity.SysRole;
import com.ztesoft.zsmartcity.spcp.biz.admin.entity.SysUser;
import com.ztesoft.zsmartcity.spcp.biz.admin.service.SysRoleService;
import com.ztesoft.zsmartcity.spcp.biz.admin.service.SysUserService;
import com.ztesoft.zsmartcity.spcp.biz.admin.util.CurrentUserUtil;
import com.ztesoft.zsmartcity.spcp.biz.admin.util.DateUtil;
import com.ztesoft.zsmartcity.spcp.biz.common.Constants;
import com.ztesoft.zsmartcity.spcp.biz.common.EventFlowStatusEnum;
import com.ztesoft.zsmartcity.spcp.biz.dTalk.dao.AdsEventInfoMapper;
import com.ztesoft.zsmartcity.spcp.biz.dTalk.dao.SysUserDepartmentQjMapper;
import com.ztesoft.zsmartcity.spcp.biz.dTalk.dingdingUtil.AuthHelper;
import com.ztesoft.zsmartcity.spcp.biz.dTalk.entity.AdsEventHandleProcess;
import com.ztesoft.zsmartcity.spcp.biz.dTalk.entity.AdsEventInfo;
import com.ztesoft.zsmartcity.spcp.biz.dTalk.service.AdsEventService;
import com.ztesoft.zsmartcity.spcp.biz.event.service.AdsEventAccessService;
import com.ztesoft.zsmartcity.spcp.biz.eventCenter.dao.AdsEventChannelMapper;
import com.ztesoft.zsmartcity.spcp.biz.eventCenter.entity.AdsEventChannelInfo;
import com.ztesoft.zsmartcity.spcp.biz.eventc.dao.AdsEventCFileMapper;
import com.ztesoft.zsmartcity.spcp.biz.eventc.dao.AdsEventSubscribeMapper;
import com.ztesoft.zsmartcity.spcp.biz.eventc.dao.AdsEventcTypeMapper;
import com.ztesoft.zsmartcity.spcp.biz.eventc.entity.AdsEventSubscribe;
import com.ztesoft.zsmartcity.spcp.biz.eventc.entity.AdsEventcConfig;
import com.ztesoft.zsmartcity.spcp.biz.eventc.service.AdsEventFileService;
import com.ztesoft.zsmartcity.spcp.biz.eventc.util.CommonUtil;
import com.ztesoft.zsmartcity.spcp.biz.eventc.util.ListUtil;
import com.ztesoft.zsmartcity.spcp.biz.eventc.util.TreeUtil;
import com.ztesoft.zsmartcity.spcp.biz.task.service.AdsEventTranForTaskService;
import com.ztesoft.zsmartcity.spcp.biz.util.EVTUtils;
import com.ztesoft.zsmartcity.spcp.biz.util.StaticConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;

@Service(“adsEventFileService”)
public class AdsEventFileServiceImpl implements AdsEventFileService {
private static final Logger logger = LoggerFactory.getLogger(AdsEventFileServiceImpl.class);
@Autowired
private AdsEventCFileMapper adsEventFileMapper;
@Autowired
public AdsEventInfoMapper adsEventInfoMapper;
@Autowired
public SysUserDepartmentQjMapper userMapper;
@Autowired
public SysUserService sysUserService;
@Autowired
public AdsEventService adsEventService;
@Autowired
private AdsEventcTypeMapper adsEventTypeMapper;
@Autowired
private AdsEventTranForTaskService adsEventTranForTaskService;

@Autowired
private AdsEventChannelMapper adsEventChannelMapper;

@Autowired
private AdsEventAccessService accessService;

@Autowired
private SysRoleService sysRoleService;

@Autowired
private AdsEventSubscribeMapper adsEventSubscribeMapper;

@Override
public Map<String,Object> selectEventInfosCount(Map<String,Object> condition){
	logger.info("step info selectEventInfosCount... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	Map<String,Object> dataMap = new HashMap<String,Object>();
	Map<String,Object> infoMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	retMap.put("INFO", infoMap);
	int count=0;
	int failNum=0;
	int fenfaNum = 0;
	try {
		String clDept = String.valueOf(condition.get("clDept"));
		if(null != clDept && !"".equals(clDept) && !"null".equals(clDept) && (
				"12".equals(clDept)||"13".equals(clDept)||"14".equals(clDept)||
						"16".equals(clDept)||"17".equals(clDept)||"43".equals(clDept)||
						"51".equals(clDept)
		)){
			condition.put("parentDept",clDept);
			condition.put("clDept","");
		}
		if(null != clDept && !"".equals(clDept) && !"null".equals(clDept) &&
				"73".equals(clDept)){
			condition.put("deptFlag",clDept);
			condition.put("clDept","");
		}

		//处理事件类型子类型情况
		condition.put("eventTypeIds",handleTypeId((String [])condition.get("eventTypeIds")));

		dataMap = adsEventFileMapper.selectEventInfosCount(condition);
		if(dataMap!=null){
			String num = String.valueOf(dataMap.get("count"));
			//count = Integer.valueOf(num);
			count = EVTUtils.getInt(num,0);
			String fail = String.valueOf(dataMap.get("failNum"));
			//failNum = Integer.valueOf(fail);
			failNum = EVTUtils.getInt(fail,0);
			String fenfa = String.valueOf(dataMap.get("fenfaNum"));
			//fenfaNum = Integer.valueOf(fenfa);
			fenfaNum = EVTUtils.getInt(fenfa,0);
		}
	} catch (Exception e) {
		logger.error("selectEventInfosCount is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件列表");
		return retMap;
	}

	retMap.put("SUCCESS", true);
	retMap.put("COUNT", count);
	retMap.put("failNum", failNum);
	retMap.put("successNum",count-fenfaNum-failNum);
	retMap.put("MESSAGE", "获取事件列表数据成功...");
	logger.info("selectEventInfosCount is success...");
	return retMap;
}

@Override
public Map<String, Object> queryEventInfos(Map<String,Object> condition,int pageSize,int pageIndex) {
	logger.info("step info queryEventInfos... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	List<Map<String,Object>> dataMap = new ArrayList<Map<String,Object>>();
	Map<String,Object> infoMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	infoMap.put("LIST", dataMap);
	retMap.put("INFO", infoMap);
	PageHelper.startPage(pageIndex, pageSize);
	try {
		dataMap = adsEventFileMapper.selectEventInfos(condition);
	} catch (Exception e) {
		logger.error("selectEventTypeCount is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件列表");
		return retMap;
	}
	
	infoMap.put("LIST", dataMap);
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "获取事件列表数据成功...");
	logger.info("queryEventInfos is success...");
	return retMap;
}

@Override
public Map<String, Object> queryEventInfosQj(Map<String,Object> condition,int pageSize,int pageIndex) {
	logger.info("step info queryEventInfosQj... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	List<Map<String,Object>> dataMap = new ArrayList<Map<String,Object>>();
	Map<String,Object> infoMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	infoMap.put("LIST", dataMap);
	retMap.put("INFO", infoMap);
	try {

// 12,13,14,16,17,43,51,73 处理部门的父级部门
String clDept = String.valueOf(condition.get(“clDept”));
if(null != clDept && !"".equals(clDept) && !“null”.equals(clDept) && (
“12”.equals(clDept)||“13”.equals(clDept)||“14”.equals(clDept)||
“16”.equals(clDept)||“17”.equals(clDept)||“43”.equals(clDept)||
“51”.equals(clDept)
)){
condition.put(“parentDept”,clDept);
condition.put(“clDept”,"");
}
if(null != clDept && !"".equals(clDept) && !“null”.equals(clDept) &&
“73”.equals(clDept)){
condition.put(“deptFlag”,clDept);
condition.put(“clDept”,"");
}

		//处理事件类型子类型情况
		condition.put("eventTypeIds",handleTypeId((String [])condition.get("eventTypeIds")));

		PageHelper.startPage(pageIndex, pageSize);
		dataMap = adsEventFileMapper.selectEventInfosQj(condition);
	} catch (Exception e) {
		logger.error("queryEventInfosQj is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件列表失败");
		return retMap;
	}
	infoMap.put("LIST", dataMap);
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "获取事件列表数据成功...");
	logger.info("queryEventInfosQj is success...");
	return retMap;
}

/**
 * 根据事件类型集合 找出这些类型下所有的类型
 * @param typeIds
 * @return
 * @throws Exception
 */
private List<Integer> handleTypeId(String [] typeIds) throws Exception {

	if(null == typeIds || typeIds.length <= 0){
		return null;
	}

	List<Map<String, Object>> typeList = adsEventFileMapper.queryEventType();

	List<Integer> idList = new ArrayList<>();

	//先遍历选中的类型id
	for(String typeId : typeIds){
		idList.add(Integer.parseInt(typeId));
		//递归找到对应类型下子类,孙类..
		getChildType(typeList,Integer.parseInt(typeId),idList);
	}

	return idList;

}

private void getChildType(List<Map<String, Object>> typeList,int pid,List<Integer> idList){

	for(Map<String, Object> map : typeList){
		int id = (Integer) map.get("parentTypeId");
		if(pid == id){

			int eventId = (Integer) map.get("eventTypeId");

			getChildType(typeList,eventId,idList);

			idList.add(eventId);

		}
	}
}

@Override
public Map<String, Object> queryEventType() {
	logger.info("step info queryEventType... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	List<Map<String,Object>> dataMap = new ArrayList<Map<String,Object>>();
	Map<String,Object> infoMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	infoMap.put("LIST", dataMap);
	retMap.put("INFO", infoMap);

	try {
		dataMap = TreeUtil.generateTree(adsEventFileMapper.queryEventType(),"eventTypeId","parentTypeId");
	} catch (Exception e) {
		logger.error("queryEventType is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件类型");
		return retMap;
	}

	infoMap.put("LIST", dataMap);
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "获取事件类型...");
	logger.info("queryEventType is success...");
	return retMap;
}

@Override
public Map<String, Object> getEventInfo(int eventInfoId) {
	logger.info("step info queryEventInfos... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	Map<String,Object> data= new HashMap<String,Object>();
	Map<String,Object> condition = new HashMap<String,Object>();
	condition.put("eventInfoId",eventInfoId);
	try {
		List<Map<String,Object>> lists = adsEventFileMapper.selectEventInfos(condition);
		if(lists!=null){
			data=lists.get(0);
		}
	} catch (Exception e) {
		logger.error("selectEventTypeCount is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件列表");
		return retMap;
	}
	_getFileAndProcess(data,condition,retMap);
	retMap.put("SUCCESS", true);
	retMap.put("INFO",data);
	retMap.put("MESSAGE", "获取事件列表数据成功...");
	logger.info("queryEventInfos is success...");
	return retMap;
}

@Override
public Map<String, Object> getEventInfoQj(int eventInfoId) {
	logger.info("step info getEventInfoQj... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	Map<String,Object> data= new HashMap<String,Object>();
	Map<String,Object> condition = new HashMap<String,Object>();
	condition.put("eventInfoId",eventInfoId);
	try {
		List<Map<String,Object>> lists = adsEventFileMapper.selectEventInfosQj(condition);
		if(lists!=null){
			data=lists.get(0);
		}
	} catch (Exception e) {
		logger.error("getEventInfoQj is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件列表");
		return retMap;
	}
	_getFileAndProcess(data,condition,retMap);

// new_getfileAndProcess(data,condition,retMap);
retMap.put(“SUCCESS”, true);
retMap.put(“INFO”,data);
retMap.put(“MESSAGE”, “获取事件列表数据成功…”);
logger.info(“queryEventInfos is success…”);
return retMap;
}

private void new_getfileAndProcess(Map<String,Object> data,Map<String,Object> condition,Map<String,Object> retMap){
	try {
		List<Map<String, Object>> processes = adsEventFileMapper.queryNewProcessByInfo(condition);
		List<Map<String,Object>> finalpro  = new ArrayList<>();

		//找出多张图片但是为一个步骤的操作

// for (int i=0;i<processes.size()-1;i++){
// boolean flag = false;
// boolean flag2 = false;
// Map<String,Object> proi = processes.get(i);
// ArrayList profile = new ArrayList();
// Map<String,Object> newpro = proi;
// for(int j = 0;j<processes.size() - 1 ; j++){
// Map<String,Object> proj = processes.get(j);
// //判断是否同一次处理事件
// if((i!=j)&&proi.get(“handleId”).toString().equals(proj.get(“handleId”).toString())){
// flag2 = true;
// }
// }
//
// for(int j=processes.size() - 1 ;j>i; j–){
// Map<String,Object> proj = processes.get(j);
// //判断是否同一次处理事件
// if((i!=j)&&proi.get(“handleId”).toString().equals(proj.get(“handleId”).toString())){
// flag = true;
// newpro = proi;
// if(proj.get(“filePath”)!=null){
// profile.add(proj.get(“filePath”));
// }
// }
// }
// if(flag2==false){
// finalpro.add(newpro);
// }
// if(flag){
// profile.add(proi.get(“filePath”));
// newpro.put(“profile”,profile);
// finalpro.add(newpro);
// }
// }
// HashSet h = new HashSet(finalpro);
// finalpro.clear();
// finalpro.addAll(h);

		data.put("processes",processes == null ? Collections.emptyList() : processes);
	}catch (Exception e) {
		logger.error("queryProcessByInfo is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件过程失败");

	}
}

private void _getFileAndProcess(Map<String,Object> data,Map<String,Object> condition,Map<String,Object> retMap){
	try {

// List<Map<String, Object>> processes = adsEventFileMapper.queryProcessByInfo(condition);
List<Map<String, Object>> processes = adsEventFileMapper.queryNewProcessByInfo(condition);
data.put(“processes”,processes == null ? Collections.emptyList() : processes);
}catch (Exception e) {
logger.error("queryProcessByInfo is failed…|| Exception Message : " + e.getMessage(), e);
retMap.put(“MESSAGE”, “获取事件过程失败”);

	}
	try {
		List<Map<String, Object>> files = adsEventFileMapper.queryFilesByInfo(condition);
		data.put("files",files == null ? Collections.emptyList() : files);
	}catch (Exception e) {
		logger.error("queryFilesByInfo is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取事件附件失败");

	}
}
@Override
public Map<String, Object> delEventInfo(HttpServletRequest request) {
	logger.info("step info delEventInfo... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	int eventInfoId = request.getParameter("eventInfoId")==null
			? 0 : Integer.valueOf(request.getParameter("eventInfoId"));
	String sourceId = String.valueOf(request.getParameter("sourceId"));
	AdsEventInfo info = new AdsEventInfo();
	info=adsEventService.getEventInfoById(Long.valueOf(String.valueOf(eventInfoId)));
	info.setEventInfoId(Long.valueOf(String.valueOf(eventInfoId)));
	info.setState("X");
	// 	1514234在事件管理中对事件进行删除、编辑、分发、归档操作时需要回填ROAD_TYPE值 A:编辑 B:分发 C:归档 D:删除
	info.setRoadType("D");
	try {
		adsEventInfoMapper.updateByPrimaryKeySelective(info);
		//20190805根据sourceId查询wz表是否有本条事件数据,如果有的话就更新数据,没有的话就新增数据
		int wzCount = adsEventService.qryInfoWzBySourceId(sourceId);
		if(wzCount>0){
			adsEventService.updateInfoWzBySourceId(info);
		}else{
			adsEventService.insertInfoWzBySourceId(info);
		}

	} catch (Exception e) {
		logger.error("delEventInfo is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "删除事件失败");
		return retMap;
	}
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "删除事件成功...");
	logger.info("delEventInfo is success...");
	return retMap;
}

@Override
public Map<String, Object> updateEventInfo(AdsEventInfo info) {
	logger.info("step info updateEventInfo... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	// 	1514234在事件管理中对事件进行删除、编辑、分发、归档操作时需要回填ROAD_TYPE值 A:编辑 B:分发 C:归档 D:删除
	info.setRoadType("A");
	try {
		adsEventInfoMapper.updateByPrimaryKeySelective(info);
		info=adsEventService.getEventInfoById(info.getEventInfoId());
		//20190805根据sourceId查询wz表是否有本条事件数据,如果有的话就更新数据,没有的话就新增数据
		int wzCount = adsEventService.qryInfoWzBySourceId(info.getSourceId());
		if(wzCount>0){
			adsEventService.updateInfoWzBySourceId(info);
		}else{
			adsEventService.insertInfoWzBySourceId(info);
		}

	} catch (Exception e) {
		logger.error("updateEventInfo is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "编辑事件失败");
		return retMap;
	}
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "编辑事件成功...");
	logger.info("updateEventInfo is success...");
	return retMap;
}

@Override
public Map<String, Object> querySameInfos(AdsEventInfo info) {
	logger.info("step info querySameInfos... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	List<AdsEventInfo> dataMap = new ArrayList<AdsEventInfo>();
	Map<String,Object> infoMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	infoMap.put("LIST", dataMap);
	retMap.put("INFO", infoMap);
	try {
		dataMap = adsEventInfoMapper.doRemoveSameRecord(info);
	} catch (Exception e) {
		logger.error("querySameInfos is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取重复事件失败");
		return retMap;
	}

	infoMap.put("LIST", dataMap);
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "获取重复事件成功...");
	logger.info("querySameInfos is success...");
	return retMap;
}

@Override
public Map<String,Object> getUserInfo(String userId){

	logger.info("step info getUserInfo... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	Map<String,Object> data= new HashMap<String,Object>();
	try {
		List<Map<String,Object>> lists = userMapper.selectUserByUserId(userId);
		if(lists!=null&&lists.size()>0){
			data=lists.get(0);
		}
	} catch (Exception e) {
		logger.error("getUserInfo is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取人员部门失败");
		return retMap;
	}
	retMap.put("SUCCESS", true);
	retMap.put("INFO",data);
	retMap.put("MESSAGE", "获取人员部门成功...");
	logger.info("getUserInfo is success...");
	return retMap;
}

@Override
public Map<String,Object> queryChannels(String name){
	logger.info("step info queryChannels... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	Map<String,Object> data= new HashMap<String,Object>();
	try {
		List<Map<String,Object>> lists = adsEventFileMapper.queryInnerDepart(name);
		data.put("INNERS",lists==null?Collections.EMPTY_LIST:lists);
	} catch (Exception e) {
		logger.error("queryInnerDepart is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取内部部门失败");
		return retMap;
	}
	try {
		List<Map<String,Object>> lists = adsEventFileMapper.queryOutterDepart(name);
		data.put("OUTTERS",lists==null?Collections.EMPTY_LIST:lists);
	} catch (Exception e) {
		logger.error("queryOutterDepart is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取外部系统失败");
		return retMap;
	}
	retMap.put("SUCCESS", true);
	retMap.put("INFO",data);
	retMap.put("MESSAGE", "获取系统成功...");
	logger.info("getUserInfo is success...");
	return retMap;
}

@Override
public Map<String,Object> innerMobileTran(HttpServletRequest request){
	//内部转派
	String userId = request.getParameter("userId");
	int systemId =StringUtil.isEmpty(request.getParameter("systemId"))?0:Integer.valueOf(request.getParameter("systemId"));
	long eventInfoId = Long.valueOf(request.getParameter("eventInfoId"));
	int userDepartmentId = StringUtil.isEmpty(request.getParameter("departmentId"))?0:Integer.valueOf(request.getParameter("departmentId"));
	String sourceId = String.valueOf(request.getParameter("sourceId"));
	String userName = "";
	try {
		userName = new String(request.getParameter("userName").getBytes("ISO8859-1"), "UTF-8");
	}catch (Exception e){
		logger.error("get eventName and userName is failed...|| Exception Message : " + e.getMessage(), e);
	}
	AdsEventInfo adsEventInfo = new AdsEventInfo();
	adsEventInfo.setEventInfoId(eventInfoId);
	adsEventInfo.setTranDeptId(systemId);
	adsEventInfo.setTransferUserName(userName);
	adsEventInfo.setDistributionStatus("A");
	adsEventInfo.setDistributionDept(userDepartmentId);
	adsEventInfo.setDdDept(systemId);
	adsEventInfo.setFlowState("C");
	adsEventInfo.setDistributionTime(new Date());
	// 	1514234在事件管理中对事件进行删除、编辑、分发、归档操作时需要回填ROAD_TYPE值 A:编辑 B:分发 C:归档 D:删除
	adsEventInfo.setRoadType("B");

	Map<String, Object> map = new HashMap<String, Object>();
	//执行状态更新
	int res=adsEventService.doTranEvent(adsEventInfo);
	int deptId = adsEventInfo.getTranDeptId();
	//发送钉钉消息
	adsEventInfo=adsEventService.getEventInfoById(adsEventInfo.getEventInfoId());
	//20190805根据sourceId查询wz表是否有本条事件数据,如果有的话就更新数据,没有的话就新增数据
	int wzCount = adsEventService.qryInfoWzBySourceId(sourceId);
	if(wzCount>0){
		adsEventService.updateInfoWzBySourceId(adsEventInfo);
	}else{
		adsEventService.insertInfoWzBySourceId(adsEventInfo);
	}
	String ddMsg="";
	String dateStr= DateUtil.getSysDateTimeString();
	HttpSession session = request.getSession();
	Map<String,Object> ddMap=new HashMap<String,Object>();

	ddMap.put("departmentId", deptId);
	ddMap.put("isLeader", true);

	try {
		if(res==1){
			ddMsg=dateStr+" --> 你收到了" + userName + "转的 " + adsEventInfo.getEventName() + " 事件,请知悉!";
			AuthHelper.setNotiFyMes(sysUserService.successDingUserId(ddMap),ddMsg);

		}else{
			ddMsg=dateStr+" --> 您的事件:" + adsEventInfo.getEventName() + "处理异常,请重新操作!";

			List<String> dlist=new ArrayList<String>();
			SysUser user = sysUserService.selectByPrimaryKey(Integer.valueOf(userId));
			dlist.add(user.getDingUserId());
			AuthHelper.setNotiFyMes(dlist,ddMsg);
		}


	} catch (Exception e) {
		logger.error(adsEventInfo.getEventName()+" --> 钉钉消息推送异常:"+e.getMessage());
	}
	_insertTranHandleProcess(eventInfoId,userName,userDepartmentId,res);
	map.put("SUCCESS", true);
	return map;
}

public Map<String,Object> outterMobileTran(HttpServletRequest request){
	Map<String, Object> map = new HashMap<String, Object>();

	String userId = request.getParameter("userId");
	int systemId =StringUtil.isEmpty(request.getParameter("systemId"))?0:Integer.valueOf(request.getParameter("systemId"));
	long eventInfoId = Long.valueOf(request.getParameter("eventInfoId"));
	int eventTypeId = StringUtil.isEmpty(request.getParameter("eventTypeId"))?0:Integer.valueOf(request.getParameter("eventTypeId"));


	//先把这个事件类型的数据置为X失效
	AdsEventcConfig config = new AdsEventcConfig();
	config.setEventTypeId(eventTypeId);
	try {
		adsEventFileMapper.updateChannelConfigX(config);
	}catch (Exception e){
		logger.error("updateChannelConfigX is failed...|| Exception Message : " + e.getMessage(), e);
		map.put("SUCCESS", false);
		return map;
	}
	try{
		adsEventFileMapper.cancelSubscribe(String.valueOf(eventTypeId),null);
	}catch (Exception e) {
		logger.error("outterCancelSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
		map.put("SUCCESS", false);
		return map;
	}
	//再插入新的数据
	List<AdsEventcConfig> adsEventCChannelConfigList = new ArrayList<AdsEventcConfig>();
	config.setEventTypeId(eventTypeId);
	config.setChannelId(systemId);
	config.setCreateBy(Integer.valueOf(userId));
	config.setCreateTime(CommonUtil.parseStrToDate(CommonUtil.getCurrentDate()));
	adsEventCChannelConfigList.add(config);
	int res=0;
	try {
		res=adsEventFileMapper.insertEventTypeConfig(adsEventCChannelConfigList);
	} catch (Exception e) {
		logger.error("insertEventTypeConfig is failed...|| Exception Message : " + e.getMessage(), e);
		map.put("SUCCESS", false);
		return map;
	}
	try {
		adsEventFileMapper.addSubscribe(String.valueOf(eventTypeId), null, "A");
	}catch (Exception e) {
		logger.error("outterAddSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
		map.put("SUCCESS", false);
		return map;
	}
	AdsEventInfo adsEventInfo = adsEventInfoMapper.selectByPrimaryKey(eventInfoId);

	return adsEventTranForTaskService.autoTranEvent(adsEventInfo);

}

private void _insertTranHandleProcess(long eventInfoId,String userName,int userDepartmentId,int res){
	AdsEventHandleProcess adsEventHandleProcess = new AdsEventHandleProcess();
	adsEventHandleProcess.setHandleDesc("(将事件(处理单位未读)分发到处置单位)");
	adsEventHandleProcess.setEventInfoId(eventInfoId);
	adsEventHandleProcess.setHandleBy(userName);
	adsEventHandleProcess.setHandleDept(userDepartmentId);
	adsEventHandleProcess.setHandleDate(new Date());
	adsEventHandleProcess.setHandleDeptName("转派员");
	adsEventHandleProcess.setState("L");
	if(res == 1){
		adsEventHandleProcess.setHandleResult("处置单位未读");
	}else if (res == 0){
		adsEventHandleProcess.setHandleResult("分发失败");
	}
	try {
		adsEventService.insertOperationLog(adsEventHandleProcess);
	} catch (Exception e) {
		logger.error("_insertTranHandleProcess is failed...|| Exception Message : " + e.getMessage(), e);

	}

}

@Override
public Map<String, Object> queryDepts(Map<String, Object> param) {

	logger.info("step info queryDepts... ");
	Map<String, Object> retMap = new HashMap<String, Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	Map<String, Object> data = new HashMap<String, Object>();
	try {
		List<Map<String, Object>> lists = adsEventFileMapper.queryDepts(param);
		if (!ListUtil.validateEmpty(lists)) {
			lists = TreeUtil.generateTree(lists, "departmentId", "parentDepartment");
		}
		else {
			lists = Collections.EMPTY_LIST;
		}
		data.put("LIST", lists);
	}
	catch (Exception e) {
		logger.error("queryDepts is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取组织树失败");
		return retMap;
	}

	retMap.put("SUCCESS", true);
	retMap.put("INFO", data);
	retMap.put("MESSAGE", "获取组织树成功...");
	logger.info("queryDepts is success...");
	return retMap;
}

@Override
public Map<String, Object> querySubscribeEventType(Map<String, Object> param, Integer pageIndex, Integer pageSize) {
	logger.info("step info querySubscribeEventType... ");
	Map<String, Object> retMap = new HashMap<String, Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	Map<String, Object> data = new HashMap<String, Object>();
	Page<Map<String, Object>> lists = new Page<Map<String, Object>>();
	PageHelper.startPage(pageIndex, pageSize);
	try {
		lists = adsEventFileMapper.querySubscribeEventType(param);
		data.put("LIST", lists);
		data.put("COUNT", lists.getTotal());
	} catch (Exception e) {
		logger.error("querySubscribeEventType is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取组织订阅事件类型失败");
		return retMap;
	}

	retMap.put("SUCCESS", true);
	retMap.put("INFO", data);
	retMap.put("MESSAGE", "获取组织订阅事件类型成功...");
	logger.info("querySubscribeEventType is success...");
	return retMap;
}

@Override
public Map<String, Object> getDepartSubscribeTypeId(String departmentId) {
	Map<String, Object> resultMap = new HashMap<String, Object>();
	resultMap.put("SUCCESS", true);
	Map<String, Object> map = new HashMap<String, Object>();
	try {
		map = adsEventFileMapper.getDepartSubscribeTypeId(departmentId);
		resultMap.put("INFO", map);
	}
	catch (Exception e) {
		logger.error("getDepartSubscribeTypeId is failed" + e.getMessage(), e);
		resultMap.put("SUCCESS", false);
	}
	return resultMap;
}

public Map<String,Object> cancelSubscribe(String eventTypeId){
	logger.info("step info cancelSubscribe... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	try {

		adsEventFileMapper.cancelSubscribe(eventTypeId,null);
	} catch (Exception e) {
		logger.error("cancelSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "取消订阅事件类型失败");
		return retMap;
	}

	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "取消订阅事件类型成功...");
	logger.info("cancelSubscribe is success...");
	return retMap;
}

/**
 * 取消事件订阅
 * @param eventTypeId
 * @param eventPublishId
 * @param eventPublishId
 * @return
 */
@Override
public Map<String, Object> cancelSubscribe(String eventTypeId, String eventPublishId) {
	logger.info("step info cancelSubscribe... ");
	Map<String, Object> retMap = new HashMap<String, Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	AdsEventSubscribe adsEventSubscribe = new AdsEventSubscribe();
	adsEventSubscribe.setEventPublishId(com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.strToLong(eventPublishId));
	try {
		//更新订阅时间
		//如果订阅过事件则修改订阅事件
		adsEventSubscribeMapper.updateAdsEventSubscribe(adsEventSubscribe);
		adsEventSubscribeMapper.cancelSubscribeOfSingle(com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.strToInt(eventTypeId),
				com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.strToLong(eventPublishId));
	}
	catch (Exception e) {
		logger.error("cancelSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "取消订阅事件类型失败");
		return retMap;
	}
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "取消订阅事件类型成功...");
	logger.info("cancelSubscribe is success...");
	return retMap;
}

/*public Map<String,Object> addSubscribe(String eventTypeIds,String departmentId){
	logger.info("step info addSubscribe... ");
	Map<String,Object> retMap = new HashMap<String,Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	try {
		//先把该部门以前订阅的事件类型都取消
		adsEventFileMapper.cancelSubscribe(null,departmentId);
	} catch (Exception e) {
		logger.error("cancelSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "取消历史订阅失败");
		return retMap;
	}
	//再新增订阅
	if(StringUtil.isNotEmpty(eventTypeIds)) {
		String[] typeIds = eventTypeIds.split(",");
		for (String typeId : typeIds) {
			try {

				adsEventFileMapper.addSubscribe(typeId, departmentId, "B");
			} catch (Exception e) {
				logger.error("addSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
				retMap.put("MESSAGE", "新增订阅事件类型失败");
				return retMap;
			}
		}
	}

	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "订阅事件类型成功...");
	logger.info("addSubscribe is success...");
	return retMap;
}*/

@Override
public Map<String, Object> addSubscribe(String eventTypeIds, String departmentId, String userId) {
	logger.info("step info addSubscribe... ");
	Map<String, Object> retMap = new HashMap<String, Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	//查询当前部门又没有订阅过事件
	AdsEventSubscribe adsEventSubscribe = adsEventSubscribeMapper.querySubscribe(departmentId);
	//没有订阅事件需要先订阅事件
	//Integer userId = null;
	try {
		if (adsEventSubscribe == null || adsEventSubscribe.getEventPublishId() == null) {
		/*	SysUser user = CurrentUserUtil.getUser();
			if (user != null) {
				userId = user.getUserId();
			}*/
			adsEventSubscribe = new AdsEventSubscribe();
			adsEventSubscribe.setCreateBy(com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.strToInt(userId));
			adsEventSubscribe.setPublishOrg(com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.strToInt(departmentId));
			adsEventSubscribeMapper.addAdsEventSubscribe(adsEventSubscribe);
		}
		else {
			//如果订阅过事件则修改订阅事件
			adsEventSubscribeMapper.updateAdsEventSubscribe(adsEventSubscribe);
			//如果之前订阅过事件则删除之前订阅的事件
			adsEventSubscribeMapper.cancelSubscribe(adsEventSubscribe);
		}
	}
	catch (Exception e) {
		logger.error("cancelSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "取消历史订阅失败");
		return retMap;
	}
	//再新增订阅
	if (StringUtil.isNotEmpty(eventTypeIds)) {
		String[] typeIds = eventTypeIds.split(",");
			try {
				adsEventSubscribeMapper.addSubscribe(typeIds, adsEventSubscribe.getEventPublishId());
			}
			catch (Exception e) {
				logger.error("addSubscribe is failed...|| Exception Message : " + e.getMessage(), e);
				retMap.put("MESSAGE", "新增订阅事件类型失败");
				return retMap;
			}
	}
	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "订阅事件类型成功...");
	logger.info("addSubscribe is success...");
	return retMap;
}

@Override
public Map<String, Object> eventCompletion(Map<String, Object> data) {

	logger.info("step info eventCompletion... ");
	Map<String,Object> retMap = new HashMap<String, Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");

	try {

		adsEventFileMapper.eventCompletion(data);

		logger.info("事件信息补全成功");

	}catch(Exception ex){
	    ex.printStackTrace();
		retMap.put("MESSAGE", "事件信息补全失败");
	}

	retMap.put("SUCCESS", true);
	retMap.put("MESSAGE", "事件信息补全成功...");

	return retMap;
}


/**
 * 合并重复事件,修改重复的事件状态为 (Z=确认重复)
 * @param event
 * @return
 */
@Override
public Map<String,Object> eventRepeatMerge(Map<String,Object> event){

    logger.info("step info eventRepeatMerge... ");
    Map<String, Object> retMap = new HashMap<String, Object>();

    String eventIds = (String)event.get("eventIds");

    //保留的事件
    Integer mainEventId = (Integer)event.get("mainEventId");

    //校验事件id
	boolean emptyFlag = com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.validateEmpty(eventIds);

    if(emptyFlag || mainEventId == null || mainEventId.intValue() == 0){
		retMap.put("SUCCESS", false);
		retMap.put("MESSAGE", "事件id 参数不能为空.");
		return retMap;
	}

    try{

        String [] ids = com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.split(eventIds,",");

        //允许合并的状态(预处理、待分发、疑似重复)
		String [] states = new String[]{EventFlowStatusEnum.REPEAT.getCode(),EventFlowStatusEnum.WAIT_DISTRIBUTE.getCode(),EventFlowStatusEnum.INIT.getCode()};

        //查询符合条件的情况
        int cnt = adsEventFileMapper.qryEventStateByIds(ids,states);

        //符合的数量如果小于 选择带合并的id的数量
        if(cnt != ids.length ){
            retMap.put("SUCCESS", false);
            retMap.put("MESSAGE", "只有事件状态为:预处理、待分发、疑似重复 的事件才能进行重复事件合并.");
            return retMap;
        }

        //修改为(Z=确认重复)
        int count = adsEventFileMapper.eventRepeatMerge(EventFlowStatusEnum.CONFIRM_REPEAT.getCode(),ids);

        //把保留的事件修改为 待分发状态
        adsEventFileMapper.eventRepeatMerge(EventFlowStatusEnum.WAIT_DISTRIBUTE.getCode(),new Integer[]{mainEventId});

        logger.info("事件信息合并成功,影响记录数:"+count);

    }catch(Exception ex){
        ex.printStackTrace();
		retMap.put("SUCCESS", false);
        retMap.put("MESSAGE", "事件信息合并失败");
    }

    retMap.put("SUCCESS", true);
    retMap.put("MESSAGE", "事件信息合并成功...");

    return retMap;
}

@Override
public Map<String, Object> distributeEvent(AdsEventInfo eventParam) {

	Map<String,Object> retMap = new HashMap<String,Object>();

	if(null == eventParam || null == eventParam.getEventInfoId()
			  			  || null == eventParam.getEventTypeId()
						  || 0 == eventParam.getEventInfoId().longValue()
						  || 0 == eventParam.getEventTypeId().intValue()){
		retMap.put("SUCCESS", false);
		retMap.put("MESSAGE", "事件类型id 参数不能为空.");
		return retMap;
	}

	try {

		//根据事件类型 和 手动状态 找到类型对应的渠道信息
		List<AdsEventChannelInfo> channelList = adsEventChannelMapper.qryChannelByEventTypeId(eventParam.getEventTypeId(),Constants.IS_AUTO_NO);

		//查询事件详情
		AdsEventInfo eventInfo = adsEventFileMapper.qryEventDetailById(eventParam.getEventInfoId());

		//进行分发
		accessService.eventSendByChannel(channelList,eventInfo, Constants.DIS_STATUS_MANUAL);
		retMap.put("SUCCESS", true);
		retMap.put("MESSAGE", "事件手动分发成功...");
	}catch(Exception ex){
		ex.printStackTrace();
		retMap.put("SUCCESS", false);
		retMap.put("MESSAGE", "事件手动分发失败");
	}
	return retMap;
}

@Override
public Map<String, Object> queryDeptsByAuthentication(Map<String, Object> param) {
	logger.info("step info queryDepts... ");
	Map<String, Object> retMap = new HashMap<String, Object>();
	retMap.put("SUCCESS", false);
	retMap.put("MESSAGE", "");
	Map<String, Object> data = new HashMap<String, Object>();
	Integer userId = null;
	String roleType = null;
	try {
	/*	SysUser user = CurrentUserUtil.getUser();
		if (user != null) {
			userId = user.getUserId();
		}*/
		userId = com.ztesoft.zsmartcity.spcp.biz.eventc.util.StringUtil.objToInt(param.get("userId"));
		List<SysRole> sysRoles = sysRoleService.qryRoleListByUserId(userId);
		for (SysRole sysRole:sysRoles) {
			if  (StaticConstants.SUPER_ADMIN.equals(sysRole.getRoleType())) {
				roleType = StaticConstants.SUPER_ADMIN;
				break;
			}
		}
		param.put("roleType", roleType);
		param.put("userId", userId);
		List<Map<String, Object>> lists = adsEventFileMapper.queryDeptsByAuthentication(param);
		if (!ListUtil.validateEmpty(lists)) {
			lists = TreeUtil.generateTree(lists, "departmentId", "parentDepartment");
		}
		else {
			lists = Collections.EMPTY_LIST;
		}
		data.put("LIST", lists);
	}
	catch (Exception e) {
		logger.error("queryDepts is failed...|| Exception Message : " + e.getMessage(), e);
		retMap.put("MESSAGE", "获取组织树失败");
		return retMap;
	}
	retMap.put("SUCCESS", true);
	retMap.put("INFO", data);
	retMap.put("MESSAGE", "获取组织树成功...");
	logger.info("queryDepts is success...");
	return retMap;
}

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!