diff --git a/common/orm/src/main/java/com/thing/common/orm/entity/BaseTenantEntity.java b/common/orm/src/main/java/com/thing/common/orm/entity/BaseTenantEntity.java index b8a9325..6978bbe 100644 --- a/common/orm/src/main/java/com/thing/common/orm/entity/BaseTenantEntity.java +++ b/common/orm/src/main/java/com/thing/common/orm/entity/BaseTenantEntity.java @@ -3,6 +3,8 @@ package com.thing.common.orm.entity; import com.google.common.collect.Maps; import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.core.keygen.KeyGenerators; import lombok.Data; import lombok.experimental.Accessors; @@ -26,7 +28,7 @@ public class BaseTenantEntity implements Serializable { @Serial private static final long serialVersionUID = 1536009703312548328L; - @Id + @Id(keyType = KeyType.Generator,value = KeyGenerators.snowFlakeId) private Long id; /*------------------------租户信息--------------------------------*/ diff --git a/common/tskv/src/main/java/com/thing/common/tskv/event/TsKvEventServiceImpl.java b/common/tskv/src/main/java/com/thing/common/tskv/event/TsKvEventServiceImpl.java index 37aa8ab..488c62a 100644 --- a/common/tskv/src/main/java/com/thing/common/tskv/event/TsKvEventServiceImpl.java +++ b/common/tskv/src/main/java/com/thing/common/tskv/event/TsKvEventServiceImpl.java @@ -1,6 +1,5 @@ package com.thing.common.tskv.event; -import com.alibaba.fastjson2.JSON; import com.thing.common.data.proto.QueueProto.DataProto; import com.thing.common.tskv.service.DBExecutor; import com.thing.common.tskv.service.TsKvService; diff --git a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java index 73d3aa9..3ba96d7 100644 --- a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java +++ b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java @@ -127,7 +127,7 @@ public class IotNewSourceMaterialController { @PostMapping("export") @Operation(summary="导出") @Parameters({ - @Parameter(name ="groupIds",description ="部件组id 多个以英文逗号分割"), + @Parameter(name ="groupIds",description ="素材组id 多个以英文逗号分割"), @Parameter(name ="name",description ="素材名称"), @Parameter(name ="type",description ="文件类型"), @Parameter(name ="ids",description ="id数组"), diff --git a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java index c8a8a74..6ec232d 100644 --- a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java +++ b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java @@ -32,4 +32,6 @@ public interface IotNewSourceMaterialService extends IBaseService getInfoByGroupIds(List groupIds); } \ No newline at end of file diff --git a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java index 40e94ae..dc5d52c 100644 --- a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java +++ b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java @@ -24,7 +24,6 @@ import com.thing.configuration.newmaterial.mapper.IotNewSourceMaterialMapper; import com.thing.configuration.newmaterial.service.IotNewSourceMaterialService; import com.thing.sys.biz.dto.SysUserDTO; import com.thing.sys.biz.service.SysUserService; -import com.thing.sys.oss.cloud.AbstractCloudStorageService; import com.thing.sys.oss.cloud.OSSFactory; import com.thing.sys.security.context.TenantContext; import com.thing.sys.security.context.UserContext; @@ -240,4 +239,12 @@ public class IotNewSourceMaterialServiceImpl extends BaseServiceImpl getInfoByGroupIds(List groupIds) { + + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq( "group_id", groupIds); + return this.mapper.selectListByQuery(wrapper); + } } \ No newline at end of file diff --git a/modules/equipment/src/main/java/com/thing/eq/eqbxwx/controller/EqWxPlanController.java b/modules/equipment/src/main/java/com/thing/eq/eqbxwx/controller/EqWxPlanController.java index d5b3211..9dc33af 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqbxwx/controller/EqWxPlanController.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqbxwx/controller/EqWxPlanController.java @@ -28,7 +28,6 @@ import com.thing.eq.file.service.FileService; import com.thing.sys.biz.dto.SysDeptDTO; import com.thing.sys.biz.dto.SysDictTypeListDTO; import com.thing.sys.biz.entity.SysDictDataEntity; -import com.thing.sys.biz.entity.SysDictTypeEntity; import com.thing.sys.biz.service.SysDeptService; import com.thing.sys.biz.service.SysDictDataService; import com.thing.sys.biz.service.SysDictTypeService; @@ -38,11 +37,13 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; + import java.util.*; import java.util.stream.Collectors; @@ -94,7 +95,7 @@ public class EqWxPlanController { // private IotDictTypeService iotDictTypeService; @GetMapping("page") - @Operation(summary= "分页") + @Operation(summary = "分页") @Parameters({ @Parameter(name = Constant.PAGE, description = "当前页码,从1开始"), @Parameter(name = Constant.LIMIT, description = "每页显示记录数"), @@ -128,16 +129,16 @@ public class EqWxPlanController { EqWxInfoRes eqWxInfoRes = ConvertUtils.sourceToTarget(data, EqWxInfoRes.class); //调整 String userId = data.getWxUser(); - if(StringUtils.isNotBlank(userId)){ + if (StringUtils.isNotBlank(userId)) { String[] split = userId.split(","); List longs = new ArrayList<>(); for (String s : split) { longs.add(Long.parseLong(s)); } List planUserName = sysUserService.getUserNameLists(longs); - String name=""; + String name = ""; for (String s : planUserName) { - name+=s+","; + name += s + ","; } name = name.substring(0, name.length() - 1); eqWxInfoRes.setWxUseText(name); @@ -157,7 +158,7 @@ public class EqWxPlanController { eqWxInfoRes.setBxInfo(storeEqBxMap.get(data.getEqBxId())); } else { EqBxEntity eqBxEntity = null; - if(!Objects.isNull(data.getEqBxId())){ + if (!Objects.isNull(data.getEqBxId())) { eqBxEntity = eqBxService.getById(data.getEqBxId()); } if (!Objects.isNull(eqBxEntity)) { @@ -177,55 +178,59 @@ public class EqWxPlanController { } @GetMapping("{id}/{relationTypeId}") - @Operation(summary= "信息") + @Operation(summary = "信息") // @RequiresPermissions("eqwxplan:eqwxplan:info") public Result get(@PathVariable("id") Long id, @PathVariable(value = "relationTypeId") Long relationTypeId) { - EqWxPlanDTO data = eqWxPlanService.getByIdAs(id,EqWxPlanDTO.class); + EqWxInfoRes data = eqWxPlanService.getByIdAs(id, EqWxInfoRes.class); if (Objects.isNull(data)) { throw new SysException("维修计划不存在"); } - - EqWxInfoRes eqWxInfoRes = new EqWxInfoRes(); - BeanUtils.copyProperties(data, eqWxInfoRes); +// +// EqWxInfoRes eqWxInfoRes = new EqWxInfoRes(); +// BeanUtils.copyProperties(data, eqWxInfoRes); // 查询设备信息 ThingDTO thingDTO = new ThingDTO(); - iotThingBaseInfoService.getThingInfo(thingDTO, data.getThingId(), null, "1", String.valueOf(relationTypeId)); - eqWxInfoRes.setBaseInfo(thingDTO); + ThingDTO thingInfo = iotThingBaseInfoService.getThingInfo(thingDTO, data.getThingId(), null, "1", String.valueOf(relationTypeId)); + data.setBaseInfo(thingInfo); //调整 String userId = data.getWxUser(); String[] split = userId.split(","); - List longs = new ArrayList<>(); + + if (ArrayUtils.isNotEmpty(split)) { + List longs = new ArrayList<>(); for (String s : split) { - longs.add(Long.parseLong(s)); - } List planUserName = sysUserService.getUserNameLists(longs); - String name=""; - for (String s : planUserName) { - name+=s+","; + if(StringUtils.isNotBlank(s)){ + longs.add(Long.parseLong(s)); + } + } + if(CollectionUtil.isNotEmpty(longs)){ + List planUserName = sysUserService.getUserNameLists(longs); + String name = ""; + for (String s : planUserName) { + name += s + ","; + } + name = name.substring(0, name.length() - 1); + data.setWxUseText(name); + } } - name = name.substring(0, name.length() - 1); - eqWxInfoRes.setWxUseText(name); - - BxInfoDTO bxInfoDTO = new BxInfoDTO(); // 查询报修信息 - EqBxEntity eqBxEntity = eqBxService.getById(data.getEqBxId()); - if (!Objects.isNull(eqBxEntity)) { - BeanUtils.copyProperties(eqBxEntity, bxInfoDTO); - eqWxInfoRes.setBxInfo(bxInfoDTO); - + BxInfoDTO bxInfoDTO = eqBxService.getByIdAs(data.getEqBxId(),BxInfoDTO.class); + if (!Objects.isNull(bxInfoDTO)) { + data.setBxInfo(bxInfoDTO); Map> document = fileService.getDocument(data.getEqBxId()); bxInfoDTO.setImageUrls(document.get("image")); bxInfoDTO.setAttachmentUrls(document.get("attachment")); } // 查询维修备件信息 - eqWxInfoRes.setReplacements(eqWxReplacementService.getWxReplacementByWxPlanId(data.getId())); + data.setReplacements(eqWxReplacementService.getWxReplacementByWxPlanId(data.getId())); - return new Result().ok(eqWxInfoRes); + return new Result().ok(data); } @PostMapping - @Operation(summary= "保存") + @Operation(summary = "保存") @LogOperation("保存") // @RequiresPermissions("equipment:maintainRecords:add") public Result save(@RequestBody EqWxPlanAddDTO dto) { @@ -254,7 +259,7 @@ public class EqWxPlanController { } @PutMapping - @Operation(summary= "修改") + @Operation(summary = "修改") @LogOperation("修改") @Transactional(rollbackFor = Exception.class) // @RequiresPermissions("equipment:maintainRecords:update") @@ -278,7 +283,7 @@ public class EqWxPlanController { } @DeleteMapping - @Operation(summary= "删除") + @Operation(summary = "删除") @LogOperation("删除") @Transactional(rollbackFor = Exception.class) // @RequiresPermissions("equipment:maintainRecords:delete") @@ -287,7 +292,7 @@ public class EqWxPlanController { AssertUtils.isArrayEmpty(ids, "id"); for (Long id : ids) { - EqWxPlanDTO eqWxPlanDTO = eqWxPlanService.getByIdAs(id,EqWxPlanDTO.class); + EqWxPlanDTO eqWxPlanDTO = eqWxPlanService.getByIdAs(id, EqWxPlanDTO.class); if (!Objects.isNull(eqWxPlanDTO) && "2".equals(eqWxPlanDTO.getWxStatus())) { throw new SysException("不能删除已完成的维修记录"); } @@ -303,7 +308,7 @@ public class EqWxPlanController { } @PostMapping("export") - @Operation(summary= "导出") + @Operation(summary = "导出") @LogOperation("导出") // @Parameters({ // @Parameter(name = "relationTypeId", description = "结构类型id", paramType = "query", required = true, dataType = "String"), @@ -356,13 +361,14 @@ public class EqWxPlanController { //调整 String userId = data.getWxUser(); String[] split = userId.split(","); - List longs = new ArrayList<>(); - for (String s : split) { - longs.add(Long.parseLong(s)); - } List planUserName = sysUserService.getUserNameLists(longs); - String name=""; + List longs = new ArrayList<>(); + for (String s : split) { + longs.add(Long.parseLong(s)); + } + List planUserName = sysUserService.getUserNameLists(longs); + String name = ""; for (String s : planUserName) { - name+=s+","; + name += s + ","; } name = name.substring(0, name.length() - 1); eqWxPlanExcel.setWxUser(name); @@ -424,16 +430,16 @@ public class EqWxPlanController { } List newList = new ArrayList<>(); List idList = new ArrayList<>(Arrays.asList(ids)); - if (CollectionUtil.isNotEmpty(idList)){ - for (EqWxPlanExcel eqWxPlanExcel : excels ){ - if (idList.contains(eqWxPlanExcel.getId())){ + if (CollectionUtil.isNotEmpty(idList)) { + for (EqWxPlanExcel eqWxPlanExcel : excels) { + if (idList.contains(eqWxPlanExcel.getId())) { newList.add(eqWxPlanExcel); } } - }else{ + } else { newList.addAll(excels); } - ExcelUtils.exportExcel(newList,null, "维修记录", EqWxPlanExcel.class,"维修记录.xls",response); + ExcelUtils.exportExcel(newList, null, "维修记录", EqWxPlanExcel.class, "维修记录.xls", response); } @@ -443,15 +449,15 @@ public class EqWxPlanController { return ""; } List temp = new ArrayList<>(); - Object obj = dictMap.get(dictType); - temp= JSON.parseArray(JSON.toJSONString(obj),SysDictDataEntity.class); + Object obj = dictMap.get(dictType); + temp = JSON.parseArray(JSON.toJSONString(obj), SysDictDataEntity.class); if (CollectionUtil.isEmpty(temp)) { return ""; } Map dictObject = new HashMap<>(); - for (SysDictDataEntity dictData:temp){ - dictObject.put(dictData.getDictValue(),dictData.getDictLabel()); + for (SysDictDataEntity dictData : temp) { + dictObject.put(dictData.getDictValue(), dictData.getDictLabel()); } // List temp = (List) dictMap.get(dictType); diff --git a/modules/equipment/src/main/java/com/thing/eq/eqbxwx/service/impl/EqBxServiceImpl.java b/modules/equipment/src/main/java/com/thing/eq/eqbxwx/service/impl/EqBxServiceImpl.java index 6dffb9f..08a46d6 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqbxwx/service/impl/EqBxServiceImpl.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqbxwx/service/impl/EqBxServiceImpl.java @@ -28,6 +28,7 @@ import com.thing.sys.biz.mapper.SysDeptMapper; import com.thing.sys.biz.mapper.SysUserMapper; import com.thing.sys.biz.service.SysUserService; import com.thing.sys.security.context.TenantContext; +import com.thing.sys.security.context.UserContext; import com.thing.sys.security.domain.SecurityUser; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -107,7 +108,7 @@ public class EqBxServiceImpl extends BaseServiceImpl imp for (EqBxDTO eqBxEntity : eqBxEntities) { EqBxDTO eqBxDTO = new EqBxDTO(); BeanUtils.copyProperties(eqBxEntity, eqBxDTO); - + eqBxDTO.setCreateDate(eqBxEntity.getHappenDate()); Map> document = fileService.getDocument(eqBxDTO.getId()); eqBxDTO.setImageUrls(document.get("image")); eqBxDTO.setAttachmentUrls(document.get("attachment")); @@ -122,8 +123,7 @@ public class EqBxServiceImpl extends BaseServiceImpl imp eqBxDTOS.add(eqBxDTO); } - PageData pageData = new PageData<>(eqBxDTOS, eqBxDTOS.size()); - return pageData; + return new PageData<>(eqBxDTOS, eqBxDTOS.size()); } @Override @@ -256,7 +256,7 @@ public class EqBxServiceImpl extends BaseServiceImpl imp lastNo = SerialNumberUnit.generateNumber("BX", eqBxEntity.getBxNo()); dto.setBxNo(lastNo); - dto.setTenantCode(SecurityUser.getTenantCode()); + dto.setTenantCode(UserContext.getRealTenantCode()); // Long eqBxId = IdWorker.getId(); // dto.setId(eqBxId); diff --git a/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByPlanPartEntity.java b/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByPlanPartEntity.java index 4e1bf02..ded9587 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByPlanPartEntity.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByPlanPartEntity.java @@ -1,11 +1,15 @@ package com.thing.eq.eqby.entity; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; -import com.thing.common.orm.entity.BaseDateEntity; +import com.mybatisflex.core.keygen.KeyGenerators; import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serial; +import java.io.Serializable; +import java.util.Date; /** * 部件使用记录 @@ -16,11 +20,37 @@ import java.io.Serial; @Data @EqualsAndHashCode(callSuper=false) @Table("eq_by_plan_part") -public class EqByPlanPartEntity extends BaseDateEntity { +public class EqByPlanPartEntity implements Serializable { @Serial private static final long serialVersionUID = 1L; + + @Id(keyType = KeyType.Generator,value = KeyGenerators.snowFlakeId) + private Long id; + + /*------------------------修改记录信息--------------------------------*/ + + /** + * 创建者 + */ + private Long creator; + + /** + * 创建时间 + */ + private Date createDate; + + /** + * 修改人 + */ + private Long updater; + + /** + * 修改时间 + */ + private Date updateDate; + /** * 更换数量 */ diff --git a/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateDetailEntity.java b/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateDetailEntity.java index f7a96ad..f0545f6 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateDetailEntity.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateDetailEntity.java @@ -1,10 +1,14 @@ package com.thing.eq.eqby.entity; import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; +import com.mybatisflex.core.keygen.KeyGenerators; import lombok.Data; import lombok.EqualsAndHashCode; +import java.io.Serial; +import java.io.Serializable; import java.util.Date; /** @@ -16,10 +20,12 @@ import java.util.Date; @Data @EqualsAndHashCode(callSuper=false) @Table("eq_by_template_detail") -public class EqByTemplateDetailEntity { +public class EqByTemplateDetailEntity implements Serializable { + + @Serial private static final long serialVersionUID = 1L; - @Id + @Id(keyType = KeyType.Generator,value = KeyGenerators.snowFlakeId) private Long id; /** * 保养模板id diff --git a/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateEntity.java b/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateEntity.java index 8d24bff..e9d44e4 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateEntity.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqby/entity/EqByTemplateEntity.java @@ -5,6 +5,8 @@ import com.mybatisflex.annotation.Table; import lombok.Data; import lombok.EqualsAndHashCode; +import java.io.Serial; +import java.io.Serializable; import java.util.Date; /** @@ -16,7 +18,9 @@ import java.util.Date; @Data @EqualsAndHashCode(callSuper=false) @Table("eq_by_template") -public class EqByTemplateEntity { +public class EqByTemplateEntity implements Serializable { + + @Serial private static final long serialVersionUID = 1L; @Id diff --git a/modules/equipment/src/main/java/com/thing/eq/eqby/service/EqByTemplateDetailService.java b/modules/equipment/src/main/java/com/thing/eq/eqby/service/EqByTemplateDetailService.java index 3c10392..732b699 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqby/service/EqByTemplateDetailService.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqby/service/EqByTemplateDetailService.java @@ -23,4 +23,6 @@ public interface EqByTemplateDetailService extends IBaseService findByName(String name); + } diff --git a/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByPlanServiceImpl.java b/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByPlanServiceImpl.java index c6915a7..4c2a730 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByPlanServiceImpl.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByPlanServiceImpl.java @@ -1,6 +1,7 @@ package com.thing.eq.eqby.service.impl; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.mybatisflex.core.paginate.Page; @@ -23,7 +24,6 @@ import com.thing.eq.utils.SerialNumberUnit; import com.thing.sys.biz.dto.SysDictTypeListDTO; import com.thing.sys.biz.entity.SysDeptEntity; import com.thing.sys.biz.entity.SysDictDataEntity; -import com.thing.sys.biz.entity.SysDictTypeEntity; import com.thing.sys.biz.entity.SysUserEntity; import com.thing.sys.biz.service.SysDeptService; import com.thing.sys.biz.service.SysDictDataService; @@ -86,24 +86,36 @@ public class EqByPlanServiceImpl extends BaseServiceImpl params) { QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq(EqByPlanEntity::getTenantCode,UserContext.getRealTenantCode()); + String byStatus = MapUtil.getStr(params, "byStatus"); + wrapper.eq(EqByPlanEntity::getByStatus, byStatus,StringUtils::isNotBlank); + String by_user = MapUtil.getStr(params, "checkUserId"); + wrapper.like(EqByPlanEntity::getByUser, by_user,StringUtils::isNotBlank); + String byNo = MapUtil.getStr(params, "byNo"); + wrapper.like(EqByPlanEntity::getByNo, byNo,StringUtils::isNotBlank); + + if (params.get("eqIds") != null) { + String eqIds = params.get("eqIds").toString(); + List eqthingIds = Arrays.stream(eqIds.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()); + wrapper.in(EqByPlanEntity::getThingsId, eqthingIds,CollectionUtil.isNotEmpty(eqthingIds)); + } + + Long startTime = MapUtil.getLong(params, "startTime"); + Long endTime = MapUtil.getLong(params, "endTime"); + String relationTypeId = MapUtil.getStr(params, "relationTypeId"); + + return wrapper; } @Override public PageData page(Map params) { - Page page = getPage(params); + int pageNumber = MapUtil.getInt(params, "page",1); + int pageSize = MapUtil.getInt(params, "limit",10); -// IPage thingsEntityPage = baseDao.selectPage(page, getWrapper(params)); - String eqIds; - List eqthingIds = new ArrayList<>(); - if (params.get("eqIds") != null) { - eqIds = params.get("eqIds").toString(); - eqthingIds = Arrays.stream(eqIds.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()); - params.put("eqIdList", eqthingIds); - } - params.put("tenantCode", TenantContext.getTenantCode(SecurityUser.getUser())); + Page paginate = mapper.paginateAs(new Page<>(pageNumber, pageSize), getWrapper(params),EqByPlanDTO.class); + List eqByPlansDTOS = paginate.getRecords(); String relationTypeId = params.get("relationTypeId").toString(); - List eqByPlansDTOS = eqByPlanDao.getListData(params); for (EqByPlanDTO eqByPlansDTO : eqByPlansDTOS) { EqInfo thingsInfo = iotThingsService.getThingInfo(eqByPlansDTO.getThingsId(),relationTypeId); if (thingsInfo != null) { @@ -160,9 +172,13 @@ public class EqByPlanServiceImpl extends BaseServiceImpl eqByPlanPartEntities = ConvertUtils.sourceToTarget(eqByParts, EqByPlanPartEntity.class); + eqByPlanPartService.saveBatch(eqByPlanPartEntities); } } } @@ -197,13 +213,14 @@ public class EqByPlanServiceImpl extends BaseServiceImpl eqByParts = new ArrayList<>(); + List eqByParts = new ArrayList<>(); if (CollectionUtil.isNotEmpty(dto.getThingParts())) { for (EqByPlanPartDTO eqpart : dto.getThingParts()) { - eqpart.setEqByPlanId(dto.getId()); - eqByParts.add(eqpart); + EqByPlanPartEntity eqByPlanPartEntity = ConvertUtils.sourceToTarget(eqpart, EqByPlanPartEntity.class); + eqByPlanPartEntity.setEqByPlanId(dto.getId()); + eqByParts.add(eqByPlanPartEntity); } - eqByPlanPartService.saveDto(ConvertUtils.sourceToTarget(eqByParts, EqByPlanPartEntity.class)); + eqByPlanPartService.saveBatch(ConvertUtils.sourceToTarget(eqByParts, EqByPlanPartEntity.class)); } } @@ -235,6 +252,8 @@ public class EqByPlanServiceImpl extends BaseServiceImpl details = eqByTemplateDetailService.getDetails(eqByTemplateDTO.getId()); + eqByTemplateDTO.setDatas(details); byTemplateInfos.add(eqByTemplateDTO); } } diff --git a/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateDetailServiceImpl.java b/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateDetailServiceImpl.java index cf462d6..ad28651 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateDetailServiceImpl.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateDetailServiceImpl.java @@ -44,4 +44,9 @@ public class EqByTemplateDetailServiceImpl extends BaseServiceImpl findByName(String name) { + return mapper.selectListByQuery(QueryWrapper.create().like(EqByTemplateDetailEntity::getName, name)); + } } diff --git a/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateServiceImpl.java b/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateServiceImpl.java index f10678d..5ebd45a 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateServiceImpl.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqby/service/impl/EqByTemplateServiceImpl.java @@ -1,27 +1,30 @@ package com.thing.eq.eqby.service.impl; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.map.MapUtil; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.thing.common.core.exception.SysException; -import com.thing.common.core.utils.ConvertUtils; import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.impl.BaseServiceImpl; import com.thing.eq.eqby.dto.EqByTemplateDTO; import com.thing.eq.eqby.dto.EqByTemplateDetailDTO; +import com.thing.eq.eqby.entity.EqByTemplateDetailEntity; import com.thing.eq.eqby.entity.EqByTemplateEntity; import com.thing.eq.eqby.mapper.EqByTemplateMapper; import com.thing.eq.eqby.service.EqByPlanService; import com.thing.eq.eqby.service.EqByTemplateDetailService; import com.thing.eq.eqby.service.EqByTemplateService; -import com.thing.sys.security.context.TenantContext; -import com.thing.sys.security.domain.SecurityUser; +import com.thing.sys.security.context.UserContext; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; +import java.util.Objects; + +import static com.thing.eq.eqby.entity.table.EqByTemplateEntityTableDef.EQ_BY_TEMPLATE_ENTITY; /** * 保养模板 @@ -48,12 +51,20 @@ public class EqByTemplateServiceImpl extends BaseServiceImpl page(Map params) { - Page page = getPage(params); + int pageNumber = MapUtil.getInt(params, "page", 1); + int pageSize = MapUtil.getInt(params, "limit", 10); //查询 - params.put("tenantCode", TenantContext.getTenantCode(SecurityUser.getUser())); - List list = eqByTemplateDao.getListData(params); - List targetList = ConvertUtils.sourceToTarget(list, EqByTemplateDTO.class); - return new PageData<>(targetList, targetList.size()); + Long deviceTypeId = MapUtil.getLong(params, "eqTypeId"); + String name = MapUtil.getStr(params, "name"); + QueryWrapper queryWrapper = QueryWrapper.create().eq(EqByTemplateEntity::getTenantCode, UserContext.getRealTenantCode()) + .eq(EqByTemplateEntity::getDeviceTypeId, deviceTypeId, Objects::nonNull); + if(StringUtils.isNotBlank(name)){ + List eqByTemplateDetailEntities = eqByTemplateDetailService.findByName(name); + List byTemplateIds = eqByTemplateDetailEntities.stream().map(EqByTemplateDetailEntity::getByTemplateId).toList(); + queryWrapper.where(EQ_BY_TEMPLATE_ENTITY.NAME.like(name).or(EQ_BY_TEMPLATE_ENTITY.ID.in(byTemplateIds))); + } + Page paginate = mapper.paginateAs(new Page<>(pageNumber, pageSize), queryWrapper,EqByTemplateDTO.class); + return new PageData<>(paginate.getRecords(), paginate.getTotalRow()); } @Override @@ -64,7 +75,7 @@ public class EqByTemplateServiceImpl extends BaseServiceImpl 0){ @@ -72,6 +83,7 @@ public class EqByTemplateServiceImpl extends BaseServiceImpl 0){ throw new SysException("该模板已被保养计划使用,不可修改,请确认"); } - Long tenantCode = TenantContext.getTenantCode(SecurityUser.getUser()); + Long tenantCode = UserContext.getRealTenantCode(); if (StringUtils.isNotBlank(dto.getName())){ int count = eqByTemplateDao.getTemplateByNameNoId(dto.getName(),dto.getId(),tenantCode); if (count > 0){ throw new SysException("模板名称已经存在,不可新增,请确认"); } } + dto.setTenantCode(tenantCode); super.updateDto(dto); //先删除模板明细 eqByTemplateDetailService.deleteByTemplateId(dto.getId()); diff --git a/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqCheckStandardController.java b/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqCheckStandardController.java index 5e25fed..48db611 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqCheckStandardController.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqCheckStandardController.java @@ -21,6 +21,7 @@ import com.thing.eq.eqcheck.excel.EqCheckStandardExcel; import com.thing.eq.eqcheck.service.EqCheckSettingService; import com.thing.eq.eqcheck.service.EqCheckStandardDetailService; import com.thing.eq.eqcheck.service.EqCheckStandardService; +import com.thing.sys.security.context.UserContext; import com.thing.sys.security.domain.SecurityUser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -139,15 +140,13 @@ public class EqCheckStandardController { if (CollectionUtil.isEmpty(detailDTOS)) { throw new SysException("请添加模板检查项"); } - - dto.setTenantCode(SecurityUser.getTenantCode()); + dto.setTenantCode(UserContext.getRealTenantCode()); dto.setCreateDate(new Date()); eqCheckStandardService.saveDto(dto); // if (Objects.isNull(dto.getId())) { // throw new SysException("保存失败"); // } - for (EqCheckStandardDetailDTO detail : detailDTOS) { if ("0".equals(detail.getType()) && (StringUtils.isBlank(detail.getLowerLimit()) || StringUtils.isBlank(detail.getUpperLimit()))) { throw new SysException("标准细项为上下限判定类型时,上下限值不能为空"); diff --git a/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqSpotCheckPlanController.java b/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqSpotCheckPlanController.java index dab4899..858f2f5 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqSpotCheckPlanController.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqcheck/controller/EqSpotCheckPlanController.java @@ -90,9 +90,7 @@ public class EqSpotCheckPlanController { if (CollectionUtil.isNotEmpty(planDTOS)) { StringBuilder stringBuilder = new StringBuilder(); planDTOS.forEach(eqSpotCheckPlanDTO -> { - iotThingBaseInfoService.getThingInfo(eqSpotCheckPlanDTO, eqSpotCheckPlanDTO.getThingId(), null, "0", String.valueOf(params.get("relationTypeId"))); - List standardList = new ArrayList<>(); List settingList = eqCheckSettingService.getSettingList(eqSpotCheckPlanDTO.getThingId(), "0"); if (CollectionUtil.isNotEmpty(settingList)) { @@ -100,25 +98,24 @@ public class EqSpotCheckPlanController { EqCheckStandardDTO eqCheckStandardDTO = eqCheckStandardService.getByIdAs(eqCheckSettingDTO.getStandardId(),EqCheckStandardDTO.class); if (!Objects.isNull(eqCheckStandardDTO)) { standardList.add(eqCheckStandardDTO.getId()); - stringBuilder.append(eqCheckStandardDTO.getName() + ","); + stringBuilder.append(eqCheckStandardDTO.getName()).append(","); } }); + eqSpotCheckPlanDTO.setEqCode(eqSpotCheckPlanDTO.getThingCode()); eqSpotCheckPlanDTO.setCheckIdList(standardList); - eqSpotCheckPlanDTO.setCheckNameList(stringBuilder.length() > 0 ? stringBuilder.toString().substring(0, stringBuilder.length() - 1) : ""); + eqSpotCheckPlanDTO.setCheckNameList(!stringBuilder.isEmpty() ? stringBuilder.substring(0, stringBuilder.length() - 1) : ""); stringBuilder.setLength(0); } - - List useIdList = StringUtils.isNotBlank(eqSpotCheckPlanDTO.getUseId()) ? Arrays.asList(eqSpotCheckPlanDTO.getUseId().split(",")) : new ArrayList<>(); if (CollectionUtil.isNotEmpty(useIdList)) { useIdList.forEach(idStr -> { SysUserDTO sysUserDTO = sysUserService.get(Long.parseLong(idStr)); if (!Objects.isNull(sysUserDTO)) { - stringBuilder.append(sysUserDTO.getRealName() + ","); + stringBuilder.append(sysUserDTO.getRealName()).append(","); } }); eqSpotCheckPlanDTO.setUseIdList(useIdList); - eqSpotCheckPlanDTO.setOperatorNameList(stringBuilder.length() > 0 ? stringBuilder.toString().substring(0, stringBuilder.length() - 1) : ""); + eqSpotCheckPlanDTO.setOperatorNameList(!stringBuilder.isEmpty() ? stringBuilder.substring(0, stringBuilder.length() - 1) : ""); stringBuilder.setLength(0); } }); @@ -139,9 +136,9 @@ public class EqSpotCheckPlanController { } iotThingBaseInfoService.getThingInfo(data, data.getThingId(), null, "0", relationTypeId); + data.setEqCode(data.getThingCode()); StringBuilder stringBuilder = new StringBuilder(); List settingList = eqCheckSettingService.getSettingList(data.getThingId(), "0"); - if (CollectionUtil.isNotEmpty(settingList)) { List standardList = new ArrayList<>(); List standardIdList = new ArrayList<>(); @@ -153,29 +150,26 @@ public class EqSpotCheckPlanController { dataVo.setName(eqCheckStandardDTO.getName()); standardIdList.add(eqCheckStandardDTO.getId()); standardList.add(dataVo); - stringBuilder.append(eqCheckStandardDTO.getName() + ","); + stringBuilder.append(eqCheckStandardDTO.getName()).append(","); } }); data.setCheckIdList(standardIdList); data.setDataList(standardList); - data.setCheckNameList(stringBuilder.length() > 0 ? stringBuilder.toString().substring(0, stringBuilder.length() - 1) : ""); + data.setCheckNameList(!stringBuilder.isEmpty() ? stringBuilder.substring(0, stringBuilder.length() - 1) : ""); stringBuilder.setLength(0); } - List useIdList = StringUtils.isNotBlank(data.getUseId()) ? Arrays.asList(data.getUseId().split(",")) : new ArrayList<>(); - if (CollectionUtil.isNotEmpty(useIdList)) { useIdList.forEach(idStr -> { SysUserDTO sysUserDTO = sysUserService.get(Long.parseLong(idStr)); if (!Objects.isNull(sysUserDTO)) { - stringBuilder.append(sysUserDTO.getRealName() + ","); + stringBuilder.append(sysUserDTO.getRealName()).append(","); } }); data.setUseIdList(useIdList); - data.setOperatorNameList(stringBuilder.length() > 0 ? stringBuilder.toString().substring(0, stringBuilder.length() - 1) : ""); + data.setOperatorNameList(!stringBuilder.isEmpty() ? stringBuilder.substring(0, stringBuilder.length() - 1) : ""); } - List detailDTOS = eqCheckStandardDetailService.getAllStandardDetailByThingId(data.getThingId(), "0"); data.setDetailDTOS(detailDTOS); diff --git a/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqCheckStandardDetailDTO.java b/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqCheckStandardDetailDTO.java index 7cc5fc3..95c9e7a 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqCheckStandardDetailDTO.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqCheckStandardDetailDTO.java @@ -3,7 +3,9 @@ package com.thing.eq.eqcheck.dto; import com.thing.common.orm.dto.BaseDTO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import lombok.EqualsAndHashCode; +import java.io.Serial; import java.io.Serializable; /** @@ -12,9 +14,12 @@ import java.io.Serializable; * @author xiezw 806671840@qq.com * @since 3.0 2021-09-22 */ +@EqualsAndHashCode(callSuper = true) @Data @Schema(description = "设备检查标准明细") public class EqCheckStandardDetailDTO extends BaseDTO implements Serializable { + + @Serial private static final long serialVersionUID = 1L; private Long id; diff --git a/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqSpotCheckPlanDTO.java b/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqSpotCheckPlanDTO.java index e545bd0..0a35713 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqSpotCheckPlanDTO.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqcheck/dto/EqSpotCheckPlanDTO.java @@ -4,8 +4,10 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.thing.common.core.utils.DateTimeUtils; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import lombok.EqualsAndHashCode; import org.springframework.format.annotation.DateTimeFormat; +import java.io.Serial; import java.io.Serializable; import java.util.Date; import java.util.List; @@ -16,9 +18,11 @@ import java.util.List; * @author zy aa@aa,com * @since 3.0 2021-10-12 */ +@EqualsAndHashCode(callSuper = true) @Data @Schema(description = "点检计划") public class EqSpotCheckPlanDTO extends ThingDTO implements Serializable { + @Serial private static final long serialVersionUID = 1L; private Long id; diff --git a/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqPatrolCheckPlanEntity.java b/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqPatrolCheckPlanEntity.java index d2386e8..0484385 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqPatrolCheckPlanEntity.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqPatrolCheckPlanEntity.java @@ -1,10 +1,14 @@ package com.thing.eq.eqcheck.entity; import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; +import com.mybatisflex.core.keygen.KeyGenerators; import lombok.Data; import lombok.EqualsAndHashCode; +import java.io.Serial; +import java.io.Serializable; import java.util.Date; /** @@ -16,13 +20,15 @@ import java.util.Date; @Data @EqualsAndHashCode(callSuper = false) @Table("eq_patrol_check_plan") -public class EqPatrolCheckPlanEntity { +public class EqPatrolCheckPlanEntity implements Serializable { + + @Serial private static final long serialVersionUID = 1L; /** * id */ - @Id + @Id(keyType = KeyType.Generator,value = KeyGenerators.snowFlakeId) private Long id; /** * 创建人 diff --git a/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqSpotCheckPlanEntity.java b/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqSpotCheckPlanEntity.java index 94c0630..5de42a8 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqSpotCheckPlanEntity.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqcheck/entity/EqSpotCheckPlanEntity.java @@ -1,10 +1,14 @@ package com.thing.eq.eqcheck.entity; import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.Table; +import com.mybatisflex.core.keygen.KeyGenerators; import lombok.Data; import lombok.EqualsAndHashCode; +import java.io.Serial; +import java.io.Serializable; import java.util.Date; /** @@ -16,10 +20,13 @@ import java.util.Date; @Data @EqualsAndHashCode(callSuper=false) @Table("eq_spot_check_plan") -public class EqSpotCheckPlanEntity { +public class EqSpotCheckPlanEntity implements Serializable { + + + @Serial private static final long serialVersionUID = 1L; - @Id + @Id(keyType = KeyType.Generator,value = KeyGenerators.snowFlakeId) private Long id; /** * 设备thingid diff --git a/modules/equipment/src/main/java/com/thing/eq/eqcheck/service/impl/EqPatrolCheckPlanServiceImpl.java b/modules/equipment/src/main/java/com/thing/eq/eqcheck/service/impl/EqPatrolCheckPlanServiceImpl.java index c0bbfe6..0976911 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqcheck/service/impl/EqPatrolCheckPlanServiceImpl.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqcheck/service/impl/EqPatrolCheckPlanServiceImpl.java @@ -27,6 +27,7 @@ import com.thing.eq.equsergroup.dto.EqUserGroupDTO; import com.thing.eq.equsergroup.service.EqUserGroupService; import com.thing.eq.utils.SerialNumberUnit; import com.thing.sys.security.context.TenantContext; +import com.thing.sys.security.context.UserContext; import com.thing.sys.security.domain.SecurityUser; import com.thing.thing.entity.dto.IotThingEntityDTO; import com.thing.thing.entity.entity.IotThingEntity; @@ -631,26 +632,25 @@ public class EqPatrolCheckPlanServiceImpl extends BaseServiceImpl deviceBaseInfoDTOS) { for (DeviceBaseInfoDTO deviceInfo : deviceBaseInfoDTOS) { - eqScrapService.checkThingStatus(deviceInfo.getThingId()); - List standardDTOS = deviceInfo.getStandardIdList(); //todo if (CollectionUtil.isEmpty(standardDTOS)) { @@ -665,12 +665,12 @@ public class EqPatrolCheckPlanServiceImpl extends BaseServiceImpl exportPartListByThingsId(@Param("params") Map params); +// List exportPartListByThingsId(@Param("params") Map params); String getStock(@Param("eqId") Long eqId); @@ -47,5 +47,5 @@ public interface IotThingBaseInfoMapper extends PowerBaseMapper exportDeviceListByThingsId(@Param("relationTypeId") Long relationTypeId, @Param("toId") Long toId, @Param("ids") Long[] ids); - List exportPartListByThingsId(@Param("relationTypeId") Long relationTypeId, @Param("toId") Long toId, @Param("ids") Long[] ids); + List exportPartListByThingsId(@Param("relationTypeId") Long relationTypeId, @Param("toId") Long toId, @Param("ids") Long[] ids,@Param("keyWord")String keyWord); } diff --git a/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/EqScrapServiceImpl.java b/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/EqScrapServiceImpl.java index 40b2bf1..947ff01 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/EqScrapServiceImpl.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/EqScrapServiceImpl.java @@ -119,6 +119,7 @@ public class EqScrapServiceImpl extends BaseServiceImpl eqDTOS = iotThingBaseInfoDao.queryDeviceListByThingsId(new Page<>(page, limit), params,aLong,aLong1,aLong2,eqTypeName,keyWord); @@ -150,7 +149,7 @@ public class IotThingBaseInfoServiceImpl extends BaseServiceImpl settingList, String showDeviceType, String relationTypeId) { - IotThingBaseInfoDTO baseThing = iotThingBaseInfoService.getByThingsId(thingId); + IotThingBaseInfoDTO baseThing = iotThingBaseInfoService.getByIdAs(thingId,IotThingBaseInfoDTO.class); EqScrapEntity eqScrapEntity = eqScrapService.getByEqId(thingId); if(!Objects.isNull(eqScrapEntity)){ @@ -198,9 +197,9 @@ public class IotThingBaseInfoServiceImpl extends BaseServiceImpl standardList = eqCheckStandardService.getStandardListByStandardIdList(standardIdList); standardList.forEach(standard -> { - stringBuilder.append(standard.getName() + ","); + stringBuilder.append(standard.getName()).append(","); }); - thingDTO.setStandardNameList(stringBuilder.length() > 0 ? stringBuilder.toString().substring(0, stringBuilder.length() - 1) : ""); + thingDTO.setStandardNameList(!stringBuilder.isEmpty() ? stringBuilder.substring(0, stringBuilder.length() - 1) : ""); } } @@ -321,8 +320,12 @@ public class IotThingBaseInfoServiceImpl extends BaseServiceImpl excels = iotThingBaseInfoDao.exportPartListByThingsId(relationTypeId,toId,ids); + List excels = iotThingBaseInfoDao.exportPartListByThingsId(relationTypeId,toId,ids,keyWord); return excels; } diff --git a/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/IotThingsServiceImpl.java b/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/IotThingsServiceImpl.java index 8aceb51..26c4a25 100644 --- a/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/IotThingsServiceImpl.java +++ b/modules/equipment/src/main/java/com/thing/eq/eqmanager/service/impl/IotThingsServiceImpl.java @@ -32,8 +32,8 @@ import com.thing.thing.entity.mapper.IotThingEntityMapper; import com.thing.thing.entity.service.IotThingEntityService; import com.thing.thing.relation.detail.dto.IotThingRelationDetailDTO; import com.thing.thing.relation.detail.dto.RelationDetailBatchSaveDTO; -import com.thing.thing.relation.detail.dto.ThingRelationDTO; import com.thing.thing.relation.detail.entity.IotThingRelationDetailEntity; +import com.thing.thing.relation.detail.param.IotThingRelationDetailParamDTO; import com.thing.thing.relation.detail.service.IotThingRelationDetailService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -187,26 +187,32 @@ public class IotThingsServiceImpl implements IotThingsService { IotThingBaseInfoDTO baseInfoDTO = new IotThingBaseInfoDTO(); BeanUtils.copyProperties(dto,baseInfoDTO); //*** + baseInfoDTO.setId(thingEntity.getId()); baseInfoDTO.setThingId(thingEntity.getId()); baseInfoDTO.setScrap("0"); baseInfoDTO.setScrapDisposal("0"); iotThingBaseInfoService.saveDto(baseInfoDTO); //保存设备的关系 - ThingRelationDTO relationDTO = new ThingRelationDTO(); + + List relationDetailDTOS = + iotThingRelationDetailService.findRootDetailChildNodeByRootIdAndFromIdAndRootThingId(dto.getRelationTypeId(), parentThing.getId(), dto.getRelationTopId()); + + IotThingRelationDetailParamDTO relationDTO = new IotThingRelationDetailParamDTO(); relationDTO.setRootId(dto.getRelationTypeId()); relationDTO.setRootThingId(dto.getRelationTopId()); relationDTO.setFromId(parentThing.getId()); relationDTO.setFromCode(parentThing.getCode()); relationDTO.setFromName(parentThing.getName()); - List relationList = new ArrayList<>(); - ThingRelationDTO.RelationEntity relation = new ThingRelationDTO.RelationEntity(); - + relationDTO.setId(relationDetailDTOS.get(0).getId()); + List relationList = new ArrayList<>(); + IotThingRelationDetailParamDTO relation = new IotThingRelationDetailParamDTO(); relation.setToId(thingEntity.getId()); relation.setToCode(code); relation.setToName(dto.getName()); relationList.add(relation); relationDTO.setRelationList(relationList); - iotThingRelationDetailService.saveRelationNodes(relationDTO); + + iotThingRelationDetailService.save(relationDTO); //保存附件 eqAttacmentService.saveBatch(ConvertUtils.sourceToTarget(attacmentDTOS, EqAttacmentEntity.class)); } @@ -388,9 +394,19 @@ public class IotThingsServiceImpl implements IotThingsService { @Override public EqDTO getInfo(Long id) { + EqDTO info = new EqDTO(); //获取设备 - IotThingEntity eq = iotThingEntityDao.selectOneById(id); + + IotThingBaseInfoEntity baseInfoEntity = iotThingBaseInfoService.getById(id); + if (baseInfoEntity==null){ + return null; + } + Long thingId = baseInfoEntity.getThingId(); + if (thingId==null){ + return null; + } + IotThingEntity eq = iotThingEntityDao.selectOneById(thingId); if (eq==null){ return null; } @@ -406,8 +422,7 @@ public class IotThingsServiceImpl implements IotThingsService { info.setUpdateDate(eq.getUpdateDate()); // BeanUtils.copyProperties(eq,info); //获取设备基础信息 - IotThingBaseInfoDTO baseInfoDTO = iotThingBaseInfoService.getByThingsId(id); - BeanUtils.copyProperties(baseInfoDTO,info); + BeanUtils.copyProperties(baseInfoEntity,info); List imageUrls = new ArrayList<>(); List attachmentUrls = new ArrayList<>(); @@ -439,13 +454,14 @@ public class IotThingsServiceImpl implements IotThingsService { result.setCode(eq.getCode()); result.setName(eq.getName()); IotThingBaseInfoDTO baseInfoDTO = iotThingBaseInfoService.getByThingsId(thingId); - result.setStandard(baseInfoDTO.getStandard()); - result.setUseDeptId(baseInfoDTO.getUseDeptId()); - result.setEqCode(baseInfoDTO.getEqCode()); - result.setScrap(baseInfoDTO.getScrap()); - result.setScrapDisposal(baseInfoDTO.getScrapDisposal()); + if(!Objects.isNull(baseInfoDTO)){ + result.setStandard(baseInfoDTO.getStandard()); + result.setUseDeptId(baseInfoDTO.getUseDeptId()); + result.setEqCode(baseInfoDTO.getEqCode()); + result.setScrap(baseInfoDTO.getScrap()); + result.setScrapDisposal(baseInfoDTO.getScrapDisposal()); + } return result; -// return iotThingsDao.getThingInfo(thingId,relationTypeId); } @Override diff --git a/modules/equipment/src/main/java/com/thing/eq/tree/controller/DeviceController.java b/modules/equipment/src/main/java/com/thing/eq/tree/controller/DeviceController.java index 4241b32..24ae894 100644 --- a/modules/equipment/src/main/java/com/thing/eq/tree/controller/DeviceController.java +++ b/modules/equipment/src/main/java/com/thing/eq/tree/controller/DeviceController.java @@ -108,10 +108,9 @@ public class DeviceController { newList.add(iotThingsExcel); } } + } else{ + newList.addAll(list); } -// else{ -// newList.addAll(list); -// } ExcelUtils.exportExcel(newList,null, "设备台账", IotThingsExcel.class,"设备台账.xls",response); } @@ -148,10 +147,9 @@ public class DeviceController { newList.add(iotThingsPartExcel); } } + } else{ + newList.addAll(list); } -// else{ -// newList.addAll(list); -// } ExcelUtils.exportExcel(newList,null, "备件库", IotThingsPartExcel.class,"备件库.xls",response); } diff --git a/modules/equipment/src/main/resources/mapper/eqmanager/IotThingBaseInfoMapper.xml b/modules/equipment/src/main/resources/mapper/eqmanager/IotThingBaseInfoMapper.xml index f240d78..2ed807f 100644 --- a/modules/equipment/src/main/resources/mapper/eqmanager/IotThingBaseInfoMapper.xml +++ b/modules/equipment/src/main/resources/mapper/eqmanager/IotThingBaseInfoMapper.xml @@ -25,7 +25,7 @@ - update iot_thing_base_info set scrap=#{scrap},scrap_disposal=#{scrapDisposal} where thing_id=#{eqId} + update iot_thing_base_info set scrap=#{scrap},scrap_disposal=#{scrapDisposal} where id=#{eqId} @@ -130,27 +130,25 @@ FROM iot_thing_base_info baseinfo LEFT JOIN iot_thing_entity things ON things.id = baseinfo.thing_id - LEFT JOIN iot_thing_relation_detail relation on relation.to_id = baseinfo.thing_id and relation.root_id = #{params.relationTypeId} and relation.from_id =#{params.toId} + LEFT JOIN iot_thing_relation_detail relation on relation.to_id = baseinfo.thing_id LEFT JOIN iot_thing_entity things2 ON relation.from_id = things2.id + relation.root_id = #{relationTypeId} baseinfo.thing_id in #{thingId} + + and relation.from_id =#{toId} + and (things.name like concat('%',#{keyWord}::varchar,'%') or things.code like concat('%',#{keyWord}::varchar,'%') or baseinfo.eq_code like concat('%',#{keyWord}::varchar,'%') or baseinfo.standard like concat('%',#{keyWord}::varchar,'%')) - - and baseinfo.use_dept_id =#{params.useDeptId} - - - and things2.name like concat('%',#{eqTypeName}::varchar,'%') - order by things.create_date desc diff --git a/modules/thing/src/main/java/com/thing/listener/QueueDeviceEventListener.java b/modules/thing/src/main/java/com/thing/listener/QueueDeviceEventListener.java index 4c3d62b..2640cf0 100644 --- a/modules/thing/src/main/java/com/thing/listener/QueueDeviceEventListener.java +++ b/modules/thing/src/main/java/com/thing/listener/QueueDeviceEventListener.java @@ -66,7 +66,7 @@ public class QueueDeviceEventListener { if (CollectionUtils.isNotEmpty(insertModelList)) { // 物实体 Map> tenantThingCodeMap = - validMsgList.parallelStream() + validMsgList.stream() .filter(item -> Objects.nonNull(item.getTenantCode()) || Objects.nonNull(item.getCompanyId()) || Objects.nonNull(item.getDeptId())) diff --git a/modules/thing/src/main/java/com/thing/sys/tenant/service/impl/SysTenantDetailServiceImpl.java b/modules/thing/src/main/java/com/thing/sys/tenant/service/impl/SysTenantDetailServiceImpl.java index eb176b0..90461bb 100644 --- a/modules/thing/src/main/java/com/thing/sys/tenant/service/impl/SysTenantDetailServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/sys/tenant/service/impl/SysTenantDetailServiceImpl.java @@ -105,6 +105,7 @@ public class SysTenantDetailServiceImpl extends BaseServiceImpl page = getPage(params, SysTenantDetailDTO.class); //不为超管时,查询自己下属 sysTenantGroupService.paramsAddTenantCodeList(params, true); @@ -413,7 +414,6 @@ public class SysTenantDetailServiceImpl extends BaseServiceImpl tenantCodeList = detailForm.getTenantCodeList(); diff --git a/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java b/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java index 87c9ee1..139ca07 100644 --- a/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java +++ b/modules/thing/src/main/java/com/thing/thing/dict/service/impl/IotThingDictServiceImpl.java @@ -138,6 +138,7 @@ public class IotThingDictServiceImpl extends BaseServiceImplcom.thing.modules thing + + + com.thing.modules + configuration + + + diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java b/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java index ac1fe86..3dd9bce 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java @@ -9,6 +9,8 @@ import com.thing.common.core.validator.group.DefaultGroup; import com.thing.common.core.validator.group.UpdateGroup; import com.thing.common.core.web.response.PageData; import com.thing.common.core.web.response.Result; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.component.dto.GroupInfo; import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.service.IotVisualComponentService; @@ -19,6 +21,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; /** @@ -41,17 +44,19 @@ public class IotVisualComponentController { @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) , @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) , @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , - @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") + @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"), + @Parameter(name = "groupIds", description = "组id,多个组id以英文逗号分隔"), + @Parameter(name = "name", description = "部件名称") }) public Result> page(@Parameter(hidden = true) @RequestParam Map params){ - PageData page = iotVisualComponentService.getPageData(params, IotVisualComponentDTO.class); + PageData page = iotVisualComponentService.getPageDataInfo(params); return new Result>().ok(page); } @GetMapping("{id}") @Operation(summary="信息") public Result get(@PathVariable("id") Long id){ - IotVisualComponentDTO data = iotVisualComponentService.getByIdAs(id, IotVisualComponentDTO.class); + IotVisualComponentDTO data = iotVisualComponentService.getByIdDto(id); return new Result().ok(data); } @@ -71,7 +76,7 @@ public class IotVisualComponentController { public Result update(@RequestBody IotVisualComponentDTO dto){ //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); - iotVisualComponentService.updateDto(dto); + iotVisualComponentService.updateIotVisualComponentDTO(dto); return new Result<>(); } @@ -86,4 +91,25 @@ public class IotVisualComponentController { } + @GetMapping("sort") + @Operation(summary="当前组的最大序号") + public Result getSort(@RequestParam("groupId") Long groupId){ + Integer sort = iotVisualComponentService.getSort(groupId); + return new Result().ok(sort); + } + + @GetMapping("businessList") + @Operation(summary="定制接口,获取 远程组件 类型列表,新增组件的时候使用") + public Result> businessList(){ + List businessList = iotVisualComponentService.businessList(); + return new Result>().ok(businessList); + } + + @GetMapping("adjustSort") + @Operation(summary="拖动修改排序") + public Result adjustSort(AdjustSortInfo sortInfo){ + String data = iotVisualComponentService.adjustSort(sortInfo); + return new Result().ok(data); + } + } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java new file mode 100644 index 0000000..4ff0630 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java @@ -0,0 +1,20 @@ +package com.thing.visual.component.dto; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "部件拖动排序入参") +public class AdjustSortInfo { + + @Schema(description = "部件id") + private Long id; + @Schema(description = "部件组类型id") + private Long groupId; + @Schema(description = "原始序号") + private Integer currentSort; + @Schema(description = "被移动的序号") + private Integer upSort; + +} diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java new file mode 100644 index 0000000..be1a025 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java @@ -0,0 +1,30 @@ +package com.thing.visual.component.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** +* 部件设计信息 +* +* @author xc +* @since 3.0 2024-08-21 +*/ +@Data +@Schema(description = "部件设计信息") +public class ComponentSortInfo implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "部件id") + private Long id; + @Schema(description = "部件名称") + private String name; + @Schema(description = "部件组id") + private Integer groupId; + @Schema(description = "部件排序序号") + private Integer sort; + +} \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java new file mode 100644 index 0000000..5aeb3f8 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java @@ -0,0 +1,18 @@ +package com.thing.visual.component.dto; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(name = "组类型信息") +public class GroupInfo { + + + @Schema(name = "id") + private Long id; + @Schema(name = "组类型名称") + private String businessName; + + +} diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java index cb63093..a2f4d42 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java @@ -24,7 +24,13 @@ public class IotVisualComponentDTO implements Serializable { @Schema(description = "部件名称") private String name; @Schema(description = "部件组id") - private Integer groupId; + private Long groupId; + + @Schema(description = "部件组名称") + private String groupName; + @Schema(description = "部件组类型名称") + private String groupBusinessName; + @Schema(description = "部件类型") private String type; @Schema(description = "部件备注描述") @@ -56,4 +62,8 @@ public class IotVisualComponentDTO implements Serializable { @Schema(description = "部件排序序号") private Integer sort; + private Integer oldSort; + + + } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java b/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java index a6f8435..7476051 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java @@ -31,7 +31,7 @@ public class IotVisualComponentEntity extends BaseInfoEntity implements Serializ /** * 部件组id */ - private Integer groupId; + private Long groupId; /** * 部件类型 */ diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java b/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java index 7d9aff9..648938e 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java @@ -1,8 +1,15 @@ package com.thing.visual.component.service; +import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.IBaseService; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.component.dto.GroupInfo; +import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.entity.IotVisualComponentEntity; +import java.util.List; +import java.util.Map; + /** * 部件设计信息 * @@ -11,4 +18,16 @@ import com.thing.visual.component.entity.IotVisualComponentEntity; */ public interface IotVisualComponentService extends IBaseService { + List getInfoByGroupIds(List groupIds); + + Integer getSort(Long groupId); + + List businessList(); + + String adjustSort(AdjustSortInfo sortInfo); + void updateIotVisualComponentDTO(IotVisualComponentDTO dto); + + PageData getPageDataInfo(Map params); + + IotVisualComponentDTO getByIdDto(Long id); } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java b/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java index eb9ab1b..99d951f 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java @@ -1,13 +1,32 @@ package com.thing.visual.component.service.impl; import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.update.UpdateChain; +import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.sys.security.context.UserContext; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.component.dto.ComponentSortInfo; +import com.thing.visual.component.dto.GroupInfo; +import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.entity.IotVisualComponentEntity; import com.thing.visual.component.mapper.IotVisualComponentMapper; import com.thing.visual.component.service.IotVisualComponentService; +import com.thing.visual.group.entity.IotVisualGroupEntity; +import com.thing.visual.group.service.IotVisualGroupService; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Arrays; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + +import static com.mybatisflex.core.query.QueryMethods.max; +import static com.thing.visual.component.entity.table.IotVisualComponentEntityTableDef.IOT_VISUAL_COMPONENT_ENTITY; /** * 部件设计信息 @@ -18,11 +37,173 @@ import java.util.Map; @Service public class IotVisualComponentServiceImpl extends BaseServiceImpl implements IotVisualComponentService { + + @Autowired + private IotVisualGroupService iotVisualGroupService; + + + @Override public QueryWrapper getWrapper(Map params){ QueryWrapper wrapper = new QueryWrapper(); + String name = MapUtils.getString(params,"name"); + String groupIds = MapUtils.getString(params,"names"); + List groupIdList = null; + if(StringUtils.isNotEmpty(groupIds)){ + groupIdList = Arrays.stream(groupIds.split(",")) + .map(String::trim) // 去掉可能的空格 + .map(Long::parseLong) // 将每个字符串转换为 Long + .collect(Collectors.toList()); + } + wrapper.in(IotVisualComponentEntity::getGroupId,groupIdList,ObjectUtils.isNotEmpty(groupIdList)); + wrapper.like(IotVisualComponentEntity::getName,name,StringUtils.isNotEmpty(name)); return wrapper; } + @Override + public List getInfoByGroupIds(List groupIds) { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq( "group_id", groupIds); + return this.mapper.selectListByQuery(wrapper); + } + + @Override + public Integer getSort(Long groupId) { + Long tenantCode = UserContext.getTenantCode(); + QueryWrapper wrapper = new QueryWrapper(); + wrapper.select(max(IOT_VISUAL_COMPONENT_ENTITY.SORT).as("sort")) + .from(IOT_VISUAL_COMPONENT_ENTITY).eq(IotVisualComponentEntity::getGroupId,groupId); + wrapper.and(IOT_VISUAL_COMPONENT_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_COMPONENT_ENTITY.IS_DEFAULT.eq("1"))); + Integer number = this.mapper.selectOneByQueryAs(wrapper,Integer.class); + if(ObjectUtils.isEmpty(number)){ + return 1; + } + return number; + } + + @Override + public List businessList() { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("name","远程组件"); + wrapper.orderBy("bs_sort",true); + return iotVisualGroupService.listAs(wrapper,GroupInfo.class); + } + + + + @Override + public String adjustSort(AdjustSortInfo sortInfo) { + List sortInfos = this.getComponentSortInfo(sortInfo.getGroupId()); + moveItem(sortInfos,sortInfo.getCurrentSort()-1,sortInfo.getUpSort()-1,null); + updateSortValues(sortInfos); + sortInfos.forEach(temp->{ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .where(IotVisualGroupEntity::getId).eq(temp.getId()) + .update(); + }); + return "排序成功!"; + } + + @Override + public PageData getPageDataInfo(Map params) { + + PageData dtoPageData = this.getPageData(params,IotVisualComponentDTO.class); + + dtoPageData.getList().forEach(temp->{ + IotVisualGroupEntity group = iotVisualGroupService.getById(temp.getGroupId()); + temp.setGroupName(group.getName()); + temp.setGroupBusinessName(group.getBusinessName()); + }); + return dtoPageData; + } + + @Override + public IotVisualComponentDTO getByIdDto(Long id) { + IotVisualComponentDTO data = this.getByIdAs(id,IotVisualComponentDTO.class); + + IotVisualGroupEntity group = iotVisualGroupService.getById(data.getGroupId()); + data.setGroupName(group.getName()); + data.setGroupBusinessName(group.getBusinessName()); + + return data; + } + + + @Override + public void updateIotVisualComponentDTO(IotVisualComponentDTO dto) { + if(ObjectUtils.isNotEmpty(dto.getOldSort())){ + List sortInfos = this.getComponentSortInfo(dto.getGroupId()); + + moveItem(sortInfos,dto.getOldSort()-1,dto.getSort()-1,dto.getName()); + //重置sort字段 + updateSortValues(sortInfos); + sortInfos.forEach(temp->{ + UpdateChain.of(IotVisualComponentEntity.class) + .set(IotVisualComponentEntity::getSort, temp.getSort()) + .set(IotVisualComponentEntity::getName,dto.getName()) + .set(IotVisualComponentEntity::getThumbnailUrl,dto.getThumbnailUrl()) + .set(IotVisualComponentEntity::getRemarks,dto.getRemarks()) + .set(IotVisualComponentEntity::getDesc,dto.getDesc()) + .set(IotVisualComponentEntity::getHash,dto.getHash()) + .set(IotVisualComponentEntity::getPreviewOptions,dto.getPreviewOptions()) + .set(IotVisualComponentEntity::getIsDefault,dto.getIsDefault()) + .where(IotVisualComponentEntity::getId).eq(temp.getId()) + .update(); + }); + }else { + this.updateDto(dto); + } + } + + + + + + + + private List getComponentSortInfo(Long groupId){ + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("group_id",groupId); + wrapper.orderBy("sort",true); + return this.listAs(wrapper,ComponentSortInfo.class); + } + + + /** + * 删除原坐标,在新的坐标插入我的对象 + * @param list + * @param fromIndex + * @param toIndex + */ + private static void moveItem(List list, int fromIndex, int toIndex, String name) { + if (fromIndex < 0 || fromIndex >= list.size()) { + throw new IndexOutOfBoundsException("Invalid index"); + } + if(toIndex < 0 ){ + toIndex=0; + } + if(toIndex >= list.size()){ + toIndex= list.size()-1; + } + + ComponentSortInfo item = list.remove(fromIndex); + if(ObjectUtils.isNotEmpty(name)){ + item.setName(name); + } + list.add(toIndex, item); + updateSortValues(list); + } + + /** + * 重新修改 name中对应的sort信息 + * @param list + */ + private static void updateSortValues(List list) { + Integer sortValue = 1; + for (ComponentSortInfo item : list) { + item.setSort(sortValue++); + } + } } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java b/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java index d09d801..141d4f0 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java @@ -4,9 +4,8 @@ import com.thing.common.core.constants.Constant; import com.thing.common.core.validator.AssertUtils; import com.thing.common.core.web.response.PageData; import com.thing.common.core.web.response.Result; -import com.thing.visual.group.dto.AdjustGroupDto; -import com.thing.visual.group.dto.GroupSortInfo; -import com.thing.visual.group.dto.IotVisualGroupDTO; +import com.thing.thing.group.dto.IotGroupInfoFormatDTO; +import com.thing.visual.group.dto.*; import com.thing.visual.group.service.IotVisualGroupService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -15,6 +14,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; /** @@ -37,13 +37,19 @@ public class IotVisualGroupController { @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) , @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) , @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , - @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") + @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"), + @Parameter(name = "type", description = "类型,1素材,2部件 必传"), + @Parameter(name = "name", description = "组名称"), + @Parameter(name = "businessName", description = "组类型名称"), + @Parameter(name = "names", description = "组名称集合,多个组名称,以英文逗号分割") }) public Result> page(@Parameter(hidden = true) @RequestParam Map params){ PageData page = iotVisualGroupService.getPageData(params, IotVisualGroupDTO.class); return new Result>().ok(page); } + + @GetMapping("{id}") @Operation(summary="信息") public Result get(@PathVariable("id") Long id){ @@ -59,14 +65,22 @@ public class IotVisualGroupController { } @PutMapping - @Operation(summary="修改") + @Operation(summary="修改,这个接口,只能修改二级得组类型") public Result update(@RequestBody IotVisualGroupDTO dto){ iotVisualGroupService.updateIotVisualGroupDTO(dto); return new Result<>(); } + + @PutMapping("group") + @Operation(summary="修改,这个接口,只能修改一级得组") + public Result updateGroup(@RequestBody IotVisualGroupDTO dto){ + iotVisualGroupService.updateGroup(dto); + return new Result<>(); + } + @DeleteMapping - @Operation(summary="删除") + @Operation(summary="删除 这个接口删除二级右侧列表里面的数据,传入数据id") public Result delete(@RequestBody Long[] ids){ //效验数据 AssertUtils.isArrayEmpty(ids, "id"); @@ -74,18 +88,46 @@ public class IotVisualGroupController { return new Result<>(); } + @DeleteMapping("group") + @Operation(summary="删除 这个接口删除一级左侧列表里面的数据,传入组名称") + public Result deleteGroup(@RequestParam(required = false) String name, @RequestParam(required = true) String type){ + return new Result().ok(iotVisualGroupService.deleteGroup(name,type)); + } + + + + @GetMapping("groupInfo") + @Operation(summary="左侧组列表,可按名称模糊查询") + public Result> groupInfo(@RequestParam(required = false) String name, @RequestParam(required = true) String type){ + List data = iotVisualGroupService.groupInfo(name,type); + return new Result>().ok(data); + } + @GetMapping("groupSortInfo") - @Operation(summary="获取排序信息,可以传入已存在的组名称") - public Result groupSortInfo(@RequestParam(required = false) String name){ - GroupSortInfo data = iotVisualGroupService.groupSortInfo(name); + @Operation(summary="获取排序信息,可以传入已存在的组名称,新增得时候使用") + public Result groupSortInfo(@RequestParam(required = false) String name,@RequestParam(required = true) String type){ + GroupSortInfo data = iotVisualGroupService.groupSortInfo(name,type); return new Result().ok(data); } @PostMapping("adjustGroupSort") - @Operation(summary="调整组排序") + @Operation(summary="调整组排序,拖动排序,如果传入name,就是组内排序") public Result adjustGroupSort(@RequestBody AdjustGroupDto dto){ String data = iotVisualGroupService.adjustGroupSort(dto); return new Result().ok(data); } + + @GetMapping("listTree") + @Operation(summary="返回所有可见组的树结构,部件素材侧边栏使用(组级别是虚拟的,没有id生成的虚拟id)") + @Parameters({ + @Parameter(name ="type",description ="1素材,2部件"), + @Parameter(name ="name",description ="组名称") + }) + public Result> listTree(String type, String name){ + return iotVisualGroupService.listTree(type,name); + } + + + } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/AdjustGroupDto.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/AdjustGroupDto.java index 2b780c3..dfacef0 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/dto/AdjustGroupDto.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/AdjustGroupDto.java @@ -8,12 +8,13 @@ import lombok.Data; @Schema(description = "调整组排序入参对象") public class AdjustGroupDto { - private String currentName; - private Long currentSort; + private String name; - private String upName; + private Integer currentSort; - private String upSort; + private Integer upSort; + + private String type; } diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java new file mode 100644 index 0000000..e39b800 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java @@ -0,0 +1,32 @@ +package com.thing.visual.group.dto; + +import com.thing.thing.group.dto.IotGroupInfoFormatDTO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + + +@Data +public class GroupInfoFormatDTO { + + @Schema(description = "id") + private Long id; + + @Schema(description = "组名称") + private String name; + + @Schema(description = "组类型名称") + private String businessName; + + @Schema(description = "缩略图url") + private String thumbnailUrl; + + private Integer sort; + + private Integer bsSort; + + @Schema(description = "组类型列表") + private List typeList; + +} diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java index aa3c9cd..b8a5e15 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java @@ -7,8 +7,8 @@ import lombok.Data; @Schema(description = "组排序信息") public class GroupSortInfo { - private Long sort; + private Integer sort; - private Long bsSort; + private Integer bsSort; } diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java index 4a0d7c9..4996174 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java @@ -32,9 +32,9 @@ public class IotVisualGroupDTO implements Serializable { @Schema(description = "缩略图url/这里放text,也可以是svg或base64") private String thumbnailUrl; @Schema(description = "组排序") - private Long sort; + private Integer sort; @Schema(description = "二级业务排序") - private Long bsSort; + private Integer bsSort; @Schema(description = "备注说明") private String remark; @Schema(description = "所属企业(租户code)") @@ -52,4 +52,17 @@ public class IotVisualGroupDTO implements Serializable { @Schema(description = "更新时间") private Long updateDate; + @Schema(description = "素材/部件组修改之前得名称") + private String oldName; + + @Schema(description = "素材/部件组修改之前得排序") + private Integer oldSort; + + + @Schema(description = "素材/部件组修改之前得业务二级名称") + private String oldBusinessName; + + + @Schema(description = "修改之前得二级业务排序") + private Integer oldBsSort; } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/NameSort.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/NameSort.java new file mode 100644 index 0000000..c834cb8 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/NameSort.java @@ -0,0 +1,17 @@ +package com.thing.visual.group.dto; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class NameSort { + + private String name; + + private Integer sort; + +} diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java b/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java index 7f1d211..a742150 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java @@ -47,11 +47,11 @@ public class IotVisualGroupEntity extends BaseInfoEntity implements Serializable /** * 组排序 */ - private Long sort; + private Integer sort; /** * 二级业务排序 */ - private Long bsSort; + private Integer bsSort; /** * 备注说明 */ diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java b/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java index 6c4e003..a85d3c5 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java @@ -1,11 +1,13 @@ package com.thing.visual.group.service; +import com.thing.common.core.web.response.Result; import com.thing.common.orm.service.IBaseService; -import com.thing.visual.group.dto.AdjustGroupDto; -import com.thing.visual.group.dto.GroupSortInfo; -import com.thing.visual.group.dto.IotVisualGroupDTO; +import com.thing.thing.group.dto.IotGroupInfoFormatDTO; +import com.thing.visual.group.dto.*; import com.thing.visual.group.entity.IotVisualGroupEntity; +import java.util.List; + /** * 素材部件组管理 * @@ -18,7 +20,14 @@ public interface IotVisualGroupService extends IBaseService groupInfo(String name, String type); + String deleteGroup(String name, String type); + + Result> listTree(String type, String name); } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java b/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java index 6b9c64a..a4afe8f 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java @@ -1,17 +1,29 @@ package com.thing.visual.group.service.impl; import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.update.UpdateChain; +import com.thing.common.core.utils.ConvertUtils; +import com.thing.common.core.web.response.Result; import com.thing.common.orm.service.impl.BaseServiceImpl; -import com.thing.visual.group.dto.AdjustGroupDto; -import com.thing.visual.group.dto.GroupSortInfo; -import com.thing.visual.group.dto.IotVisualGroupDTO; +import com.thing.configuration.newmaterial.entity.IotNewSourceMaterialEntity; +import com.thing.configuration.newmaterial.service.IotNewSourceMaterialService; +import com.thing.sys.security.context.UserContext; +import com.thing.thing.group.dto.IotGroupInfoDTO; +import com.thing.thing.group.dto.IotGroupInfoFormatDTO; +import com.thing.visual.component.entity.IotVisualComponentEntity; +import com.thing.visual.component.service.IotVisualComponentService; +import com.thing.visual.group.dto.*; import com.thing.visual.group.mapper.IotVisualGroupMapper; import com.thing.visual.group.entity.IotVisualGroupEntity; import com.thing.visual.group.service.IotVisualGroupService; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; import static com.mybatisflex.core.query.QueryMethods.max; import static com.mybatisflex.core.query.QueryMethods.max; @@ -20,55 +32,298 @@ import static com.thing.visual.group.entity.table.IotVisualGroupEntityTableDef.I /** * 素材部件组管理 * - * @author xc + * @author xc * @since 3.0 2024-08-21 */ @Service public class IotVisualGroupServiceImpl extends BaseServiceImpl implements IotVisualGroupService { + + + @Autowired + private IotNewSourceMaterialService iotNewSourceMaterialService; + @Autowired + private IotVisualComponentService iotVisualComponentService; + + + + @Override public QueryWrapper getWrapper(Map params){ + Long tenantCode = UserContext.getTenantCode(); QueryWrapper wrapper = new QueryWrapper(); + String name = MapUtils.getString(params,"name"); + String names = MapUtils.getString(params,"names"); + List nameList = null; + if(StringUtils.isNotEmpty(names)){ + nameList = Arrays.asList(names.split(",")); + } + String businessName = MapUtils.getString(params,"businessName"); + wrapper.eq(IotVisualGroupEntity::getType,MapUtils.getString(params,"type")); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); + wrapper.like(IotVisualGroupEntity::getName,name, StringUtils.isNotEmpty(name)); + wrapper.like(IotVisualGroupEntity::getBusinessName,businessName, StringUtils.isNotEmpty(businessName)); + wrapper.in(IotVisualGroupEntity::getName,nameList,ObjectUtils.isNotEmpty(nameList)); + wrapper.orderBy(IotVisualGroupEntity::getSort,true); + wrapper.orderBy(IotVisualGroupEntity::getBsSort,true); return wrapper; } @Override public void saveIotVisualGroupDTO(IotVisualGroupDTO dto) { - + GroupSortInfo groupSortInfo = this.groupSortInfo(dto.getName(),dto.getType()); + dto.setSort(groupSortInfo.getSort()); + dto.setBsSort(groupSortInfo.getBsSort()); + this.saveDto(dto); } @Override public void updateIotVisualGroupDTO(IotVisualGroupDTO dto) { - + List sortInfo = this.getNameSort(dto.getName(),dto.getType()); + if(dto.getOldBusinessName().equals(dto.getBusinessName())){ + moveItem(sortInfo,dto.getOldBsSort()-1,dto.getBsSort()-1,null); + //重置sort字段 + updateSortValues(sortInfo); + }else { + moveItem(sortInfo,dto.getOldBsSort()-1,dto.getBsSort()-1,dto.getBusinessName()); + //重置sort字段 + updateSortValues(sortInfo); + } + sortInfo.forEach(temp->{ + if(dto.getBusinessName().equals(temp.getName())){ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getBsSort, temp.getSort()) + .set(IotVisualGroupEntity::getThumbnailUrl,dto.getThumbnailUrl()) + .set(IotVisualGroupEntity::getBusinessName,dto.getBusinessName()) + .set(IotVisualGroupEntity::getRemark,dto.getRemark()) + .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) + .update(); + }else { + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getBsSort, temp.getSort()) + .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) + .update(); + } + }); } @Override - public GroupSortInfo groupSortInfo(String name) { + public GroupSortInfo groupSortInfo(String name,String type) { + Long tenantCode = UserContext.getTenantCode(); QueryWrapper wrapper = new QueryWrapper(); wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), max(IOT_VISUAL_GROUP_ENTITY.BS_SORT).as("bs_sort")) - .from(IOT_VISUAL_GROUP_ENTITY); + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); if(ObjectUtils.isNotEmpty(name)){ - wrapper.eq(IotVisualGroupEntity::getName,name); + wrapper.eq(IotVisualGroupEntity::getName,name); } GroupSortInfo sortInfo = this.mapper.selectOneByQueryAs(wrapper,GroupSortInfo.class); if(ObjectUtils.isEmpty(sortInfo)){ sortInfo = new GroupSortInfo(); - sortInfo.setBsSort(1L); - sortInfo.setSort(1L); + sortInfo.setBsSort(1); + wrapper = new QueryWrapper(); + //当前最大 sort 返回 + wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort")) + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); + GroupSortInfo maxSort = this.mapper.selectOneByQueryAs(wrapper,GroupSortInfo.class); + sortInfo.setSort(maxSort.getSort()+1); + return sortInfo; } - if(ObjectUtils.isNotEmpty(name)){ - sortInfo.setSort(sortInfo.getSort()==null?1L:sortInfo.getSort()); - }else { - sortInfo.setSort(sortInfo.getSort()==null?1L:sortInfo.getSort()+1); - } - sortInfo.setBsSort(sortInfo.getBsSort()==null?1L:sortInfo.getBsSort()+1); + sortInfo.setBsSort(sortInfo.getBsSort()==null?1:sortInfo.getBsSort()+1); return sortInfo ; } @Override public String adjustGroupSort(AdjustGroupDto dto) { - return null; + List sortInfo = this.getNameSort(dto.getName(),dto.getType()); + //修改排序 + moveItem(sortInfo,dto.getCurrentSort()-1,dto.getUpSort()-1,null); + //重置sort字段 + updateSortValues(sortInfo); + + if(ObjectUtils.isNotEmpty(dto.getName())){ + //组内排序 + sortInfo.forEach(temp->{ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getBsSort, temp.getSort()) + .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) + .update(); + }); + }else { + //组排序 + sortInfo.forEach(temp->{ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .where(IotVisualGroupEntity::getName).eq(temp.getName()) + .update(); + }); + } + return "ok"; + } + + @Override + public void updateGroup(IotVisualGroupDTO dto) { + //修改一级得组,名称or排序 + List sortInfo = this.getNameSort(null,dto.getType()); + if(dto.getOldName().equals(dto.getName())){ + //修改排序 + moveItem(sortInfo,dto.getOldSort()-1,dto.getSort()-1,null); + //重置sort字段 + updateSortValues(sortInfo); + }else { + //修改排序 + moveItem(sortInfo,dto.getOldSort()-1,dto.getSort()-1,dto.getName()); + //重置sort字段 + updateSortValues(sortInfo); + } + //组排序 + sortInfo.forEach(temp->{ + if(temp.getName().equals(dto.getName())){ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .set(IotVisualGroupEntity::getName, temp.getName()) + .where(IotVisualGroupEntity::getName).eq(dto.getOldName()).and("type = '"+dto.getType()+"'") + .update(); + }else { + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .where(IotVisualGroupEntity::getName).eq(temp.getName()).and("type = '"+dto.getType()+"'") + .update(); + } + }); + } + + @Override + public List groupInfo(String name, String type) { + Long tenantCode = UserContext.getTenantCode(); + + QueryWrapper wrapper = new QueryWrapper(); + wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.NAME.as("name")) + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + //本企业得or 默认得 + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); + wrapper.eq(IotVisualGroupEntity::getName,name,StringUtils.isNotEmpty(name)); + wrapper.groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true); + return this.mapper.selectListByQueryAs(wrapper,NameSort.class); + } + + @Override + public String deleteGroup(String name, String type) { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq(IotVisualGroupEntity::getName,name); + wrapper.eq(IotVisualGroupEntity::getType,type); + List entities = this.list(wrapper); + + List groupIds = entities.stream() + .map(IotVisualGroupEntity::getId) + .toList(); + //素材or部件 有被引用,则不允许删除 + List materialList = iotNewSourceMaterialService.getInfoByGroupIds(groupIds); + if(ObjectUtils.isNotEmpty(materialList)){ + return "当前组下有类型被引用,不允许删除!"; + } + List componentEntityList = iotVisualComponentService.getInfoByGroupIds(groupIds); + if(ObjectUtils.isNotEmpty(componentEntityList)){ + return "当前组下有类型被引用,不允许删除!"; + } + //删除组 + QueryWrapper queryWrapper = QueryWrapper.create(); + queryWrapper.eq(IotVisualGroupEntity::getName,name); + queryWrapper.eq(IotVisualGroupEntity::getType,type); + this.mapper.deleteByQuery(queryWrapper); + return "删除成功!"; + + } + + @Override + public Result> listTree(String type, String name) { + List resultList = new ArrayList<>(); + QueryWrapper queryWrapper = QueryWrapper.create(); + queryWrapper.eq(IotVisualGroupEntity::getType,type); + queryWrapper.like(IotVisualGroupEntity::getName,name); + List infos = listAs(queryWrapper, IotVisualGroupDTO.class); + + Map> map = infos.stream().collect(Collectors.groupingBy(IotVisualGroupDTO::getName)); + + for (String temp : map.keySet()) { + GroupInfoFormatDTO dto = new GroupInfoFormatDTO(); + dto.setName(temp); + dto.setBusinessName(temp); + dto.setId((new Random().nextInt()*-1- 19900000000L)); + List infoDTOS = map.get(temp).parallelStream().sorted(Comparator.comparingLong(IotVisualGroupDTO::getBsSort)).collect(Collectors.toList()); + dto.setThumbnailUrl(infoDTOS.get(0).getThumbnailUrl()); + map.get(temp).forEach(info->{ + info.setName(info.getBusinessName()); + }); + dto.setSort(infoDTOS.get(0).getSort()); + dto.setTypeList(ConvertUtils.sourceToTarget(infoDTOS,GroupInfoFormatDTO.class)); + resultList.add(dto); + } + return new Result>().ok(resultList.parallelStream().sorted(Comparator.comparingLong(GroupInfoFormatDTO::getSort)).collect(Collectors.toList())); } + + + /** + * 获取所有排序信息,看没有没有穿name,传name了,就是组内排序,没传name就是组排序 + * @param name + * @return + */ + private List getNameSort(String name,String type){ + Long tenantCode = UserContext.getTenantCode(); + QueryWrapper wrapper = new QueryWrapper(); + if(ObjectUtils.isNotEmpty(name)){ + wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.BS_SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.BUSINESS_NAME.as("name")) + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + //本企业得or 默认得 + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); + wrapper.eq(IotVisualGroupEntity::getName,name).groupBy(IOT_VISUAL_GROUP_ENTITY.BUSINESS_NAME).orderBy("sort",true); + }else { + wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.NAME.as("name")) + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); + wrapper.groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true);; + } + return this.mapper.selectListByQueryAs(wrapper,NameSort.class); + } + + + /** + * 删除原坐标,在新的坐标插入我的对象 + * @param list + * @param fromIndex + * @param toIndex + */ + private static void moveItem(List list, int fromIndex, int toIndex,String name) { + if (fromIndex < 0 || fromIndex >= list.size()) { + throw new IndexOutOfBoundsException("Invalid index"); + } + if(toIndex < 0 ){ + toIndex=0; + } + if(toIndex >= list.size()){ + toIndex= list.size()-1; + } + + NameSort item = list.remove(fromIndex); + if(ObjectUtils.isNotEmpty(name)){ + item.setName(name); + } + list.add(toIndex, item); + updateSortValues(list); + } + + /** + * 重新修改 name中对应的sort信息 + * @param list + */ + private static void updateSortValues(List list) { + Integer sortValue = 1; + for (NameSort item : list) { + item.setSort(sortValue++); + } + } + } \ No newline at end of file