package com.purui.prims.headless.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.purui.prims.common.util.BeanMapper;
import com.purui.prims.headless.api.pojo.request.SysParameterReq;
import com.purui.prims.headless.api.pojo.response.SysParameterResp;
import com.purui.prims.headless.server.persistence.dataobject.SysParameterDO;
import com.purui.prims.headless.server.persistence.mapper.SysParameterMapper;
import com.purui.prims.headless.server.service.SysParameterService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SysParameterServiceImpl extends ServiceImpl<SysParameterMapper, SysParameterDO>
    implements SysParameterService {

    @Override
    public boolean save(SysParameterReq sysParameterReq) {
        SysParameterDO systemParameterDO = new SysParameterDO();
        BeanMapper.mapper(sysParameterReq, systemParameterDO);
        return super.saveOrUpdate(systemParameterDO);
    }

    @Override
    public SysParameterResp get(int id) {
        SysParameterDO systemParameterDO = getById(id);
        SysParameterResp sysParameterResp = new SysParameterResp();
        BeanMapper.mapper(systemParameterDO, sysParameterResp);
        return sysParameterResp;
    }

    @Override
    public List<SysParameterResp> getParameterList() {
        QueryWrapper<SysParameterDO> queryWrapper = new QueryWrapper<>();
        List<SysParameterDO> list = baseMapper.selectList(queryWrapper);
        return list.stream().map(item -> {
            SysParameterResp sysParameterResp = new SysParameterResp();
            BeanMapper.mapper(item, sysParameterResp);
            return sysParameterResp;
        }).collect(Collectors.toList());
    }
}
