package com.tuoheng.admin.service.inspectionfile.delete;

import cn.hutool.core.collection.CollectionUtil;
import com.tuoheng.admin.mapper.InspectionFileMapper;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 修改任务问题类型业务层处理
 *
 * @author wanjing
 * @team tuoheng
 * @date 2022-12-16
 */
@Slf4j
@Service
public class DeleteInspectionFileByIdListService {

    @Autowired
    private InspectionFileMapper inspectionFileMapper;

    /**
     * 修改任务问题类型
     *
     * @return
     */
    public JsonResult deletedByIdList(List<String> idList) {
        log.info("进入删除问题接口");
        String userId = CurrentUserUtil.getUserId();
        JsonResult result = this.check(idList);
        if (0 != result.getCode()) {
            log.info("修改任务问题类型业务接口：校验失败：{}", result.getMsg());
            return result;
        }

        Map<String, Object> map = new HashMap<>();
        map.put("idList", idList);
        map.put("mark", 0);
        map.put("updateUser", userId);
        map.put("updateTime", DateUtils.now());
        Integer rowId = inspectionFileMapper.deleteLogicByIdList(map);
        if (rowId <= 0) {
            log.info("删除问题失败：inspectionFileId:{}", idList);
            throw new ServiceException("删除问题失败");
        }
        return JsonResult.success();
    }

    /**
     * 检查参数
     *
     * @param idList
     * @return
     */
    private JsonResult check(List<String> idList) {
        if (CollectionUtil.isEmpty(idList)) {
            throw new ServiceException("问题ID为空");
        }
        return JsonResult.success();
    }

}
