integrated_traffic/src/main/java/com/zcloud/controller/comprehensive/TrafficSafetyManualControll...

180 lines
7.3 KiB
Java

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.TrafficSafetyManualService;
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("/manual")
public class TrafficSafetyManualController extends BaseController {
@Autowired
private TrafficSafetyManualService safetyManualService;
@Autowired
private Smb smb;
@RequestMapping(value = "/add")
@ResponseBody
public Object add(@RequestParam(value="FFILE",required=false) MultipartFile file) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = this.getPageData();
String manual_Id = this.get32UUID();
pd.put("CREATOR", Jurisdiction.getUSER_ID()); // 创建人id
pd.put("CREATORNAME", Jurisdiction.getName()); // 创建人姓名
pd.put("OPERATINGCOMPANY", Jurisdiction.getCORPINFO_ID()); // 经营企业
pd.put("MANUAL_ID", manual_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()));
}
safetyManualService.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<String, Object> map = new HashMap<String, Object>();
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()));
}
safetyManualService.edit(pd);
map.put("result", errInfo);
map.put("pd", pd);
return map;
}
/**
* 列表
* @param page
* @return
* @throws Exception
*/
@RequestMapping(value = "/listForSafetyManuallist")
@ResponseBody
public Object listForSafetyManuallist(Page page) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
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<PageData> varList = safetyManualService.listForSafetyManuallist(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<String,Object> map = new HashMap<String,Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd = safetyManualService.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<String,String> map = new HashMap<String,String>();
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()));//删除时间
safetyManualService.delete(pd);
map.put("result", errInfo);
return map;
}
}