package com.xinelu.manage.service.tasktypedict.impl;

import com.xinelu.common.constant.Constants;
import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.common.utils.codes.GenerateSystemCodeUtil;
import com.xinelu.manage.domain.tasktypedict.TaskTypeDict;
import com.xinelu.manage.mapper.tasktypedict.TaskTypeDictMapper;
import com.xinelu.manage.service.tasktypedict.ITaskTypeDictService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 任务类型字典Service业务层处理
 *
 * @author xinelu
 * @date 2024-03-11
 */
@Service
public class TaskTypeDictServiceImpl implements ITaskTypeDictService {
    @Resource
    private TaskTypeDictMapper taskTypeDictMapper;
    @Resource
    private GenerateSystemCodeUtil generateSystemCodeUtil;

    /**
     * 查询任务类型字典
     *
     * @param id 任务类型字典主键
     * @return 任务类型字典
     */
    @Override
    public TaskTypeDict selectTaskTypeDictById(Long id) {
        return taskTypeDictMapper.selectTaskTypeDictById(id);
    }

    /**
     * 查询任务类型字典列表
     *
     * @param taskTypeDict 任务类型字典
     * @return 任务类型字典
     */
    @Override
    public List<TaskTypeDict> selectTaskTypeDictList(TaskTypeDict taskTypeDict) {
        return taskTypeDictMapper.selectTaskTypeDictList(taskTypeDict);
    }

    /**
     * 新增任务类型字典
     *
     * @param taskTypeDict 任务类型字典
     * @return 结果
     */
    @Override
    public int insertTaskTypeDict(TaskTypeDict taskTypeDict) {
        taskTypeDict.setTaskTypeCode(Constants.TASK_TYPE_CODE + generateSystemCodeUtil.generateSystemCode(Constants.TASK_TYPE_CODE));
        taskTypeDict.setCreateTime(LocalDateTime.now());
        taskTypeDict.setCreateBy(SecurityUtils.getUsername());
        return taskTypeDictMapper.insertTaskTypeDict(taskTypeDict);
    }

    /**
     * 修改任务类型字典
     *
     * @param taskTypeDict 任务类型字典
     * @return 结果
     */
    @Override
    public int updateTaskTypeDict(TaskTypeDict taskTypeDict) {
        taskTypeDict.setUpdateTime(LocalDateTime.now());
        taskTypeDict.setUpdateBy(SecurityUtils.getUsername());
        return taskTypeDictMapper.updateTaskTypeDict(taskTypeDict);
    }

    /**
     * 批量删除任务类型字典
     *
     * @param ids 需要删除的任务类型字典主键
     * @return 结果
     */
    @Override
    public int deleteTaskTypeDictByIds(Long[] ids) {
        return taskTypeDictMapper.deleteTaskTypeDictByIds(ids);
    }

    /**
     * 删除任务类型字典信息
     *
     * @param id 任务类型字典主键
     * @return 结果
     */
    @Override
    public int deleteTaskTypeDictById(Long id) {
        return taskTypeDictMapper.deleteTaskTypeDictById(id);
    }
}
