package com.fs.doc.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.fs.common.utils.DateUtils;
import com.fs.common.utils.StringUtils;
import com.fs.doc.mapper.DocRecordReplyMapper;
import com.fs.doc.param.DocRecordParam;
import com.fs.doc.param.DocRecordQueryParam;
import com.fs.doc.param.DocRecordReplyQueryParam;
import com.fs.doc.vo.DocRecordListQueryVO;
import com.fs.doc.vo.DocRecordReplyListQueryVO;
import com.fs.doc.vo.DocRecordVO;
import com.fs.store.mapper.FsStoreProductMapper;
import com.fs.store.vo.FsStoreProductListQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.doc.mapper.DocRecordMapper;
import com.fs.doc.domain.DocRecord;
import com.fs.doc.service.IDocRecordService;

/**
 * 记录Service业务层处理
 * 
 * @author fs
 * @date 2023-01-09
 */
@Service
public class DocRecordServiceImpl implements IDocRecordService 
{
    @Autowired
    private DocRecordMapper docRecordMapper;
    @Autowired
    private DocRecordReplyMapper docRecordReplyMapper;
    @Autowired
    private FsStoreProductMapper storeProductMapper;
    /**
     * 查询记录
     * 
     * @param recordId 记录ID
     * @return 记录
     */
    @Override
    public DocRecord selectDocRecordById(Long recordId)
    {
        return docRecordMapper.selectDocRecordById(recordId);
    }

    /**
     * 查询记录列表
     * 
     * @param docRecord 记录
     * @return 记录
     */
    @Override
    public List<DocRecord> selectDocRecordList(DocRecord docRecord)
    {
        return docRecordMapper.selectDocRecordList(docRecord);
    }

    /**
     * 新增记录
     * 
     * @param docRecord 记录
     * @return 结果
     */
    @Override
    public int insertDocRecord(DocRecord docRecord)
    {
        docRecord.setCreateTime(DateUtils.getNowDate());
        return docRecordMapper.insertDocRecord(docRecord);
    }

    /**
     * 修改记录
     * 
     * @param docRecord 记录
     * @return 结果
     */
    @Override
    public int updateDocRecord(DocRecord docRecord)
    {
        docRecord.setUpdateTime(DateUtils.getNowDate());
        return docRecordMapper.updateDocRecord(docRecord);
    }

    /**
     * 批量删除记录
     * 
     * @param recordIds 需要删除的记录ID
     * @return 结果
     */
    @Override
    public int deleteDocRecordByIds(Long[] recordIds)
    {
        return docRecordMapper.deleteDocRecordByIds(recordIds);
    }

    /**
     * 删除记录信息
     * 
     * @param recordId 记录ID
     * @return 结果
     */
    @Override
    public int deleteDocRecordById(Long recordId)
    {
        return docRecordMapper.deleteDocRecordById(recordId);
    }

    @Override
    public List<DocRecordListQueryVO> selectDocRecordListVOQuery(DocRecordQueryParam param) {
        List<DocRecordListQueryVO> list=docRecordMapper.selectDocRecordListVOQuery(param);
        for(DocRecordListQueryVO vo:list){
            DocRecordReplyQueryParam map=new DocRecordReplyQueryParam();
            map.setLimit(10);
            map.setRecordId(vo.getRecordId());
            List<DocRecordReplyListQueryVO> replys=docRecordReplyMapper.selectDocRecordReplyListVOQuery(map);
            for(DocRecordReplyListQueryVO replyVO:replys){
                List<FsStoreProductListQueryVO> productList=new ArrayList<>();
                if(StringUtils.isEmpty(replyVO.getProductIds())){
                    productList=storeProductMapper.selectFsStoreProductListByIds(replyVO.getProductIds());
                }
                replyVO.setProducts(productList);
            }
            vo.setReplys(replys);
        }
        return list;
    }

    @Override
    public List<DocRecordVO> selectDocRecordListVO(DocRecordParam docRecord) {
        return docRecordMapper.selectDocRecordListVO(docRecord);
    }
}
