354798ggg
2023-10-08 58f6d099d3ba1a0c995efc52ba8558be838322d6
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
package com.product.base.service;
 
import java.util.ArrayList;
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.product.base.config.BaseErrorCode;
import com.product.base.config.CmnConst;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
 
/**
 *     材料信息
 * @author 86151
 *
 */
@Component
public class MaterialManagerService extends AbstractBaseService{
 
    @Autowired
    BaseDao baseDao;
    
    /**
     *     获取材料分类树数据
     * @return
     */
    public DataTableEntity getMaterialTypeTree() {
        return baseDao.listTable(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL_TYPE);
    }
    
    /**
     *     新增材料类型
     * @param fse
     * @return
     */
    public String saveMaterialType(FieldSetEntity fse) {
        if (BaseUtil.strIsNull(fse.getUUID())) {
            FieldSetEntity fseMaxValue = baseDao.getFieldSetEntityBySQL("SELECT IFNULL((MAX(material_type_value) + 1),0) material_type_value FROM product_project_base_material_type", new Object[] {}, false);
            fse.setValue(CmnConst.MATERIAL_TYPE_VALUE, fseMaxValue.getString(CmnConst.MATERIAL_TYPE_VALUE));
        } else {
            if ("0".equals(fse.getString(CmnConst.IS_USED))) {
                StringBuilder sb = new StringBuilder(256);
                sb.append("SELECT SUM(num)num FROM ( ")
                .append(" select COUNT(*)num from product_project_budget A  where a.material_type=? ")
                .append(" UNION ALL ")
                .append(" select COUNT(*)num from product_project_base_material WHERE  FIND_IN_SET (?,material_type)>0 ")
                .append(" )A ");
                FieldSetEntity fseCount = baseDao.getFieldSetEntityBySQL(sb.toString(), new Object[] { fse.getString("material_type_value"),fse.getString("material_type_value") }, false);
                if (fseCount.getInteger("num")<1) {
                    baseDao.executeUpdate("DELETE FROM product_project_base_material_type WHERE uuid=?", new Object[] {fse.getUUID()});
                    return fse.getUUID();
                }
            }
        }
        baseDao.saveFieldSetEntity(fse);
        return fse.getUUID();
    }
    
    /**
     *     分页获取材料信息
     * @param fse
     * @return
     */
    public DataTableEntity listMaterialInfo(FieldSetEntity fse) {
        DataTableEntity dt;
        if (BaseUtil.strIsNull(fse.getString(CmnConst.MATERIAL_TYPE)) || fse.getInteger(CmnConst.MATERIAL_TYPE)==-1) {
            dt = baseDao.listTable(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, null, null, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
        }else {
            dt = baseDao.listTable(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, "material_type like ?", new Object[] {"%"+fse.getInteger(CmnConst.MATERIAL_TYPE)+"%"}, null, null, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
        }
        
        baseDao.loadPromptData(dt);
        return dt;
    }
    
    
    /**
     *     保存材料信息
     * @param fse
     * @return
     */
    public boolean saveMaterialInfo(FieldSetEntity fse) {
        
        //验重条件
        String filter = "material_code=?";
        List<String> param = new ArrayList<>();
        param.add(fse.getString(CmnConst.MATERIAL_CODE));
        
        SystemUser sysUser = SpringMVCContextHolder.getCurrentUser();
        if (BaseUtil.strIsNull(fse.getUUID())) {
            BaseUtil.createCreatorAndCreationTime(sysUser, fse);
        }else {
            filter += " AND uuid !=?";
            param.add(fse.getUUID());
            BaseUtil.updatedRegeneratorAndUpdateTime(sysUser, fse);
        }
        FieldSetEntity fseExistMaterialCode = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_PROJECT_BASE_MATERIAL, filter, param.toArray(), false);
        if (fseExistMaterialCode!=null) {
            throw new BaseException(BaseErrorCode.PROJECT_BASE_MATERIAL_CODE_REPEAT.getValue(), BaseErrorCode.PROJECT_BASE_MATERIAL_CODE_REPEAT.getText());
        }
        return baseDao.saveFieldSetEntity(fse);
    }
}