jiazx0107@163.com
2023-07-04 785ce007ce4b7b2119a99aacc95cefe9da09e32e
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
package com.ld.igds.view.service;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Component;
 
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.bstek.dorado.data.entity.EntityState;
import com.bstek.dorado.data.entity.EntityUtils;
import com.ld.igds.constant.Constant;
import com.ld.igds.models.DicSlogan;
import com.ld.igds.util.ContextUtil;
 
/**
 * 
 * @author Andy
 *
 */
@Component
public class SloganService extends HibernateDao {
 
    public List<DicSlogan> loadData(Map<String, Object> parameter) {
 
        String hql = " from " + DicSlogan.class.getName()
                + " where companyId=:companyId order by id + 0";
        if (null == parameter) {
            parameter = new HashMap<String, Object>();
        }
        String companyId = (String) parameter.get("companyId");
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
 
        parameter.put("companyId", companyId);
        return this.query(hql, parameter);
 
    }
 
    public String saveAll(List<DicSlogan> items) {
        Session session = this.getSessionFactory().openSession();
        try {
            EntityState state;
            for (DicSlogan item : items) {
                state = EntityUtils.getState(item);
                if (state == EntityState.NEW) {
                    item.setId(System.currentTimeMillis() + "");
                    item.setCompanyId(ContextUtil.getCompanyId());
                    item.setCreateTime(new Date());
                    item.setCreateUser(ContextUtil.getLoginUser().getUsername());
                    session.save(item);
                }
                
                if (state == EntityState.DELETED) {
                    session.delete(item);
                }
                
                if (state == EntityState.MODIFIED) {
                    item.setUpdateTime(new Date());
                    item.setUpdateUser(ContextUtil.getLoginUser().getUsername());
                    session.update(item);
                }
                
            }
        } finally {
            session.flush();
            session.close();
        }
        return null;
    }
 
    public void updateStatusY(DicSlogan items) {
        Session session = this.getSessionFactory().openSession();
        try {
            items.setPushTime(new Date());
            items.setPushUser(ContextUtil.getLoginUser().getUsername());
            items.setStatus(Constant.YN_Y);
            session.update(items);
        } finally {
            session.flush();
            session.close();
        }
    }
 
    public void updateStatusN() {
        Session session = this.getSessionFactory().openSession();
        try {
            String hql = " update " + DicSlogan.class.getName()
                    + " set status =:status where companyId=:companyId ";
            String companyId = (String) ContextUtil.getCompanyId();
            Query query = session.createQuery(hql);
            query.setString("companyId", companyId);
            query.setString("status", Constant.YN_N);
            query.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.flush();
            session.close();
        }
    }
}