package com.zjrs.zwnw.portal.bpo.impl;

import org.mohrss.leaf.core.framework.domain.bpo.impl.BPOImpl;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.zwnw.portal.blo.CommonBLO;
import com.zjrs.zwnw.portal.bpo.CommonBPO;
import com.zjrs.zwnw.portal.dto.CommonDTO;
import com.zjrs.zwnw.portal.dto.LdUserDTO;
import com.zjrs.zwnw.portal.dto.common.CommonDictDTO;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CommonBPOimpl extends BPOImpl implements CommonBPO {
    @Resource
    private CommonBLO commonBLO;

    @Override
    public Map<String, Object> getDicts(CommonDictDTO dto) {
        return commonBLO.getDicts(dto);
    }

    @Override
    public Map<String, Object> getNums() {
        return commonBLO.getNums();
    }

    @Override
    public List<Object> getOrgTree(CommonDTO dto) {
        return commonBLO.getOrgTree(dto);
    }
    @Override
    public Map<String, String> checkLDUser(){
        return this.commonBLO.checkLDUser();
    }
    @Override
    public Map<String, String> bindLDUser(LdUserDTO dto){
        return this.commonBLO.bindLDUser(dto);
    }
    @Override
    public void unbindLDUser(){
        this.commonBLO.unbindLDUser();
    }
    @Override
    public AjaxResponse checkRequestParameter(BindingResult bindingResult){
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.setAppcode("1");
        List<FieldError> fieldErrors = bindingResult.getFieldErrors();
        String errmsg = "";
        for (int i=0;i<fieldErrors.size();i++){
            if (i == 0){
                errmsg = errmsg + fieldErrors.get(i).getDefaultMessage();
            } else {
                errmsg = errmsg + "；" + fieldErrors.get(i).getDefaultMessage();
            }
        }
        ajaxResponse.setErrorMsg(errmsg);
        return ajaxResponse;
    }
}
