package com.zcloud.controller.keyProjects; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.service.keyProjects.DeviceService; import com.zcloud.service.system.DictionariesService; import com.zcloud.util.*; import org.apache.shiro.authz.annotation.RequiresPermissions; 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 org.springframework.web.servlet.ModelAndView; import java.util.*; /** * 说明:相关方管理 * 作者:luoxiaobao * 时间:2022-06-07 * 官网:www.zcloudchina.com */ @Controller @RequestMapping("/device") public class DeviceController extends BaseController { @Autowired private DeviceService deviceService; @Autowired private DictionariesService dictionariesService; /** * 新增 * * @param * @throws Exception */ @RequestMapping(value = "/add") @ResponseBody public Object add(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("DEVICE_ID", this.get32UUID()); //主键 pd.put("CREATOR", Jurisdiction.getUsername()); //添加人 pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间 pd.put("OPERATOR", Jurisdiction.getUsername()); //修改人 pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间 pd.put("ISDELETE", "0"); //是否删除 // if (null != file && !file.isEmpty()) { // String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1).toLowerCase(); // if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName) && !"mp4".equals(suffixName)) { // errInfo = "fail"; // map.put("result", errInfo); // map.put("msg", "文件格式不正确!"); // return map; // } // String ffile = DateUtil.getDays(); // String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile; //文件上传路径 // String fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传 // String fileName = this.get32UUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); // Smb.sshSftp(file, fileName, Const.FILEPATHFILE + "/" + ffile); // pd.put("FILEPATH", Const.FILEPATHFILE + "/" + ffile + "/" + fileName); // } pd.put("DEVICE_ID", pd.getString("DEVICE_ID")); List list = deviceService.listAll(pd); deviceService.save(pd); map.put("result", errInfo); return map; } /** * 判断相关方单位名是否存在 * * @return */ @RequestMapping(value = "/hasName") @ResponseBody public Object hasName() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd = deviceService.findByName(pd); if (pd != null) { map.put("pd", pd); } map.put("result", errInfo); //返回结果 return map; } /** * 判断摄像头id是不是重复 * * @return */ @RequestMapping(value = "/hasCode") @ResponseBody public Object hasCode() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); if (deviceService.findByCode(pd) != null) { map.put("pd", pd); } map.put("result", errInfo); //返回结果 return map; } /** * 删除 * * @param out * @throws Exception */ @RequestMapping(value = "/delete") // @RequiresPermissions("units:del") @ResponseBody public Object delete() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); deviceService.delete(pd); map.put("result", errInfo); //返回结果 return map; } /** * 修改 * * @param * @throws Exception */ @RequestMapping(value = "/edit") // @RequiresPermissions("units:edit") @ResponseBody public Object edit(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); deviceService.edit(pd); map.put("result", errInfo); return map; } /** * 列表 * * @param page * @throws Exception */ @RequestMapping(value = "/list") // @RequiresPermissions("units:list") @ResponseBody public Object list(Page page) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件 if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim()); page.setPd(pd); List varList = deviceService.list(page); //列出Units列表 map.put("varList", varList); map.put("page", page); map.put("result", errInfo); return map; } /** * 去修改页面获取数据 * * @param * @throws Exception */ @RequestMapping(value = "/goEdit") // @RequiresPermissions("units:edit") @ResponseBody public Object goEdit(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd = deviceService.findById(pd); //根据ID读取 map.put("pd", 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"; 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(","); deviceService.deleteAll(ArrayDATA_IDS); errInfo = "success"; }else{ errInfo = "fail"; } map.put("result", errInfo); //返回结果 return map; } /** * 修改 * * @param * @throws Exception */ @RequestMapping(value = "/editOut") @ResponseBody public Object editOut() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); deviceService.editOut(pd); map.put("result", errInfo); return map; } }