package com.younike.service.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import com.younike.common.constant.ResultPacketCode;
import com.younike.service.mapper.StoreMapper;
import com.younike.service.pojo.Store;
import com.younike.service.pojo.StoreImage;
import com.younike.service.pojo.vo.StoreVo;
import com.younike.service.service.IStoreImageService;
import com.younike.service.service.IStoreService;
import com.younike.common.core.page.PageParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 门店基础信息Service业务层处理
 *
 * @author dail
 * @date 2022-05-24
 */
@Service
@Transactional
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store>  implements IStoreService {


    @Autowired
    private IStoreImageService storeImageService;

    /**
     * 自定义分页逻辑 这里就省略掉
     * @param pageParam
     * @return
     */
    @Override
    public PageParam<Store> page(PageParam<Store> pageParam) {

        PageParam<Store> page = this.page(pageParam, new LambdaQueryWrapper<Store>()
                //.like(Printer::getName,pageParam.getParam().getName())
                // 查询逻辑 适合单表 多表 重写XML查询
        );

        return page;
    }

    /**
     * 商家端创建门店
     * @param vo
     * @return
     */
    @Override
    public Boolean add(StoreVo vo) {

        //商家基础信息
//        Store store = new Store();
//        BeanUtils.copyProperties(vo,store);
//        //生成id
//        store.setStoreId("1");
//        store.setUpdatedBy("当前用户");
//
//        for ( StoreImage image:vo.getStoreImageList()) {
//            image.setStoreImgId("1");
//            image.setStoreId("1");
//        }
//        if(vo.getStoreImageList().size()>0){
//            //批量添加
//            if(!storeImageService.saveBatch(vo.getStoreImageList())){
//                throw new ArithmeticException("添加商家相关图片信息失败");
//            }
//        }
//        this.save(store);
        return true;
    }

}
