ProjectController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. package platform.modules.government.web;
  2. import java.time.LocalDateTime;
  3. import java.util.List;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.apache.ibatis.annotations.Param;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.ui.ModelMap;
  9. import org.springframework.web.bind.annotation.DeleteMapping;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.PathVariable;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import com.github.pagehelper.PageInfo;
  17. import platform.common.Constant;
  18. import platform.common.annotation.OperationLog;
  19. import platform.common.base.controller.BaseController;
  20. import platform.common.base.model.DictionaryItem;
  21. import platform.common.base.service.DictionaryItemService;
  22. import platform.common.exception.BaseException;
  23. import platform.modules.company.entity.ProjectMaterial;
  24. import platform.modules.company.service.ProjectMaterialService;
  25. import platform.modules.government.entity.Project;
  26. import platform.modules.government.entity.ProjectType;
  27. import platform.modules.government.service.ProjectService;
  28. import platform.modules.government.service.ProjectTypeService;
  29. import platform.modules.sys.web.ResponseMessage;
  30. @Controller
  31. @RequestMapping("/project")
  32. public class ProjectController extends BaseController {
  33. @Autowired
  34. private ProjectService projectService;
  35. @Autowired
  36. private ProjectMaterialService projectMaterialService;
  37. @Autowired
  38. private ProjectTypeService projectTypeService;
  39. @Autowired
  40. private DictionaryItemService dictionaryItemService;
  41. @OperationLog(value = "查看项目申报项目列表")
  42. @RequestMapping("/list")
  43. public String list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  44. String keyword, ModelMap modelMap) {
  45. PageInfo<Project> pageInfo = projectService.findPage(pageNum, PAGESIZE, keyword);
  46. modelMap.put("keyword", keyword);
  47. modelMap.put("pageInfo", pageInfo);
  48. return BASE_GOVERNMENT_PATH + "project/list";
  49. }
  50. /**
  51. * 跳转到项目添加页面
  52. */
  53. @GetMapping(value = "/add")
  54. public String add(ModelMap modelMap) {
  55. log.info("跳转到项目添加页面!");
  56. projectService.getDictInfo(modelMap);
  57. // List<ProjectType> projectTypes = projectTypeService.findBySuperType("1");
  58. List<ProjectType> projectTypes = projectTypeService.findByYear(LocalDateTime.now().getYear());
  59. modelMap.put("projectTypes", projectTypes);
  60. return BASE_GOVERNMENT_PATH + "project/project_add";
  61. }
  62. /**
  63. * 按年份获取项目大类
  64. *
  65. * @return
  66. */
  67. @GetMapping("/getProjectByYear")
  68. @ResponseBody
  69. public Object getProjectByYear(Integer year) {
  70. List<ProjectType> projectTypes = projectTypeService.findByYear(year);
  71. return ResponseMessage.success("success", projectTypes);
  72. }
  73. /**
  74. * 添加/编辑项目
  75. */
  76. @OperationLog(value = "新增项目申报项目")
  77. @ResponseBody
  78. @PostMapping(value = "/save")
  79. public ResponseMessage save(Project project) throws Exception {
  80. if (IsTooFrequently()) {
  81. return ResponseMessage.error("操作过于频繁,请稍后再试!");
  82. }
  83. Boolean flag = true;
  84. if (null != project.getId()) {
  85. projectService.updateProject(project);
  86. } else {
  87. projectService.saveProject(project);
  88. }
  89. if (flag) {
  90. return ResponseMessage.success("保存成功!");
  91. }
  92. return ResponseMessage.error("保存失败!");
  93. }
  94. /**
  95. * 跳转到项目编辑页面
  96. */
  97. @GetMapping(value = "/edit/{id}")
  98. public String edit(@PathVariable("id") int id, ModelMap modelMap) {
  99. Project project = projectService.findById(id);
  100. log.info("跳转到项目编辑页面!id = {}", id);
  101. modelMap.put("project", project);
  102. projectService.getDictInfo(modelMap);
  103. // if(StringUtils.isNotBlank(project.getProject_super_type())) {
  104. // List<ProjectType> projectTypeList = projectTypeService.findBySuperType(project.getProject_super_type());
  105. // }
  106. List<ProjectType> projectTypeList = projectTypeService.findByYear(project.getProject_year());
  107. modelMap.put("projectTypeList", projectTypeList);
  108. return BASE_GOVERNMENT_PATH + "project/project_edit";
  109. }
  110. /**
  111. * 删除项目
  112. */
  113. @OperationLog(value = "删除项目申报项目")
  114. @ResponseBody
  115. @DeleteMapping(value = "/delete/{id}")
  116. public ResponseMessage delete(@PathVariable("id") String id) throws Exception {
  117. try {
  118. projectService.deleteProject(id);
  119. return ResponseMessage.success("删除成功!");
  120. } catch (BaseException e) {
  121. return ResponseMessage.success(e.getMessage());
  122. } catch (Exception e) {
  123. e.printStackTrace();
  124. }
  125. return ResponseMessage.error("删除失败!");
  126. }
  127. /**
  128. * 检验项目名称是否存在
  129. *
  130. * @return
  131. */
  132. @ResponseBody
  133. @GetMapping(value = "/isExistProjectName")
  134. public Boolean isExistProjectName(String id, String name, String type, Integer year) throws Exception {
  135. boolean flag = true;
  136. log.debug("检验项目名称是否存在参数! id= {}, name= {}", id, name, type);
  137. Project project = projectService.findProjectByName(name, type);
  138. // Project project= projectService.findProjectByYear(name, type, year);
  139. if (null != project) {
  140. if (StringUtils.isBlank(id)) {
  141. flag = false;
  142. } else {
  143. if (project.getId() != (Integer.parseInt(id))) {
  144. flag = false;
  145. }
  146. }
  147. }
  148. log.info("检验项目名称是否存在结果! flag = {}", flag);
  149. return flag;
  150. }
  151. /**
  152. * 获取相应类型的项目
  153. */
  154. @ResponseBody
  155. @GetMapping(value = "/getProjectByType")
  156. public ResponseMessage getProjectByType(@Param("type") String type, @Param("isApplication") String isApplication) {
  157. List<Project> projects = projectService.findByType(type, isApplication);
  158. return ResponseMessage.success("查询成功", projects);
  159. }
  160. /**
  161. * 获取相应类型的项目
  162. */
  163. @ResponseBody
  164. @GetMapping(value = "/getProjectMaterials")
  165. public ResponseMessage getProjectMaterials(ModelMap modelMap, Integer id) {
  166. List<ProjectMaterial> materials = projectMaterialService.findProjectMaterialByType(id);
  167. modelMap.put("applyMaterials", materials);
  168. return ResponseMessage.success("查询成功", modelMap);
  169. }
  170. /**
  171. * 项目类别列表页
  172. *
  173. * @param pageNum
  174. * @param keyword
  175. * @param modelMap
  176. * @return
  177. */
  178. @RequestMapping("/type/list")
  179. public String typeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  180. String keyword, ModelMap modelMap) {
  181. PageInfo<ProjectType> pageInfo = projectTypeService.findPage(pageNum, PAGESIZE, keyword);
  182. modelMap.put("keyword", keyword);
  183. modelMap.put("pageInfo", pageInfo);
  184. return BASE_GOVERNMENT_PATH + "project/type_list";
  185. }
  186. /**
  187. * 跳转到项目类别添加页面
  188. */
  189. @GetMapping(value = "type/add")
  190. public String addType(ModelMap modelMap) {
  191. log.info("跳转到项目类别添加页面!");
  192. List<DictionaryItem> projectSuperTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.PROJECT_APPLICATION_SUPER_TYPE);
  193. modelMap.put("projectSuperTypeList", projectSuperTypeList);
  194. return BASE_GOVERNMENT_PATH + "project/project_type_add";
  195. }
  196. /**
  197. * 添加/编辑项目
  198. */
  199. @OperationLog(value = "新增项目申报类别")
  200. @ResponseBody
  201. @PostMapping(value = "type/save")
  202. public ResponseMessage saveType(ProjectType projectType) throws Exception {
  203. if (IsTooFrequently()) {
  204. return ResponseMessage.error("操作过于频繁,请稍后再试!");
  205. }
  206. Boolean flag = true;
  207. if (null != projectType.getId()) {
  208. projectTypeService.updateType(projectType);
  209. } else {
  210. projectTypeService.saveType(projectType);
  211. }
  212. if (flag) {
  213. return ResponseMessage.success("保存成功!");
  214. }
  215. return ResponseMessage.error("保存失败!");
  216. }
  217. /**
  218. * 跳转到项目编辑页面
  219. */
  220. @GetMapping(value = "type/edit/{id}")
  221. public String editType(@PathVariable("id") int id, ModelMap modelMap) {
  222. ProjectType projectType = projectTypeService.findById(id);
  223. log.info("跳转到项目编辑页面!id = {}", id);
  224. modelMap.put("projectType", projectType);
  225. List<DictionaryItem> projectSuperTypeList = dictionaryItemService.findListByTypeName(Constant.DictionaryType.PROJECT_APPLICATION_SUPER_TYPE);
  226. modelMap.put("projectSuperTypeList", projectSuperTypeList);
  227. return BASE_GOVERNMENT_PATH + "project/project_type_edit";
  228. }
  229. /**
  230. * 删除项目
  231. */
  232. @OperationLog(value = "删除项目申报项目")
  233. @ResponseBody
  234. @DeleteMapping(value = "type/delete/{id}")
  235. public ResponseMessage deleteType(@PathVariable("id") Integer id) throws Exception {
  236. try {
  237. projectTypeService.deleteProjectType(id);
  238. return ResponseMessage.success("删除成功!");
  239. } catch (BaseException e) {
  240. return ResponseMessage.success(e.getMessage());
  241. } catch (Exception e) {
  242. e.printStackTrace();
  243. }
  244. return ResponseMessage.error("删除失败!");
  245. }
  246. /**
  247. * 检验项目类型是否存在
  248. */
  249. @ResponseBody
  250. @GetMapping(value = "/isExistProjectTypeName")
  251. public Boolean isExistProjectTypeName(String id, String name, String type, Integer project_year) throws Exception {
  252. boolean flag = true;
  253. log.debug("检验项目类型是否存在参数! id= {}, name= {}", id, name, type);
  254. ProjectType projectType = projectTypeService.findProjectTypeByName(name, type, project_year);
  255. if (null != projectType) {
  256. if (StringUtils.isBlank(id)) {
  257. flag = false;
  258. } else {
  259. if (projectType.getId() != (Integer.parseInt(id))) {
  260. flag = false;
  261. }
  262. }
  263. }
  264. log.info("检验项目名称是否存在结果! flag = {}", flag);
  265. return flag;
  266. }
  267. /**
  268. * 获取相应大类的项目类型
  269. */
  270. @ResponseBody
  271. @GetMapping(value = "/getProjectTypeBySuper")
  272. public ResponseMessage getProjectTypeBySuper(ModelMap modelMap, String superType) {
  273. List<ProjectType> projectTypes = projectTypeService.findBySuperType(superType);
  274. return ResponseMessage.success("查询成功", projectTypes);
  275. }
  276. }