package platform.modules.government.web; import java.time.LocalDateTime; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.github.pagehelper.PageInfo; import platform.common.Constant; import platform.common.annotation.OperationLog; import platform.common.base.controller.BaseController; import platform.common.base.model.DictionaryItem; import platform.common.base.service.DictionaryItemService; import platform.common.exception.BaseException; import platform.modules.company.entity.ProjectMaterial; import platform.modules.company.service.ProjectMaterialService; import platform.modules.government.entity.Project; import platform.modules.government.entity.ProjectType; import platform.modules.government.service.ProjectService; import platform.modules.government.service.ProjectTypeService; import platform.modules.sys.web.ResponseMessage; @Controller @RequestMapping("/project") public class ProjectController extends BaseController { @Autowired private ProjectService projectService; @Autowired private ProjectMaterialService projectMaterialService; @Autowired private ProjectTypeService projectTypeService; @Autowired private DictionaryItemService dictionaryItemService; @OperationLog(value = "查看项目申报项目列表") @RequestMapping("/list") public String list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap) { PageInfo pageInfo = projectService.findPage(pageNum, PAGESIZE, keyword); modelMap.put("keyword", keyword); modelMap.put("pageInfo", pageInfo); return BASE_GOVERNMENT_PATH + "project/list"; } /** * 跳转到项目添加页面 */ @GetMapping(value = "/add") public String add(ModelMap modelMap) { log.info("跳转到项目添加页面!"); projectService.getDictInfo(modelMap); // List projectTypes = projectTypeService.findBySuperType("1"); List projectTypes = projectTypeService.findByYear(LocalDateTime.now().getYear()); modelMap.put("projectTypes", projectTypes); return BASE_GOVERNMENT_PATH + "project/project_add"; } /** * 按年份获取项目大类 * * @return */ @GetMapping("/getProjectByYear") @ResponseBody public Object getProjectByYear(Integer year) { List projectTypes = projectTypeService.findByYear(year); return ResponseMessage.success("success", projectTypes); } /** * 添加/编辑项目 */ @OperationLog(value = "新增项目申报项目") @ResponseBody @PostMapping(value = "/save") public ResponseMessage save(Project project) throws Exception { if (IsTooFrequently()) { return ResponseMessage.error("操作过于频繁,请稍后再试!"); } Boolean flag = true; if (null != project.getId()) { projectService.updateProject(project); } else { projectService.saveProject(project); } if (flag) { return ResponseMessage.success("保存成功!"); } return ResponseMessage.error("保存失败!"); } /** * 跳转到项目编辑页面 */ @GetMapping(value = "/edit/{id}") public String edit(@PathVariable("id") int id, ModelMap modelMap) { Project project = projectService.findById(id); log.info("跳转到项目编辑页面!id = {}", id); modelMap.put("project", project); projectService.getDictInfo(modelMap); // if(StringUtils.isNotBlank(project.getProject_super_type())) { // List projectTypeList = projectTypeService.findBySuperType(project.getProject_super_type()); // } List projectTypeList = projectTypeService.findByYear(project.getProject_year()); modelMap.put("projectTypeList", projectTypeList); return BASE_GOVERNMENT_PATH + "project/project_edit"; } /** * 删除项目 */ @OperationLog(value = "删除项目申报项目") @ResponseBody @DeleteMapping(value = "/delete/{id}") public ResponseMessage delete(@PathVariable("id") String id) throws Exception { try { projectService.deleteProject(id); return ResponseMessage.success("删除成功!"); } catch (BaseException e) { return ResponseMessage.success(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } return ResponseMessage.error("删除失败!"); } /** * 检验项目名称是否存在 * * @return */ @ResponseBody @GetMapping(value = "/isExistProjectName") public Boolean isExistProjectName(String id, String name, String type, Integer year) throws Exception { boolean flag = true; log.debug("检验项目名称是否存在参数! id= {}, name= {}", id, name, type); Project project = projectService.findProjectByName(name, type); // Project project= projectService.findProjectByYear(name, type, year); if (null != project) { if (StringUtils.isBlank(id)) { flag = false; } else { if (project.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验项目名称是否存在结果! flag = {}", flag); return flag; } /** * 获取相应类型的项目 */ @ResponseBody @GetMapping(value = "/getProjectByType") public ResponseMessage getProjectByType(@Param("type") String type, @Param("isApplication") String isApplication) { List projects = projectService.findByType(type, isApplication); return ResponseMessage.success("查询成功", projects); } /** * 获取相应类型的项目 */ @ResponseBody @GetMapping(value = "/getProjectMaterials") public ResponseMessage getProjectMaterials(ModelMap modelMap, Integer id) { List materials = projectMaterialService.findProjectMaterialByType(id); modelMap.put("applyMaterials", materials); return ResponseMessage.success("查询成功", modelMap); } /** * 项目类别列表页 * * @param pageNum * @param keyword * @param modelMap * @return */ @RequestMapping("/type/list") public String typeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, String keyword, ModelMap modelMap) { PageInfo pageInfo = projectTypeService.findPage(pageNum, PAGESIZE, keyword); modelMap.put("keyword", keyword); modelMap.put("pageInfo", pageInfo); return BASE_GOVERNMENT_PATH + "project/type_list"; } /** * 跳转到项目类别添加页面 */ @GetMapping(value = "type/add") public String addType(ModelMap modelMap) { log.info("跳转到项目类别添加页面!"); List projectSuperTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.PROJECT_APPLICATION_SUPER_TYPE); modelMap.put("projectSuperTypeList", projectSuperTypeList); return BASE_GOVERNMENT_PATH + "project/project_type_add"; } /** * 添加/编辑项目 */ @OperationLog(value = "新增项目申报类别") @ResponseBody @PostMapping(value = "type/save") public ResponseMessage saveType(ProjectType projectType) throws Exception { if (IsTooFrequently()) { return ResponseMessage.error("操作过于频繁,请稍后再试!"); } Boolean flag = true; if (null != projectType.getId()) { projectTypeService.updateType(projectType); } else { projectTypeService.saveType(projectType); } if (flag) { return ResponseMessage.success("保存成功!"); } return ResponseMessage.error("保存失败!"); } /** * 跳转到项目编辑页面 */ @GetMapping(value = "type/edit/{id}") public String editType(@PathVariable("id") int id, ModelMap modelMap) { ProjectType projectType = projectTypeService.findById(id); log.info("跳转到项目编辑页面!id = {}", id); modelMap.put("projectType", projectType); List projectSuperTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.PROJECT_APPLICATION_SUPER_TYPE); modelMap.put("projectSuperTypeList", projectSuperTypeList); return BASE_GOVERNMENT_PATH + "project/project_type_edit"; } /** * 删除项目 */ @OperationLog(value = "删除项目申报项目") @ResponseBody @DeleteMapping(value = "type/delete/{id}") public ResponseMessage deleteType(@PathVariable("id") Integer id) throws Exception { try { projectTypeService.deleteProjectType(id); return ResponseMessage.success("删除成功!"); } catch (BaseException e) { return ResponseMessage.success(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } return ResponseMessage.error("删除失败!"); } /** * 检验项目类型是否存在 */ @ResponseBody @GetMapping(value = "/isExistProjectTypeName") public Boolean isExistProjectTypeName(String id, String name, String type, Integer project_year) throws Exception { boolean flag = true; log.debug("检验项目类型是否存在参数! id= {}, name= {}", id, name, type); ProjectType projectType = projectTypeService.findProjectTypeByName(name, type, project_year); if (null != projectType) { if (StringUtils.isBlank(id)) { flag = false; } else { if (projectType.getId() != (Integer.parseInt(id))) { flag = false; } } } log.info("检验项目名称是否存在结果! flag = {}", flag); return flag; } /** * 获取相应大类的项目类型 */ @ResponseBody @GetMapping(value = "/getProjectTypeBySuper") public ResponseMessage getProjectTypeBySuper(ModelMap modelMap, String superType) { List projectTypes = projectTypeService.findBySuperType(superType); return ResponseMessage.success("查询成功", projectTypes); } }