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 implements OssFileService { @Override public PageData page(Map params) { IPage page = baseDao.selectPage( getPage(params, Constant.CREATE_DATE, false), getWrapper(params) ); return getPageData(page, OssFileDTO.class); } private QueryWrapper getWrapper(Map params) { String businessId = (String) params.get("businessId"); String type = (String) params.get("type"); String fileName = (String) params.get("fileName"); QueryWrapper 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 list(Map params) { QueryWrapper 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 getByBusinessId(String businessId) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq(StringUtils.isNotBlank(businessId), "business_id", businessId); List 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 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 queryWrapper = new QueryWrapper<>(); queryWrapper.eq("business_id", businessId); baseDao.delete(queryWrapper); } }