许鹏程
2023-05-25 213cc37cbf0b2515a4de56cc1e01813211bad183
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
package com.product.admin.service;
 
import com.product.core.entity.FieldSetEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.product.core.dao.BaseDao;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.util.CodeUtil;
 
@Component
public class CodeService extends AbstractBaseService {
    /**
     * 数据查询 ,spring 注入
     */
    @Autowired
    public BaseDao baseDao;
 
    public String createCode(FieldSetEntity fse, String table, String field, String parentCode) throws BaseException {
        fse.setValue(field, CodeUtil.getNewCodeByTemp(table, field, parentCode == null ? "" : parentCode));
        fse.setCodeFieldUpdateFlat(field, true);
        return fse.getString(field);
    }
 
    /**
     * 获取临时编码
     *
     * @param table      表名
     * @param field      字段名
     * @param parentCode 上级编码,如果没有上级编码,则为"",不能为null
     * @return
     * @throws BaseException
     */
    public String createCode(String table, String field, String parentCode) throws BaseException {
        return CodeUtil.getNewCodeByTemp(table, field, parentCode == null ? "" : parentCode);
    }
 
    /**
     * 获取固定编码,除导入数据时要求自动生成外,不要调些方法
     *
     * @param table      表名
     * @param field      字段名
     * @param parentCode 上级编码,如果没有上级编码,则为"",不能为null
     * @return
     * @throws BaseException
     */
    public String createFixCode(String table, String field, String parentCode) throws BaseException {
        return CodeUtil.getNewCode(table, field, CodeUtil.getNewCodeByTemp(table, field, parentCode));
    }
}