123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package com.persagy.proxy.adm.controller;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import com.persagy.dmp.basic.utils.JsonNodeUtils;
- import com.persagy.proxy.adm.model.AdmEquipment;
- 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.IAdmEquipmentService;
- 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.*;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Adm 楼层 API
- * @author lvxy
- * @date 2021/8/16
- */
- @RestController
- @RequestMapping("/object/equip")
- public class AdmEquipmentController {
- @Autowired
- private IAdmEquipmentService service;
- /**
- * 统计
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/count")
- public AdmResponse count(@RequestBody AdmQueryCriteria request) throws Exception {
- request.setName(AdmEquipment.OBJ_TYPE);
- request.setOnlyCount(true);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
- }
- /**
- * 创建
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/create")
- public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
- List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
- if(CollUtil.isEmpty(vos)){
- return AdmResponse.success();
- }
- //创建设备
- vos.stream().forEach(equipment -> {
- if (StrUtil.isEmpty(equipment.getName())){
- equipment.setName(ObjectNameUtil.objectName("设备-"));
- }
- });
- vos = service.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 根据ID删除
- * @param vos
- * @return
- * @throws Exception
- */
- @PostMapping("/delete")
- public AdmResponse delete( @RequestBody List<AdmEquipment> vos) throws Exception {
- // 组装上下文条件
- service.doDelete(AdmContextUtil.toDmpContext(), vos);
- return AdmResponse.success();
- }
- /**
- * 更新
- * @param createRequest
- * @return
- * @throws Exception
- */
- @PostMapping("/update")
- public AdmResponse update(@RequestBody AdmCreateRequest<AdmEquipment> createRequest) throws Exception {
- List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
- //vos = service.doUpdateEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
- //针对设备更新时,所有更新的字段都放到信息点中的情况特殊处理
- if(CollUtil.isNotEmpty(vos)){
- List<AdmEquipment> equipmentList = new ArrayList<>(vos.size());
- vos.stream().forEach(equipment -> {
- if(CollUtil.isNotEmpty(equipment.getInfos())){
- AdmEquipment admEquipment = new AdmEquipment();
- admEquipment.setId(equipment.getId());
- admEquipment.setInfos(equipment.getInfos());
- ObjectNode objectNode = JsonNodeUtils.toObjectNode(admEquipment, "infos", null);
- AdmEquipment admEquipmentNew = JsonNodeUtils.toEntity(objectNode, AdmEquipment.class, "infos");
- equipmentList.add(admEquipmentNew);
- }
- });
- vos = equipmentList;
- }
- vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 查询
- *
- * @param request
- * @return
- * @throws Exception
- */
- @PostMapping("/query")
- public AdmResponse query(@RequestBody AdmQueryCriteria request) throws Exception {
- // 组装上下文条件
- request.setName(AdmEquipment.OBJ_TYPE);
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
- }
- /**
- * 设备绑定的动态信息点或静态信息点
- * @param admEquipment
- * @return
- * @throws Exception
- */
- @GetMapping("/export")
- public AdmResponse exportInfos(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
- List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
- vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 设备上传excel识别静态信息点
- * @param admEquipment
- * @return
- * @throws Exception
- */
- @PostMapping("/import")
- public AdmResponse importInfos(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
- List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
- vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
- return AdmResponse.success(vos);
- }
- /**
- * 根据项目id查询所有的设备和部件
- *
- * @param request
- * @return
- * @throws Exception
- */
- @GetMapping("/query-equip")
- public AdmResponse queryEquip(@RequestBody AdmQueryCriteria request) throws Exception {
- //request.setName("equipment");
- if(StrUtil.isNotEmpty(request.getFilters())){
- request.setFilters(String.join(";",request.getFilters(),"objType in ['equipment','component']"));
- }else{
- request.setFilters("objType in ['equipment','component']");
- }
- return service.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
- }
- /**
- * 批量创建设备同时创建资产、创建设备和系统的关系
- * @param admEquipment
- * @return
- * @throws Exception
- */
- @PostMapping("/creat-equip-pro")
- public AdmResponse createExt(@RequestBody AdmCreateRequest<AdmEquipment> admEquipment) throws Exception {
- List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
- if(CollUtil.isEmpty(vos)){
- return AdmResponse.success();
- }
- //创建设备
- vos.stream().forEach(equipment -> {
- if (StrUtil.isEmpty(equipment.getName())){
- equipment.setName(ObjectNameUtil.objectName("设备-"));
- }
- });
- vos = service.doInsertExt(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
- return AdmResponse.success(vos);
- }
- }
|