dangsn
2024-12-03 d0ae279ff3b83358d1c07f4481a041c4ad335026
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.vci.web.dao.impl;
 
import com.vci.model.OsCodeRuleElementDO;
import com.vci.pagemodel.BatchCBO;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.PageHelper;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.dao.OsCodeRuleElementDaoI;
import com.vci.web.service.WebBoServiceI;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
 
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import static com.vci.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST;
 
/**
 * Description:编码规则明细数据操作层实现类
 *
 * @author KangDong
 * @date 2021/10/15 11:51
 */
@Repository
public class OsCodeRuleElementDaoImpl implements OsCodeRuleElementDaoI {
    /**
     * 业务类型的服务
     */
    @Autowired
    private WebBoServiceI boService;
 
    /**
     * 使用主键删除
     * @param oid 数据主键
     * @return 执行结果
     */
    @Override
    public int deleteByPrimaryKey(String oid) {
        VciBaseUtil.alertNotNull(oid,"主键");
        OsCodeRuleElementDO codeRuleElementDO = selectByPrimaryKey(oid);
        this.boService.delete(codeRuleElementDO);
        return 1;
    }
 
    /**
     * 添加数据
     * @param record 编码规则明细数据对象
     * @return 执行结果
     */
    @Override
    public int insert(OsCodeRuleElementDO record) {
        VciBaseUtil.alertNotNull(record,"要添加的数据");
        this.boService.addSave(record);
        return 1;
    }
 
    /**
     * 根据主键查询
     * @param oid 数据主键
     * @return 数据对象
     */
    @Override
    public OsCodeRuleElementDO selectByPrimaryKey(String oid) {
        VciBaseUtil.alertNotNull(oid,"主键");
        OsCodeRuleElementDO record = this.boService.selectByOid(oid,OsCodeRuleElementDO.class);
        if (record == null || StringUtils.isBlank(record.getOid())){
            throw new VciBaseException(DATA_OID_NOT_EXIST);
        }
        return record;
    }
 
    /**
     * 根据主键批量获取对象
     * @param oids 主键,包含单引号,但是不能超过1000
     * @return 数据对象列表
     */
    @Override
    public List<OsCodeRuleElementDO> selectByPrimaryKeys(String oids) {
        VciBaseUtil.alertNotNull(oids,"主键集合");
        return this.boService.selectByOidCollection(VciBaseUtil.str2List(oids),OsCodeRuleElementDO.class);
    }
 
    /**
     * 根据主键批量查询对象
     * @param oids 对象主键,使用逗号分隔,但是不能超过1000
     * @return 业务对象
     */
    @Override
    public List<OsCodeRuleElementDO> selectByPrimaryKeyCollection(Collection<String> oids) {
        VciBaseUtil.alertNotNull(oids,"主键集合");
        return this.boService.selectByOidCollection(oids,OsCodeRuleElementDO.class);
    }
 
    /**
     * 查询所有分类
     * @return 执行结果
     */
    @Override
    public List<OsCodeRuleElementDO> selectAll() {
        return this.boService.queryObject(OsCodeRuleElementDO.class,null);
    }
 
    /**
     * 更新对象
     * @param record 物料、工具基本分类数据对象
     * @return 执行结果
     */
    @Override
    public int updateByPrimaryKey(OsCodeRuleElementDO record) {
        VciBaseUtil.alertNotNull(record,"要修改的对象",record.getOid(),"主键");
        this.boService.editSave(record);
        return 1;
    }
 
    /**
     * 根据查询条件查询数据
     * @param condition 查询条件
     * @param pageHelper 分页,排序
     * @return 数据对象列表
     */
    @Override
    public List<OsCodeRuleElementDO> selectByWrapper(Map<String, String> condition, PageHelper pageHelper) {
        return this.boService.queryObject(OsCodeRuleElementDO.class,condition,pageHelper);
    }
 
    /**
     * 根据查询条件来查询总数
     * @param condition 查询条件
     * @return 总数
     */
    @Override
    public String countByWrapper(Map<String, String> condition) {
        return VciBaseUtil.getLong(String.valueOf(this.boService.queryCount(OsCodeRuleElementDO.class,condition))) + "";
    }
 
    /**
     * 根据主键获取名称
     * @param oid 主键
     * @return 中文名称
     */
    @Override
    public String selectNameByOid(String oid) {
        return selectByPrimaryKey(oid).getName();
    }
 
    /**
     * 批量删除对象
     * @param oids 对象的主键集合
     * @return 受影响的行数
     */
    @Override
    public long batchDeleteByOids(Collection<String> oids) {
        List<OsCodeRuleElementDO> dos = this.boService.selectByOidCollection(oids, OsCodeRuleElementDO.class);
        BatchCBO batchCBO = this.boService.batchDelete(dos);
        return batchCBO.getDeleteCbos().size();
    }
 
    /**
     * 使用规则查询明细,会按照序号排序
     * @param ruleOid 规则的主键
     * @return 明细数据对象
     */
    @Override
    public List<OsCodeRuleElementDO> selectByRuleOid(String ruleOid) {
        VciBaseUtil.alertNotNull(ruleOid,"规则主键");
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("pkcoderule",ruleOid);
        List<OsCodeRuleElementDO> dos = this.boService.queryObject(OsCodeRuleElementDO.class, conditionMap);
        if (CollectionUtils.isEmpty(dos)){
            return null;
        }
        return dos;
    }
 
    /**
     * 批量添加数据
     * @param elementDOS 元素的数据对象
     * @return 执行结果数
     */
    @Override
    public int batchInsert(List<OsCodeRuleElementDO> elementDOS) {
        VciBaseUtil.alertNotNull(elementDOS,"要添加的数据");
        for (OsCodeRuleElementDO elementDO : elementDOS) {
            elementDO.setCodeDateFormat(elementDO.getCodeDateFormat() == null ? "" : elementDO.getCodeDateFormat());
            elementDO.setCodeElementType(elementDO.getCodeElementType() == null ? "" : elementDO.getCodeElementType());
        }
        BatchCBO batchCBO = this.boService.batchAddSave(elementDOS);
        return batchCBO.getCreateCbos().size();
    }
 
    /**
     * 使用编码规则和排序号获取
     *
     * @param pkCodeRule 规则
     * @param orderIndex 排序号
     * @return 内容
     */
    @Override
    public List<OsCodeRuleElementDO> selectByRuleOidAndIndex(String pkCodeRule, int orderIndex) {
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("pkCodeRule",pkCodeRule);
        conditionMap.put("ruleOrderNumber",orderIndex+"");
        return boService.queryObject(OsCodeRuleElementDO.class,conditionMap);
    }
 
    /**
     * 获取编码规则明细对象,并按照排序号进行排序
     * @param pkCodeRule 规则的主键
     * @return 排序后的明细对象
     */
    @Override
    public List<OsCodeRuleElementDO> selectByRuleOidOrderByRuleOrderNumber(String pkCodeRule) {
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("pkCodeRule",pkCodeRule);
        PageHelper ph = new PageHelper(-1);
        ph.setSort("ruleordernumber");
        ph.setOrder("asc");
        return boService.queryObject(OsCodeRuleElementDO.class,conditionMap,ph);
    }
}