# SysServiceImpl.java

    package com.mycim.server.system.service;

    import com.alipay.sofa.runtime.api.annotation.SofaService;
    import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
    import com.fa.sesa.i18n.Languages;
    import com.mycim.framework.jdbc.Page;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.collections.CollectionUtils;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.server.base.manager.RelationManager;
    import com.mycim.server.system.manager.*;
    import com.mycim.valueobject.SystemConstant;
    import com.mycim.valueobject.bas.NamedObject;
    import com.mycim.valueobject.bas.Relation;
    import com.mycim.valueobject.consts.ReferenceFileConst;
    import com.mycim.valueobject.security.SecurityClass;
    import com.mycim.valueobject.sys.*;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.util.Collection;
    import java.util.List;
    import java.util.Map;

    /**
     * @author Johnson W
     */
    @Service
    @SofaService(interfaceType = SysService.class, bindings = {@SofaServiceBinding(bindingType = "bolt")})
    public class SysServiceImpl implements SysService {

        @Autowired
        private LabelManager labelManager;

        @Autowired
        private MessageManager messageManager;

        @Autowired
        private FieldManager fieldManager;

        @Autowired
        private CheckRuleManager checkRuleManager;

        @Autowired
        private ScreenManager screenManager;

        @Autowired
        private FacilityManager facilityManager;

        @Autowired
        private ValidatorManager validatorManager;

        @Autowired
        private ShiftManager shiftManager;

        @Autowired
        private TaskManager taskManager;

        @Autowired
        private ObjectAttributeManager attributeManager;

        @Autowired
        private SysParameterSetManager sysParameterSetManager;

        @Autowired
        private ReferenceFileManager referenceFileManager;

        @Autowired
        private RelationManager relationManager;

        @Autowired
        private LoginManager loginManager;

        @Override
        public long insertLabel(Label label) {
            return labelManager.insertLabel(label);
        }

        @Override
        public long insertMessage(Message message) {
            return messageManager.insertMessage(message);
        }

        @Override
        public long insertField(Field field) {
            return fieldManager.insertField(field);
        }

        @Override
        public List<CheckRule> getCheckRules(Field field) {
            return checkRuleManager.getCheckRules(field.getInstanceRrn());
        }

        @Override
        public boolean checkRMSFlagReference(String lotType) {
            String rmsFlag = getReferenceFileData1ValueByKey1Value("$$LOTTYPE_RMSFLAG",lotType);//当查询不到对应的值时，此函数返回值为第二个参数,即rmsFlag不会为空
            if (StringUtils.equalsIgnoreCase(SystemConstant.Str.ONE, rmsFlag)) {//只有lotType对应的RMSFlag值为"1"时,返回值为true
                return true;
            }
            return false;
        }

        @Override
        public void updateField(Field field) {
            fieldManager.updateField(field);
        }

        @Override
        public void deleteField(Field field) {
            fieldManager.deleteField(field);
        }

        @Override
        public Field getField(String fieldId, String namedSpace) {
            return fieldManager.getField(fieldId, namedSpace);
        }

        @Override
        public Field getField(long filedRrn) {
            return fieldManager.getField(filedRrn);
        }

        @Override
        public Field getField(Field field) {
            return fieldManager.getField(field);
        }

        @Override
        public long insertFacility(Facility facility) {
            return facilityManager.insertFacility(facility);
        }

        @Override
        public void updateFacility(Facility facility) {
            facilityManager.updateFacility(facility);
        }

        @Override
        public void deleteFacility(Facility facility) {
            facilityManager.deleteFacility(facility);
        }

        @Override
        public Facility getFacility(String facilityId, String namedSpace) {
            return facilityManager.getFacility(facilityId, namedSpace);
        }

        @Override
        public Facility getFacility(long facilityRrn) {
            return facilityManager.getFacility(facilityRrn);
        }

        @Override
        public Facility getFacility(Facility facility) {
            return facilityManager.getFacility(facility);
        }

        @Override
        public void updateNamedSpaceDefOfFacility(Facility facility) {
            facilityManager.updateNamedSpaceDefOfFacility(facility);
        }

        @Override
        public Collection getNamedSpaceDef(Facility facility) {
            return facilityManager.getNamedSpaceDef(facility.getInstanceRrn());
        }

        @Override
        public Label getLabel(Label label) {
            return labelManager.getLabel(label);
        }

        @Override
        public Message getMessage(Message message) {
            return messageManager.getMessage(message);
        }

        @Override
        public void updateLabel(Label label) {
            labelManager.updateLabel(label);
        }

        @Override
        public void updateMessage(Message message) {
            messageManager.updateMessage(message);
        }

        @Override
        public void deleteLabel(Label label) {
            labelManager.deleteLabel(label);
        }

        @Override
        public void deleteMessage(Message message) {
            messageManager.deleteMessage(message);
        }

        @Override
        public Collection getLabelItems(NamedObject namedObject) {
            return labelManager.getLabelItems(namedObject.getInstanceRrn());
        }

        @Override
        public List<MessageDetail> getMessageItems(NamedObject namedObject) {
            return messageManager.getMessageDetails(namedObject.getInstanceRrn());
        }

        @Override
        public void updateMessageDetail(long messageRrn, MessageDetail messageDetail) {
            messageManager.updateMessageDetail(messageRrn, messageDetail);
        }

        @Override
        public void updateLabelItem(long labelRrn, LabelItem labelItem) {
            labelManager.updateLabelItem(labelRrn, labelItem);
        }

        @Override
        public long insertScreen(Screen screen) {
            return screenManager.insertScreen(screen);
        }

        @Override
        public void updateScreen(Screen screen) {
            screenManager.updateScreen(screen);
        }

        @Override
        public void deleteScreen(Screen screen) {
            screenManager.deleteScreen(screen);
        }

        @Override
        public Screen getScreen(Screen screen) {
            return screenManager.getScreen(screen);
        }

        @Override
        public List<Validator> getScreenValidators(Screen screen) {
            return validatorManager.getScreenValidators(screen);
        }

        @Override
        public ObjectAttribute getObjectAttribute(ObjectAttribute objectAttribute) {
            return attributeManager.getObjectAttribute(objectAttribute);
        }

        @Override
        public ObjectAttributeField getObjectAttributeField(ObjectAttributeField objectAttributeField) {
            return attributeManager.getObjectAttributeField(objectAttributeField);
        }

        @Override
        public long insertObjectAttributeField(ObjectAttributeField objectAttributeField) {
            return attributeManager.insertObjectAttributeField(objectAttributeField);
        }

        @Override
        public void deleteObjectAttributeField(ObjectAttributeField objectAttributeField) {
            attributeManager.deleteObjectAttributeField(objectAttributeField);
        }

        @Override
        public void updateObjectAttributeField(ObjectAttributeField objectAttributeField) {
            attributeManager.updateObjectAttributeField(objectAttributeField);
        }

        @Override
        public ObjectAttributeIndex getObjectAttributeIndex(ObjectAttributeIndex objectAttributeIndex) {
            return attributeManager.getObjectAttributeIndex(objectAttributeIndex);
        }

        @Override
        public long insertObjectAttributeIndex(ObjectAttributeIndex objectAttributeIndex) {
            return attributeManager.insertObjectAttributeIndex(objectAttributeIndex);
        }

        @Override
        public void deleteObjectAttributeIndex(ObjectAttributeIndex objectAttributeIndex) {
            attributeManager.deleteObjectAttributeIndex(objectAttributeIndex);
        }

        @Override
        public ObjectAttributeIndex getObjectAttributeIndexs(ObjectAttributeIndex objectAttributeIndex) {
            return attributeManager.getObjectAttributeIndex(objectAttributeIndex);
        }

        @Override
        public void deleteObjectTransAttribute(ObjectTransAttribute objectTransAttribute) {
            attributeManager.deleteObjectTransAttribute(objectTransAttribute);
        }

        @Override
        public Collection getObjectTransAttributes(ObjectTransAttribute objectTransAttribute) {
            return attributeManager.getObjectTransAttributes(objectTransAttribute);
        }

        @Override
        public void insertObjectTransAttribute(ObjectTransAttribute objectTransAttribute) {
            attributeManager.insertObjectTransAttribute(objectTransAttribute);
        }

        @Override
        public void updateObjectTransAttribute(ObjectTransAttribute objectTransAttribute) {
            attributeManager.updateObjectTransAttribute(objectTransAttribute);
        }

        @Override
        public Task getTask(Task task) {
            return taskManager.getTask(task);
        }

        @Override
        public long insertTask(Task task) {
            return taskManager.insertTask(task);
        }

        @Override
        public void updateTask(Task task) {
            taskManager.updateTask(task);
        }

        @Override
        public void deleteTask(Task task) {
            taskManager.deleteTask(task);
        }

        @Override
        public long insertShift(Shift shift) {
            return shiftManager.insertShift(shift);
        }

        @Override
        public void updateShift(Shift shift) {
            shiftManager.updateShift(shift);
        }

        @Override
        public void deleteShift(Shift shift) {
            shiftManager.deleteShift(shift);
        }

        @Override
        public Shift getShift(Shift shift) {
            return shiftManager.getShift(shift);
        }

        @Override
        public Collection getObjectTransAttributes(ObjectTransAttribute objectTransAttribute, Languages language) {
            return attributeManager.getObjectTransAttributes(objectTransAttribute, language);
        }

        @Override
        public void insertSysParameterSet(SysParameterSet sysParameterSet) {
            sysParameterSetManager.insertSysParameterSet(sysParameterSet);
        }

        @Override
        public void updateSysParameterSet(SysParameterSet sysParameterSet) {
            sysParameterSetManager.updateSysParameterSet(sysParameterSet);
        }

        @Override
        public void deleteSysParameterSet(SysParameterSet sysParameterSet) {
            sysParameterSetManager.deleteSysParameterSet(sysParameterSet);
        }

        @Override
        public SysParameterSet getSysParameterSet(long instanceRrn) {
            return sysParameterSetManager.getSysParameterSet(instanceRrn);
        }

        @Override
        public List<Map> querySysParaSetList(Languages language) {
            return sysParameterSetManager.getSysParameterSetInfos(language);
        }

        @Override
        public List<Map> querySysParaSetListById(String menuRrn, Languages language) {
            return sysParameterSetManager.getSysParameterSetInfosById(menuRrn, language);
        }

        @Override
        public Map getScreenInfos(Languages language, String programId) {
            return screenManager.getScreenInfos(language, programId);
        }

        @Override
        public Map getValidateMessageList(Languages language) {
            return messageManager.getValidateMessageList(language);
        }

        @Override
        public Collection getOption(String value, String text, String table, String refFile, String where) {
            return referenceFileManager.getOption(value, text, table, refFile, where);
        }

        @Override
        public List<String> getRefFileValues(String refFileId, String key_1_value, String get_Value_key) {
            return referenceFileManager.getRefFileValues(refFileId, key_1_value, get_Value_key);
        }

        @Override
        public List<ReferenceFileDetail> getRefFileValues(String refFileId, long facility) {
            return referenceFileManager.getRefFileValues(refFileId, facility);
        }

        @Override
        public String getRefFileValue(String refFileId, String key_1_value, String get_Value_key) {
            return referenceFileManager.getRefFileValue(refFileId, key_1_value, get_Value_key);
        }

        @Override
        public String getObjectAttributeValue(long instanceRrn, int instanceVersion, long fieldRrn) {
            return attributeManager.getObjectAttributeValue(instanceRrn, instanceVersion, fieldRrn);
        }

        @Override
        public void copyNamedSpaceDef(long fromFacility, long targetFacility) {
            facilityManager.copyNamedSpaceDef(fromFacility, targetFacility);
        }

        @Override
        public List<Map> getAllAttributes(long instanceRrn, String namedSpace, String object, Languages language) {
            return attributeManager.getAllAttributeInfo(instanceRrn, namedSpace, object, language);
        }

        @Override
        public Collection getAttributesByGroup(long instanceRrn, String namedSpace, String object, Languages language,
                                               String group) {
            return null;
        }

        @Override
        public void deleteSecurityClass(SecurityClass instance) {

        }

        // @Override
        // public List<String> getRefData1Values(String referenceId) {
        //     return null;
        // }

        @Override
        public List<Map> getAllFacility() {
            return facilityManager.getAllFacility();
        }

        @Override
        public List<Map> getLabInfo() {
            return facilityManager.getLabInfo();
        }

        @Override
        public List<Map> getAllFacilityVersion() {
            return facilityManager.getAllFacilityVersion();
        }

        @Override
        public ReferenceFileDetail getReferenceFileDetail(ReferenceFileDetail detail) {
            return referenceFileManager.getReferenceFileDetail(detail);
        }

        @Override
        public boolean checkButtonFlag(long facilityRrn) {
            return facilityManager.checkButtonFlag(facilityRrn);
        }

        @Override
        public ReferenceFile getReferenceFile(ReferenceFile referenceFile) {
            return referenceFileManager.getReferenceFile(referenceFile);
        }

        @Override
        public long insertReferenceFile(ReferenceFile referenceFile) {
            return referenceFileManager.insertReferenceFile(referenceFile);
        }

        @Override
        public long insertReferenceFileDetail(ReferenceFileDetail detail) {
            return referenceFileManager.insertReferenceFileDetail(detail);
        }

        @Override
        public void deleteReferenceFile(ReferenceFile referenceFile) {
            referenceFileManager.deleteReferenceFile(referenceFile);
        }

        @Override
        public void deleteReferenceFileDetail(ReferenceFileDetail fileDetail) {
            referenceFileManager.deleteReferenceFileDetail(fileDetail);
        }

        @Override
        public void updateReferenceFile(ReferenceFile referenceFile) {
            referenceFileManager.updateReferenceFile(referenceFile);
        }

        @Override
        public void updateReferenceFileDetail(ReferenceFileDetail fileDetail) {
            referenceFileManager.updateReferenceFileDetail(fileDetail);
        }

        @Override
        public List<ReferenceFileDetail> getReferenceFileDetails(long rrn) {
            return referenceFileManager.getReferenceFileDetails(rrn);
        }

        @Override
        public List<ReferenceFileDetail> getReferenceFileDetails(ReferenceFileDetail fileDetail, Long facilityRrn) {
            return referenceFileManager.getReferenceFileDetails(fileDetail, facilityRrn);
        }

        @Override
        public String referenceDetailExchangeNull(String ref, String value, String value1) {
            return referenceFileManager.getReferenceDetailExchange(ref, value, value1);
        }

        @Override
        public String referenceDetailExchangeNull(String ref, String key_1_value, String key_2_value, String value1) {
            return referenceFileManager.getReferenceDetailExchange(ref, key_1_value, key_2_value, value1);
        }

        @Override
        public void maintainAttribute(List<Map> objectAttributeValues) {
            if (CollectionUtils.isNotEmpty(objectAttributeValues)) {
                for (Map attributeValueMap : objectAttributeValues) {
                    long instanceRrn = MapUtils.getLong(attributeValueMap, "instanceRrn", 0L);
                    int instanceVersion = Integer.parseInt((String) attributeValueMap.get("instanceVersion"));
                    long fieldRrn = MapUtils.getLongValue(attributeValueMap, "fieldRrn");
                    String attributeValue = (String) attributeValueMap.get("attributeValue");

                    if (attributeManager.isObjectAttributeValueExisted(instanceRrn, instanceVersion, fieldRrn)) {
                        attributeManager.updateObjectAttributeValue(instanceRrn, instanceVersion, fieldRrn, attributeValue);
                    } else {
                        attributeManager.insertObjectAttributeValue(instanceRrn, instanceVersion, fieldRrn, attributeValue);
                    }
                }
            }
        }

        @Override
        public List<String> getRefFileKey(String refFile, String dataValue) {
            return referenceFileManager.getRefFileKey(refFile, dataValue);
        }

        @Override
        public void batchUpdateScreensForField(long fieldRrn, Collection validators) {
            fieldManager.batchUpdateScreensForField(fieldRrn, validators);
        }

        @Override
        public String getMenuLabelText(Languages language, long labelRrn, long menuItemRrn) {
            return labelManager.getMenuLabelText(language, labelRrn, menuItemRrn);
        }

        @Override
        public void maintainAttribute(Map attributeValueMap) {
            if (MapUtils.isNotEmpty(attributeValueMap)) {
                long instanceRrn = MapUtils.getLong(attributeValueMap, "instanceRrn");
                int instanceVersion = MapUtils.getIntValue(attributeValueMap, "instanceVersion");
                long fieldRrn = MapUtils.getLong(attributeValueMap, "FIELD_RRN");
                String attributeValue = MapUtils.getString(attributeValueMap, "attributeValue");

                if (attributeManager.isObjectAttributeValueExisted(instanceRrn, instanceVersion, fieldRrn)) {
                    attributeManager.updateObjectAttributeValue(instanceRrn, instanceVersion, fieldRrn, attributeValue);
                } else {
                    attributeManager.insertObjectAttributeValue(instanceRrn, instanceVersion, fieldRrn, attributeValue);
                }
            }
        }

        @Override
        public String translateRefValue(String refFile, String value) {
            return referenceFileManager.getRefValue(refFile, value);
        }

        @Override
        public void reBuilddValidatorsOfScreen(Collection relations) {
            screenManager.reBuilddValidatorsOfScreen(relations);
        }

        @Override
        public void removeValidatorFromScreen(Relation relation) {
            screenManager.removeValidatorFromScreen(relation);
        }

        @Override
        public void addValidatorToScreen(Relation relation) {
            screenManager.addValidatorToScreen(relation);
        }

        @Override
        public void updateValidatorOfScreen(Relation relation, Validator validator) {
        }

        @Override
        public String getContentText(long fieldRrn, Languages language) {
            return labelManager.getContentText(fieldRrn, language);
        }

        @Override
        public List<String> getRefFileKeys(String reference_file, String key_1_value, String dataValue) {
            return referenceFileManager.getRefFileKeys(reference_file, key_1_value, dataValue);
        }

        @Override
        public List<Map> getAllReferenceValue(String referenceFile, String key1Value, String valuekey) {
            return referenceFileManager.getAllReferenceValue(referenceFile, key1Value, valuekey);
        }

        @Override
        public String referenceDetailExchangeByKey2(String referenceFileId, String key2Value, String getValueFiled) {
            return referenceFileManager.referenceDetailExchangeByKey2(referenceFileId, key2Value, getValueFiled);
        }

        @Override
        public List<String> getRefFileKeysByDataValue(String refFile, String dataValue, String dataValueCode) {
            return referenceFileManager.getRefFileKeysByDataValue(refFile, dataValue, dataValueCode);
        }

        @Override
        public List<Relation> getRelationsUseFromRrn(long fromRrn, String linkType) {
            return relationManager.getRelationsUseFromRrn(fromRrn, linkType);
        }

        @Override
        public List<Map> querySysParaSetList(String search, String mid) {
            return sysParameterSetManager.querySysParaSetList(search, mid);
        }

        @Override
        public String referenceDetailExchange(String reference_file, String key_1_value, String key_2_value,
                                              String get_Value_key) {
            return referenceFileManager.referenceDetailExchange(reference_file, key_1_value, key_2_value, get_Value_key);
        }

        @Override
        public List<Relation> getFullRelations(Relation relation) {
            return relationManager.getFullRelations(relation);
        }

        @Override
        public String getReferenceFileData1ValueByKey1Value(String referenceFileId, String key1Value) {
            return referenceFileManager
                    .referenceDetailExchange(referenceFileId, key1Value, ReferenceFileConst.DATA_1_VALUE);
        }

        @Override
        public String getDataPermissionFlag(long facilityRrn) {
            return facilityManager.getDataPermissionFlag(facilityRrn);
        }

        @Override
        public long getFacilityRrn(String facilityId) {
            return facilityManager.getFacilityRrn(facilityId);
        }

        @Override
        public Map<String, Object> getLoginAuthenticationInfo(Long facilityRrn) {
            return loginManager.getLoginAuthenticationInfo(facilityRrn);
        }

        @Override
        public void setLoginAuthenticationInfo(Map<String, Object> info) {
            loginManager.setLoginAuthenticationInfo(info);
        }

        @Override
        public Page querySysForPage(Page page) {
            return labelManager.querySysForPage(page);
        }

        @Override
        public Page queryRefFileForPage(Page page){
            return referenceFileManager.queryRefFileForPage(page);
        }

        @Override
        public void updateReferenceFileDetailList(List<ReferenceFileDetail> list) {
            for (ReferenceFileDetail referenceFileDetail : list) {
                referenceFileManager.updateReferenceFileDetail(referenceFileDetail);
            }
        }

    }