123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import com.persagy.proxy.adm.model.AdmComponent;
- import com.persagy.proxy.adm.request.AdmCreateRequest;
- import com.persagy.proxy.adm.request.AdmQueryCriteria;
- import com.persagy.proxy.adm.request.AdmResponse;
- import com.persagy.proxy.adm.service.IAdmComponentService;
- import com.persagy.proxy.adm.utils.AdmContextUtil;
- import com.persagy.proxy.adm.utils.ObjectNameUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.ws.rs.QueryParam;
- import java.util.List;
- /**
- * Adm 部件 API
- * @author lvxy
- * @date 2021/8/16
- */
- @RestController
- @RequestMapping("/object/component")
- public class AdmComponentController {
- @Autowired
- private IAdmComponentService service;
- /**
- * 统计
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/count")
- public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
- request.setName(AdmComponent.OBJ_TYPE);
- request.setOnlyCount(true);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmComponent.class);
- }
- /**
- * 创建
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/create")
- public AdmResponse create(@RequestBody AdmCreateRequest<AdmComponent> createRequest, @QueryParam("projectId") String projectId) throws Exception {
- List<AdmComponent> vos = CollUtil.newArrayList(createRequest.getContent());
- if(CollUtil.isEmpty(vos)){
- return AdmResponse.success();
- }
- //创建部件
- vos.stream().forEach(component -> {
- if (StrUtil.isEmpty(component.getName())){
- component.setName(ObjectNameUtil.objectName("部件-"));
- }
- });
- vos = service.doInsertExt(AdmContextUtil.toDmpContext(), AdmComponent.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 根据ID删除
- * @param vos
- * @return
- * @throws Exception
- */
- @PostMapping("/delete")
- public AdmResponse delete( @RequestBody List<AdmComponent> vos) throws Exception {
- service.doDelete(AdmContextUtil.toDmpContext(), vos);
- return AdmResponse.success();
- }
- /**
- * 更新
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/update")
- public AdmResponse update(@RequestBody AdmCreateRequest<AdmComponent> createRequest, @QueryParam("projectId") String projectId) throws Exception {
- List<AdmComponent> vos = CollUtil.newArrayList(createRequest.getContent());
- vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmComponent.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 查询
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/query")
- public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
- request.setName(AdmComponent.OBJ_TYPE);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmComponent.class);
- }
- }
|