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; //新增 @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("CORPINFO_ID", Jurisdiction.getPOST_ID()); // 创建人id pd.put("CREATORNAME", Jurisdiction.getName()); // 创建人姓名 pd.put("TRANSPORTATIONCOMPANY", Jurisdiction.getCORPINFO_ID()); // 运输企业 pd.put("NOTIFICATION_ID", notificationId); // 主键 pd.put("CREATETIME", DateUtil.date2Str(new Date())); // 添加时间 pd.put("POSTSTATUS", "1"); // 发布状态 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")); } pd.put("SIGNING", "0"); // 签收情况 pd.put("REPLY", "0"); // 回复情况 securityNoticeService.save(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; } //阅读情况 @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(); String TITLE = pd.getString("TITLE");// 关键词检索条件 if (Tools.notEmpty(TITLE)) pd.put("TITLE", TITLE.trim()); String REPLYSTATUS = pd.getString("REPLYSTATUS");// 关键词检索条件 if (Tools.notEmpty(REPLYSTATUS)) pd.put("REPLYSTATUS", REPLYSTATUS.trim()); 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("TOTALREADDETAIL", currentTotalReadDetail); data.put("REPLYSTATUSNUM", currentReplyStatusNum); data.put("SIGNEDSTATUSNUM", currentSignedStatusNum); } map.put("REPLYSTATUSNUM", String.valueOf(replyStatusNum)); map.put("SIGNEDSTATUSNUM", String.valueOf(signedStatusNum)); map.put("varList", varList); map.put("page", page); map.put("result", errInfo); return map; } //详情 @RequestMapping(value="/goEdit") // @RequiresPermissions("traininginfo:edit") @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读取 map.put("pd", pd); map.put("result", errInfo); 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.getUsername());//删除人姓名 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.getUsername());//删除人 pd.put("DELETETIME", DateUtil.date2Str(new Date()));//删除时间 securityNoticeService.delete(pd); } errInfo = "success"; }else{ errInfo = "error"; } map.put("result", errInfo);//返回结果 return map; } }