package com.zcloud.controller.comprehensive; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.service.comprehensive.TrafficSecurityNoticeService; import com.zcloud.service.comprehensive.TrafficSecurityReadDetailService; import com.zcloud.service.system.UsersService; import com.zcloud.util.*; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; 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 java.util.*; import static org.apache.logging.log4j.ThreadContext.isEmpty; @Controller @RequestMapping("/securitynotice") public class TrafficSecurityNoticeController extends BaseController { @Autowired private TrafficSecurityNoticeService securityNoticeService; @Autowired private TrafficSecurityReadDetailService securityReadDetail; @Autowired private Smb smb; @Autowired private UsersService usersService; @Autowired private TrafficSecurityReadDetailService trafficSecurityReadDetailService; //新增 @RequestMapping(value = "/add") @ResponseBody public Object add(@RequestParam(value="fileList",required=false) MultipartFile file,@RequestParam(value="videoList",required=false) MultipartFile videoFile) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = this.getPageData(); String notificationId = this.get32UUID(); pd.put("CREATOR", Jurisdiction.getUSER_ID()); // 创建人id pd.put("CREATORNAME", Jurisdiction.getName()); // 创建人姓名 pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 运输企业 pd.put("NOTIFICATION_ID", notificationId); // 主键 pd.put("CREATETIME", DateUtil.date2Str(new Date())); // 添加时间 pd.put("POSTSTATUS", "0"); // 发布状态 pd.put("SIGNEDSTATUS", "0"); // 签收状态 pd.put("ISDELETE", "0"); String ffile = DateUtil.getDays(); if (file != null && StringUtils.isNotBlank(pd.getString("CREATORNAME"))){ String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1).toLowerCase(); if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName)) { errInfo = "fail"; map.put("result", errInfo); map.put("msg", "文件格式不正确!"); return map; } String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); smb.sshSftp(file, fileName, Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile); pd.put("ATTACHMENT_ROUTE", Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile + "/" + fileName); pd.put("ATTACHMENT_NAME",pd.getString("CREATORNAME")); pd.put("CONFIRM_MESSAGE_TIME",DateUtil.date2Str(new Date())); } // 处理 videoFile if (videoFile != null && StringUtils.isNotBlank(pd.getString("CREATORNAME"))) { String videoSuffixName = videoFile.getOriginalFilename().substring(videoFile.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase(); if (!"mp4".equals(videoSuffixName)) { errInfo = "fail"; map.put("result", errInfo); map.put("msg", "视频文件格式不正确!"); return map; } String videoFileName = this.get32UUID() + videoFile.getOriginalFilename().substring(videoFile.getOriginalFilename().lastIndexOf(".")); smb.sshSftp(videoFile, videoFileName, Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile); pd.put("VIDEO_ROUTE", Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile + "/" + videoFileName); pd.put("VIDEO_NAME",pd.getString("CREATORNAME")); } if(StringUtils.equals(pd.getString("allStatus"), "1")) { PageData data = new PageData(); data.put("CORPINFO_ID", pd.getString("CORPINFO_ID")); List allUser = usersService.getAllUser(data); System.out.println("allUser = " + allUser); String userIds = ""; for (PageData pageData : allUser) { userIds = userIds + pageData.getString("USER_ID") + ","; } userIds = userIds.substring(0, userIds.length() - 1); pd.put("PERSON_ID", userIds); } pd.put("SIGNING", "0"); // 签收情况 pd.put("REPLY", "0"); // 回复情况 securityNoticeService.save(pd); map.put("result", errInfo); map.put("pd", pd); return map; } //阅读情况 @RequestMapping(value = "/getAllReadDetail") @ResponseBody public Object getAllReadDetail(Page page) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); String PRACTITIONER = pd.getString("PRACTITIONER");// 关键词检索条件 if (Tools.notEmpty(PRACTITIONER)) pd.put("PRACTITIONER", PRACTITIONER.trim()); String PRACTITIONERTYPE = pd.getString("PRACTITIONERTYPE");// 关键词检索条件 if (Tools.notEmpty(PRACTITIONERTYPE)) pd.put("PRACTITIONERTYPE", PRACTITIONERTYPE.trim()); String SIGNEDSTATUS = pd.getString("SIGNEDSTATUS");// 关键词检索条件 if (Tools.notEmpty(SIGNEDSTATUS)) pd.put("SIGNEDSTATUS", SIGNEDSTATUS.trim()); String REPLYSTATUS = pd.getString("REPLYSTATUS");// 关键词检索条件 if (Tools.notEmpty(REPLYSTATUS)) pd.put("REPLYSTATUS", REPLYSTATUS.trim()); page.setPd(pd); List notifications = securityReadDetail.getAllReadDetail(page); map.put("varList", notifications); map.put("page", page); map.put("result", errInfo); return map; } //列表 @RequestMapping(value = "/listForSecurityNotice") @ResponseBody public Object listForSecurityNotice(Page page) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业ID page.setPd(pd); List varList = securityNoticeService.listForSecurityNotice(page); long replyStatusNum = 0; long signedStatusNum = 0; for (PageData data : varList) { // pd.put("NOTIFICATION_ID", data.get("NOTIFICATION_ID")); // page.setPd(pd); // List readDetail = securityReadDetail.getAllReadDetail(page); // // long currentReplyStatusNum = readDetail.stream() // .filter(d -> "1".equals(d.getString("REPLY"))) // .count(); // long currentSignedStatusNum = readDetail.stream() // .filter(d -> "1".equals(d.getString("SIGNING"))) // .count(); // long currentTotalReadDetail = readDetail.size(); // // replyStatusNum += currentReplyStatusNum; // signedStatusNum += currentSignedStatusNum; // data.put("REPLYSTATUSNUM", currentReplyStatusNum); // data.put("SIGNEDSTATUSNUM", currentSignedStatusNum); // 获取 回复与签收 的总人数 data.put("TOTALREADDETAIL", Tools.notEmpty(data.getString("PERSON_ID"))?data.getString("PERSON_ID").split(",").length : 0); } map.put("varList", varList); map.put("page", page); map.put("result", errInfo); return map; } //详情 @RequestMapping(value="/goEdit") @ResponseBody public Object goEdit() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd = securityNoticeService.findById(pd);//根据ID读取 String[] personIds = pd.getString("PERSON_ID").split(","); List readDetail = new ArrayList<>(); List names = new ArrayList<>(); for (String personId : personIds) { PageData pd2 = new PageData(); pd2.put("NOTIFICATION_ID", pd.getString("NOTIFICATION_ID")); pd2.put("PERSON_ID",personId.trim()); PageData pageData = trafficSecurityReadDetailService.listByUserIdOrNoticeId(pd2); readDetail.add(pageData); // 通过 用户id获取用户名 PageData user = new PageData(); user.put("USER_ID",personId.trim()); PageData pageData1 = usersService.findById(user); names.add(pageData1); } pd.put("readDetail",readDetail); pd.put("names",names); map.put("pd", pd); map.put("result", errInfo); return map; } @RequestMapping(value = "/edit") @ResponseBody public Object edit( @RequestParam(value="fileList",required=false) MultipartFile file, @RequestParam(value="videoList",required=false) MultipartFile videoFile) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = this.getPageData(); pd.put("OPERATOR", Jurisdiction.getUSER_ID()); // 创建人id pd.put("CORPINFO_ID", Jurisdiction.getPOST_ID()); // 创建人id pd.put("OPERATORNAME", Jurisdiction.getName()); // 创建人姓名 pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // 运输企业 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); // 添加时间 pd.put("POSTSTATUS", "0"); // 发布状态 pd.put("SIGNEDSTATUS", "0"); // 签收状态 pd.put("ISDELETE", "0"); String ffile = DateUtil.getDays(); if (file != null && StringUtils.isNotBlank(pd.getString("CREATORNAME"))){ String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1).toLowerCase(); if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName)) { errInfo = "fail"; map.put("result", errInfo); map.put("msg", "文件格式不正确!"); return map; } String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); smb.sshSftp(file, fileName, Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile); pd.put("ATTACHMENT_ROUTE", Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile + "/" + fileName); pd.put("ATTACHMENT_NAME",pd.getString("CREATORNAME")); pd.put("CONFIRM_MESSAGE_TIME",DateUtil.date2Str(new Date())); } // 处理 videoFile if (videoFile != null && StringUtils.isNotBlank(pd.getString("CREATORNAME"))) { String videoSuffixName = videoFile.getOriginalFilename().substring(videoFile.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase(); if (!"mp4".equals(videoSuffixName)) { errInfo = "fail"; map.put("result", errInfo); map.put("msg", "视频文件格式不正确!"); return map; } String videoFileName = this.get32UUID() + videoFile.getOriginalFilename().substring(videoFile.getOriginalFilename().lastIndexOf(".")); smb.sshSftp(videoFile, videoFileName, Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile); pd.put("VIDEO_ROUTE", Const.FILEPATHFILE + pd.getString("CORPINFO_ID") + "/" + ffile + "/" + videoFileName); pd.put("VIDEO_NAME",pd.getString("CREATORNAME")); } if(StringUtils.equals(pd.getString("allStatus"), "1")) { PageData data = new PageData(); data.put("CORPINFO_ID", pd.getString("CORPINFO_ID")); List allUser = usersService.getAllUser(data); System.out.println("allUser = " + allUser); String userIds = ""; for (PageData pageData : allUser) { userIds = userIds + pageData.getString("USER_ID") + ","; } userIds = userIds.substring(0, userIds.length() - 1); pd.put("PERSON_ID", userIds); } pd.put("SIGNING", "0"); // 签收情况 pd.put("REPLY", "0"); // 回复情况 securityNoticeService.edit(pd); /*String[] personIds = pd.getString("PERSON_ID").split(","); for (String personId : personIds) { //pd.put("NOTIFICATION_ID", notificationId); pd.put("PERSON_ID", personId.trim()); pd.put("READDETAIL_ID", this.get32UUID()); // 主键 pd.put("REPLYSTATUS", "0"); // 主键 pd.put("SIGNEDSTATUS", "0"); // 主键 securityReadDetail.save(pd); }*/ map.put("result", errInfo); map.put("pd", pd); return map; } /**删除 * @param * @throws Exception */ @RequestMapping(value="/delete") // @RequiresPermissions("traininginfo:del") @ResponseBody public Object delete() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("DELETOR", Jurisdiction.getUSER_ID());//删除人id pd.put("DELETORNAME", Jurisdiction.getName());//删除人姓名 pd.put("DELETETIME", DateUtil.date2Str(new Date()));//删除时间 securityNoticeService.delete(pd); securityReadDetail.delete(pd); map.put("result", errInfo);//返回结果 return map; } /**批量删除 * @param * @throws Exception */ @RequestMapping(value="/deleteAll") @ResponseBody public Object deleteAll() throws Exception{ Map map = new HashMap(); String errInfo = "success"; String err=""; PageData pd = new PageData(); pd = this.getPageData(); String DATA_IDS = pd.getString("DATA_IDS"); if(Tools.notEmpty(DATA_IDS)){ String ArrayDATA_IDS[] = DATA_IDS.split(","); for (String id : ArrayDATA_IDS) { pd.put("NOTIFICATION_ID", id); pd.put("DELETORNAME", Jurisdiction.getName());//删除人 pd.put("DELETETIME", DateUtil.date2Str(new Date()));//删除时间 securityNoticeService.delete(pd); } errInfo = "success"; }else{ errInfo = "error"; } map.put("result", errInfo);//返回结果 return map; } @RequestMapping(value="/issueSecurityNotice") @ResponseBody public Object issueSecurityNotice() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); // 修改安全通知发布状态 securityNoticeService.issueSecurityNotice(pd); // 查询此条通知的信息,获取 推送的ID PageData securityNotice = securityNoticeService.findById(pd); // 把此条通知的ID 和 推送人的ID 存入到 发部表 String[] personIds = securityNotice.getString("PERSON_ID").split(","); for (int i = 0; i < personIds.length; i++) { PageData issue = new PageData(); issue.put("READDETAIL_ID", this.get32UUID()); issue.put("NOTIFICATION_ID",securityNotice.getString("NOTIFICATION_ID")); issue.put("TITLE",securityNotice.getString("TITLE")); issue.put("LEVEL",securityNotice.getString("LEVEL")); issue.put("REPLY", "0"); issue.put("SIGNING", "0"); issue.put("CORPINFO_ID", securityNotice.getString("CORPINFO_ID")); issue.put("PERSON_ID",personIds[i].trim()); issue.put("ISDELETE", "0"); issue.put("CREATOR", Jurisdiction.getUSER_ID()); issue.put("CREATORNAME", Jurisdiction.getName()); issue.put("CREATETIME",DateUtil.date2Str(new Date())); // 编写发布的 insert trafficSecurityReadDetailService.save(issue); } map.put("pd", pd); map.put("result", errInfo); return map; } }