package com.yuchen.saas.park.service.service.repair.impl;

import com.alibaba.fastjson.JSON;
import com.yuchen.saas.park.api.dto.repair.SaasMatterRepairSetDto;
import com.yuchen.saas.park.api.entity.repair.SaasMatterRepairSet;
import com.yuchen.saas.park.api.vo.repair.SaasMatterRepairSetVo;
import com.yuchen.saas.park.service.mapper.repair.SaasMatterRepairSetMapper;
import com.yuchen.saas.park.service.service.repair.ISaasMatterRepairSetService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.tool.utils.BeanUtil;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 报事报修基础设置表 服务实现类
 * </p>
 *
 * @author caiwq
 * @since 2024-04-23
 */
@Service
public class SaasMatterRepairSetServiceImpl extends BaseServiceImpl<SaasMatterRepairSetMapper, SaasMatterRepairSet> implements ISaasMatterRepairSetService {

    @Override
    public Boolean add(SaasMatterRepairSetDto matterRepairSetDto) {
        SaasMatterRepairSet matterRepairSet = BeanUtil.copyProperties(matterRepairSetDto, SaasMatterRepairSet.class);
        matterRepairSet.setDispatchUserSet(JSON.toJSONString(matterRepairSetDto.getDispatchUserSetList()));
        return saveOrUpdate(matterRepairSet);
    }

    @Override
    public SaasMatterRepairSetVo getDetail() {
        SaasMatterRepairSet matterRepairSet = this.lambdaQuery().last("LIMIT 1").one();
        SaasMatterRepairSetVo vo = BeanUtil.copyProperties(matterRepairSet, SaasMatterRepairSetVo.class);
        if (matterRepairSet != null){
            vo.setDispatchUserSetList(JSON.parseArray(vo.getDispatchUserSet(), SaasMatterRepairSetDto.DispatchUserSet.class));
        }
        return vo;
    }
}

