package com.zcloud.controller.system; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.service.system.VersionManagerService; 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 * 时间:2021-02-07 * 官网:www.zcloudchina.com */ @Controller @RequestMapping("/app/versionmanager") public class AppVersionManagerController extends BaseController { @Autowired private VersionManagerService versionmanagerService; @Autowired private Smb smb; /**新增 * @param * @throws Exception */ @RequestMapping(value="/add") @RequiresPermissions("versionmanager:add") @ResponseBody public Object add(@RequestParam(value="FFILE",required=false) MultipartFile file, @RequestParam(value="VERSIONMANAGER_ID",required=false) String VERSIONMANAGER_ID, @RequestParam(value="VERSION",required=false) String VERSION, @RequestParam(value="FILETYPE",required=false) String FILETYPE, @RequestParam(value="ISEFFECTIVE",required=false) String ISEFFECTIVE, @RequestParam(value="ISUPDATE",required=false) String ISUPDATE) throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); String ffile = DateUtil.getDays(), fileName = ""; if (null != file && !file.isEmpty()) { //String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile; //文件上传路径 //fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传 fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile); pd.put("FILEURL", Const.FILEPATHFILE + ffile + "/" + fileName); //文件路径 pd.put("VERSION", VERSION); pd.put("FILETYPE", FILETYPE); pd.put("ISEFFECTIVE", ISEFFECTIVE); pd.put("ISUPDATE", ISUPDATE); pd.put("OPUSER", Jurisdiction.getUsername()); pd.put("OPTIME", DateUtil.date2Str(new Date())); pd.put("VERSIONMANAGER_ID", this.get32UUID()); //主键 versionmanagerService.save(pd); //存入数据库表 }else{ errInfo = "error"; } map.put("result", errInfo); //返回结果 return map; } /**删除 * @param out * @throws Exception */ @RequestMapping(value="/delete") @RequiresPermissions("versionmanager:del") @ResponseBody public Object delete() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); versionmanagerService.delete(pd); map.put("result", errInfo); //返回结果 return map; } /**修改 * @param * @throws Exception */ @RequestMapping(value="/edit") @RequiresPermissions("versionmanager:edit") @ResponseBody public Object edit(@RequestParam(value="FFILE",required=false) MultipartFile file, @RequestParam(value="VERSIONMANAGER_ID",required=false) String VERSIONMANAGER_ID, @RequestParam(value="VERSION",required=false) String VERSION, @RequestParam(value="FILETYPE",required=false) String FILETYPE, @RequestParam(value="ISEFFECTIVE",required=false) String ISEFFECTIVE, @RequestParam(value="ISUPDATE",required=false) String ISUPDATE) throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); String ffile = DateUtil.getDays(), fileName = ""; if (null != file && !file.isEmpty()) { // String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile; //文件上传路径 // fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传 fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); smb.sshSftp(file, fileName, Const.FILEPATHFILE + ffile); pd.put("FILEURL", Const.FILEPATHFILE + ffile + "/" + fileName); //文件路径 pd.put("VERSION", VERSION); pd.put("FILETYPE", FILETYPE); pd.put("ISEFFECTIVE", ISEFFECTIVE); pd.put("ISUPDATE", ISUPDATE); pd.put("OPUSER", Jurisdiction.getUsername()); pd.put("OPTIME", DateUtil.date2Str(new Date())); pd.put("VERSIONMANAGER_ID",VERSIONMANAGER_ID); //主键 versionmanagerService.edit(pd); //存入数据库表 }else{ pd.put("VERSION", VERSION); pd.put("FILETYPE", FILETYPE); pd.put("ISEFFECTIVE", ISEFFECTIVE); pd.put("ISUPDATE", ISUPDATE); pd.put("OPUSER", Jurisdiction.getUsername()); pd.put("OPTIME", DateUtil.date2Str(new Date())); pd.put("VERSIONMANAGER_ID",VERSIONMANAGER_ID); //主键 versionmanagerService.edit(pd); //存入数据库表 } map.put("result", errInfo); //返回结果 return map; } /**列表 * @param page * @throws Exception */ @RequestMapping(value="/list") @RequiresPermissions("versionmanager: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 = versionmanagerService.list(page); //列出VersionManager列表 map.put("varList", varList); map.put("page", page); map.put("result", errInfo); return map; } /**列表 * @param page * @throws Exception */ @RequestMapping(value="/getVersion") @ResponseBody public Object getVersion() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); List varList = versionmanagerService.listAll(pd); //列出VersionManager列表 map.put("pd", varList.get(0)); map.put("result", errInfo); return map; } /**去修改页面获取数据 * @param * @throws Exception */ @RequestMapping(value="/goEdit") @RequiresPermissions("versionmanager:edit") @ResponseBody public Object goEdit() throws Exception{ Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd = versionmanagerService.findById(pd); //根据ID读取 map.put("pd", pd); map.put("result", errInfo); return map; } /**批量删除 * @param * @throws Exception */ @RequestMapping(value="/deleteAll") @RequiresPermissions("versionmanager:del") @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(","); versionmanagerService.deleteAll(ArrayDATA_IDS); errInfo = "success"; }else{ errInfo = "error"; } map.put("result", errInfo); //返回结果 return map; } /**导出到excel * @param * @throws Exception */ @RequestMapping(value="/excel") @RequiresPermissions("toExcel") public ModelAndView exportExcel() throws Exception{ ModelAndView mv = new ModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); Map dataMap = new HashMap(); List titles = new ArrayList(); titles.add("版本"); //1 titles.add("文件地址"); //2 titles.add("文件类型"); //3 titles.add("操作人"); //4 titles.add("操作日期"); //5 titles.add("是否有效"); //6 titles.add("是否更新 1,强制更新,2不强制更新"); //7 dataMap.put("titles", titles); List varOList = versionmanagerService.listAll(pd); List varList = new ArrayList(); for(int i=0;i