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, AutoDao extends BaseDao, AttachModel, AttachModelAutoMapper extends IMapper, AttachModelAutoDao extends BaseDao> { abstract AutoDao getAutoDao(); abstract AttachModelAutoDao getAttachFileAutoDao(); abstract List createAttachList(Model model); abstract Object getModelId(Model model); public abstract String getAttachBzIdName(); @Transactional public boolean save(Model model) { List attachList = createAttachList(model); if (attachList != null) { getAttachFileAutoDao().saveBatch(attachList); } return getAutoDao().save(model); } @Transactional public boolean updateById(Model model) { List attachList = getAttachFileAutoDao().list(new QueryWrapper().eq(getAttachBzIdName(), getModelId(model))); getAttachFileAutoDao().removeByIds(attachList); attachList = createAttachList(model); getAttachFileAutoDao().saveBatch(attachList); return getAutoDao().updateById(model); } @Transactional public boolean removeById(Serializable id) { List attachList = getAttachFileAutoDao().list(new QueryWrapper().eq(getAttachBzIdName(), id)); getAttachFileAutoDao().removeByIds(attachList); return getAutoDao().removeById(id); } public Model getById(Serializable id) { return getAutoDao().getById(id); } public Page getPage(Page page) { return getAutoDao().page(page); } public AttachModel getAttachByAttachId(Serializable attachId) { return getAttachFileAutoDao().getById(attachId); } public List getAttachListByModelId(Serializable modelId) { return getAttachFileAutoDao().list(new QueryWrapper().eq(getAttachBzIdName(), modelId)); } public interface GetFileIds { List getFileIds(); } }