package com.changhong.epc.tenant.service.norm.impl.value;
|
|
import com.changhong.epc.bean.count.MeInfo;
|
import com.changhong.epc.bean.tenant.master.AutoMasterVal;
|
import com.changhong.epc.bean.tenant.master.MasterElement;
|
import com.changhong.epc.bean.tenant.master.extend.MasterDefinesExtend;
|
import com.changhong.epc.config.service.MasterValueService;
|
import com.changhong.epc.rely.api.epc.admin.AdminMasterApi;
|
import com.changhong.epc.tenant.service.norm.impl.SimplAbstractMasterTools;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 自定义查询主数据值
|
*/
|
@Service
|
@Slf4j
|
public class AutoMasterTools extends SimplAbstractMasterTools<AutoMasterVal, String> {
|
|
@Resource
|
private MasterValueService masterValueService;
|
|
@Resource
|
private AdminMasterApi adminMasterApi;
|
|
@Override
|
protected String adminOneDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
|
return adminMasterApi.adminOneDimensional(autoMasterVal);
|
}
|
|
@Override
|
protected String adminTwoDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
|
return adminMasterApi.adminTwoDimensional(
|
getTwoDimensionalParam(masterDefine, autoMasterVal));
|
}
|
|
@Override
|
protected String tenantOneDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
|
return masterValueService.getValString(
|
autoMasterVal.getMdCode()
|
, autoMasterVal.getMeCode()
|
, autoMasterVal.getParams());
|
}
|
|
@Override
|
protected String tenantTwoDimensional(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal) {
|
AutoMasterVal towDimensional = getTwoDimensionalParam(masterDefine, autoMasterVal);
|
return masterValueService.getValTwoDimensional(
|
towDimensional.getMdCode()
|
, towDimensional.getMeCode()
|
, towDimensional.getParams()
|
);
|
}
|
|
public AutoMasterVal getTwoDimensionalParam(MasterDefinesExtend masterDefine, AutoMasterVal autoMasterVal){
|
MasterElement field = getMasterElement(masterDefine.getEleList(), autoMasterVal.getMeCode());
|
if(ObjectUtil.empty(field) || ObjectUtil.empty(field.getDefMapTalbeField())){
|
log.warn("twoDimensional'{}'返回元素没有映射!", autoMasterVal.getMeCode());
|
return null;
|
}
|
|
List<MeInfo> params =
|
autoMasterVal.getParams().stream().filter(param->{
|
MasterElement paramField = getMasterElement(masterDefine.getEleList(), param.getLeftMeCode());
|
if(ObjectUtil.empty(paramField) || ObjectUtil.empty(paramField.getDefMapTalbeField())){
|
log.warn("twoDimensional'{}'条件元素没有映射!", param.getLeftMeCode());
|
return false;
|
}
|
param.setFieldName(paramField.getDefMapTalbeField());
|
return true;
|
}).collect(Collectors.toList());
|
|
return new AutoMasterVal(masterDefine.getDefMapTableName(), field.getDefMapTalbeField(), params);
|
}
|
|
public MasterElement getMasterElement(List<MasterElement> masterElementList, String meCode){
|
if(ObjectUtil.empty(masterElementList)){
|
return null;
|
}
|
return masterElementList.stream().filter(ele->Objects.equals(ele.getCode(), meCode)).findFirst().orElse(null);
|
}
|
}
|