13 changed files with 768 additions and 41 deletions
-
9modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java
-
36modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java
-
2modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java
-
10modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java
-
8modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java
-
7modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java
-
82modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java
-
156modules/visual-design/src/main/java/com/thing/visual/material/controller/IotVisualMaterialController.java
-
67modules/visual-design/src/main/java/com/thing/visual/material/dto/IotVisualMaterialDTO.java
-
58modules/visual-design/src/main/java/com/thing/visual/material/entity/IotVisualMaterialEntity.java
-
21modules/visual-design/src/main/java/com/thing/visual/material/mapper/IotVisualMaterialMapper.java
-
41modules/visual-design/src/main/java/com/thing/visual/material/service/IotVisualMaterialService.java
-
312modules/visual-design/src/main/java/com/thing/visual/material/service/impl/IotVisualMaterialServiceImpl.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)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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; |
||||
|
|
||||
|
} |
||||
@ -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; |
||||
|
|
||||
|
} |
||||
@ -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> { |
||||
|
|
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue