管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-04-18 48897e3d10652ad6ed1f790357a5839baff8de31
src/main/java/com/lf/server/service/show/ApplyService.java
@@ -1,12 +1,16 @@
package com.lf.server.service.show;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.ctrl.DownloadReqEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.show.ApplyEntity;
import com.lf.server.entity.show.FlowEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.AesHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.mapper.show.ApplyMapper;
import com.lf.server.service.data.MetaService;
import com.lf.server.service.sys.UserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +32,12 @@
    @Autowired
    FlowService flowService;
    @Autowired
    UserService userService;
    @Autowired
    MetaService metaService;
    @Autowired
    DataLibService dataLibService;
@@ -134,9 +144,12 @@
        }
        List<FlowEntity> list = getFlowEntities(apply.getId(), ue, dr);
        rows = flowService.inserts(list);
        if (list.isEmpty()) {
            applyMapper.delete(apply.getId());
            throw new Exception("找不到待审核人");
        }
        return rows;
        return flowService.inserts(list);
    }
    /**
@@ -145,11 +158,12 @@
    private ApplyEntity getApplyEntity(UserEntity ue, DownloadReqEntity dr) throws Exception {
        // String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd()))
        String aesPwd = AesHelper.encrypt(dr.getPwd());
        String gids = null == dr.getIds() || dr.getIds().isEmpty() ? null : StringHelper.join(dr.getIds(), ",");
        ApplyEntity apply = new ApplyEntity();
        apply.setUserid(ue.getId());
        apply.setDepids(StringHelper.join(dr.getDepcodes(), ","));
        apply.setTabs(StringHelper.join(dr.getTabs(), ","));
        apply.setTabs(getTabs(dr));
        apply.setEntities(StringHelper.join(dr.getEntities(), ","));
        apply.setWkt(dr.getWkt());
        apply.setPwd(aesPwd);
@@ -157,8 +171,39 @@
        apply.setCount(dr.getDepcodes().size());
        apply.setDescr(dr.getDescr());
        apply.setCreateUser(ue.getId());
        apply.setDepcode(dr.getDepcode());
        apply.setDircodes(dr.getDirs());
        apply.setGids(gids);
        apply.setFilters(dr.getFilter());
        return apply;
    }
    /**
     * 获取表名
     */
    private String getTabs(DownloadReqEntity dr) {
        if (!StaticData.SYS_META.equals(dr.getEntities().get(0))) {
            return StringHelper.join(dr.getTabs(), ",");
        }
        List<MetaEntity> list = metaService.selectMetaFiles(dr.getIds());
        if (null == list || list.isEmpty()) {
            return "元数据表";
        }
        StringBuilder sb = new StringBuilder();
        for (MetaEntity me : list) {
            sb.append(me.getName()).append(",");
            if (sb.length() > StaticData.I1000) {
                break;
            }
        }
        if (sb.length() > 1) {
            sb.deleteCharAt(sb.length() - 1);
        }
        return sb.toString();
    }
    /**
@@ -169,12 +214,12 @@
        for (String depcode : dr.getDepcodes()) {
            UserEntity user = selectUserByDepcode(depcode);
            if (null == user) {
                continue;
                user = userService.selectByUid(StaticData.ADMIN);
            }
            FlowEntity flow = new FlowEntity();
            flow.setApplyid(applyId);
            flow.setDepcode(user.getDepcode());
            flow.setDepcode(depcode);
            flow.setUserid(user.getId());
            flow.setStatus(0);
            flow.setDescr(null);
@@ -191,12 +236,41 @@
     */
    public void zipDbData(UserEntity ue, ApplyEntity entity) {
        try {
            List<String> entities = Arrays.asList(entity.getEntities().split(","));
            List<String> entities = Arrays.asList(entity.getEntities().split(StaticData.COMMA));
            String pwd = AesHelper.decrypt(entity.getPwd());
            dataLibService.createZipFile(ue, entities, null, null, entity.getWkt(), pwd);
            DownloadReqEntity dr = new DownloadReqEntity();
            dr.setEntities(entities);
            dr.setWkt(dr.getWkt());
            dr.setPwd(pwd);
            dr.setDepcode(entity.getDepcode());
            dr.setDirs(entity.getDircodes());
            dr.setIds(getIds(entity.getGids()));
            dr.setFilter(entity.getFilters());
            String guid = StaticData.SYS_META.equals(entity.getEntities()) ? metaService.downloadMeteReq(ue, dr) : dataLibService.downloadDbReq(ue, dr);
            if (!StringHelper.isEmpty(guid)) {
                entity.setGuid(guid);
                update(entity);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    /**
     * 获取ID集合
     */
    private List<Integer> getIds(String gids) {
        if (StringHelper.isEmpty(gids)) {
            return null;
        }
        List<Integer> list = new ArrayList<>();
        for (String str : gids.split(StaticData.COMMA)) {
            list.add(Integer.parseInt(str));
        }
        return list;
    }
}