package com.iailab.module.oss.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.iailab.framework.common.constant.Constant;
|
import com.iailab.framework.common.page.PageData;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.oss.dao.OssFileDao;
|
import com.iailab.module.oss.dto.OssFileDTO;
|
import com.iailab.module.oss.entity.OssFileEntity;
|
import com.iailab.module.oss.service.OssFileService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2023年12月26日 11:12:00
|
*/
|
@Service
|
public class OssFileServiceImpl extends BaseServiceImpl<OssFileDao, OssFileEntity> implements OssFileService {
|
|
@Override
|
public PageData<OssFileDTO> page(Map<String, Object> params) {
|
IPage<OssFileEntity> page = baseDao.selectPage(
|
getPage(params, Constant.CREATE_DATE, false),
|
getWrapper(params)
|
);
|
return getPageData(page, OssFileDTO.class);
|
}
|
|
private QueryWrapper<OssFileEntity> getWrapper(Map<String, Object> params) {
|
String businessId = (String) params.get("businessId");
|
String type = (String) params.get("type");
|
String fileName = (String) params.get("fileName");
|
QueryWrapper<OssFileEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(businessId), "business_id", businessId)
|
.like(StringUtils.isNotBlank(type), "type", type)
|
.like(StringUtils.isNotBlank(fileName), "file_name", fileName);
|
return wrapper;
|
}
|
|
@Override
|
public List<OssFileEntity> list(Map<String, Object> params) {
|
QueryWrapper<OssFileEntity> wrapper = getWrapper(params);
|
wrapper.orderByAsc("sort");
|
return baseDao.selectList(wrapper);
|
}
|
|
@Override
|
public OssFileDTO get(String id) {
|
OssFileEntity entity = baseDao.selectById(id);
|
|
return ConvertUtils.sourceToTarget(entity, OssFileDTO.class);
|
}
|
|
@Override
|
public List<OssFileDTO> getByBusinessId(String businessId) {
|
QueryWrapper<OssFileEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(businessId), "business_id", businessId);
|
List<OssFileEntity> list = baseDao.selectList(wrapper);
|
|
return ConvertUtils.sourceToTarget(list, OssFileDTO.class);
|
}
|
|
@Override
|
public void save(OssFileDTO dto) {
|
OssFileEntity entity = ConvertUtils.sourceToTarget(dto, OssFileEntity.class);
|
insert(entity);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void saveList(String businessId, List<OssFileDTO> list) {
|
deleteByBusinessId(businessId);
|
if (CollectionUtils.isEmpty(list)) {
|
return;
|
}
|
list.forEach(item -> {
|
save(item);
|
});
|
}
|
|
@Override
|
public void update(OssFileDTO dto) {
|
OssFileEntity entity = ConvertUtils.sourceToTarget(dto, OssFileEntity.class);
|
updateById(entity);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delete(Long[] ids) {
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
}
|
|
private void deleteByBusinessId(String businessId) {
|
QueryWrapper<OssFileEntity> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("business_id", businessId);
|
baseDao.delete(queryWrapper);
|
}
|
}
|