CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.ld.igds.sys.service;
 
import com.bstek.bdf2.core.model.Url;
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.ld.igds.constant.Constant;
import org.hibernate.Session;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Component
public class SysUrlService extends HibernateDao {
 
    public List<Url> getAll(String companyId) {
        String hql = " from " + Url.class.getName()
                + " where companyId=:companyId";
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("companyId", companyId);
        return this.query(hql, args);
    }
 
    /**
     * 菜单copy
     * 
     * @param sourceId
     *            源ID
     * @param targetId
     * @return
     */
    public String copy2Target(String sourceId, String targetId, String model) {
        if (sourceId.equals(targetId)) {
            return "不支持相同组织编码复制!";
        }
 
        // 目標下已有菜单,取消复制
        List<Url> list = getAll(targetId);
        if (null != list && list.size() > 0) {
            return null;
        }
 
        // 源菜单
        list = getAll(sourceId);
        if (null == list || list.isEmpty())
            return null;
 
        Session session = this.getSessionFactory().openSession();
        try {
            for (Url url : list) {
 
                if (url.getName().indexOf("多组织") >= 0) {
                    continue;
                }
                //根据选中的模块生成菜单
                if("all".equals(model)){
                    //多功能模块,生成全部菜单
                    if (url.getId().startsWith(sourceId)) {
                        url.setId(url.getId().replace(sourceId, targetId));
                    } else {
                        url.setId(targetId + "-" + url.getId().substring(4));
                    }
 
                    if (null != url.getParentId()) {
                        if (url.getParentId().startsWith(sourceId)) {
                            url.setParentId(url.getParentId().replace(sourceId,
                                    targetId));
                        } else {
                            url.setParentId(targetId + "-" + url.getParentId().substring(4));
                        }
                    }
 
                    url.setCompanyId(targetId);
                    session.saveOrUpdate(url);
                }else {
 
                    //单功能模块,只生成对应模块菜单和系统模块菜单(且系统模块菜单标记成对应模块)
                    if(model.equals(url.getSystemId()) || Constant.MODEL_SYS.equals(url.getSystemId()) || Constant.MODEL_GROUP.equals(url.getSystemId())){
                        if (url.getId().startsWith(sourceId)) {
                            url.setId(url.getId().replace(sourceId, targetId));
                        } else {
                            url.setId(targetId + "-" + url.getId().substring(4));
                        }
 
                        if (null != url.getParentId()) {
                            if (url.getParentId().startsWith(sourceId)) {
                                url.setParentId(url.getParentId().replace(sourceId,
                                        targetId));
                            } else {
                                url.setParentId(targetId + "-" + url.getParentId().substring(4));
                            }
                        }
 
                        //将系统模块标记到选中模块中
                        if(Constant.MODEL_SYS.equals(url.getSystemId())){
                            url.setSystemId(model);
                        }
 
                        url.setCompanyId(targetId);
                        session.saveOrUpdate(url);
                    }
                }
            }
        } finally {
            session.flush();
            session.close();
        }
 
        return null;
    }
 
}