CZT
2023-10-11 564295458c720206db9b5194b90481b711f4b010
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
package com.ld.igds.view.service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.models.DicSysConf;
import com.ld.igds.util.ContextUtil;
 
@Component
public class SysConfService extends HibernateDao {
    
    @Autowired
    private CoreCommonService coreCommonService;
    
    public DicSysConf getSysConf(String companyId) {
        String hql = " from " + DicSysConf.class.getName()
                + " where companyId=:companyId";
        
        if(null == companyId){
            companyId = ContextUtil.getDefaultCompanyId();
        }
        
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("companyId", companyId);
 
        List<DicSysConf> list = this.query(hql, args);
 
        if (null == list || list.isEmpty()) {
            return new DicSysConf();
        }
 
        return list.get(0);
    }
 
    public void updateSysConf(DicSysConf data) throws Exception {
        Session session = this.getSessionFactory().openSession();
        try {
            if (null == data.getCompanyId()) {
                data.setCompanyId(ContextUtil.getCompanyId());
            }
            session.saveOrUpdate(data);
            
            coreCommonService.setCacheSysConf(data.getCompanyId(),data);
            
        } finally {
            session.flush();
            session.close();
        }
    }
 
    public void flushCacheSysConf(String companyId) {
        
        if(null == companyId){
            companyId = ContextUtil.getCompanyId();
        }
        
        DicSysConf data = this.getSysConf(companyId);
        
        coreCommonService.setCacheSysConf(companyId,data);
    }
 
}