package com.hw.system.common.service.impl;

import java.util.List;
import com.hw.common.core.utils.DateUtils;
import com.hw.system.api.domain.common.WfProcessActivityAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hw.system.common.mapper.WfProcessActivityAuthMapper;
import com.hw.system.common.service.IWfProcessActivityAuthService;

/**
 * 工单流程节点步骤权限Service业务层处理
 *
 * @author Open Platform
 * @date 2024-01-25
 */
@Service
public class WfProcessActivityAuthServiceImpl implements IWfProcessActivityAuthService
{
    @Autowired
    private WfProcessActivityAuthMapper wfProcessActivityAuthMapper;

    /**
     * 查询工单流程节点步骤权限
     *
     * @param processActivityAuthId 工单流程节点步骤权限主键
     * @return 工单流程节点步骤权限
     */
    @Override
    public WfProcessActivityAuth selectWfProcessActivityAuthByProcessActivityAuthId(Long processActivityAuthId)
    {
        return wfProcessActivityAuthMapper.selectWfProcessActivityAuthByProcessActivityAuthId(processActivityAuthId);
    }

    /**
     * 查询工单流程节点步骤权限列表
     *
     * @param wfProcessActivityAuth 工单流程节点步骤权限
     * @return 工单流程节点步骤权限
     */
    @Override
    public List<WfProcessActivityAuth> selectWfProcessActivityAuthList(WfProcessActivityAuth wfProcessActivityAuth)
    {
        return wfProcessActivityAuthMapper.selectWfProcessActivityAuthList(wfProcessActivityAuth);
    }

    /**
     * 新增工单流程节点步骤权限
     *
     * @param wfProcessActivityAuth 工单流程节点步骤权限
     * @return 结果
     */
    @Override
    public int insertWfProcessActivityAuth(WfProcessActivityAuth wfProcessActivityAuth)
    {

        wfProcessActivityAuth.setCreateTime(DateUtils.getNowDate());
        wfProcessActivityAuth.setAuthTargetType("1");
        String authTargetIds = wfProcessActivityAuth.getParams().get("authTargetId").toString();
//        System.out.println();
        String[] split = authTargetIds.substring(1, authTargetIds.length() - 1).split(",");

        for (int i = 0; i < split.length;i++){
        wfProcessActivityAuth.setAuthTargetId(Long.valueOf(split[i].replaceAll(" ","")));
            int flag = wfProcessActivityAuthMapper.insertWfProcessActivityAuth(wfProcessActivityAuth);
            if (flag ==0){
                return 0;
            }
        }
        return 1;
    }

    /**
     * 修改工单流程节点步骤权限
     *
     * @param wfProcessActivityAuth 工单流程节点步骤权限
     * @return 结果
     */
    @Override
    public int updateWfProcessActivityAuth(WfProcessActivityAuth wfProcessActivityAuth)
    {
        wfProcessActivityAuth.setUpdateTime(DateUtils.getNowDate());
        return wfProcessActivityAuthMapper.updateWfProcessActivityAuth(wfProcessActivityAuth);
    }

    /**
     * 批量删除工单流程节点步骤权限
     *
     * @param processActivityAuthIds 需要删除的工单流程节点步骤权限主键
     * @return 结果
     */
    @Override
    public int deleteWfProcessActivityAuthByProcessActivityAuthIds(Long[] processActivityAuthIds)
    {
        return wfProcessActivityAuthMapper.deleteWfProcessActivityAuthByProcessActivityAuthIds(processActivityAuthIds);
    }

    /**
     * 删除工单流程节点步骤权限信息
     *
     * @param processActivityAuthId 工单流程节点步骤权限主键
     * @return 结果
     */
    @Override
    public int deleteWfProcessActivityAuthByProcessActivityAuthId(Long processActivityAuthId)
    {
        return wfProcessActivityAuthMapper.deleteWfProcessActivityAuthByProcessActivityAuthId(processActivityAuthId);
    }

    @Override
    public List<WfProcessActivityAuth> selectUserAuth(WfProcessActivityAuth wfProcessActivityAuth) {
        return wfProcessActivityAuthMapper.selectUserAuth(wfProcessActivityAuth);
    }
}
