|
@@ -0,0 +1,305 @@
|
|
|
+/**
|
|
|
+ * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
|
|
|
+ */
|
|
|
+package com.jeeplus.modules.projectAccessory.web;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.jeeplus.common.config.Global;
|
|
|
+import com.jeeplus.common.json.AjaxJson;
|
|
|
+import com.jeeplus.common.persistence.Page;
|
|
|
+import com.jeeplus.common.utils.DateUtils;
|
|
|
+import com.jeeplus.common.utils.MyBeanUtils;
|
|
|
+import com.jeeplus.common.utils.StringUtils;
|
|
|
+import com.jeeplus.common.utils.excel.ExportExcel;
|
|
|
+import com.jeeplus.common.utils.excel.ImportExcel;
|
|
|
+import com.jeeplus.common.web.BaseController;
|
|
|
+import com.jeeplus.modules.projectAccessory.entity.ProjectAccessoryInfo;
|
|
|
+import com.jeeplus.modules.projectAccessory.entity.ProjectAccessoryTree;
|
|
|
+import com.jeeplus.modules.projectAccessory.entity.ProjectTemplateInfo;
|
|
|
+import com.jeeplus.modules.projectAccessory.service.ProjectAccessoryService;
|
|
|
+import com.jeeplus.modules.projectAccessory.service.ProjectTemplateService;
|
|
|
+import com.jeeplus.modules.sys.entity.MainDictDetail;
|
|
|
+import com.jeeplus.modules.sys.utils.DictUtils;
|
|
|
+import com.jeeplus.modules.workclientinfo.entity.WorkClientAttachment;
|
|
|
+import org.apache.shiro.authz.annotation.Logical;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.ConstraintViolationException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 附件结构(字典版)Controller
|
|
|
+ * @author 徐滕
|
|
|
+ * @version 2020-11-18
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/projectTemplate/projectTemplate")
|
|
|
+public class ProjectTemplateController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProjectTemplateService projectTemplateService;
|
|
|
+
|
|
|
+ @ModelAttribute
|
|
|
+ public ProjectTemplateInfo get(@RequestParam(required=false) String id) {
|
|
|
+ ProjectTemplateInfo entity = null;
|
|
|
+ if (StringUtils.isNotBlank(id)){
|
|
|
+ entity = projectTemplateService.get(id);
|
|
|
+ }
|
|
|
+ if (entity == null){
|
|
|
+ entity = new ProjectTemplateInfo();
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 附件结构列表页面
|
|
|
+ * @param projectTemplateInfo
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("projectTemplate:projectTemplate:list")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(ProjectTemplateInfo projectTemplateInfo, Model model) {
|
|
|
+ List<ProjectTemplateInfo> list = projectTemplateService.findList(projectTemplateInfo);
|
|
|
+ model.addAttribute("list", list);
|
|
|
+ return "modules/projectAccessory/projectTemplate/projectTemplateList";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看,增加,编辑附件结构表单页面
|
|
|
+ * @param projectAccessoryInfo
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions(value={"projectTemplate:projectTemplate:add","projectTemplate:projectTemplate:edit"},logical=Logical.OR)
|
|
|
+ @RequestMapping(value = "form")
|
|
|
+ public String form(ProjectTemplateInfo projectAccessoryInfo, Model model) {
|
|
|
+ if(projectAccessoryInfo!=null&&projectAccessoryInfo.getParent()!=null&&StringUtils.isNotBlank(projectAccessoryInfo.getParent().getId())){
|
|
|
+ ProjectTemplateInfo parent = projectTemplateService.getFromParentInfo(projectAccessoryInfo);
|
|
|
+ projectAccessoryInfo.setParent(parent);
|
|
|
+ }
|
|
|
+ model.addAttribute("projectAccessoryInfo", projectAccessoryInfo);
|
|
|
+ return "modules/projectAccessory/projectTemplate/projectTemplateForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询附件类型
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("getPostfixType")
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxJson getPostfixType(){
|
|
|
+ AjaxJson ajaxJson = new AjaxJson();
|
|
|
+ try {
|
|
|
+ List<MainDictDetail> typeList = DictUtils.getMainDictList("attachment_template_postfix_type");
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < typeList.size(); i++) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("name", typeList.get(i).getLabel());
|
|
|
+ map.put("value", typeList.get(i).getValue());
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+ ajaxJson.getBody().put("list", mapList);
|
|
|
+ ajaxJson.setMsg("获取数据成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("获取数据异常!", e);
|
|
|
+ ajaxJson.setSuccess(false);
|
|
|
+ ajaxJson.setMsg("获取数据异常");
|
|
|
+ }
|
|
|
+ return ajaxJson;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id查询相关的附件类型
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("getPostfixTypeById")
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxJson getPostfixTypeById(String id){
|
|
|
+ AjaxJson ajaxJson = new AjaxJson();
|
|
|
+ try {
|
|
|
+ ProjectTemplateInfo info= projectTemplateService.get(id);
|
|
|
+ if(StringUtils.isNotBlank(id) && StringUtils.isNotBlank(info.getAttachTypes())){
|
|
|
+ String types[] = info.getAttachTypes().split(",");
|
|
|
+ List<String> typeList = Arrays.asList(types);
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < typeList.size(); i++) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("value", typeList.get(i));
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+ ajaxJson.getBody().put("list", mapList);
|
|
|
+ }
|
|
|
+ ajaxJson.setMsg("获取数据成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("获取数据异常!", e);
|
|
|
+ ajaxJson.setSuccess(false);
|
|
|
+ ajaxJson.setMsg("获取数据异常");
|
|
|
+ }
|
|
|
+ return ajaxJson;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看
|
|
|
+ * @param projectAccessoryInfo
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions(value={"projectTemplate:projectTemplate:view"},logical=Logical.OR)
|
|
|
+ @RequestMapping(value = "view")
|
|
|
+ public String view(ProjectTemplateInfo projectAccessoryInfo, Model model) {
|
|
|
+ if(projectAccessoryInfo!=null&&projectAccessoryInfo.getParent()!=null&&StringUtils.isNotBlank(projectAccessoryInfo.getParent().getId())){
|
|
|
+ ProjectTemplateInfo parent = projectTemplateService.get(projectAccessoryInfo.getParent().getId());
|
|
|
+ projectAccessoryInfo.setParent(parent);
|
|
|
+ List<ProjectTemplateInfo> list = new ArrayList<>();
|
|
|
+ list.add(projectAccessoryInfo);
|
|
|
+ }
|
|
|
+ model.addAttribute("projectAccessoryInfo", projectAccessoryInfo);
|
|
|
+ return "modules/projectAccessory/projectTemplate/projectTemplateView";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存附件结构
|
|
|
+ * @param projectAccessoryInfo
|
|
|
+ * @param model
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @RequiresPermissions(value={"projectTemplate:projectTemplate:add","projectTemplate:projectTemplate:edit"},logical=Logical.OR)
|
|
|
+ @RequestMapping(value = "save")
|
|
|
+ public String save(ProjectTemplateInfo projectAccessoryInfo, Model model, RedirectAttributes redirectAttributes) throws Exception{
|
|
|
+ if (!beanValidator(model, projectAccessoryInfo)){
|
|
|
+ return form(projectAccessoryInfo, model);
|
|
|
+ }
|
|
|
+ if(!projectAccessoryInfo.getIsNewRecord()){//编辑表单保存
|
|
|
+ ProjectTemplateInfo t = projectTemplateService.get(projectAccessoryInfo.getId());//从数据库取出记录的值
|
|
|
+ MyBeanUtils.copyBeanNotNull2Bean(projectAccessoryInfo, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
|
|
|
+ projectTemplateService.save(t);//保存
|
|
|
+ }else{//新增表单保存
|
|
|
+ projectTemplateService.save(projectAccessoryInfo);//保存
|
|
|
+ }
|
|
|
+ addMessage(redirectAttributes, "保存附件结构成功");
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/projectTemplate/projectTemplate/?repage";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除附件结构
|
|
|
+ * @param projectAccessoryInfo
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("projectTemplate:projectTemplate:del")
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
+ public String delete(ProjectTemplateInfo projectAccessoryInfo, RedirectAttributes redirectAttributes) {
|
|
|
+ projectTemplateService.delete(projectAccessoryInfo);
|
|
|
+ addMessage(redirectAttributes, "删除附件结构成功");
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/projectTemplate/projectTemplate/?repage";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除附件结构
|
|
|
+ * @param ids
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("projectTemplate:projectTemplate:del")
|
|
|
+ @RequestMapping(value = "deleteAll")
|
|
|
+ public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
|
|
|
+ String idArray[] =ids.split(",");
|
|
|
+ for(String id : idArray){
|
|
|
+ projectTemplateService.delete(projectTemplateService.get(id));
|
|
|
+ }
|
|
|
+ addMessage(redirectAttributes, "删除附件结构成功");
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/projectTemplate/projectTemplate/?repage";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel文件
|
|
|
+ * @param projectAccessoryInfo
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("projectTemplate:projectTemplate:export")
|
|
|
+ @RequestMapping(value = "export", method=RequestMethod.POST)
|
|
|
+ public String exportFile(ProjectTemplateInfo projectAccessoryInfo, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
|
|
|
+ try {
|
|
|
+ String fileName = "附件结构"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
|
|
|
+ Page<ProjectTemplateInfo> page = projectTemplateService.findPage(new Page<ProjectTemplateInfo>(request, response, -1), projectAccessoryInfo);
|
|
|
+ new ExportExcel("附件结构", ProjectTemplateInfo.class).setDataList(page.getList()).write(response, fileName).dispose();
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "导出附件结构记录失败!失败信息:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/projectTemplate/projectTemplate/?repage";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入Excel数据
|
|
|
+ * @param file
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("projectTemplate:projectTemplate:import")
|
|
|
+ @RequestMapping(value = "import", method=RequestMethod.POST)
|
|
|
+ public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
|
|
|
+ try {
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ ImportExcel ei = new ImportExcel(file, 1, 0);
|
|
|
+ List<ProjectTemplateInfo> list = ei.getDataList(ProjectTemplateInfo.class);
|
|
|
+ for (ProjectTemplateInfo projectAccessoryInfo : list){
|
|
|
+ try{
|
|
|
+ projectTemplateService.save(projectAccessoryInfo);
|
|
|
+ successNum++;
|
|
|
+ }catch(ConstraintViolationException ex){
|
|
|
+ failureNum++;
|
|
|
+ }catch (Exception ex) {
|
|
|
+ failureNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (failureNum>0){
|
|
|
+ failureMsg.insert(0, ",失败 "+failureNum+" 条附件结构记录。");
|
|
|
+ }
|
|
|
+ addMessage(redirectAttributes, "已成功导入 "+successNum+" 条附件结构记录"+failureMsg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "导入附件结构失败!失败信息:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/projectTemplate/projectTemplate/?repage";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载导入附件结构数据模板
|
|
|
+ * @param response
|
|
|
+ * @param redirectAttributes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("projectTemplate:projectTemplate:import")
|
|
|
+ @RequestMapping(value = "import/template")
|
|
|
+ public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
|
|
|
+ try {
|
|
|
+ String fileName = "附件结构数据导入模板.xlsx";
|
|
|
+ List<ProjectTemplateInfo> list = Lists.newArrayList();
|
|
|
+ new ExportExcel("附件结构数据", ProjectTemplateInfo.class, 1).setDataList(list).write(response, fileName).dispose();
|
|
|
+ return null;
|
|
|
+ } catch (Exception e) {
|
|
|
+ addMessage(redirectAttributes, "导入模板下载失败!失败信息:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return "redirect:"+Global.getAdminPath()+"/projectTemplate/projectTemplate/?repage";
|
|
|
+ }
|
|
|
+
|
|
|
+}
|