package com.sqx.modules.printInfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.printInfo.dao.PrintInfoShopDao;
import com.sqx.modules.printInfo.entity.PrintInfo;
import com.sqx.modules.printInfo.entity.PrintInfoShop;
import com.sqx.modules.printInfo.service.PrintInfoShopService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class PrintInfoShopServiceImpl extends ServiceImpl<PrintInfoShopDao, PrintInfoShop> implements PrintInfoShopService {

    @Override
    public PrintInfoShop selectPrintInfoShopById(Integer shopId) {
        QueryWrapper<PrintInfoShop> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("shop_id", shopId);
        queryWrapper.eq("delete_flag", 0);
        PrintInfoShop printInfoShop = baseMapper.selectOne(queryWrapper);
        return printInfoShop;
    }

    @Override
    public Result insertPrintInfoShop(PrintInfoShop PrintInfoShop) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        PrintInfoShop.setCreateTime(format);
        PrintInfoShop.setUpdateTime(format);
        PrintInfoShop.setDeleteFlag(0);
        baseMapper.insert(PrintInfoShop);
        return Result.success();
    }

    @Override
    public Result updatePrintInfoShop(PrintInfoShop PrintInfoShop) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        PrintInfoShop.setUpdateTime(format);
        baseMapper.updateById(PrintInfoShop);
        return Result.success();
    }
}
