jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.ld.igds.sys;
 
import java.util.*;
 
import org.apache.commons.lang.StringUtils;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
 
import com.bstek.bdf2.core.CoreHibernateDao;
import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.core.exception.NoneLoginException;
import com.bstek.bdf2.core.model.Url;
import com.bstek.bdf2.core.view.frame.main.MainFrame;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.bstek.dorado.data.entity.EntityState;
import com.bstek.dorado.data.entity.EntityUtils;
 
/**
 * @since 2013-2-3
 * @author Jacky.gao
 */
@Component("core.urlMaintain")
public class UrlMaintain extends CoreHibernateDao {
 
    @Autowired
    @Qualifier(MainFrame.BEAN_ID)
    private MainFrame mainFrame;
 
    @Expose
    public void refreshUrlCache() {
        mainFrame.cacheNavigatorUrls();
    }
    
    /**
     * core.urlMaintain#loadUrls0
     * @param parentId
     * @return
     * @throws Exception
     */
    @DataProvider
    public Collection<Url> loadUrls0(String key) throws Exception {
        IUser user = ContextHolder.getLoginUser();
        if (user == null) {
            throw new NoneLoginException("Please login first");
        }
        
        if(StringUtils.isEmpty(key)){
            return loadUrls(null);
        }
        
        String companyId = user.getCompanyId();
        
        String hql = "from " + Url.class.getName()
                + " u where u.companyId=:companyId";
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("companyId", companyId);
        
        hql += " and u.parentId is null ";
        
        if (StringUtils.isEmpty(key)) {
            hql += " order by u.order asc";
            return this.query(hql, map);
        } else {
            map.put("systemId", key);
            hql += " and u.systemId=:systemId order by u.order asc";
            return this.query(hql, map);
        }
    }
 
    /**
     * core.urlMaintain#loadUrls
     * @param parentId
     * @return
     * @throws Exception
     */
    @DataProvider
    public Collection<Url> loadUrls(String parentId) throws Exception {
        IUser user = ContextHolder.getLoginUser();
        if (user == null) {
            throw new NoneLoginException("Please login first");
        }
        String companyId = user.getCompanyId();
        
        String hql = "from " + Url.class.getName()
                + " u where u.companyId=:companyId";
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("companyId", companyId);
        if (StringUtils.isEmpty(parentId)) {
            hql += " and u.parentId is null order by u.order asc";
            return this.query(hql, map);
        } else {
            map.put("parentId", parentId);
            hql += " and u.parentId=:parentId order by u.order asc";
            return this.query(hql, map);
        }
    }
 
    @DataResolver
    public void saveUrls(Collection<Url> urls) throws Exception {
        IUser user = ContextHolder.getLoginUser();
        if (user == null) {
            throw new NoneLoginException("Please login first");
        }
        String companyId = user.getCompanyId();
        Session session = this.getSessionFactory().openSession();
        try {
            for (Url url : urls) {
                EntityState state = EntityUtils.getState(url);
                if (state.equals(EntityState.NEW)) {
                    url.setId(UUID.randomUUID().toString());
                    url.setCompanyId(companyId);
                    session.save(url);
                }
                if (state.equals(EntityState.MODIFIED)
                        || state.equals(EntityState.MOVED)) {
                    session.update(url);
                }
                if (url.getChildren() != null) {
                    saveUrls(url.getChildren());
                }
                if (state.equals(EntityState.DELETED)) {
                    session.delete(url);
                }
            }
        } finally {
            session.flush();
            session.close();
        }
    }
 
    @Expose
    public int countChildren(String parentId) {
        String hql = "select count(*) from " + Url.class.getName()
                + " d where d.parentId = :parentId";
        Map<String, Object> parameterMap = new HashMap<String, Object>();
        parameterMap.put("parentId", parentId);
        return this.queryForInt(hql, parameterMap);
    }
    
 
}