package com.ruoyi.system.service.impl;

import cn.hutool.core.bean.BeanUtil;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.ZsOperationGoodsDetail;
import com.ruoyi.system.domain.bo.ZsOperationGoodsDetailBo;
import com.ruoyi.system.domain.vo.ZsOperationGoodsDetailVo;
import com.ruoyi.system.mapper.ZsOperationGoodsDetailMapper;
import com.ruoyi.system.service.IZsOperationGoodsDetailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商品配置Service业务层处理
 *
 * @author 王强
 * @date 2025-05-08
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class ZsOperationGoodsDetailServiceImpl implements IZsOperationGoodsDetailService {

    @Autowired
    private  ZsOperationGoodsDetailMapper baseMapper;

    private LambdaQueryWrapper<ZsOperationGoodsDetail> buildQueryWrapper(ZsOperationGoodsDetailBo bo) {
       // Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ZsOperationGoodsDetail> lqw = Wrappers.lambdaQuery();
        //lqw.eq(StringUtils.isNotBlank(bo.getModule()), ZsOperationSendconfig::getModule, bo.getModule());
        return lqw;
    }


    @Override
    public TableDataInfo<ZsOperationGoodsDetailVo> queryPageList(ZsOperationGoodsDetailBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ZsOperationGoodsDetail> lqw = buildQueryWrapper(bo);
        Page<ZsOperationGoodsDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    @Override
    public Boolean insertByBo(ZsOperationGoodsDetailBo bo) {
        ZsOperationGoodsDetail add = BeanUtil.toBean(bo, ZsOperationGoodsDetail.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }
    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ZsOperationGoodsDetail entity){
        //TODO 做一些数据校验,如唯一约束
    }
}
