派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
package com.qxueyou.scc.org.service.impl;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
 
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.service.impl.CommonAppService;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.TraceUtils;
import com.qxueyou.scc.org.model.OrgText;
import com.qxueyou.scc.org.service.IOrgTextService;
 
@Service
public class OrgTextService extends CommonAppService implements IOrgTextService {
    
    /**
     * 插入OrgText - 单个
     */
    @Override
    public Result doInsertOrgText(String key,String tableName,String content){
        
        if(StringUtils.isBlank(key)){
            
            return new Result(true);
        }
        
        OrgText orgText = new OrgText();
        orgText = new OrgText();
        orgText.setKey(key);
        orgText.setTableName(tableName);
        orgText.setContent(content);
        orgText.setDeleteFlag(false);
        TraceUtils.setCreateTrace(orgText);
        save(orgText);
        
        return new Result(true,"",CollectionUtils.newObjectMap("orgTextId",orgText.getOrgTextId()));
    }
    
    /**
     * 保存OrgText - 单个
     */
    @Override
    public Result doSaveOrgText(String key,String tableName,String content) {
 
        if(StringUtils.isBlank(key)){
            return new Result(true);
        }
        
        OrgText orgText = getOrgText(key, tableName);
        if(orgText == null){// 新增
            orgText = new OrgText();
            orgText.setKey(key);
            orgText.setTableName(tableName);
            orgText.setContent(content);
            orgText.setDeleteFlag(false);
            TraceUtils.setCreateTrace(orgText);
            
        }else{// 编辑
            orgText.setContent(content);
            TraceUtils.setUpdateTrace(orgText);
        }
        
        return this.save(orgText);
    }
    
    /**
     * 保存OrgText - 多个
     */
    @Override
    public Result doSaveOrgTexts(List<String> keys,String tableName,String content){
        
        if(keys.isEmpty()){
            
            return new Result(true);
        }
        
        Map<String,Object> map = getOrgTextMap(keys, tableName);
        
        for (int i = 0; i < keys.size(); i++) {
            OrgText orgText = (OrgText) map.get(keys.get(i));
            if(orgText == null){// 新增
                orgText = new OrgText();
                orgText.setKey(keys.get(i));
                orgText.setTableName(tableName);
                orgText.setContent(content);
                orgText.setDeleteFlag(false);
                TraceUtils.setCreateTrace(orgText);
            }else{// 编辑
                orgText.setContent(content);
                TraceUtils.setUpdateTrace(orgText);
            }
            save(orgText);
        }
        
        return new Result(true);
    }
    
    /**
     * 获取OrgText - 单个
     */
    @Override
    public OrgText getOrgText(String key,String tableName){
 
        String hql = "from OrgText where key=? and tableName=? and deleteFlag is false";
        return this.findUnique(hql, CollectionUtils.newList(key, tableName), OrgText.class);
    }
    
    /**
     * 获取OrgText —— 多个(组长Map:key-key,value-OrgText)
     */
    @Override
    public Map<String,Object> getOrgTextMap(List<String> keys,String tableName){
        
        if(keys.isEmpty()){
            
            return null;
        }
        
        Map<String, Object> orgTextMap = new HashMap<String, Object>();
        orgTextMap.put("keys", keys);
        orgTextMap.put("tableName", tableName);
        
        String hql = "from OrgText where key in (:keys) and tableName=:tableName and deleteFlag is false";
        List<OrgText> orgTextLst = findByComplexHql(hql, orgTextMap, OrgText.class);
        Map<String,Object> map = new HashMap<String,Object>(orgTextLst.size());
        for (OrgText orgText : orgTextLst) {
            map.put(orgText.getKey(), orgText);
        }
        
        return map;
    }
}