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
package com.ld.igds.three.impl;
 
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.models.ThreeConf;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.RedisUtil;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
 
@Component
public class ThreeConfServiceImpl extends HibernateDao{
 
    @Autowired
    private RedisUtil redisUtil;
 
    public List<ThreeConf> getAllThreeConf(String companyId) {
        String hql = " from " + ThreeConf.class.getName() + " where companyId =:companyId";
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("companyId", companyId);
        return this.query(hql, args);
    }
 
    public void updateThreeConf(ThreeConf data) {
 
        if (null == data.getCompanyId()) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
 
        Session session = null;
        try {
            session = this.getSessionFactory().openSession();
            if (null == data.getId()) {
                data.setId(ContextUtil.getUUID());
                session.save(data);
            } else {
                session.update(data);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.flush();
            session.close();
        }
    }
 
    public void delThreeConf(ThreeConf threeConf) {
        Session session = this.getSessionFactory().openSession();
        try {
            session.delete(threeConf);
        } finally {
            session.flush();
            session.close();
        }
    }
 
 
    public void refreshCache(String companyId) {
        List<ThreeConf> list = this.getAllThreeConf(companyId);
        if (null == list || list.isEmpty()){
            return;
        }
 
        for (ThreeConf threeConf : list) {
            redisUtil.set(RedisConst.buildKey(companyId, RedisConst.KEY_THREE_CONF, threeConf.getUid()), threeConf);
        }
    }
 
}