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

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

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

import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.common.websocket.service.system.SystemInfoSocketHandler;
import com.jeeplus.modules.oa.entity.OaNotify;
import com.jeeplus.modules.oa.entity.OaNotifyMaterial;
import com.jeeplus.modules.oa.entity.OaNotifyRecord;
import com.jeeplus.modules.oa.service.OaNotifyService;
import com.jeeplus.modules.sg.managementcenter.materialInventory.entity.MaterialInventory;
import com.jeeplus.modules.sg.managementcenter.materialInventory.service.MaterialInventoryService;
import com.jeeplus.modules.sg.managementcenter.project.entity.PickingRequisition;
import com.jeeplus.modules.sg.managementcenter.project.entity.Project;
import com.jeeplus.modules.sg.managementcenter.project.entity.ProjectAcquisition;
import com.jeeplus.modules.sg.managementcenter.project.entity.ProjectManager;
import com.jeeplus.modules.sg.managementcenter.project.mapper.PickingRequisitionMapper;
import com.jeeplus.modules.sg.managementcenter.project.service.PickingRequisitionService;
import com.jeeplus.modules.sg.managementcenter.project.service.ProjectService;
import com.jeeplus.modules.sg.managementcenter.project.util.ImportUtil;
import com.jeeplus.modules.sg.managementcenter.project.util.PickingInfo;
import com.jeeplus.modules.sg.managementcenter.project.util.ProExcelInfo;
import com.jeeplus.modules.sg.picking.activiti.entity.Acquisition;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.service.SystemService;
import com.jeeplus.modules.sys.utils.UserUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
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 org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;

import static com.jeeplus.modules.sg.managementcenter.project.util.ProExcelInfo.getProjectUtilFlag;

/**
 * 表单Controller
 * @author lgf
 * @version 2018-06-12
 */
@Controller
@RequestMapping(value = "${adminPath}/sg/managementcenter/project")
public class ProjectController extends BaseController {

	@Autowired
	private ProjectService projectService;

	@Autowired
	private PickingRequisitionService pickingRequisitionService;

	@Autowired
	private MaterialInventoryService materialInventoryService;
	@Autowired
	private OaNotifyService oaNotifyService;//通知服务类

	@Autowired
	private SystemService systemService;
	
	@ModelAttribute
	public Project get(@RequestParam(required=false) String id) {
		Project entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = projectService.get(id);
		}
		if (entity == null){
			entity = new Project();
		}
		return entity;
	}
	
	/**
	 * 工程管理表单列表页面
	 */
	@RequiresPermissions("sg:managementcenter:project:list")
	@RequestMapping(value = {"list", ""})
	public String list(Project project, Model model) {
		model.addAttribute("leave1", project);
		return "modules/sg/managementcenter/project/projectList";
	}
	
	 /**
	 	* 表单列表数据
	 */
	@ResponseBody
	@RequiresPermissions("sg:managementcenter:project:list")
	@RequestMapping(value = "data")
	public Map<String, Object> data(Project project, HttpServletRequest request, HttpServletResponse response, Model model) {
		//获取登录名
		String loginName = UserUtils.getUser().getName();//获取登录名
		if (!"admin".equals(loginName)){
			project.setLoginNameFindStats("1");
			project.setLoginNameFind(loginName);
		}
		HttpSession session = request.getSession();
		session.setAttribute("projectEpo",project);
		Page<Project> page = projectService.findPage(new Page<Project>(request, response), project);
		return getBootstrapData(page);
	}

	@ResponseBody
	@RequiresPermissions("sg:managementcenter:project:list")
	@RequestMapping(value = "dataSys")
	public Map<String, Object> dataSys(Project project, HttpServletRequest request, HttpServletResponse response, Model model) {
		project.setStatus("0");
		project.setWhetherCloseStatus("0");
		Page<Project> page = projectService.findPage(new Page<Project>(request, response), project);
		return getBootstrapData(page);
	}

	/**
	 * 领料模块项目选择框
	 * */
	@ResponseBody
	@RequestMapping(value = "dataPicking")
	public Map<String, Object> dataPicking(Project project, HttpServletRequest request, HttpServletResponse response, Model model) {
		project.setStatus("2");
		project.setWhetherCloseStatus("0");
		project.setEarlyMaterial(1);
		project.setConstructionUnitRole(UserUtils.getUser().getLoginName());
		Page<Project> page = projectService.findPage(new Page<Project>(request, response), project);
		return getBootstrapData(page);
	}

	/**
	 * 施工模块项目选择框
	 * */
	@ResponseBody
	@RequestMapping(value = "materialDataPicking")
	public Map<String, Object> materialDataPicking(Project project, HttpServletRequest request, HttpServletResponse response, Model model) {
		//运行提前施工
		project.setPreConstruction(1);
		//未进行施工流程
		project.setConstructionStatus("0");
		Page<Project> page = projectService.findPage(new Page<Project>(request, response), project);
		return getBootstrapData(page);
	}

	/**
	 * 提前施工项目选择
	 * */
	@ResponseBody
	@RequestMapping(value = "dataAdvance")
	public Map<String, Object> dataAdvance(Project project, HttpServletRequest request, HttpServletResponse response, Model model) {
		project.setPreConstruction(0);
		project.setConstructionUnitManage(UserUtils.getUser().getLoginName());//施工项目经理
		Page<Project> page = projectService.findPage(new Page<Project>(request, response), project);
		return getBootstrapData(page);
	}

	/**
	 * 领料申请项目选择框
	 * */
	@ResponseBody
	@RequestMapping(value = "pickingApplication")
	public Map<String, Object> pickingApplication(Project project, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Project> page = projectService.findPage(new Page<Project>(request, response), project);
		return getBootstrapData(page);
	}



	/**
	 * 查看，增加，编辑表单表单页面
	 */
	@RequiresPermissions(value={"sg:managementcenter:project:view","sg:managementcenter:project:add","sg:managementcenter:project:edit"},logical= Logical.OR)
	@RequestMapping(value = "form")
	public String form(Project project, Model model) {
		model.addAttribute("leave1", project);
		User userByLoginName = systemService.getUserByLoginName(UserUtils.getUser().getLoginName());
		String judgeRole = ProExcelInfo.getJudgeRole(userByLoginName);
		if ("0".equals(judgeRole)){
			return "modules/sg/managementcenter/project/projectForm";
		}else if ("3".equals(judgeRole)){
			return "modules/sg/managementcenter/project/projectForm3";
		}else {
			return "modules/sg/managementcenter/project/projectForm2";
		}

	}

	/**
	 * 保存表单
	 */
	@ResponseBody
	@RequiresPermissions(value={"sg:managementcenter:project:add","sg:managementcenter:project:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public AjaxJson save(Project project, Model model) throws Exception{
		AjaxJson j = new AjaxJson();
		/**
		 * 后台hibernate-validation插件校验
		 */
		String errMsg = beanValidator(project);
		if (StringUtils.isNotBlank(errMsg)){
			j.setSuccess(false);
			j.setMsg(errMsg);
			return j;
		}
		List<Project> projects = new ArrayList<Project>();
		projects.add(project);
		//获取登录名
		User userByLoginName = systemService.getUserByLoginName(UserUtils.getUser().getLoginName());
		String judgeRole = ProExcelInfo.getJudgeRole(userByLoginName);
		if (judgeRole.equals("2")){
			j.setSuccess(false);
			j.setMsg("操作失败：您还没有操作的权限，如果需要请联系管理员!");
			return j;
		}
		String loginName = UserUtils.getUser().getLoginName();
		List<String> allUser = projectService.findAllUser();
		if ("0".equals(judgeRole)||"3".equals(judgeRole)){
			String judgeValue = ProExcelInfo.getJudgeValue(projects,allUser);
			if (project.getIsNewRecord()){
				if (!"".equals(judgeValue)||!project.getDistributionEngineering().equals(loginName)){
					j.setSuccess(false);
					j.setMsg("新建失败:"+judgeValue+"数据不符合规范");
					return j;
				}
				projectService.saveList(projects);
				j.setSuccess(true);
				j.setMsg("保存需求基本信息成功");
			}else{
				boolean flagUpdate = ProExcelInfo.getFlagUpdate(project);
				if (flagUpdate){
					j.setSuccess(false);
					j.setMsg("修改失败：流程正在发起中");
					return j;
				}
				if (!"".equals(judgeValue)||!project.getDistributionEngineering().equals(loginName)){
					j.setSuccess(false);
					j.setMsg("修改失败："+judgeValue+"数据不符合规范");
					return j;
				}
				projectService.saveList(projects);
				j.setSuccess(true);
				j.setMsg("修改需求基本信息成功");
			}
		}else {
			String judgeValue = ProExcelInfo.getJudgeValueManager(projects);
			if (project.getIsNewRecord()){
				j.setSuccess(true);
				j.setMsg("保存需求基本信息成功");
			}else{
				if (!"".equals(judgeValue)||!project.getProjectManageRole().equals(loginName)){
					j.setSuccess(false);
					j.setMsg("修改失败："+judgeValue+"数据不符合规范");
					return j;
				}
				project.preUpdate();
				projectService.save(project);
				j.setSuccess(true);
				j.setMsg("修改需求基本信息成功");
			}
		}
		return j;
	}
	
	/**
	 * 删除表单
	 */
	@ResponseBody
	@RequiresPermissions("sg:managementcenter:project:del")
	@RequestMapping(value = "delete")
	public AjaxJson delete(Project project) {
		AjaxJson j = new AjaxJson();
		String requireName="";
		boolean flag = false;
		List<Project> listProject = projectService.findList(project);
		for (Project project1:listProject){
			flag = false;
			requireName = project1.getRequireName();
			if (!project1.getStatus().equals("0")||!project1.getConstructionStatus().equals("0")
					||!project1.getWhetherCloseStatus().equals("0")||!project1.getAcquisitionStatus().equals("0")){
				flag = true;
			}
		}
		if (flag){
			j.setSuccess(false);
			j.setMsg(requireName+":该项目在流程中运行,禁止删除");
			return  j;
		}
		projectService.delete(project);
		j.setMsg("删除需求基本信息成功");
		return j;
	}
	
	/**
	 * 批量表单
	 */
	@ResponseBody
	@RequiresPermissions("sg:managementcenter:project:del")
	@RequestMapping(value = "deleteAll")
	public AjaxJson deleteAll(String ids) {
		AjaxJson j = new AjaxJson();
		Project project = new Project();
		String idArray[] =ids.split(",");
		List<Project> listById = projectService.findListById(idArray);
		boolean flag=false;
		String requireName="";
		for (Project project1:listById){
			if (!project1.getStatus().equals("0")||!project1.getConstructionStatus().equals("0")
					||!project1.getWhetherCloseStatus().equals("0")||!project1.getAcquisitionStatus().equals("0")){
				flag = true;
				requireName += project1.getRequireName()+"、";
			}
		}
		if (flag){
			j.setSuccess(false);
			j.setMsg(requireName+"项目已经在流程中运行,禁止删除");
			return  j;
		}
		for(String id : idArray){
			projectService.delete(projectService.get(id));
		}
		j.setMsg("删除需求基本信息成功");
		return j;
	}
	
	/**
	 * 导出excel文件
	 */
	@ResponseBody
	@RequiresPermissions("sg:managementcenter:project:export")
    @RequestMapping(value = "export")
    public AjaxJson exportFile(Project project, HttpServletRequest request, HttpServletResponse response){
		AjaxJson j = new AjaxJson();

		try {
//			project.setProjectManageRole(UserUtils.getUser().getLoginName());
			String fileName = "需求基本信息"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";

			HttpSession session = request.getSession();
			Project projectEpo = (Project)session.getAttribute("projectEpo");

            Page<Project> page = projectService.findPage(new Page<Project>(request, response, -1), projectEpo);
    		new ExportExcel("需求基本信息", Project.class).setDataList(page.getList()).write(response, fileName).dispose();
    		j.setSuccess(true);
    		j.setMsg("导出成功！");
    		return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出需求基本信息记录失败！失败信息："+e.getMessage());
		}
			return j;
    }

	/**
	 * 导入Excel数据

	 */
	@ResponseBody
	@RequiresPermissions("sg:managementcenter:project:import")
    @RequestMapping(value = "import")
   	public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request){
		AjaxJson j = new AjaxJson();
		//获取登录名
		User userByLoginName = systemService.getUserByLoginName(UserUtils.getUser().getLoginName());
		String judgeRole = ProExcelInfo.getJudgeRole(userByLoginName);
		if (judgeRole.equals("2")){
			j.setSuccess(true);
			j.setMsg("导入失败：您还没有导入的权限，如果需要请联系管理员!");
			return j;
		}
		try {
			ImportUtil importUtil = new ImportUtil(file, 0, 0);
			//验证表是否规范
			Boolean projectUtilFlag = ProExcelInfo.getProjectUtilFlag(importUtil);
			if (projectUtilFlag){
				j.setSuccess(false);
				j.setMsg("导入失败：表不符合规范,请修改后再导入");
				return j;
			}
			if (judgeRole.equals("3")){
				return getProject(j,importUtil);
			}
			if (judgeRole.equals("0")){
				List<Project> projects =ProExcelInfo.getSureProjects(ProExcelInfo.getProjectUtilDistribution(importUtil));
				List<String> users = projectService.findAllUser();
				String judgeValue = ProExcelInfo.getJudgeValue(projects,users);
				if (!"".equals(judgeValue)){
					j.setSuccess(false);
					j.setMsg("导入失败："+judgeValue+"数据不符合规范！");
					return j;
				}
				if (null==projects||projects.size()<=0){
					j.setSuccess(false);
					j.setMsg("导入失败:无符合数据,请检查后再重新导入.");
					return j;
				}
				projectService.saveList(projects);
				j.setMsg( "已成功导入 "+projects.size()+" 条项目表单记录");
			}
			//项目经理操作
			if (judgeRole.equals("1")){
				//得到项目经理操作的集合
				List<Project> projectsManager =ProExcelInfo.getSureProjectsManager(ProExcelInfo.getProjectUtilProjectManager(importUtil));
				if(null==projectsManager||projectsManager.size()<=0){
					j.setSuccess(false);
					j.setMsg("导入失败:无符合数据,请检查后再重新导入.");
					return j;
				}
				//根据项目名称去查找数据库中集合
				List<Project> projectList = projectService.getListProject(projectsManager);
				//得到可以导入数据库中集合
				List<Project> sureManagerProject = ProExcelInfo.getSureManagerProject(projectsManager, projectList);
				String judgeValue = ProExcelInfo.getJudgeValueManager(sureManagerProject);
				if (!"".equals(judgeValue)){
					j.setSuccess(false);
					j.setMsg("导入失败："+judgeValue+"数据不符合规范！");
					return j;
				}
				if (null!=sureManagerProject && sureManagerProject.size()>0){
					projectService.saveListManager(sureManagerProject,projectList);
					j.setMsg( "已成功导入 "+sureManagerProject.size()+" 条项目表单记录");
				}else {
					j.setSuccess(false);
					j.setMsg("导入失败:配网工程专职还没有导入基础数据表.");
					return j;
				}
			}
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入需求基本信息表单失败！失败信息："+e.getMessage());
		}
		return j;
    }

	public AjaxJson getProject(AjaxJson j,ImportUtil importUtil){
		List<Project> projects =ProExcelInfo.getSureProjects(ProExcelInfo.getProjectUtilDistribution(importUtil));
		List<String> users = projectService.findAllUser();
		String judgeValue = ProExcelInfo.getJudgeValue(projects,users);
		if (!"".equals(judgeValue)){
			j.setSuccess(false);
			j.setMsg("导入失败："+judgeValue+"数据不符合规范！");
			return j;
		}
		if (null==projects||projects.size()<=0){
			j.setSuccess(false);
			j.setMsg("导入失败:无符合数据,请检查后再重新导入.");
			return j;
		}
		projectService.saveList(projects);

		//得到项目经理操作的集合
		List<Project> projectsManager =ProExcelInfo.getSureProjectsManager(ProExcelInfo.getProjectUtilProjectManager(importUtil));
		if(null==projectsManager||projectsManager.size()<=0){
			j.setSuccess(false);
			j.setMsg("导入失败:无符合数据,请检查后再重新导入.");
			return j;
		}
		//根据项目名称去查找数据库中集合
		List<Project> projectList = projectService.getListProject(projectsManager);
		//得到可以导入数据库中集合
		List<Project> sureManagerProject = ProExcelInfo.getSureManagerProject(projectsManager, projectList);
		String judgeValue1 = ProExcelInfo.getJudgeValueManager(sureManagerProject);
		if (!"".equals(judgeValue1)){
			j.setSuccess(false);
			j.setMsg("导入失败："+judgeValue+"数据不符合规范！");
			return j;
		}
		if (null!=sureManagerProject && sureManagerProject.size()>0){
			projectService.saveListManager(sureManagerProject,projectList);
			j.setMsg( "已成功导入 "+sureManagerProject.size()+" 条项目表单记录");
		}
		return j;
	}


//	/**
//	 * 导入Excel数据
//		领料单
//	 */
//	@ResponseBody
//	@RequiresPermissions("sg:managementcenter:project:importPicking")
//	@RequestMapping(value = "importPicking")
//	public AjaxJson importFileRequisition(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request){
//		AjaxJson j = new AjaxJson();
//		String str = "";//提示
//		try {
//			ImportUtil importUtil = new ImportUtil(file, 0, 0);
//			//读取表格list
//			List<PickingRequisition> listPickRequisition = PickingInfo.getListPickRequisition(importUtil);
//			/*
//				如下3个list是导入操作（得到最终保存数据库的集合）。对领料单进行数据库保存。
//			 */
//			List<PickingRequisition> duplicateRemoval = PickingInfo.getDuplicateRemoval(listPickRequisition);//去重集合
//			if (null==duplicateRemoval || duplicateRemoval.size()<=0){
//				j.setSuccess(false);
//				j.setMsg("导入失败：导入表格无数据");
//				return j;
//			}
//			List<PickingRequisition> repeatRequisition = PickingInfo.getRepeatRequisition(duplicateRemoval);//去掉重复的领料单号
//			List<PickingRequisition> pickingRequisitions = pickingRequisitionService.pickingRequisitions(repeatRequisition);//得到数据库中数据
//			List<PickingRequisition> sureSavePicking = PickingInfo.getSureSavePicking(pickingRequisitions, repeatRequisition);//参数1：得到数据库集合 参数2：读取表格list
//			if (null!=sureSavePicking&&sureSavePicking.size()>0){
//				pickingRequisitionService.saveList(sureSavePicking);
//			}
//			//判断该项目已完成首次领料
//			List<PickingRequisition> judgePicking = PickingInfo.getJudgePicking(listPickRequisition);//获取领料状态
//			/**
//			 * 一致的,修改领料状态
//			 */
//			//获取需求数量和已出库数量都一致领料单集合
//			List<PickingRequisition> changePicking = PickingInfo.getChangePicking(judgePicking);
//			if (null!=changePicking&&changePicking.size()>0){
//				List<Project> listProjectPicking1 = projectService.findListProjectPicking(changePicking);
//				for (Project project:listProjectPicking1){
//					projectService.getUpdateAcquisitionStatus("2",project.getId());
//				}
//			}
//			/*
//				发送通知方法集合
//			 */
//			//获得该项目是否允许领料是否允许领料状态的项目:返回不一致集合
//			List<PickingRequisition> notifyPickingRequisitions = PickingInfo.getUnifiedPicking(judgePicking);
//			//去重
//			List<PickingRequisition> duplicate = PickingInfo.getDuplicateRemoval(notifyPickingRequisitions);
//			//根据项目定义号去项目表中查找项目信息
//			List<Project> listProjectPicking = projectService.findListProjectPicking(duplicate);
//			if (null!=listProjectPicking&&listProjectPicking.size()>0){
//				//根据项目的id去数据库中查找项目领导审核时间
//				List<Acquisition> findListDate = pickingRequisitionService.getFindListDate(listProjectPicking);
//				if (null!=findListDate&&findListDate.size()>0){
//					List<Acquisition> sureFindListDate = PickingInfo.getSureFindListDate(findListDate);
//					//得到整合后的list集合（存在项目信息）
//					List<ProjectAcquisition> listProjectAcquisition = PickingInfo.getListProjectAcquisition(listProjectPicking, sureFindListDate);
//
//					//得到和项目表匹配的pickAcquisition的集合同时判断给超过三天的领料做标识
//					List<PickingRequisition> listSameSetOf = PickingInfo.getListSameSetOf(listProjectAcquisition, listPickRequisition);
//					if (null!=listSameSetOf&&listSameSetOf.size()>0){
//						//根据物料编码进行去重
//						List<PickingRequisition> duplicateRemovalMaterCode = PickingInfo.getDuplicateRemovalMaterCode(listSameSetOf);
//						//得到库存对应的集合
//						List<MaterialInventory> byListPicking = materialInventoryService.findByListPicking(duplicateRemovalMaterCode);
//
//						//所有缺货未缺货信息的登记
//						List<PickingRequisition> whetherStock = PickingInfo.getWhetherStock(listSameSetOf, byListPicking);
//
//						//得到非缺货信息1的通知
//						List<OaNotifyMaterial> noStockList = PickingInfo.getNoStock(whetherStock);
//						//得到缺货信息3的通知（缺货项目信息）
//						List<OaNotifyMaterial> yesStock2List = PickingInfo.getYesStock2(whetherStock);
//						//得到缺货信息2的通知
//						List<OaNotifyMaterial> yesStock1List = PickingInfo.getYesStock1(whetherStock);
//						//发送通知方法
//						//非缺货信息1
//						if (null!=noStockList && noStockList.size()>0){
//							int count = 0;
//							List<String> listUserId = PickingInfo.getListUserId(PickingInfo.ALL_USER_ID);
//							List<String> userId = pickingRequisitionService.findUserId(listUserId);
//							String stringJoiningTogether = PickingInfo.getStringJoiningTogether(userId);//获取通知人
//							OaNotify oaNotify = new OaNotify();
//							oaNotify.setType("5");
//							oaNotify.setTitle("非缺货信息");//非缺货信息
////							oaNotify.setContent(noStock);
//							oaNotify.setContent("请在详情中查看...");
//							oaNotify.setStatus("1");
//							oaNotify.setOaNotifyRecordIds(stringJoiningTogether);
//							oaNotifyService.saveList(oaNotify,noStockList);
//							List<OaNotifyRecord> list = oaNotify.getOaNotifyRecordList();
//							for(OaNotifyRecord o : list){
//								count++;
//								//发送通知到客户端
//								ServletContext context = SpringContextHolder
//										.getBean(ServletContext.class);
//								new SystemInfoSocketHandler().sendMessageToUser(UserUtils.get(o.getUser().getId()).getLoginName(), "收到一条新通知，请到我的通知查看！");
//							}
//							str="已经发送非缺货信息通知;";
//						}
//						//非缺货信息2
//						if (null!=yesStock1List&&yesStock1List.size()>0){
//							int count = 0;
//							List<String> listUserId = PickingInfo.getListUserId(PickingInfo.QH_USER_ID);
//							List<String> userId = pickingRequisitionService.findUserId(listUserId);
//							String stringJoiningTogether = PickingInfo.getStringJoiningTogether(userId);//获取通知人
//							OaNotify oaNotify = new OaNotify();
//							oaNotify.setType("6");
//							oaNotify.setTitle("缺货信息");
//							oaNotify.setContent("请在详情中查看...");
//							oaNotify.setStatus("1");
//							oaNotify.setOaNotifyRecordIds(stringJoiningTogether);
//							oaNotifyService.saveList(oaNotify,yesStock1List);
//							List<OaNotifyRecord> list = oaNotify.getOaNotifyRecordList();
//							for(OaNotifyRecord o : list){
//								count++;
//								//发送通知到客户端
//								ServletContext context = SpringContextHolder
//										.getBean(ServletContext.class);
//								new SystemInfoSocketHandler().sendMessageToUser(UserUtils.get(o.getUser().getId()).getLoginName(), "收到一条新通知，请到我的通知查看！");
//							}
//							str+="已经发送缺货信息通知;";
//						}
//						//非缺货信息2
//						if (null!=yesStock2List&&yesStock2List.size()>0){
//							int count = 0;
//							List<String> listUserId = PickingInfo.getListUserId(PickingInfo.QH_USER_ID);
//							List<String> userId = pickingRequisitionService.findUserId(listUserId);
//							String stringJoiningTogether = PickingInfo.getStringJoiningTogether(userId);//获取通知人
//							OaNotify oaNotify = new OaNotify();
//							oaNotify.setType("7");
//							oaNotify.setTitle("缺货项目信息");
//							oaNotify.setContent("请在详情中查看...");
//							oaNotify.setStatus("1");
//							oaNotify.setOaNotifyRecordIds(stringJoiningTogether);
//							oaNotifyService.saveList(oaNotify,yesStock2List);
//							List<OaNotifyRecord> list = oaNotify.getOaNotifyRecordList();
//							for(OaNotifyRecord o : list){
//								count++;
//								//发送通知到客户端
//								ServletContext context = SpringContextHolder
//										.getBean(ServletContext.class);
//								new SystemInfoSocketHandler().sendMessageToUser(UserUtils.get(o.getUser().getId()).getLoginName(), "收到一条新通知，请到我的通知查看！");
//							}
//							str+="已经发送缺货项目信息通知;";
//						}
//					}
//
//				}
//			}
//			if (str.length()<=0){
//				str+="暂无通知！";
//			}
//			j.setMsg( "已成功导入 "+listPickRequisition.size()+" 条领料表单记录."+str);
//		} catch (Exception e) {
//			j.setSuccess(false);
//			j.setMsg("导入领料表单失败！失败信息："+e.getMessage());
//		}
//		return j;
//	}
}