package cn.iocoder.yudao.module.tickets.service.impl;

import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.tickets.entity.BaseRepairRecords;
import cn.iocoder.yudao.module.tickets.mapper.BaseRepairRecordsMapper;
import cn.iocoder.yudao.module.tickets.service.BaseRepairRecordsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 维修记录 Service 实现类
 *
 * @author lzt
 */
@Service
@Validated
public class BaseRepairRecordsServiceImpl extends ServiceImpl<BaseRepairRecordsMapper, BaseRepairRecords> implements BaseRepairRecordsService {

    @Resource
    private AdminUserApi userApi;

    /**
     * 保存维修记录
     *
     * @param ticketId     工单id
     * @param repairItemId 工单子表id
     * @param type         工作类型（数据字典：repair_records_type;后端对应 RecordTypeEnum 枚举）
     * @param remark       备注
     * @param images       图片(相对路径按照“，”分隔)
     * @author PQZ
     * @date 14:51 2024/10/11
     **/
    @Override
    public void saveRepairRecord(String ticketId, String repairItemId, String type, String remark, String images) {
        //获取当前登录用户
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO loginUser = userApi.getUser(userId);
        //初始化维修记录
        BaseRepairRecords repairRecords = new BaseRepairRecords();
        repairRecords.setTicketId(ticketId);
        repairRecords.setRepairItemId(repairItemId);
        repairRecords.setType(type);
        repairRecords.setRemark(remark);
        repairRecords.setDealUserId(loginUser.getId());
        repairRecords.setDealUserName(loginUser.getNickname());
        //保存维修记录
        save(repairRecords);
    }

}
