gunshi-project-ss/src/main/java/com/gunshi/project/xyt/service/AbstractModelWithAttachServ...

82 lines
2.6 KiB
Java

package com.gunshi.project.xyt.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.db.dao.BaseDao;
import com.gunshi.db.dao.IMapper;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
/**
* 类描述
*
* @author lyf
* @version 1.0.0
* @since 2024-03-19
*/
public abstract class AbstractModelWithAttachService<Model extends AbstractModelWithAttachService.GetFileIds, AutoMapper extends IMapper<Model>, AutoDao extends BaseDao<AutoMapper, Model>,
AttachModel, AttachModelAutoMapper extends IMapper<AttachModel>, AttachModelAutoDao extends BaseDao<AttachModelAutoMapper, AttachModel>> {
abstract AutoDao getAutoDao();
abstract AttachModelAutoDao getAttachFileAutoDao();
abstract List<AttachModel> createAttachList(Model model);
abstract Object getModelId(Model model);
public abstract String getAttachBzIdName();
@Transactional
public boolean save(Model model) {
List<AttachModel> attachList = createAttachList(model);
if (attachList != null) {
getAttachFileAutoDao().saveBatch(attachList);
}
return getAutoDao().save(model);
}
@Transactional
public boolean updateById(Model model) {
List<AttachModel> attachList = getAttachFileAutoDao().list(new QueryWrapper<AttachModel>().eq(getAttachBzIdName(), getModelId(model)));
getAttachFileAutoDao().removeByIds(attachList);
attachList = createAttachList(model);
getAttachFileAutoDao().saveBatch(attachList);
return getAutoDao().updateById(model);
}
@Transactional
public boolean removeById(Serializable id) {
List<AttachModel> attachList = getAttachFileAutoDao().list(new QueryWrapper<AttachModel>().eq(getAttachBzIdName(), id));
getAttachFileAutoDao().removeByIds(attachList);
return getAutoDao().removeById(id);
}
public Model getById(Serializable id) {
return getAutoDao().getById(id);
}
public Page<Model> getPage(Page<Model> page) {
return getAutoDao().page(page);
}
public AttachModel getAttachByAttachId(Serializable attachId) {
return getAttachFileAutoDao().getById(attachId);
}
public List<AttachModel> getAttachListByModelId(Serializable modelId) {
return getAttachFileAutoDao().list(new QueryWrapper<AttachModel>().eq(getAttachBzIdName(), modelId));
}
public interface GetFileIds {
List<String> getFileIds();
}
}