package com.pinganfu.tortoise.admin.common.biz;
import com.github.pagehelper.PageInfo;
import com.pinganfu.tortoise.admin.common.facade.IndustryFieldFacade;
import com.pinganfu.tortoise.admin.common.model.bean.*;
import com.pinganfu.tortoise.admin.common.model.request.IndustryFieldRequest;
import com.pinganfu.tortoise.admin.common.model.request.QueryCriteriaRequest;
import com.pinganfu.tortoise.admin.common.model.response.IndustryFieldResponse;
import com.pinganfu.tortoise.framework.context.TenantContext;
import com.pinganfu.tortoise.framework.domain.BusinessException;
import com.pinganfu.tortoise.framework.domain.QueryCriteria;
import com.pinganfu.tortoise.org.config.domain.IndustryField;
import com.pinganfu.tortoise.org.config.domain.IndustryFieldEnum;
import com.pinganfu.tortoise.org.config.domain.IndustryFieldScene;
import com.pinganfu.tortoise.org.config.dto.IndustryFieldAssembler;
import com.pinganfu.tortoise.org.config.service.OrganizationConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
- @author WANGHONGCHAO912
- @date 2020-12-25 9:19
*/@Service(“industryFieldFacade”)
public class IndustryFieldFacadeImpl implements IndustryFieldFacade {
private static final Logger logger = LoggerFactory.getLogger(IndustryFieldFacadeImpl.class);
@Autowired
private OrganizationConfigService organizationConfigService;
@Override
public IndustryFieldResponse addIndustryField(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
IndustryField ifield = IndustryFieldAssembler.populate(request.getIndustryFieldBean(), tenantContext, true);
organizationConfigService.addIndustryField(tenantContext, ifield);
// 新增行业字段 - 场景
List<IndustryFieldScene> iFieldScenes = IndustryFieldAssembler.populate()
organizationConfigService.addIndustryFieldScenes(tenantContext, iFieldScenes);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("addIndustryField: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("addIndustryField: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse updateIndustryField(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
IndustryField ifield = IndustryFieldAssembler.populate(request.getIndustryFieldBean(), tenantContext, false);
organizationConfigService.updateIndustryField(tenantContext, ifield);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("updateIndustryField: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("updateIndustryField: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse getIndustryFields(QueryCriteriaRequest criteria) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(criteria.getOrgCode());
QueryCriteria queryCriteria = QueryCriteria.newCriteria(criteria.getQueryCriteria());
PageInfo<IndustryField> industryFields = organizationConfigService.getIndustryFields(tenantContext, queryCriteria);
Page<IndustryFieldBean> beanPageInfo = IndustryFieldAssembler.populate(industryFields);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
response.setIndustryFieldBeans(beanPageInfo);
} catch (BusinessException be) {
logger.error("getIndustryFields: {}", criteria, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("getIndustryFields: {}", criteria, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse getIndustryField(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
IndustryField industryField = organizationConfigService.getIndustryField(tenantContext, request.getIndustryFieldBean().getFieldCode());
IndustryFieldBean industryFieldBean = IndustryFieldAssembler.populate(industryField);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
response.setIndustryField(industryFieldBean);
} catch (BusinessException be) {
logger.error("getIndustryField: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("getIndustryField: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse deleteIndustryField(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
organizationConfigService.deleteIndustryField(tenantContext, request.getIndustryFieldBean().getFieldCode());
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("deleteIndustryField: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("deleteIndustryField: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse addIndustryFieldEnum(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
IndustryFieldEnum industryFieldEnum = IndustryFieldAssembler.populate(request.getIndustryFieldEnumBean(), tenantContext, true);
organizationConfigService.addIndustryFieldEnum(tenantContext, industryFieldEnum);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("addIndustryFieldEnum: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("addIndustryFieldEnum: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse updateIndustryFieldEnum(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
IndustryFieldEnum industryFieldEnum = IndustryFieldAssembler.populate(request.getIndustryFieldEnumBean(), tenantContext, false);
organizationConfigService.updateIndustryFieldEnum(tenantContext, industryFieldEnum);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("updateIndustryFieldEnum: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("updateIndustryFieldEnum: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse getIndustryFieldEnums(QueryCriteriaRequest criteria) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(criteria.getOrgCode());
QueryCriteria queryCriteria = QueryCriteria.newCriteria(criteria.getQueryCriteria());
PageInfo<IndustryFieldEnum> industryFieldEnums = organizationConfigService.getIndustryFieldEnums(tenantContext, queryCriteria);
Page<IndustryFieldEnumBean> beanPage = IndustryFieldAssembler.populateEnum(industryFieldEnums);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
response.setIndustryFieldEnumBeans(beanPage);
} catch (BusinessException be) {
logger.error("getIndustryFieldEnums: {}", criteria, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("getIndustryFieldEnums: {}", criteria, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse getIndustryFieldEnum(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
IndustryFieldEnumBean industryFieldEnumBean = request.getIndustryFieldEnumBean();
IndustryFieldEnum industryFieldEnum = organizationConfigService.getIndustryFieldEnum(tenantContext, industryFieldEnumBean.getFieldCode(), industryFieldEnumBean.getEnumCode());
IndustryFieldEnumBean enumBean = IndustryFieldAssembler.populate(industryFieldEnum);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
response.setIndustryFieldEnumBean(enumBean);
} catch (BusinessException be) {
logger.error("getIndustryFieldEnum: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("getIndustryFieldEnum: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse deleteIndustryFieldEnum(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
IndustryFieldEnumBean industryFieldEnumBean = request.getIndustryFieldEnumBean();
organizationConfigService.deleteIndustryFieldEnum(tenantContext, industryFieldEnumBean.getFieldCode(), industryFieldEnumBean.getEnumCode());
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("deleteIndustryFieldEnum: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("deleteIndustryFieldEnum: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse addScenes(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
PageInfo<IndustryField> iFields = organizationConfigService.getIndustryFields(tenantContext,
IndustryFieldAssembler.populateFieldCodes(request.getIndustryFieldBean().getFieldCodes()));
List<IndustryFieldScene> iFieldScenes = IndustryFieldAssembler.populate(iFields, request.getIndustryFieldBean().getSceneIds(),
request.getIndustryFieldBean().getCreatedBy(),
true);
// 批量新增:行业字段可用场景
organizationConfigService.addIndustryFieldScenes(tenantContext, iFieldScenes);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("addScenes: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
} catch (Exception e) {
logger.error("addScenes: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse deleteScenes(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
PageInfo<IndustryField> iFields = organizationConfigService.getIndustryFields(tenantContext,
IndustryFieldAssembler.populateFieldCodes(request.getIndustryFieldBean().getFieldCodes()));
List<IndustryFieldScene> iFieldScenes = IndustryFieldAssembler.populate(iFields, request.getIndustryFieldBean().getSceneIds(),
request.getIndustryFieldBean().getUpdatedBy(),
false);
// 批量删除
organizationConfigService.deleteIndustryFieldScenes(tenantContext, iFieldScenes);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("deleteScenes: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
} catch (Exception e) {
logger.error("deleteScenes: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse getIndustryFieldScenes(QueryCriteriaRequest criteria) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(criteria.getOrgCode());
QueryCriteria queryCriteria = QueryCriteria.newCriteria(criteria.getQueryCriteria());
List<IndustryFieldScene> fieldScenes = organizationConfigService.getIndustryFieldScenes(tenantContext, queryCriteria);
List<IndustryFieldSceneBean> industryFieldSceneBeans = IndustryFieldAssembler.populateFieldScene(fieldScenes);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
response.setSceneBeans(industryFieldSceneBeans);
} catch (BusinessException be) {
logger.error("getIndustryFieldScenes: {}", criteria, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
response.setRespMsg(be.getMessage());
} catch (Exception e) {
logger.error("getIndustryFieldScenes: {}", criteria, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
@Override
public IndustryFieldResponse addIndustryFields(IndustryFieldRequest request) {
IndustryFieldResponse response = new IndustryFieldResponse();
try {
TenantContext tenantContext = new TenantContext(request.getOrgCode());
List<IndustryField> fields = IndustryFieldAssembler.populateIndustryField(request.getIndustryFieldBeans(), tenantContext);
organizationConfigService.addIndustryFields(tenantContext, fields);
response.setRespCode(RetCodeEnum.SUCCESS.getRetCode());
response.setRespMsg(RetCodeEnum.SUCCESS.getMsg());
} catch (BusinessException be) {
logger.error("addIndustryFields: {}", request, be);
response.setRespCode(RetCodeEnum.BUSINESS_ERROR.getRetCode());
} catch (Exception e) {
logger.error("addIndustryFields: {}", request, e);
response.setRespCode(RetCodeEnum.ERROR.getRetCode());
response.setRespMsg(RetCodeEnum.ERROR.getMsg());
}
return response;
}
}