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.TrafficSafetyActivitiesService; import com.zcloud.service.comprehensive.TrafficSafetyProductionService; 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.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Controller @RequestMapping("/activities") public class TrafficSafetyActivitiesController extends BaseController { @Autowired private TrafficSafetyActivitiesService activeService; @Autowired private Smb smb; @RequestMapping(value = "/add") @ResponseBody public Object add(@RequestParam(value="FFILE",required=false) MultipartFile file) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = this.getPageData(); String activities_Id = this.get32UUID(); pd.put("CREATOR", Jurisdiction.getUSER_ID()); // 创建人id pd.put("CREATORNAME", Jurisdiction.getName()); // 创建人姓名 pd.put("OPERATINGCOMPANY", Jurisdiction.getCORPINFO_ID()); // 经营企业 pd.put("ACTIVITIES_ID", activities_Id); // 主键 pd.put("CREATETIME", DateUtil.date2Str(new Date())); // 添加时间 pd.put("COMPLETIONSTATUS", "0"); pd.put("ISDELETE", "0"); if (DateUtil.compareDate(DateUtil.getDay(), pd.getString("EXPIRYDATE"))) { pd.put("VALIDSTATUS", "0"); } else { pd.put("VALIDSTATUS", "1"); } String ffile = DateUtil.getDays(); if (file != null && StringUtils.isNotBlank(pd.getString("CREATORNAME"))){ pd.put("COMPLETIONSTATUS", "1"); 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("OPERATINGCOMPANY") + "/" + ffile); pd.put("ATTACHMENT_ROUTE", Const.FILEPATHFILE + pd.getString("OPERATINGCOMPANY") + "/" + ffile + "/" + fileName); pd.put("ATTACHMENT_NAME",pd.getString("CREATORNAME")); pd.put("CONFIRM_MESSAGE_TIME",DateUtil.date2Str(new Date())); } activeService.save(pd); map.put("result", errInfo); map.put("pd", pd); return map; } //修改 @RequestMapping(value = "/edit") @ResponseBody public Object edit(@RequestParam(value="FFILE",required=false) MultipartFile file) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = this.getPageData(); pd.put("OPERATOR", Jurisdiction.getUSER_ID()); // 修改人id pd.put("OPERATORNAME", Jurisdiction.getName()); // 修改人姓名 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); // 修改时间 pd.put("OPERATINGCOMPANY", Jurisdiction.getCORPINFO_ID()); // 经营企业 pd.put("ISDELETE", "0"); String ffile = DateUtil.getDays(); if (file != null && StringUtils.isNotBlank(pd.getString("OPERATORNAME"))){ pd.put("COMPLETIONSTATUS", "1"); 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("OPERATINGCOMPANY") + "/" + ffile); pd.put("ATTACHMENT_ROUTE", Const.FILEPATHFILE + pd.getString("OPERATINGCOMPANY") + "/" + ffile + "/" + fileName); pd.put("ATTACHMENT_NAME",pd.getString("CREATORNAME")); pd.put("CONFIRM_MESSAGE_TIME",DateUtil.date2Str(new Date())); } activeService.edit(pd); map.put("result", errInfo); map.put("pd", pd); return map; } /** * 列表 * @param page * @return * @throws Exception */ @RequestMapping(value = "/listForSafetyActivitieslist") @ResponseBody public Object listForSafetyActivitieslist(Page page) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); String SYSTEMNAME = pd.getString("SYSTEMNAME"); // 关键词检索条件 if (Tools.notEmpty(SYSTEMNAME)) pd.put("SYSTEMNAME", SYSTEMNAME.trim()); String COMPLETIONSTATUS = pd.getString("COMPLETIONSTATUS"); // 关键词检索条件 if (Tools.notEmpty(COMPLETIONSTATUS)) pd.put("COMPLETIONSTATUS", COMPLETIONSTATUS.trim()); String VALIDSTATUS = pd.getString("VALIDSTATUS"); // 关键词检索条件 if (Tools.notEmpty(VALIDSTATUS)) pd.put("VALIDSTATUS", VALIDSTATUS.trim()); page.setPd(pd); List varList = activeService.listForSafetyActivitieslist(page); 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 = activeService.findById(pd); //根据ID读取 map.put("pd", pd); map.put("result", errInfo); return map; } /** * 删除 * @return * @throws Exception */ @RequestMapping(value="/delete") @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()));//删除时间 activeService.delete(pd); map.put("result", errInfo); return map; } }