AdmComponentController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package com.persagy.proxy.adm.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.persagy.proxy.adm.model.AdmComponent;
  5. import com.persagy.proxy.adm.request.AdmCreateRequest;
  6. import com.persagy.proxy.adm.request.AdmQueryCriteria;
  7. import com.persagy.proxy.adm.request.AdmResponse;
  8. import com.persagy.proxy.adm.service.IAdmComponentService;
  9. import com.persagy.proxy.adm.utils.AdmContextUtil;
  10. import com.persagy.proxy.adm.utils.ObjectNameUtil;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import javax.ws.rs.QueryParam;
  17. import java.util.List;
  18. /**
  19. * Adm 部件 API
  20. * @author lvxy
  21. * @date 2021/8/16
  22. */
  23. @RestController
  24. @RequestMapping("/object/component")
  25. public class AdmComponentController {
  26. @Autowired
  27. private IAdmComponentService service;
  28. /**
  29. * 统计
  30. *
  31. * @param request
  32. * @return
  33. * @throws Exception
  34. */
  35. @PostMapping("/count")
  36. public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
  37. request.setName(AdmComponent.OBJ_TYPE);
  38. request.setOnlyCount(true);
  39. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmComponent.class);
  40. }
  41. /**
  42. * 创建
  43. * @param createRequest
  44. * @return
  45. * @throws Exception
  46. */
  47. @PostMapping("/create")
  48. public AdmResponse create(@RequestBody AdmCreateRequest<AdmComponent> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  49. List<AdmComponent> vos = CollUtil.newArrayList(createRequest.getContent());
  50. if(CollUtil.isEmpty(vos)){
  51. return AdmResponse.success();
  52. }
  53. //创建部件
  54. vos.stream().forEach(component -> {
  55. if (StrUtil.isEmpty(component.getName())){
  56. component.setName(ObjectNameUtil.objectName("部件-"));
  57. }
  58. });
  59. vos = service.doInsertExt(AdmContextUtil.toDmpContext(), AdmComponent.class, vos);
  60. return AdmResponse.success(vos);
  61. }
  62. /**
  63. * 根据ID删除
  64. * @param vos
  65. * @return
  66. * @throws Exception
  67. */
  68. @PostMapping("/delete")
  69. public AdmResponse delete( @RequestBody List<AdmComponent> vos) throws Exception {
  70. service.doDelete(AdmContextUtil.toDmpContext(), vos);
  71. return AdmResponse.success();
  72. }
  73. /**
  74. * 更新
  75. * @param createRequest
  76. * @return
  77. * @throws Exception
  78. */
  79. @PostMapping("/update")
  80. public AdmResponse update(@RequestBody AdmCreateRequest<AdmComponent> createRequest, @QueryParam("projectId") String projectId) throws Exception {
  81. List<AdmComponent> vos = CollUtil.newArrayList(createRequest.getContent());
  82. vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmComponent.class, vos);
  83. return AdmResponse.success(vos);
  84. }
  85. /**
  86. * 查询
  87. *
  88. * @param request
  89. * @return
  90. * @throws Exception
  91. */
  92. @PostMapping("/query")
  93. public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
  94. request.setName(AdmComponent.OBJ_TYPE);
  95. return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmComponent.class);
  96. }
  97. }