package com.zcloud.primeport.service;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.primeport.api.MkmjApprovalUserServiceI;
import com.zcloud.primeport.command.MkmjApprovalUserAddExe;
import com.zcloud.primeport.command.MkmjApprovalUserRemoveExe;
import com.zcloud.primeport.command.MkmjApprovalUserUpdateExe;
import com.zcloud.primeport.command.query.MkmjApprovalUserQueryExe;
import com.zcloud.primeport.dto.MkmjApprovalUserAddCmd;
import com.zcloud.primeport.dto.MkmjApprovalUserPageQry;
import com.zcloud.primeport.dto.MkmjApprovalUserUpdateCmd;
import com.zcloud.primeport.dto.clientobject.AvailableResultCO;
import com.zcloud.primeport.dto.clientobject.MkmjApprovalUserCO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * web-app
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:17
 */
@Service
@AllArgsConstructor
public class MkmjApprovalUserServiceImpl implements MkmjApprovalUserServiceI {
    private final MkmjApprovalUserAddExe mkmjApprovalUserAddExe;
    private final MkmjApprovalUserUpdateExe mkmjApprovalUserUpdateExe;
    private final MkmjApprovalUserRemoveExe mkmjApprovalUserRemoveExe;
    private final MkmjApprovalUserQueryExe mkmjApprovalUserQueryExe;

    @Override
    public PageResponse<MkmjApprovalUserCO> listPage(MkmjApprovalUserPageQry qry) {

        return mkmjApprovalUserQueryExe.execute(qry);
    }

    @Override
    public SingleResponse add(MkmjApprovalUserAddCmd cmd) {

        mkmjApprovalUserAddExe.execute(cmd);
        return SingleResponse.buildSuccess();
    }

    @Override
    public void edit(MkmjApprovalUserUpdateCmd mkmjApprovalUserUpdateCmd) {
        mkmjApprovalUserUpdateExe.execute(mkmjApprovalUserUpdateCmd);
    }

    @Override
    public void remove(Long id) {
        mkmjApprovalUserRemoveExe.execute(id);
    }

    @Override
    public void removeBatch(Long[] ids) {
        mkmjApprovalUserRemoveExe.execute(ids);
    }

    @Override
    public List<MkmjApprovalUserCO> listAll(MkmjApprovalUserPageQry qry) {
        return mkmjApprovalUserQueryExe.listAll(qry);
    }

    @Override
    public MkmjApprovalUserCO getInfoById(Long id) {
        return mkmjApprovalUserQueryExe.getInfoById(id);
    }

    @Override
    public SingleResponse<AvailableResultCO> checkExistByUserId(Long userId) {
        AvailableResultCO result = new AvailableResultCO();
        if (!mkmjApprovalUserQueryExe.getByUserId(userId).isEmpty()) {
            result.setAvailable(false);
            result.setAvailableMessage("该审批人已录入，不可重复添加");
        } else {
            result.setAvailable(true);
        }
        return SingleResponse.of(result);
    }
}

