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 dc5d52c..11c7a20 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 @@ -205,17 +205,8 @@ public class IotNewSourceMaterialServiceImpl extends BaseServiceImpl entityList= mapper.selectListByQuery(wrapper); -// entityList.parallelStream().forEach(temp->{ -// String str = temp.getImage(); -// if(StringUtils.isNotBlank(str)){ -// OSSService.delFile(OSSFactory.cutOut(str)); -// } -// }); - this.batchDelete(ids); } 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 3dd9bce..bcecaaf 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 @@ -2,24 +2,23 @@ package com.thing.visual.component.controller; import com.thing.common.core.annotation.LogOperation; import com.thing.common.core.constants.Constant; +import com.thing.common.core.utils.JsonProcessingUtils; import com.thing.common.core.validator.AssertUtils; -import com.thing.common.core.validator.ValidatorUtils; -import com.thing.common.core.validator.group.AddGroup; -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; - import io.swagger.v3.oas.annotations.Operation; 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.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; import java.util.Map; @@ -64,9 +63,7 @@ public class IotVisualComponentController { @Operation(summary="保存") @LogOperation("保存") public Result save(@RequestBody IotVisualComponentDTO dto){ - //效验数据 - ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); - iotVisualComponentService.saveDto(dto); + iotVisualComponentService.saveIotVisualComponentDTO(dto); return new Result<>(); } @@ -74,8 +71,6 @@ public class IotVisualComponentController { @Operation(summary="修改") @LogOperation("修改") public Result update(@RequestBody IotVisualComponentDTO dto){ - //效验数据 - ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); iotVisualComponentService.updateIotVisualComponentDTO(dto); return new Result<>(); } @@ -92,7 +87,7 @@ public class IotVisualComponentController { @GetMapping("sort") - @Operation(summary="当前组的最大序号") + @Operation(summary="当前组中部件的最大序号") public Result getSort(@RequestParam("groupId") Long groupId){ Integer sort = iotVisualComponentService.getSort(groupId); return new Result().ok(sort); @@ -112,4 +107,23 @@ public class IotVisualComponentController { return new Result().ok(data); } + + @GetMapping("export") + @Operation(summary="导出") + @Parameters({ + @Parameter(name ="groupIds", description = "部件组id 多个以英文逗号分割"), + @Parameter(name ="name", description = "部件名称") + }) + public void export( @RequestParam Map params, HttpServletResponse response) { + List list = iotVisualComponentService.listAs(params,IotVisualComponentDTO.class); + JsonProcessingUtils.exportJson(response, list, "detail.json"); + } + + + @PostMapping("importJson") + @Operation(summary="json导入,返回失败的数据信息") + public Result> importJson(MultipartFile file, HttpServletRequest request) { + return new Result>().ok(iotVisualComponentService.importJson(file, request)); + } + } \ 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 index 4ff0630..41324bb 100644 --- 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 @@ -5,7 +5,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data -@Schema(description = "部件拖动排序入参") +@Schema(description = "部件/素材拖动排序入参") public class AdjustSortInfo { @Schema(description = "部件id") 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 index be1a025..f1122c7 100644 --- 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 @@ -13,18 +13,18 @@ import java.io.Serializable; * @since 3.0 2024-08-21 */ @Data -@Schema(description = "部件设计信息") +@Schema(description = "部件/素材设计信息") public class ComponentSortInfo implements Serializable { @Serial private static final long serialVersionUID = 1L; - @Schema(description = "部件id") + @Schema(description = "部件/素材id") private Long id; - @Schema(description = "部件名称") + @Schema(description = "部件/素材名称") private String name; - @Schema(description = "部件组id") + @Schema(description = "部件/素材组id") private Integer groupId; - @Schema(description = "部件排序序号") + @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/IotVisualComponentDTO.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java index a2f4d42..fc47cbf 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 @@ -31,6 +31,10 @@ public class IotVisualComponentDTO implements Serializable { @Schema(description = "部件组类型名称") private String groupBusinessName; + private Integer groupSort; + + private Integer groupBSort; + @Schema(description = "部件类型") private String type; @Schema(description = "部件备注描述") @@ -61,9 +65,7 @@ public class IotVisualComponentDTO implements Serializable { private Long updateDate; @Schema(description = "部件排序序号") private Integer sort; - + @Schema(description = "被修改前的序号") private Integer oldSort; - - } \ No newline at end of file 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 648938e..90254b4 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 @@ -2,10 +2,13 @@ package com.thing.visual.component.service; import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.IBaseService; +import com.thing.configuration.section.dto.IotSectionDetailDTO; 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 jakarta.servlet.http.HttpServletRequest; +import org.springframework.web.multipart.MultipartFile; import java.util.List; import java.util.Map; @@ -30,4 +33,8 @@ public interface IotVisualComponentService extends IBaseService getPageDataInfo(Map params); IotVisualComponentDTO getByIdDto(Long id); + + List importJson(MultipartFile file, HttpServletRequest request); + + Integer saveIotVisualComponentDTO(IotVisualComponentDTO dto); } \ 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 99d951f..2fd6725 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,9 +1,16 @@ package com.thing.visual.component.service.impl; +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.update.UpdateChain; +import com.thing.common.core.exception.ErrorCode; +import com.thing.common.core.exception.SysException; +import com.thing.common.core.utils.JsonProcessingUtils; import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.configuration.section.dto.IotSectionDetailDTO; import com.thing.sys.security.context.UserContext; import com.thing.visual.component.dto.AdjustSortInfo; import com.thing.visual.component.dto.ComponentSortInfo; @@ -14,12 +21,15 @@ 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 jakarta.servlet.http.HttpServletRequest; 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 org.springframework.web.multipart.MultipartFile; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -27,6 +37,7 @@ 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; +import static com.thing.visual.group.entity.table.IotVisualGroupEntityTableDef.IOT_VISUAL_GROUP_ENTITY; /** * 部件设计信息 @@ -41,13 +52,13 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl params){ QueryWrapper wrapper = new QueryWrapper(); + wrapper.leftJoin("iot_visual_group").on("iot_visual_component.group_id = iot_visual_group.id"); + Long tenantCode = UserContext.getTenantCode(); String name = MapUtils.getString(params,"name"); - String groupIds = MapUtils.getString(params,"names"); + String groupIds = MapUtils.getString(params,"groupIds"); List groupIdList = null; if(StringUtils.isNotEmpty(groupIds)){ groupIdList = Arrays.stream(groupIds.split(",")) @@ -57,6 +68,8 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl businessList() { + Long tenantCode = UserContext.getTenantCode(); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("name","远程组件"); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); wrapper.orderBy("bs_sort",true); + return iotVisualGroupService.listAs(wrapper,GroupInfo.class); } @@ -98,9 +114,9 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl{ - UpdateChain.of(IotVisualGroupEntity.class) - .set(IotVisualGroupEntity::getSort, temp.getSort()) - .where(IotVisualGroupEntity::getId).eq(temp.getId()) + UpdateChain.of(IotVisualComponentEntity.class) + .set(IotVisualComponentEntity::getSort, temp.getSort()) + .where(IotVisualComponentEntity::getId).eq(temp.getId()) .update(); }); return "排序成功!"; @@ -115,6 +131,8 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl importJson(MultipartFile file, HttpServletRequest request) { + List resultErrorList = new ArrayList<>(); + + String jsonString = JsonProcessingUtils.readJson(file); + List iotGroupList = JSON.parseObject(jsonString, new TypeReference<>() { + }); + if (CollectionUtil.isEmpty(iotGroupList)) { + throw new SysException("导入json为空,请检查json后再进行导入"); + } + for (IotVisualComponentDTO temp : iotGroupList) { + temp.setCreateDate(null); + temp.setCreator(null); + temp.setUpdater(null); + temp.setUpdateDate(null); + temp.setTenantCode(null); + temp.setCompanyId(null); + if(ErrorCode.INTERNAL_SERVER_ERROR==this.saveIotVisualComponentDTO(temp)){ + resultErrorList.add(temp); + }; + } + return resultErrorList; + } + + @Override + public Integer saveIotVisualComponentDTO(IotVisualComponentDTO dto) { + + + Integer sort = getSort(dto.getGroupId()); + + dto.setSort(sort); + + try { + this.saveDto(dto); + } catch (Exception e) { + e.printStackTrace(); + return 500; + } + return 200; + } + @Override public void updateIotVisualComponentDTO(IotVisualComponentDTO dto) { @@ -158,15 +217,14 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl getComponentSortInfo(Long groupId){ + Long tenantCode = UserContext.getTenantCode(); + QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("group_id",groupId); wrapper.orderBy("sort",true); + + wrapper.and(IOT_VISUAL_COMPONENT_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_COMPONENT_ENTITY.IS_DEFAULT.eq("1"))); return this.listAs(wrapper,ComponentSortInfo.class); } diff --git a/modules/visual-design/src/main/java/com/thing/visual/material/controller/IotVisualMaterialController.java b/modules/visual-design/src/main/java/com/thing/visual/material/controller/IotVisualMaterialController.java new file mode 100644 index 0000000..aee25bb --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/material/controller/IotVisualMaterialController.java @@ -0,0 +1,156 @@ +package com.thing.visual.material.controller; + +import com.thing.common.core.annotation.LogOperation; +import com.thing.common.core.constants.Constant; +import com.thing.common.core.utils.JsonProcessingUtils; +import com.thing.common.core.validator.AssertUtils; +import com.thing.common.core.validator.ValidatorUtils; +import com.thing.common.core.validator.group.AddGroup; +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.thing.group.entity.IotGroupInfoEntity; +import com.thing.thing.group.mapper.IotGroupInfoMapper; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.material.dto.IotVisualMaterialDTO; +import com.thing.visual.material.service.IotVisualMaterialService; +import io.swagger.v3.oas.annotations.Operation; +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.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.Map; + + +/** +* 素材管理 +* +* @author xc +* @since 3.0 2023-05-09 +*/ +@RestController +@RequestMapping("v2/visual/material") +@Tag(name="新素材管理") +public class IotVisualMaterialController { + @Autowired + private IotVisualMaterialService iotVisualMaterialService; + + @Autowired + private IotGroupInfoMapper iotGroupInfoDao; + + @GetMapping("page") + @Operation(summary="分页") + @Parameters({ + @Parameter(name = Constant.PAGE,description ="当前页码,从1开始") , + @Parameter(name = Constant.LIMIT,description ="每页显示记录数") , + @Parameter(name = Constant.ORDER_FIELD,description ="排序字段") , + @Parameter(name = Constant.ORDER,description ="排序方式,可选值(asc、desc)"), + @Parameter(name ="ids",description ="素材id 多个以英文逗号分割"), + @Parameter(name ="name",description ="素材名称"), + @Parameter(name ="type",description ="文件类型"), + @Parameter(name ="groupIds",description ="素材组id 多个以英文逗号分割"), + + }) + public Result> page(@RequestParam Map params){ + PageData page = iotVisualMaterialService.pageIotSourceMaterialDTO(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + @Operation(summary="信息") + public Result get(@PathVariable("id") Long id){ + IotVisualMaterialDTO data = iotVisualMaterialService.getIotSourceMaterialDTO(id); + + return new Result().ok(data); + } + + @PostMapping + @Operation(summary="保存") + public Result save(@RequestBody IotVisualMaterialDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + if("0".equals(String.valueOf(dto.getIsDefault()))){ + IotGroupInfoEntity entity = new IotGroupInfoEntity(); + entity.setId(dto.getGroupId()); + entity.setIsDefault(0); + iotGroupInfoDao.update(entity); + } + return iotVisualMaterialService.saveIotSourceMaterialDTO(dto); + } + + + @PostMapping("saveBatch") + @Operation(summary="批量保存") + public Result saveBatch(@RequestBody IotVisualMaterialDTO[] dtos){ + return iotVisualMaterialService.saveBatch(dtos); + + } + + @GetMapping("sort") + @Operation(summary="当前组中部件的最大序号") + public Result getSort(@RequestParam("groupId") Long groupId){ + Integer sort = iotVisualMaterialService.getSort(groupId); + return new Result().ok(sort); + } + + @PutMapping + @Operation(summary="修改") + @LogOperation("修改") + public Result update(@RequestBody IotVisualMaterialDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + iotVisualMaterialService.updateIotVisualMaterialDTO(dto); + return new Result(); + } + + @DeleteMapping + @Operation(summary="删除") + @LogOperation("删除") + public Result delete(@RequestBody Long[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + + iotVisualMaterialService.deleteIotNewSourceMaterialDTO(ids); + + return new Result(); + } + + + @GetMapping("adjustSort") + @Operation(summary="拖动修改排序") + public Result adjustSort(AdjustSortInfo sortInfo){ + String data = iotVisualMaterialService.adjustSort(sortInfo); + return new Result().ok(data); + } + + + @PostMapping("export") + @Operation(summary="导出") + @Parameters({ + @Parameter(name ="groupIds",description ="素材组id 多个以英文逗号分割"), + @Parameter(name ="name",description ="素材名称"), + @Parameter(name ="type",description ="文件类型"), + @Parameter(name ="ids",description ="id数组"), + }) + public void export(@RequestBody Long[] ids, @RequestParam Map params, HttpServletResponse response) throws Exception { + params.put("ids", ids); + List list = iotVisualMaterialService.listAs(params, IotVisualMaterialDTO.class); + JsonProcessingUtils.exportJson(response, list, "detail.json"); + + } + + + @PostMapping("importJson") + @Operation(summary="json导入,返回失败的数据信息") + public Result> importJson(MultipartFile file, HttpServletRequest request) { + return new Result>().ok(iotVisualMaterialService.importJson(file, request)); + } + +} \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/material/dto/IotVisualMaterialDTO.java b/modules/visual-design/src/main/java/com/thing/visual/material/dto/IotVisualMaterialDTO.java new file mode 100644 index 0000000..f4fa2bc --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/material/dto/IotVisualMaterialDTO.java @@ -0,0 +1,67 @@ +package com.thing.visual.material.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 素材管理 + * + * @author xc + * @since 3.0 2023-05-09 + */ +@Data +@Schema( name= "素材管理") +public class IotVisualMaterialDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "素材id") + private Long id; + @Schema(description = "素材名称") + private String name; + @Schema(description = "素材文件类型") + private String type; + @Schema(description = "是否默认 0是,1否") + private Integer isDefault; + @Schema(description = "所属素材组id 新增/修改必传") + private Long groupId; + + @Schema(description = "所属素材组名称/不必传,回显使用") + private String groupName; + @Schema(description = "所属素材组类型名称/不必传,回显使用") + private String groupBusinessName; + @Schema(description = "所属素材组缩略图URL/不必传,回显使用") + private String thumbnailUrl; + + + + @Schema(description = "文件url") + private String image; + @Schema(description = "备注说明") + private String remark; + @Schema(description = "所属企业(租户code)") + private Long tenantCode; + @Schema(description = "企业详情id") + private Long companyId; + @Schema(description = "部门id") + private Long deptId; + @Schema(description = "创建者") + private Long creator; + @Schema(description = "创建时间") + private Date createDate; + @Schema(description = "更新者") + private Long updater; + @Schema(description = "更新时间") + private Date updateDate; + + @Schema(description = "是否可以编辑 0可编辑 1不可编辑") + private String isOperate ="0"; + @Schema(description = "部件序号") + private Integer sort; + + @Schema(description = "被修改前的序号") + private Integer oldSort; + +} \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/material/entity/IotVisualMaterialEntity.java b/modules/visual-design/src/main/java/com/thing/visual/material/entity/IotVisualMaterialEntity.java new file mode 100644 index 0000000..dfa0f43 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/material/entity/IotVisualMaterialEntity.java @@ -0,0 +1,58 @@ +package com.thing.visual.material.entity; + + +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import com.thing.common.orm.entity.BaseInfoEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 素材管理 + * + * @author xc + * @since 3.0 2023-05-09 + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper=false) +@Table("iot_visual_material") +public class IotVisualMaterialEntity extends BaseInfoEntity { + private static final long serialVersionUID = 1L; + + /** + * 素材id + */ + @Id + private Long id; + /** + * 素材名称 + */ + private String name; + /** + * 素材类型 + */ + private String type; + /** + * 是否默认 0是,1否 + */ + private Integer isDefault; + /** + * 所属素材组id + */ + private Long groupId; + /** + * 文件url + */ + private String image; + /** + * 备注说明 + */ + private String remark; + /** + * 排序 + */ + private Integer sort; + +} \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/material/mapper/IotVisualMaterialMapper.java b/modules/visual-design/src/main/java/com/thing/visual/material/mapper/IotVisualMaterialMapper.java new file mode 100644 index 0000000..05e539e --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/material/mapper/IotVisualMaterialMapper.java @@ -0,0 +1,21 @@ +package com.thing.visual.material.mapper; + + +import com.thing.common.orm.mapper.PowerBaseMapper; +import com.thing.visual.material.dto.IotVisualMaterialDTO; +import com.thing.visual.material.entity.IotVisualMaterialEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +import java.util.Map; + +/** +* 素材管理 +* +* @author xc +* @since 3.0 2023-05-09 +*/ +@Mapper +public interface IotVisualMaterialMapper extends PowerBaseMapper { + +} \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/material/service/IotVisualMaterialService.java b/modules/visual-design/src/main/java/com/thing/visual/material/service/IotVisualMaterialService.java new file mode 100644 index 0000000..cba1690 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/material/service/IotVisualMaterialService.java @@ -0,0 +1,41 @@ +package com.thing.visual.material.service; + + +import com.thing.common.core.web.response.PageData; +import com.thing.common.core.web.response.Result; +import com.thing.common.orm.service.IBaseService; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.material.dto.IotVisualMaterialDTO; +import com.thing.visual.material.entity.IotVisualMaterialEntity; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.Map; + +/** + * 素材管理 + * + * @author xc + * @since 3.0 2023-05-09 + */ +public interface IotVisualMaterialService extends IBaseService { + + PageData pageIotSourceMaterialDTO(Map params); + + IotVisualMaterialDTO getIotSourceMaterialDTO(Long id); + + Result saveIotSourceMaterialDTO(IotVisualMaterialDTO dto); + + List importJson(MultipartFile file, HttpServletRequest request); + + void deleteIotNewSourceMaterialDTO(Long[] ids); + + Result saveBatch(IotVisualMaterialDTO[] dtos); + + Integer getSort(Long groupId); + + String adjustSort(AdjustSortInfo sortInfo); + + void updateIotVisualMaterialDTO(IotVisualMaterialDTO dto); +} \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/material/service/impl/IotVisualMaterialServiceImpl.java b/modules/visual-design/src/main/java/com/thing/visual/material/service/impl/IotVisualMaterialServiceImpl.java new file mode 100644 index 0000000..504acf2 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/material/service/impl/IotVisualMaterialServiceImpl.java @@ -0,0 +1,312 @@ +package com.thing.visual.material.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.alibaba.fastjson.TypeReference; +import com.mybatisflex.core.query.QueryColumn; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.update.UpdateChain; +import com.thing.common.core.enumeration.SuperAdminEnum; +import com.thing.common.core.exception.ErrorCode; +import com.thing.common.core.exception.SysException; +import com.thing.common.core.utils.ConvertUtils; +import com.thing.common.core.utils.JsonProcessingUtils; +import com.thing.common.core.validator.ValidatorUtils; +import com.thing.common.core.validator.group.AddGroup; +import com.thing.common.core.validator.group.DefaultGroup; +import com.thing.common.core.web.response.PageData; +import com.thing.common.core.web.response.Result; +import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.sys.biz.dto.SysUserDTO; +import com.thing.sys.biz.service.SysUserService; +import com.thing.sys.oss.cloud.OSSFactory; +import com.thing.sys.security.context.TenantContext; +import com.thing.sys.security.context.UserContext; +import com.thing.sys.security.domain.SecurityUser; +import com.thing.sys.security.domain.UserDetail; +import com.thing.thing.group.dto.IotGroupInfoDTO; +import com.thing.thing.group.entity.IotGroupInfoEntity; +import com.thing.thing.group.mapper.IotGroupInfoMapper; +import com.thing.thing.group.service.IotGroupInfoService; +import com.thing.util.TenantSubsetUtil; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.component.dto.ComponentSortInfo; +import com.thing.visual.component.entity.IotVisualComponentEntity; +import com.thing.visual.group.entity.IotVisualGroupEntity; +import com.thing.visual.group.service.IotVisualGroupService; +import com.thing.visual.material.dto.IotVisualMaterialDTO; +import com.thing.visual.material.entity.IotVisualMaterialEntity; +import com.thing.visual.material.mapper.IotVisualMaterialMapper; +import com.thing.visual.material.service.IotVisualMaterialService; +import jakarta.servlet.http.HttpServletRequest; +import org.apache.commons.collections4.CollectionUtils; +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 org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.util.*; +import java.util.stream.Collectors; + +import static com.mybatisflex.core.query.QueryMethods.column; +import static com.mybatisflex.core.query.QueryMethods.max; +import static com.thing.visual.component.entity.table.IotVisualComponentEntityTableDef.IOT_VISUAL_COMPONENT_ENTITY; +import static com.thing.visual.material.entity.table.IotVisualMaterialEntityTableDef.IOT_VISUAL_MATERIAL_ENTITY; + +/** + * 素材管理 + * + * @author xc + * @since 3.0 2023-05-09 + */ +@Service +public class IotVisualMaterialServiceImpl extends BaseServiceImpl implements IotVisualMaterialService { + + @Autowired + private IotVisualGroupService iotVisualGroupService; + + + @Override + public QueryWrapper getWrapper(Map params){ + QueryColumn is_default = column("is_default"); + QueryColumn tenant_code = column("tenant_code"); + + QueryWrapper wrapper = new QueryWrapper(); + wrapper.leftJoin("iot_visual_group").on("iot_visual_material.group_id = iot_visual_group.id"); + + List group_ids = null; + String strs = (String)params.get("groupIds"); + if(StringUtils.isNotBlank(strs)&&!"null".equals(params.get("strs"))){ + group_ids = Arrays.stream(strs.split(",")) + .map(Long::parseLong) + .collect(Collectors.toList()); + wrapper.in("group_id", group_ids,CollectionUtils.isNotEmpty(group_ids)); + } + + String type = (String) params.get("type"); + wrapper.like("type", type,StringUtils.isNotBlank(type)); + String name = (String) params.get("name"); + wrapper.like( "name", name,StringUtils.isNotBlank(name)); + ArrayList ids = MapUtil.get(params, "ids",ArrayList.class); + if (ObjectUtil.isNotNull(ids)&& !ids.isEmpty()) { + wrapper.in("id", ids); + } + wrapper.and(is_default.eq(0).or(tenant_code.eq(UserContext.getTenantCode()))); + wrapper.orderBy("iot_visual_group.sort,iot_visual_group.bs_sort,iot_visual_material.sort",true); + return wrapper; + } + + + @Override + public PageData pageIotSourceMaterialDTO(Map params) { + + PageData data = getPageData(params, IotVisualMaterialDTO.class); + + data.getList().forEach(temp->{ + IotVisualGroupEntity groupInfoDTO = iotVisualGroupService.getByIdAs(temp.getGroupId(), IotVisualGroupEntity.class); + if(ObjectUtil.isNotNull(groupInfoDTO)){ + temp.setGroupName(groupInfoDTO.getName()); + temp.setGroupBusinessName(groupInfoDTO.getBusinessName()); + } + temp.setImage(OSSFactory.splice(temp.getImage())); + //数据创建者,以及超管,拥有编辑删除权限, + //默认数据不得编辑删除 + checkIsOperate(temp); + + }); + return data; + } + + @Override + public IotVisualMaterialDTO getIotSourceMaterialDTO(Long id) { + IotVisualMaterialDTO data = getByIdAs(id, IotVisualMaterialDTO.class); + IotVisualGroupEntity groupInfoDTO = iotVisualGroupService.getByIdAs(data.getGroupId(),IotVisualGroupEntity.class); + data.setGroupName(groupInfoDTO.getName()); + data.setGroupBusinessName(groupInfoDTO.getBusinessName()); + data.setImage(OSSFactory.splice(data.getImage())); + //数据创建者,以及超管,拥有编辑删除权限, + //默认数据不得编辑删除 + checkIsOperate(data); + return data; + } + + private void checkIsOperate(IotVisualMaterialDTO data) { + if(0==data.getIsDefault()){ + if(!"1001".equals(String.valueOf(UserContext.getTenantCode()))){ + data.setIsOperate("1"); + } + } + if (!String.valueOf(data.getTenantCode()).equals(String.valueOf(UserContext.getTenantCode()))){ + if(!UserContext.isAdmin()){ + data.setIsOperate("1"); + } + } + } + + + @Override + public Result saveIotSourceMaterialDTO(IotVisualMaterialDTO dto) { + IotVisualMaterialEntity entity = ConvertUtils.convertWithTypeAdapt(dto, IotVisualMaterialEntity.class); + if(null!=entity.getId()){ + updateById(entity); + return new Result().ok("修改成功!"); + } + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq( "group_id", dto.getGroupId(),ObjectUtil.isNotEmpty(dto.getGroupId())); + wrapper.eq("name", dto.getName(),ObjectUtil.isNotEmpty(dto.getName())); + wrapper.eq("type", dto.getType(),ObjectUtil.isNotEmpty(dto.getType())); + if(this.mapper.selectCountByQuery(wrapper)>0){ + entity.setName(entity.getName()+"_COPY"+UUID.randomUUID().toString().substring(1,5)); + } + Integer sort = this.getSort(dto.getGroupId()); + entity.setSort(sort); + entity.setImage(OSSFactory.cutOut(entity.getImage())); + save(entity); + return new Result().ok("添加成功!"); + } + + + @Override + public List importJson(MultipartFile file, HttpServletRequest request) { + List resultErrorList = new ArrayList<>(); + String jsonString = JsonProcessingUtils.readJson(file); + List iotGroupList = JSON.parseObject(jsonString, new TypeReference<>() { + }); + if (CollectionUtil.isEmpty(iotGroupList)) { + throw new SysException("导入json为空,请检查json后再进行导入"); + } + for (IotVisualMaterialDTO temp : iotGroupList) { + if(ErrorCode.INTERNAL_SERVER_ERROR==this.saveIotSourceMaterialDTO(temp).getCode()){ + resultErrorList.add(temp); + }; + } + return resultErrorList; + } + + @Override + @Transactional + public void deleteIotNewSourceMaterialDTO(Long[] ids) { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.in( "id", ids); + this.batchDelete(ids); + } + + @Override + @Transactional + public Result saveBatch(IotVisualMaterialDTO[] dtos) { + try { + for (IotVisualMaterialDTO dto : dtos) { + this.saveIotSourceMaterialDTO(dto); + } + } catch (SysException e) { + return new Result().error("批量新增失败"); + } + return new Result().ok("批量新增成功"); + } + + @Override + public Integer getSort(Long groupId) { + Long tenantCode = UserContext.getTenantCode(); + QueryWrapper wrapper = new QueryWrapper(); + wrapper.select(max(IOT_VISUAL_MATERIAL_ENTITY.SORT).as("sort")) + .from(IOT_VISUAL_MATERIAL_ENTITY).eq(IotVisualMaterialEntity::getGroupId,groupId); + wrapper.and(IOT_VISUAL_MATERIAL_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_MATERIAL_ENTITY.IS_DEFAULT.eq("1"))); + Integer number = this.mapper.selectOneByQueryAs(wrapper,Integer.class); + if(ObjectUtils.isEmpty(number)){ + return 1; + } + return number+1; + } + + @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(IotVisualMaterialEntity.class) + .set(IotVisualMaterialEntity::getSort, temp.getSort()) + .where(IotVisualMaterialEntity::getId).eq(temp.getId()) + .update(); + }); + return "排序成功!"; + } + + + @Override + public void updateIotVisualMaterialDTO(IotVisualMaterialDTO 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(IotVisualMaterialEntity.class) + .set(IotVisualMaterialEntity::getSort, temp.getSort()) + .set(IotVisualMaterialEntity::getName,dto.getName()) + .set(IotVisualMaterialEntity::getType,dto.getType()) + .set(IotVisualMaterialEntity::getImage,dto.getImage()) + .set(IotVisualMaterialEntity::getGroupId,dto.getGroupId()) + .set(IotVisualMaterialEntity::getIsDefault,dto.getIsDefault()) + .where(IotVisualMaterialEntity::getId).eq(temp.getId()) + .update(); + }); + }else { + this.updateDto(dto); + } + } + + + + + + /** + * 删除原坐标,在新的坐标插入我的对象 + * @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++); + } + } + private List getComponentSortInfo(Long groupId){ + Long tenantCode = UserContext.getTenantCode(); + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("group_id",groupId); + wrapper.orderBy("sort",true); + wrapper.and(IOT_VISUAL_MATERIAL_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_MATERIAL_ENTITY.IS_DEFAULT.eq("1"))); + return this.listAs(wrapper,ComponentSortInfo.class); + } + +} \ No newline at end of file