package ink.wgink.module.form.service.docnolog.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.module.form.dao.docnolog.IDocNoLogDao;
import ink.wgink.module.form.pojo.dtos.docnolog.DocNoLogDTO;
import ink.wgink.module.form.pojo.pos.docnolog.DocNoLogPO;
import ink.wgink.module.form.pojo.vos.docnolog.DocNoLogVO;
import ink.wgink.module.form.service.docnolog.IDocNoLogService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.util.UUIDUtil;
import ink.wgink.util.map.HashMapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: DocNoLogServiceImpl
 * @Description: 文号日志
 * @Author: CodeFactory
 * @Date: 2022-06-29 14:19:06
 * @Version: 3.0
 **/
@Service
public class DocNoLogServiceImpl extends DefaultBaseService implements IDocNoLogService {

    @Autowired
    private IDocNoLogDao docNoLogDao;

    @Override
    public void save(DocNoLogVO docNoLogVO) {
        saveReturnId(docNoLogVO);
    }

    @Override
    public String saveReturnId(DocNoLogVO docNoLogVO) {
        String docNoLogId = UUIDUtil.getUUID();
        Map<String, Object> params = HashMapUtil.beanToMap(docNoLogVO);
        params.put("docNoLogId", docNoLogId);
        setSaveInfoByUserId(params, "1");
        docNoLogDao.save(params);
        return docNoLogId;
    }

    @Override
    public void delete(List<String> ids) {
        Map<String, Object> params = getHashMap(2);
        params.put("docNoLogIds", ids);
        docNoLogDao.delete(params);
    }

    @Override
    public DocNoLogDTO get(Map<String, Object> params) {
        return docNoLogDao.get(params);
    }

    @Override
    public DocNoLogDTO get(String docNoLogId) {
        Map<String, Object> params = super.getHashMap(2);
        params.put("docNoLogId", docNoLogId);
        return get(params);
    }

    @Override
    public DocNoLogPO getPO(Map<String, Object> params) {
        return docNoLogDao.getPO(params);
    }

    @Override
    public DocNoLogPO getPO(String docNoLogId) {
        Map<String, Object> params = super.getHashMap(2);
        params.put("docNoLogId", docNoLogId);
        return getPO(params);
    }

    @Override
    public DocNoLogPO getLatestPOByDocNoIdAndUsedId(String docNoId, String docNoUsedId) {
        Map<String, Object> params = getHashMap(2);
        params.put("docNoId", docNoId);
        params.put("docNoUsedId", docNoUsedId);
        return docNoLogDao.getLatestPO(params);
    }

    @Override
    public List<DocNoLogDTO> list(Map<String, Object> params) {
        return docNoLogDao.list(params);
    }

    @Override
    public List<DocNoLogPO> listPO(Map<String, Object> params) {
        return docNoLogDao.listPO(params);
    }

    @Override
    public SuccessResultList<List<DocNoLogDTO>> listPage(ListPage page) {
        PageHelper.startPage(page.getPage(), page.getRows());
        List<DocNoLogDTO> docNoLogDTOs = list(page.getParams());
        PageInfo<DocNoLogDTO> pageInfo = new PageInfo<>(docNoLogDTOs);
        return new SuccessResultList<>(docNoLogDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
    }

    @Override
    public Integer count(Map<String, Object> params) {
        Integer count = docNoLogDao.count(params);
        return count == null ? 0 : count;
    }

}