package com.yonge.cooleshow.biz.dal.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.dao.SysManualDao;
import com.yonge.cooleshow.biz.dal.entity.SysManual;
import com.yonge.cooleshow.biz.dal.queryInfo.SysManualQueryInfo;
import com.yonge.cooleshow.biz.dal.service.SysManualService;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.utils.collection.MapUtil;
import jodd.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * (SysManual)表服务实现类
 *
 * @author makejava
 * @since 2021-12-20 17:19:38
 */
@Service("sysManualService")
public class SysManualServiceImpl extends ServiceImpl<SysManualDao, SysManual> implements SysManualService {

    private final static Logger logger = LoggerFactory.getLogger(SysManualServiceImpl.class);

    @Autowired
    private SysManualDao sysManualDao;

    public PageInfo<SysManual> query(SysManualQueryInfo queryInfo) {
        PageInfo<SysManual> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
        Map<String, Object> params = new HashMap<>();
        MapUtil.populateMap(params, queryInfo);
        List<SysManual> dataList = null;
        int count = sysManualDao.findRecordCount(params);
        if (count > 0) {
            pageInfo.setTotal(count);
            params.put("offset", pageInfo.getOffset());
            dataList = sysManualDao.queryRecord(params);
        }
        if (count == 0) {
            dataList = new ArrayList<>();
        }
        pageInfo.setRows(dataList);

        return pageInfo;
    }

    public Boolean add(SysManual sysManual, Long userId) {
        sysManual.setOperatorId(userId);
        sysManual.setCreateTime(new Date());
        sysManual.setUpdateTime(new Date());
        return this.save(sysManual);
    }

    public int update(SysManual sysManual, Long userId) {
        sysManual.setOperatorId(userId);
        sysManual.setUpdateTime(new Date());
        return sysManualDao.updateById(sysManual);
    }

    @Override
    public String listMenuIds() {
        List<String> menuIds = sysManualDao.listMenuIds();
        return StringUtil.join(menuIds, ",");
    }
}

