| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.sys.AttachEntity; |
| | | import com.lf.server.helper.PathHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.helper.WebHelper; |
| | | import com.lf.server.mapper.data.MetaMapper; |
| | | import com.lf.server.service.all.UploadAttachService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 源数据 |
| | | * 元数据 |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | public class MetaService implements MetaMapper { |
| | | @Autowired |
| | | PathHelper pathHelper; |
| | | |
| | | @Autowired |
| | | MetaMapper metaMapper; |
| | | |
| | | private final static Log log = LogFactory.getLog(MetaService.class); |
| | | |
| | | @Override |
| | | public Integer selectCount(String depcode, String dircode, Integer verid, String name) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectAll() { |
| | | return metaMapper.selectAll(); |
| | | public Integer selectCountByPid(Integer metaid, String name) { |
| | | name = StringHelper.getLikeStr(name); |
| | | |
| | | return metaMapper.selectCountByPid(metaid, name); |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectPageByPid(Integer metaid, String name, Integer limit, Integer offset) { |
| | | name = StringHelper.getLikeStr(name); |
| | | |
| | | return metaMapper.selectPageByPid(metaid, name, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public MetaEntity selectByGuid(String guid, String tab) { |
| | | return metaMapper.selectByGuid(guid, tab); |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectByIdsForTab(String ids) { |
| | | return metaMapper.selectByIdsForTab(ids); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer delete(int id) { |
| | | return metaMapper.delete(id); |
| | | } |
| | | |
| | | @Override |
| | | public Integer deletes(List<Integer> ids) { |
| | | return metaMapper.deletes(ids); |
| | | public Integer deletes(String sql, String ids) { |
| | | return metaMapper.deletes(sql, ids); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public Integer updates(List<MetaEntity> list) { |
| | | return metaMapper.updates(list); |
| | | } |
| | | |
| | | /** |
| | | * 删除元数据 |
| | | */ |
| | | public Integer deletes(List<Integer> list) { |
| | | String ids = StringHelper.join(list, ","); |
| | | |
| | | String sql = null; |
| | | List<MetaEntity> metas = selectByIdsForTab(ids); |
| | | if (null != metas && metas.size() > 0) { |
| | | sql = getDelTabsSql(metas); |
| | | } |
| | | |
| | | return deletes(sql, ids); |
| | | } |
| | | |
| | | /** |
| | | * 获取删除表记录SQL |
| | | */ |
| | | public String getDelTabsSql(List<MetaEntity> metas) { |
| | | List<String> list = new ArrayList<>(); |
| | | String tab = metas.get(0).getTab(); |
| | | |
| | | List<String> pids = new ArrayList<>(); |
| | | for (MetaEntity me : metas) { |
| | | if (tab.equals(me.getTab())) { |
| | | pids.add("'" + me.getEventid() + "'"); |
| | | } else { |
| | | list.add(String.format("delete from %s where parentid in (%s)", tab, StringHelper.join(pids, ","))); |
| | | |
| | | pids.clear(); |
| | | tab = me.getTab(); |
| | | pids.add("'" + me.getEventid() + "'"); |
| | | } |
| | | } |
| | | |
| | | if (pids.size() > 0) { |
| | | list.add(String.format("delete from %s where parentid in (%s)", tab, StringHelper.join(pids, ","))); |
| | | } |
| | | |
| | | return StringHelper.join(list, ";"); |
| | | } |
| | | |
| | | /** |
| | | * 查看文件 |
| | | */ |
| | | public void downloadForView(String guid, boolean inline, HttpServletResponse res) { |
| | | try { |
| | | if (StringHelper.isEmpty(guid)) { |
| | | WebHelper.writeStr2Page(res, StaticData.NO_FILE); |
| | | return; |
| | | } |
| | | |
| | | MetaEntity me = selectByGuid(guid, null); |
| | | if (me == null) { |
| | | WebHelper.writeStr2Page(res, StaticData.NO_FILE); |
| | | return; |
| | | } |
| | | |
| | | String filePath = pathHelper.getConfig().getUploadPath() + File.separator + me.getPath(); |
| | | File file = new File(filePath); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | WebHelper.writeJson2Page(res, "文件不存在"); |
| | | } |
| | | |
| | | WebHelper.download(filePath, me.getName(), inline, res); |
| | | } catch (Exception ex) { |
| | | WebHelper.writeJson2Page(res, "文件下载出错"); |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |