|
@ -3,7 +3,6 @@ package com.qs.serve.modules.tag.controller; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.qs.serve.common.model.annotation.SysLog; |
|
|
import com.qs.serve.common.model.annotation.SysLog; |
|
|
import com.qs.serve.common.model.dto.PageVo; |
|
|
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
import com.qs.serve.common.model.dto.R; |
|
|
import com.qs.serve.common.model.dto.TargetObjectDTO; |
|
|
import com.qs.serve.common.model.dto.TargetObjectDTO; |
|
|
import com.qs.serve.common.model.enums.BizType; |
|
|
import com.qs.serve.common.model.enums.BizType; |
|
@ -11,7 +10,6 @@ import com.qs.serve.common.model.enums.SystemModule; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.common.util.PageUtil; |
|
|
import com.qs.serve.common.util.PageUtil; |
|
|
import com.qs.serve.common.util.StringUtils; |
|
|
|
|
|
import com.qs.serve.modules.bms.entity.BmsChannel; |
|
|
import com.qs.serve.modules.bms.entity.BmsChannel; |
|
|
import com.qs.serve.modules.bms.entity.BmsChannelPoint; |
|
|
import com.qs.serve.modules.bms.entity.BmsChannelPoint; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
@ -23,23 +21,18 @@ import com.qs.serve.modules.sys.service.SysUserService; |
|
|
import com.qs.serve.modules.tag.TagTypeConst; |
|
|
import com.qs.serve.modules.tag.TagTypeConst; |
|
|
import com.qs.serve.modules.tag.entity.TagData; |
|
|
import com.qs.serve.modules.tag.entity.TagData; |
|
|
import com.qs.serve.modules.tag.entity.TagInfo; |
|
|
import com.qs.serve.modules.tag.entity.TagInfo; |
|
|
import com.qs.serve.modules.tag.entity.bo.TagInfoApiBindBo; |
|
|
import com.qs.serve.modules.tag.entity.bo.*; |
|
|
import com.qs.serve.modules.tag.entity.bo.TagInfoBindBo; |
|
|
|
|
|
import com.qs.serve.modules.tag.entity.bo.TagInfoBo; |
|
|
|
|
|
import com.qs.serve.modules.tag.entity.so.TagDataSo; |
|
|
import com.qs.serve.modules.tag.entity.so.TagDataSo; |
|
|
import com.qs.serve.modules.tag.entity.so.TagInfoSo; |
|
|
|
|
|
import com.qs.serve.modules.tag.entity.vo.TagDataVo; |
|
|
import com.qs.serve.modules.tag.entity.vo.TagDataVo; |
|
|
import com.qs.serve.modules.tag.service.TagDataService; |
|
|
import com.qs.serve.modules.tag.service.TagDataService; |
|
|
import com.qs.serve.modules.tag.service.TagInfoService; |
|
|
import com.qs.serve.modules.tag.service.TagInfoService; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import javax.validation.Valid; |
|
|
import javax.validation.Valid; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -86,6 +79,55 @@ public class TagDataController { |
|
|
return R.ok(tagDataVoList); |
|
|
return R.ok(tagDataVoList); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取标签数据(PAGE) |
|
|
|
|
|
* @param query |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@GetMapping("batchQueryPage") |
|
|
|
|
|
public R<?> queryBatchPage(TagData query){ |
|
|
|
|
|
PageUtil.startPage(); |
|
|
|
|
|
List<TagData> tagDataList = tagDataService.selectList(query); |
|
|
|
|
|
return R.byPageHelperList(tagDataList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Id查询 |
|
|
|
|
|
* @param id |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@GetMapping("getById/{id}") |
|
|
|
|
|
public R<?> getById(@PathVariable String id){ |
|
|
|
|
|
TagData data = tagDataService.getById(id); |
|
|
|
|
|
return R.ok(data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Id更新 |
|
|
|
|
|
* @param param |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@PostMapping("updateById/{id}") |
|
|
|
|
|
public R<?> updateById(@RequestBody TagData param){ |
|
|
|
|
|
TagData data = new TagData(); |
|
|
|
|
|
data.setId(param.getId()); |
|
|
|
|
|
data.setStartDate(param.getStartDate()); |
|
|
|
|
|
data.setEndDate(param.getEndDate()); |
|
|
|
|
|
tagDataService.updateById(data); |
|
|
|
|
|
return R.ok(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Id更新 |
|
|
|
|
|
* @param id |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@DeleteMapping("deleteById/{id}") |
|
|
|
|
|
public R<?> deleteById(@PathVariable String id){ |
|
|
|
|
|
tagDataService.removeById(id); |
|
|
|
|
|
return R.ok(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 删除(对接JSL接口) |
|
|
* 删除(对接JSL接口) |
|
|
* @param param |
|
|
* @param param |
|
@ -267,6 +309,146 @@ public class TagDataController { |
|
|
return R.ok(); |
|
|
return R.ok(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 新增(拓展了数据和时间绑定) |
|
|
|
|
|
* @param param |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@PostMapping("/bind2") |
|
|
|
|
|
@SysLog(module = SystemModule.Tag, title = "标签信息", biz = BizType.INSERT) |
|
|
|
|
|
public R<?> save2(@RequestBody @Valid TagInfoBind2Bo param){ |
|
|
|
|
|
|
|
|
|
|
|
//移除历史记录时,加载所有业务标签,并排除在外
|
|
|
|
|
|
List<TagInfo> tagInfos = tagInfoService.list(new LambdaQueryWrapper<TagInfo>() |
|
|
|
|
|
.eq(TagInfo::getBusinessFlag,1)); |
|
|
|
|
|
List<Long> businessTagIds = tagInfos.stream() |
|
|
|
|
|
.map(TagInfo::getId) |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
businessTagIds.add(-999L); |
|
|
|
|
|
|
|
|
|
|
|
if(CollUtil.isNotEmpty(param.getSave1Params())){ |
|
|
|
|
|
List<TagData> tagDataList = new ArrayList<>(); |
|
|
|
|
|
for (TagTargetObject3Bo obj : param.getSave1Params()) { |
|
|
|
|
|
//跳过业务类标签数据
|
|
|
|
|
|
boolean isBsn = businessTagIds.stream().anyMatch(a->a.equals(obj.getTagId())); |
|
|
|
|
|
if(isBsn){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
//移除旧数据
|
|
|
|
|
|
LambdaQueryWrapper<TagData> lqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw.eq(TagData::getTagId,obj.getTagId()) |
|
|
|
|
|
.eq(TagData::getTargetType,obj.getTargetType()) |
|
|
|
|
|
.eq(TagData::getTargetId,obj.getTargetId()); |
|
|
|
|
|
tagDataService.remove(lqw); |
|
|
|
|
|
//重新保存
|
|
|
|
|
|
String targetType = obj.getTargetType(); |
|
|
|
|
|
String targetId = obj.getTargetId(); |
|
|
|
|
|
TagData data = new TagData(); |
|
|
|
|
|
//设置target信息
|
|
|
|
|
|
this.toSetTagData(targetType, targetId, data); |
|
|
|
|
|
Long tagId = obj.getTagId(); |
|
|
|
|
|
TagInfo tagInfo = tagInfoService.getById(tagId); |
|
|
|
|
|
data.setTagId(tagId); |
|
|
|
|
|
data.setStartDate(obj.getStartDate()); |
|
|
|
|
|
data.setEndDate(obj.getEndDate()); |
|
|
|
|
|
if(tagInfo!=null){ |
|
|
|
|
|
data.setTagName(tagInfo.getTagName()); |
|
|
|
|
|
data.setTagRemark(tagInfo.getRemark()); |
|
|
|
|
|
} |
|
|
|
|
|
tagDataList.add(data); |
|
|
|
|
|
} |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(tagDataList)){ |
|
|
|
|
|
tagDataService.saveBatch(tagDataList); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (CollUtil.isNotEmpty(param.getSave2Params())){ |
|
|
|
|
|
List<TagData> tagDataList = new ArrayList<>(); |
|
|
|
|
|
for (TagItem2Bo obj : param.getSave2Params()) { |
|
|
|
|
|
Long tagId = obj.getTagId(); |
|
|
|
|
|
TagInfo tagInfo = tagInfoService.getById(tagId); |
|
|
|
|
|
if(tagInfo.getBusinessFlag().equals("1")){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
for (TagTargetObject2Bo object2Bo : obj.getTargetList()) { |
|
|
|
|
|
TagData data = new TagData(); |
|
|
|
|
|
data.setTagName(tagInfo.getTagName()); |
|
|
|
|
|
data.setTagId(tagInfo.getId()); |
|
|
|
|
|
this.toSetTagData(object2Bo.getTargetType(), object2Bo.getTargetId(), data); |
|
|
|
|
|
tagDataList.add(data); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//移除历史记录
|
|
|
|
|
|
List<Long> tagIds = param.getSave2Params().stream().map(TagItem2Bo::getTagId).collect(Collectors.toList()); |
|
|
|
|
|
if(CollUtil.isNotEmpty(tagIds)){ |
|
|
|
|
|
tagDataService.remove( |
|
|
|
|
|
new LambdaQueryWrapper<TagData>() |
|
|
|
|
|
.in(TagData::getTagId,tagIds) |
|
|
|
|
|
.notIn(TagData::getTagId,businessTagIds) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
//重新保存
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(tagDataList)){ |
|
|
|
|
|
tagDataService.saveBatch(tagDataList); |
|
|
|
|
|
} |
|
|
|
|
|
}else if (CollUtil.isNotEmpty(param.getSave3Params())){ |
|
|
|
|
|
List<TagData> tagDataList = new ArrayList<>(); |
|
|
|
|
|
for (TagTargetObjectBo objectDTO : param.getSave3Params()) { |
|
|
|
|
|
//移除历史数据
|
|
|
|
|
|
LambdaQueryWrapper<TagData> lqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw.eq(TagData::getTargetId,objectDTO.getTargetId()) |
|
|
|
|
|
.eq(TagData::getTargetType,objectDTO.getTargetType()) |
|
|
|
|
|
.notIn(TagData::getTagId,businessTagIds); |
|
|
|
|
|
tagDataService.remove(lqw); |
|
|
|
|
|
TagData tmpTagData = new TagData(); |
|
|
|
|
|
this.toSetTagData(objectDTO.getTargetType(), objectDTO.getTargetId(),tmpTagData); |
|
|
|
|
|
for (TagItemBo item : objectDTO.getTagItems()) { |
|
|
|
|
|
//跳过业务类型
|
|
|
|
|
|
boolean isBsn = businessTagIds.stream().anyMatch(a->a.equals(item.getTagId())); |
|
|
|
|
|
if(isBsn){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
TagInfo tagInfo = tagInfoService.getById(item.getTagId()); |
|
|
|
|
|
TagData data = CopierUtil.copy(tmpTagData,new TagData()); |
|
|
|
|
|
data.setTagId(item.getTagId()); |
|
|
|
|
|
data.setStartDate(item.getStartDate()); |
|
|
|
|
|
data.setEndDate(item.getEndDate()); |
|
|
|
|
|
if(tagInfo!=null){ |
|
|
|
|
|
data.setTagName(tagInfo.getTagName()); |
|
|
|
|
|
data.setTagRemark(tagInfo.getRemark()); |
|
|
|
|
|
} |
|
|
|
|
|
tagDataList.add(data); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(tagDataList)){ |
|
|
|
|
|
tagDataService.saveBatch(tagDataList); |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
return R.error2(); |
|
|
|
|
|
} |
|
|
|
|
|
return R.ok(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void toSetTagData(String targetType, String targetId, TagData data) { |
|
|
|
|
|
data.setTargetId(targetId); |
|
|
|
|
|
data.setTargetType(targetType); |
|
|
|
|
|
if(targetType.equals(TagTypeConst.Customer)){ |
|
|
|
|
|
BmsSupplier bmsSupplier = bmsSupplierService.getById(targetId); |
|
|
|
|
|
data.setTargetCode(bmsSupplier.getCode()); |
|
|
|
|
|
data.setTargetName(bmsSupplier.getName()); |
|
|
|
|
|
}else if (targetType.equals(TagTypeConst.Channel)){ |
|
|
|
|
|
BmsChannel channel = bmsChannelService.getById(targetId); |
|
|
|
|
|
data.setTargetCode(channel.getChannelCode()); |
|
|
|
|
|
data.setTargetName(channel.getChannelName()); |
|
|
|
|
|
}else if (targetType.equals(TagTypeConst.Point)){ |
|
|
|
|
|
BmsChannelPoint point = bmsChannelPointService.getById(targetId); |
|
|
|
|
|
data.setTargetCode(point.getPointCode()); |
|
|
|
|
|
data.setTargetName(point.getPointName()); |
|
|
|
|
|
}else{ |
|
|
|
|
|
SysUser sysUser = sysUserService.getById(targetId); |
|
|
|
|
|
data.setTargetCode(sysUser.getCode()); |
|
|
|
|
|
data.setTargetName(sysUser.getName()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|