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.inout.InoutConstant; 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 deptId * @param foodVariety * @return */ public List listCheckItem(String checkId, String companyId, String deptId, String foodVariety) { if (StringUtils.isEmpty(companyId)) { companyId = ContextUtil.getCompanyId(); } if (StringUtils.isEmpty(deptId)) { deptId = ContextUtil.subDeptId(ContextUtil.getLoginUser()); } List list = checkStandardService.getCheckItemById(checkId, companyId); if (list == null || list.isEmpty()) { list = checkStandardService.getCheckItemByStandard(checkId, companyId, deptId, foodVariety); } return list; } public CheckUpdateResult updateCheckItems(String checkId, String companyId, List 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 (InoutConstant.CHECK_ITEM_C01.equals(item.getStandardId()) || InoutConstant.CHECK_ITEM_C020101.equals(item.getStandardId())) { if(null != item.getValue()) result.setWet(Double.valueOf(item.getValue())); } //杂质信息回填 if (InoutConstant.CHECK_ITEM_C02.equals(item.getStandardId()) || InoutConstant.CHECK_ITEM_C01010301.equals(item.getStandardId())) { if(null != item.getValue()) result.setImpurity(Double.valueOf(item.getValue())); } //先更新,更新失败则新增 int i = checkStandardService.updateCheckItem(item); if (i < 1) { checkStandardService.insertCheckItem(item); } } return result; } }