czt
15 小时以前 256f9c48f2c52985a094a220b644d60d24cb6ed4
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
package com.ld.igds.check;
 
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.ld.igds.check.dto.CheckItemData;
import com.ld.igds.check.dto.CheckUpdateResult;
import com.ld.igds.check.service.CoreCheckStandardService;
import com.ld.igds.models.*;
import com.ld.igds.util.ContextUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 检验项 ---- 管理业务
 *
 * @author: chen
 */
@Component(CheckStandardManager.BEAN_ID)
public class CheckStandardManager extends HibernateDao {
 
    public static final String BEAN_ID = "check.checkStandardManager";
 
    @Autowired
    private CoreCheckStandardService checkStandardService;
 
    /**
     * 根据参数获取化验项列表
     *
     * @param checkId
     * @param companyId
     * @param foodVariety
     * @return
     */
    public List<CheckItemData> listCheckItem(String companyId, String checkId,
                                             String foodVariety) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
 
        List<CheckItemData> list = null;
        if (null != checkId)
            list = checkStandardService.getCheckItemById(checkId, companyId);
 
        if (list == null || list.isEmpty()) {
            list = checkStandardService.getCheckItemByStandard(companyId, checkId, foodVariety);
        }
 
        return list;
    }
 
    public CheckUpdateResult updateCheckItems(String checkId, String companyId, List<CheckItemData> checkItems) {
 
        CheckUpdateResult result = new CheckUpdateResult();
        if (null == checkItems || checkItems.isEmpty()) {
            return result;
        }
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
 
        for (CheckItemData item : checkItems) {
            if (null == item.getCheckId()) {
                item.setCheckId(checkId);
            }
            item.setCompanyId(companyId);
            if (item.getUpperLimit() == null) {
                item.setUpperLimit(0.0);
            }
 
            if (null != item.getDeNum() && item.getDeNum() > 0) {
                result.setDeSum(result.getDeSum() + item.getDeNum());
            }
            if (null != item.getAddNum() && item.getAddNum() > 0) {
                result.setAddSum(result.getAddSum() + item.getAddNum());
            }
            if (null != item.getAddPrice() && item.getAddPrice() > 0) {
                result.setAddPriceSum(result.getAddPriceSum()
                        + item.getAddPrice());
            }
            if (null != item.getDePrice() && item.getDePrice() > 0) {
                result.setDePriceSum(result.getDePriceSum() + item.getDePrice());
            }
 
            //如果没有外键不执行持久化操作
            if (null == checkId) return result;
 
            // 先更新,更新失败则新增
            int i = checkStandardService.updateCheckItem(item);
            if (i < 1) {
                checkStandardService.insertCheckItem(item);
            }
        }
        return result;
    }
 
    /************省质检报告检验项**************/
 
    /**
     * 大豆
     * @param param
     * @return
     */
    public List<CheckItemDd> findDataDd(Map<String, Object> param){
        String hql = " from " + CheckItemDd.class.getName()
                + " where 1 =1";
 
        Map<String,Object> args = new HashMap<String,Object>();
        if(null != param){
            String str = (String) param.get("qlyOrgReportId");
            if (StringUtils.isNotEmpty(str)) {
                hql += " and qlyOrgReportId =:qlyOrgReportId";
                args.put("qlyOrgReportId", str);
            }
        }
        hql += " order by qlyOrgReportSoybeanId";
        return this.query(hql, args);
    }
 
    /**
     * 大米
     * @param param
     * @return
     */
    public List<CheckItemDm> findDataDm(Map<String, Object> param){
        String hql = " from " + CheckItemDm.class.getName()
                + " where 1 =1";
 
        Map<String,Object> args = new HashMap<String,Object>();
        if(null != param){
            String str = (String) param.get("qlyOrgReportId");
            if (StringUtils.isNotEmpty(str)) {
                hql += " and qlyOrgReportId =:qlyOrgReportId";
                args.put("qlyOrgReportId", str);
            }
        }
        hql += " order by qlyOrgReportRiceId";
        return this.query(hql, args);
    }
 
    /**
     * 大米
     * @param param
     * @return
     */
    public List<CheckItemXmf> findDataXmf(Map<String, Object> param){
        String hql = " from " + CheckItemXmf.class.getName()
                + " where 1 =1";
 
        Map<String,Object> args = new HashMap<String,Object>();
        if(null != param){
            String str = (String) param.get("qlyOrgReportId");
            if (StringUtils.isNotEmpty(str)) {
                hql += " and qlyOrgReportId =:qlyOrgReportId";
                args.put("qlyOrgReportId", str);
            }
        }
        hql += " order by qlyOrgReportNoodlesId";
        return this.query(hql, args);
    }
 
    /**
     * 大米
     * @param param
     * @return
     */
    public List<CheckItemSyy> findDataSyy(Map<String, Object> param){
        String hql = " from " + CheckItemSyy.class.getName()
                + " where 1 =1";
 
        Map<String,Object> args = new HashMap<String,Object>();
        if(null != param){
            String str = (String) param.get("qlyOrgReportId");
            if (StringUtils.isNotEmpty(str)) {
                hql += " and qlyOrgReportId =:qlyOrgReportId";
                args.put("qlyOrgReportId", str);
            }
        }
        hql += " order by qlyOrgReportOilId";
        return this.query(hql, args);
    }
 
}