Browse Source

素材管理 代码提交

thing_master
xiachao 1 year ago
parent
commit
77eb93dbea
  1. 9
      modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java
  2. 36
      modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java
  3. 2
      modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java
  4. 10
      modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java
  5. 8
      modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java
  6. 7
      modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java
  7. 82
      modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java
  8. 156
      modules/visual-design/src/main/java/com/thing/visual/material/controller/IotVisualMaterialController.java
  9. 67
      modules/visual-design/src/main/java/com/thing/visual/material/dto/IotVisualMaterialDTO.java
  10. 58
      modules/visual-design/src/main/java/com/thing/visual/material/entity/IotVisualMaterialEntity.java
  11. 21
      modules/visual-design/src/main/java/com/thing/visual/material/mapper/IotVisualMaterialMapper.java
  12. 41
      modules/visual-design/src/main/java/com/thing/visual/material/service/IotVisualMaterialService.java
  13. 312
      modules/visual-design/src/main/java/com/thing/visual/material/service/impl/IotVisualMaterialServiceImpl.java

9
modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java

@ -205,17 +205,8 @@ public class IotNewSourceMaterialServiceImpl extends BaseServiceImpl<IotNewSourc
@Override @Override
@Transactional @Transactional
public void deleteIotNewSourceMaterialDTO(Long[] ids) { public void deleteIotNewSourceMaterialDTO(Long[] ids) {
// AbstractCloudStorageService OSSService = OSSFactory.build();
QueryWrapper wrapper = new QueryWrapper(); QueryWrapper wrapper = new QueryWrapper();
wrapper.in( "id", ids); wrapper.in( "id", ids);
List<IotNewSourceMaterialEntity> entityList= mapper.selectListByQuery(wrapper);
// entityList.parallelStream().forEach(temp->{
// String str = temp.getImage();
// if(StringUtils.isNotBlank(str)){
// OSSService.delFile(OSSFactory.cutOut(str));
// }
// });
this.batchDelete(ids); this.batchDelete(ids);
} }

36
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.annotation.LogOperation;
import com.thing.common.core.constants.Constant; 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.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.PageData;
import com.thing.common.core.web.response.Result; import com.thing.common.core.web.response.Result;
import com.thing.visual.component.dto.AdjustSortInfo; import com.thing.visual.component.dto.AdjustSortInfo;
import com.thing.visual.component.dto.GroupInfo; import com.thing.visual.component.dto.GroupInfo;
import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.dto.IotVisualComponentDTO;
import com.thing.visual.component.service.IotVisualComponentService; import com.thing.visual.component.service.IotVisualComponentService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -64,9 +63,7 @@ public class IotVisualComponentController {
@Operation(summary="保存") @Operation(summary="保存")
@LogOperation("保存") @LogOperation("保存")
public Result<Void> save(@RequestBody IotVisualComponentDTO dto){ public Result<Void> save(@RequestBody IotVisualComponentDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
iotVisualComponentService.saveDto(dto);
iotVisualComponentService.saveIotVisualComponentDTO(dto);
return new Result<>(); return new Result<>();
} }
@ -74,8 +71,6 @@ public class IotVisualComponentController {
@Operation(summary="修改") @Operation(summary="修改")
@LogOperation("修改") @LogOperation("修改")
public Result<Void> update(@RequestBody IotVisualComponentDTO dto){ public Result<Void> update(@RequestBody IotVisualComponentDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
iotVisualComponentService.updateIotVisualComponentDTO(dto); iotVisualComponentService.updateIotVisualComponentDTO(dto);
return new Result<>(); return new Result<>();
} }
@ -92,7 +87,7 @@ public class IotVisualComponentController {
@GetMapping("sort") @GetMapping("sort")
@Operation(summary="当前组的最大序号")
@Operation(summary="当前组中部件的最大序号")
public Result<Integer> getSort(@RequestParam("groupId") Long groupId){ public Result<Integer> getSort(@RequestParam("groupId") Long groupId){
Integer sort = iotVisualComponentService.getSort(groupId); Integer sort = iotVisualComponentService.getSort(groupId);
return new Result<Integer>().ok(sort); return new Result<Integer>().ok(sort);
@ -112,4 +107,23 @@ public class IotVisualComponentController {
return new Result<String>().ok(data); return new Result<String>().ok(data);
} }
@GetMapping("export")
@Operation(summary="导出")
@Parameters({
@Parameter(name ="groupIds", description = "部件组id 多个以英文逗号分割"),
@Parameter(name ="name", description = "部件名称")
})
public void export( @RequestParam Map<String, Object> params, HttpServletResponse response) {
List<IotVisualComponentDTO> list = iotVisualComponentService.listAs(params,IotVisualComponentDTO.class);
JsonProcessingUtils.exportJson(response, list, "detail.json");
}
@PostMapping("importJson")
@Operation(summary="json导入,返回失败的数据信息")
public Result<List<IotVisualComponentDTO>> importJson(MultipartFile file, HttpServletRequest request) {
return new Result<List<IotVisualComponentDTO>>().ok(iotVisualComponentService.importJson(file, request));
}
} }

2
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; import lombok.Data;
@Data @Data
@Schema(description = "部件拖动排序入参")
@Schema(description = "部件/素材拖动排序入参")
public class AdjustSortInfo { public class AdjustSortInfo {
@Schema(description = "部件id") @Schema(description = "部件id")

10
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 * @since 3.0 2024-08-21
*/ */
@Data @Data
@Schema(description = "部件设计信息")
@Schema(description = "部件/素材设计信息")
public class ComponentSortInfo implements Serializable { public class ComponentSortInfo implements Serializable {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Schema(description = "部件id")
@Schema(description = "部件/素材id")
private Long id; private Long id;
@Schema(description = "部件名称")
@Schema(description = "部件/素材名称")
private String name; private String name;
@Schema(description = "部件组id")
@Schema(description = "部件/素材组id")
private Integer groupId; private Integer groupId;
@Schema(description = "部件排序序号")
@Schema(description = "部件/素材排序序号")
private Integer sort; private Integer sort;
} }

8
modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java

@ -31,6 +31,10 @@ public class IotVisualComponentDTO implements Serializable {
@Schema(description = "部件组类型名称") @Schema(description = "部件组类型名称")
private String groupBusinessName; private String groupBusinessName;
private Integer groupSort;
private Integer groupBSort;
@Schema(description = "部件类型") @Schema(description = "部件类型")
private String type; private String type;
@Schema(description = "部件备注描述") @Schema(description = "部件备注描述")
@ -61,9 +65,7 @@ public class IotVisualComponentDTO implements Serializable {
private Long updateDate; private Long updateDate;
@Schema(description = "部件排序序号") @Schema(description = "部件排序序号")
private Integer sort; private Integer sort;
@Schema(description = "被修改前的序号")
private Integer oldSort; private Integer oldSort;
} }

7
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.core.web.response.PageData;
import com.thing.common.orm.service.IBaseService; 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.AdjustSortInfo;
import com.thing.visual.component.dto.GroupInfo; import com.thing.visual.component.dto.GroupInfo;
import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.dto.IotVisualComponentDTO;
import com.thing.visual.component.entity.IotVisualComponentEntity; 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.List;
import java.util.Map; import java.util.Map;
@ -30,4 +33,8 @@ public interface IotVisualComponentService extends IBaseService<IotVisualCompone
PageData<IotVisualComponentDTO> getPageDataInfo(Map<String, Object> params); PageData<IotVisualComponentDTO> getPageDataInfo(Map<String, Object> params);
IotVisualComponentDTO getByIdDto(Long id); IotVisualComponentDTO getByIdDto(Long id);
List<IotVisualComponentDTO> importJson(MultipartFile file, HttpServletRequest request);
Integer saveIotVisualComponentDTO(IotVisualComponentDTO dto);
} }

82
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; 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.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain; 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.core.web.response.PageData;
import com.thing.common.orm.service.impl.BaseServiceImpl; 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.sys.security.context.UserContext;
import com.thing.visual.component.dto.AdjustSortInfo; import com.thing.visual.component.dto.AdjustSortInfo;
import com.thing.visual.component.dto.ComponentSortInfo; 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.component.service.IotVisualComponentService;
import com.thing.visual.group.entity.IotVisualGroupEntity; import com.thing.visual.group.entity.IotVisualGroupEntity;
import com.thing.visual.group.service.IotVisualGroupService; import com.thing.visual.group.service.IotVisualGroupService;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -27,6 +37,7 @@ import java.util.stream.Collectors;
import static com.mybatisflex.core.query.QueryMethods.max; 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.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<IotVisualComp
@Autowired @Autowired
private IotVisualGroupService iotVisualGroupService; private IotVisualGroupService iotVisualGroupService;
@Override @Override
public QueryWrapper getWrapper(Map<String, Object> params){ public QueryWrapper getWrapper(Map<String, Object> params){
QueryWrapper wrapper = new QueryWrapper(); 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 name = MapUtils.getString(params,"name");
String groupIds = MapUtils.getString(params,"names");
String groupIds = MapUtils.getString(params,"groupIds");
List<Long> groupIdList = null; List<Long> groupIdList = null;
if(StringUtils.isNotEmpty(groupIds)){ if(StringUtils.isNotEmpty(groupIds)){
groupIdList = Arrays.stream(groupIds.split(",")) groupIdList = Arrays.stream(groupIds.split(","))
@ -57,6 +68,8 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
} }
wrapper.in(IotVisualComponentEntity::getGroupId,groupIdList,ObjectUtils.isNotEmpty(groupIdList)); wrapper.in(IotVisualComponentEntity::getGroupId,groupIdList,ObjectUtils.isNotEmpty(groupIdList));
wrapper.like(IotVisualComponentEntity::getName,name,StringUtils.isNotEmpty(name)); wrapper.like(IotVisualComponentEntity::getName,name,StringUtils.isNotEmpty(name));
wrapper.and(IOT_VISUAL_COMPONENT_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_COMPONENT_ENTITY.IS_DEFAULT.eq("1")));
wrapper.orderBy("iot_visual_group.sort,iot_visual_group.bs_sort,iot_visual_component.sort",true);
return wrapper; return wrapper;
} }
@ -79,14 +92,17 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
if(ObjectUtils.isEmpty(number)){ if(ObjectUtils.isEmpty(number)){
return 1; return 1;
} }
return number;
return number+1;
} }
@Override @Override
public List<GroupInfo> businessList() { public List<GroupInfo> businessList() {
Long tenantCode = UserContext.getTenantCode();
QueryWrapper wrapper = new QueryWrapper(); QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("name","远程组件"); 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); wrapper.orderBy("bs_sort",true);
return iotVisualGroupService.listAs(wrapper,GroupInfo.class); return iotVisualGroupService.listAs(wrapper,GroupInfo.class);
} }
@ -98,9 +114,9 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
moveItem(sortInfos,sortInfo.getCurrentSort()-1,sortInfo.getUpSort()-1,null); moveItem(sortInfos,sortInfo.getCurrentSort()-1,sortInfo.getUpSort()-1,null);
updateSortValues(sortInfos); updateSortValues(sortInfos);
sortInfos.forEach(temp->{ sortInfos.forEach(temp->{
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(); .update();
}); });
return "排序成功!"; return "排序成功!";
@ -115,6 +131,8 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
IotVisualGroupEntity group = iotVisualGroupService.getById(temp.getGroupId()); IotVisualGroupEntity group = iotVisualGroupService.getById(temp.getGroupId());
temp.setGroupName(group.getName()); temp.setGroupName(group.getName());
temp.setGroupBusinessName(group.getBusinessName()); temp.setGroupBusinessName(group.getBusinessName());
temp.setGroupSort(group.getSort());
temp.setGroupBSort(group.getBsSort());
}); });
return dtoPageData; return dtoPageData;
} }
@ -130,6 +148,47 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
return data; return data;
} }
@Override
public List<IotVisualComponentDTO> importJson(MultipartFile file, HttpServletRequest request) {
List<IotVisualComponentDTO> resultErrorList = new ArrayList<>();
String jsonString = JsonProcessingUtils.readJson(file);
List<IotVisualComponentDTO> 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 @Override
public void updateIotVisualComponentDTO(IotVisualComponentDTO dto) { public void updateIotVisualComponentDTO(IotVisualComponentDTO dto) {
@ -158,15 +217,14 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
} }
private List<ComponentSortInfo> getComponentSortInfo(Long groupId){ private List<ComponentSortInfo> getComponentSortInfo(Long groupId){
Long tenantCode = UserContext.getTenantCode();
QueryWrapper wrapper = new QueryWrapper(); QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("group_id",groupId); wrapper.eq("group_id",groupId);
wrapper.orderBy("sort",true); 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); return this.listAs(wrapper,ComponentSortInfo.class);
} }

156
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<PageData<IotVisualMaterialDTO>> page(@RequestParam Map<String, Object> params){
PageData<IotVisualMaterialDTO> page = iotVisualMaterialService.pageIotSourceMaterialDTO(params);
return new Result<PageData<IotVisualMaterialDTO>>().ok(page);
}
@GetMapping("{id}")
@Operation(summary="信息")
public Result<IotVisualMaterialDTO> get(@PathVariable("id") Long id){
IotVisualMaterialDTO data = iotVisualMaterialService.getIotSourceMaterialDTO(id);
return new Result<IotVisualMaterialDTO>().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<Integer> getSort(@RequestParam("groupId") Long groupId){
Integer sort = iotVisualMaterialService.getSort(groupId);
return new Result<Integer>().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<String> adjustSort(AdjustSortInfo sortInfo){
String data = iotVisualMaterialService.adjustSort(sortInfo);
return new Result<String>().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<String, Object> params, HttpServletResponse response) throws Exception {
params.put("ids", ids);
List<IotVisualMaterialDTO> list = iotVisualMaterialService.listAs(params, IotVisualMaterialDTO.class);
JsonProcessingUtils.exportJson(response, list, "detail.json");
}
@PostMapping("importJson")
@Operation(summary="json导入,返回失败的数据信息")
public Result<List<IotVisualMaterialDTO>> importJson(MultipartFile file, HttpServletRequest request) {
return new Result<List<IotVisualMaterialDTO>>().ok(iotVisualMaterialService.importJson(file, request));
}
}

67
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;
}

58
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;
}

21
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<IotVisualMaterialEntity> {
}

41
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<IotVisualMaterialEntity> {
PageData<IotVisualMaterialDTO> pageIotSourceMaterialDTO(Map<String, Object> params);
IotVisualMaterialDTO getIotSourceMaterialDTO(Long id);
Result saveIotSourceMaterialDTO(IotVisualMaterialDTO dto);
List<IotVisualMaterialDTO> 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);
}

312
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<IotVisualMaterialMapper, IotVisualMaterialEntity> implements IotVisualMaterialService {
@Autowired
private IotVisualGroupService iotVisualGroupService;
@Override
public QueryWrapper getWrapper(Map<String, Object> 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<Long> 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<IotVisualMaterialDTO> pageIotSourceMaterialDTO(Map<String, Object> params) {
PageData<IotVisualMaterialDTO> 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<IotVisualMaterialDTO> importJson(MultipartFile file, HttpServletRequest request) {
List<IotVisualMaterialDTO> resultErrorList = new ArrayList<>();
String jsonString = JsonProcessingUtils.readJson(file);
List<IotVisualMaterialDTO> 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<ComponentSortInfo> 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<ComponentSortInfo> 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<ComponentSortInfo> 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<ComponentSortInfo> list) {
Integer sortValue = 1;
for (ComponentSortInfo item : list) {
item.setSort(sortValue++);
}
}
private List<ComponentSortInfo> 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);
}
}
Loading…
Cancel
Save