|
|
|
@ -2,7 +2,10 @@ package com.zdxt.enforcementcode.service.impl; |
|
|
|
|
|
|
|
import com.zdxt.enforcementcode.domain.bean.EnforcementCarouselBanner; |
|
|
|
import com.zdxt.enforcementcode.domain.bo.ZdxtFileBo; |
|
|
|
import com.zdxt.enforcementcode.domain.vo.EnforcementEducationServicesVo; |
|
|
|
import com.zdxt.enforcementcode.domain.vo.ZdxtFileVo; |
|
|
|
import com.zdxt.enforcementcode.service.IZdxtFileService; |
|
|
|
import org.dromara.common.core.service.DictService; |
|
|
|
import org.dromara.common.core.utils.MapstructUtils; |
|
|
|
import org.dromara.common.core.utils.StringUtils; |
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
|
@ -35,6 +38,7 @@ public class EnforcementCarouselBannerServiceImpl implements IEnforcementCarouse |
|
|
|
|
|
|
|
private final EnforcementCarouselBannerMapper baseMapper; |
|
|
|
private final IZdxtFileService zdxtFileService; |
|
|
|
private final DictService dictService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询轮播公告信息 |
|
|
|
@ -44,9 +48,59 @@ public class EnforcementCarouselBannerServiceImpl implements IEnforcementCarouse |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public EnforcementCarouselBannerVo queryById(String id){ |
|
|
|
return baseMapper.selectVoById(id); |
|
|
|
EnforcementCarouselBannerVo vo= baseMapper.selectVoById(id); |
|
|
|
if (vo != null) { |
|
|
|
// 回显附件信息
|
|
|
|
ZdxtFileBo fileBo = new ZdxtFileBo(); |
|
|
|
fileBo.setBusinessId(id); |
|
|
|
List<ZdxtFileVo> fileList = zdxtFileService.queryList(fileBo); |
|
|
|
vo.setFileList(fileList); |
|
|
|
|
|
|
|
// 设置字典标签
|
|
|
|
setDictLabels(vo); |
|
|
|
} |
|
|
|
|
|
|
|
return vo; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 为单条记录设置字典标签 |
|
|
|
* |
|
|
|
* @param vo 记录对象 |
|
|
|
*/ |
|
|
|
private void setDictLabels(EnforcementCarouselBannerVo vo) { |
|
|
|
if (vo == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 发布平台标签
|
|
|
|
if (vo.getTargetPlatform() != null) { |
|
|
|
String targetPlatformLabel = dictService.getDictLabel("web_publishing_platform", vo.getTargetPlatform().toString()); |
|
|
|
vo.setTargetPlatformLabel(targetPlatformLabel); |
|
|
|
} |
|
|
|
|
|
|
|
//状态标签
|
|
|
|
if(vo.getStatus()!=null){ |
|
|
|
String statusLabel = dictService.getDictLabel("web_status", vo.getStatus().toString()); |
|
|
|
vo.setStatusLabel(statusLabel); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 为列表设置字典标签 |
|
|
|
* |
|
|
|
* @param records 记录列表 |
|
|
|
*/ |
|
|
|
private void setDictLabels(List<EnforcementCarouselBannerVo> records) { |
|
|
|
if (records == null || records.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
records.forEach(this::setDictLabels); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 分页查询轮播公告信息列表 |
|
|
|
* |
|
|
|
@ -58,6 +112,12 @@ public class EnforcementCarouselBannerServiceImpl implements IEnforcementCarouse |
|
|
|
public TableDataInfo<EnforcementCarouselBannerVo> queryPageList(EnforcementCarouselBannerBo bo, PageQuery pageQuery) { |
|
|
|
LambdaQueryWrapper<EnforcementCarouselBanner> lqw = buildQueryWrapper(bo); |
|
|
|
Page<EnforcementCarouselBannerVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); |
|
|
|
|
|
|
|
// 为每条记录设置字典标签和已读状态
|
|
|
|
if (result.getRecords() != null && !result.getRecords().isEmpty()) { |
|
|
|
setDictLabels(result.getRecords()); |
|
|
|
} |
|
|
|
|
|
|
|
return TableDataInfo.build(result); |
|
|
|
} |
|
|
|
|
|
|
|
@ -156,14 +216,59 @@ public class EnforcementCarouselBannerServiceImpl implements IEnforcementCarouse |
|
|
|
public Boolean updateByBo(EnforcementCarouselBannerBo bo) { |
|
|
|
EnforcementCarouselBanner update = MapstructUtils.convert(bo, EnforcementCarouselBanner.class); |
|
|
|
validEntityBeforeSave(update); |
|
|
|
return baseMapper.updateById(update) > 0; |
|
|
|
|
|
|
|
boolean flag = baseMapper.updateById(update) > 0; |
|
|
|
|
|
|
|
if (flag && bo.getId() != null) { |
|
|
|
// 判断附件是否需要修改,附件有值也需要更新
|
|
|
|
if (bo.getFileList() != null) { |
|
|
|
// 先删除旧附件
|
|
|
|
deleteOldAttachments(bo.getId()); |
|
|
|
// 再保存新附件
|
|
|
|
if (!bo.getFileList().isEmpty()) { |
|
|
|
saveAttachmentFiles(bo.getFileList(), bo.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return flag; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除旧附件 |
|
|
|
* |
|
|
|
* @param businessId 业务ID |
|
|
|
*/ |
|
|
|
private void deleteOldAttachments(String businessId) { |
|
|
|
ZdxtFileBo queryBo = new ZdxtFileBo(); |
|
|
|
queryBo.setBusinessId(businessId); |
|
|
|
List<ZdxtFileVo> oldFiles = zdxtFileService.queryList(queryBo); |
|
|
|
|
|
|
|
if (oldFiles != null && !oldFiles.isEmpty()) { |
|
|
|
List<String> ids = oldFiles.stream() |
|
|
|
.map(ZdxtFileVo::getGuid) |
|
|
|
.toList(); |
|
|
|
zdxtFileService.deleteWithValidByIds(ids, false); |
|
|
|
log.info("成功删除旧附件: businessId={}, 数量={}", businessId, ids.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 保存前的数据校验 |
|
|
|
*/ |
|
|
|
private void validEntityBeforeSave(EnforcementCarouselBanner entity){ |
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
|
if (entity.getCarouselPosition() == null) { |
|
|
|
throw new IllegalArgumentException("轮播位置不能为空"); |
|
|
|
} |
|
|
|
if (entity.getTargetPlatform() == null) { |
|
|
|
throw new IllegalArgumentException("目标平台不能为空"); |
|
|
|
} |
|
|
|
if (entity.getDisplayDays() == null) { |
|
|
|
throw new IllegalArgumentException("显示天数不能为空"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(entity.getLinkUrl())) { |
|
|
|
throw new IllegalArgumentException("跳转链接不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|