jiazx0107@163.com
2023-06-23 7b5c179e17c9a106dcce3b2b0574af833cf97132
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
package com.ld.igds.check;
 
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.util.ContextUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
/**
 * 检验项 ---- 管理业务
 *
 * @author: chen
 */
@Component(CheckStandardManager.BEAN_ID)
public class CheckStandardManager {
 
    public static final String BEAN_ID = "check.checkStandardManager";
 
    @Autowired
    private CoreCheckStandardService checkStandardService;
 
 
    /**
     * 根据参数获取化验项列表
     *
     * @param checkId
     * @param companyId
     * @param foodVariety
     * @return
     */
    public List<CheckItemData> listCheckItem(String checkId, String companyId, String foodVariety) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getCompanyId();
        }
 
        List<CheckItemData> list = checkStandardService.getCheckItemById(checkId, companyId);
 
        if (list == null || list.isEmpty()) {
            list = checkStandardService.getCheckItemByStandard(checkId, companyId, 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());
            }
 
            //先更新,更新失败则新增
            int i = checkStandardService.updateCheckItem(item);
            if (i < 1) {
                checkStandardService.insertCheckItem(item);
            }
        }
        return result;
    }
}