qa-prevention-gwj/src/main/java/com/zcloud/controller/keyProjects/DeviceController.java

242 lines
6.9 KiB
Java
Raw Normal View History

2023-11-07 09:32:12 +08:00
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<String, Object> map = new HashMap<String, Object>();
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<PageData> list = deviceService.listAll(pd);
deviceService.save(pd);
map.put("result", errInfo);
return map;
}
/**
*
*
* @return
*/
@RequestMapping(value = "/hasName")
@ResponseBody
public Object hasName() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
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<String, Object> map = new HashMap<String, Object>();
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<String, String> map = new HashMap<String, String>();
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<String, Object> map = new HashMap<String, Object>();
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<String, Object> map = new HashMap<String, Object>();
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<PageData> 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<String, Object> map = new HashMap<String, Object>();
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<String,Object> map = new HashMap<String,Object>();
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<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
deviceService.editOut(pd);
map.put("result", errInfo);
return map;
}
}