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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.entity.UserMoneyDetails;
import com.sqx.modules.printInfo.dao.PrintInfoDao;
import com.sqx.modules.printInfo.dao.PrintInfoDetailDao;
import com.sqx.modules.printInfo.entity.PrintInfo;
import com.sqx.modules.printInfo.entity.PrintInfoDetail;
import com.sqx.modules.printInfo.service.PrintInfoDetailService;
import com.sqx.modules.printInfo.service.PrintInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author www.javacoder.top
 * @since 2022-11-04
 */
@Service
public class PrintInfoDetailServiceImpl extends ServiceImpl<PrintInfoDetailDao, PrintInfoDetail> implements PrintInfoDetailService {

    @Override
    public Result selectPrintInfoDetailList(Integer page, Integer limit, Long orderId) {
        Page<PrintInfoDetail> pages = new Page<>(page, limit);
        QueryWrapper<PrintInfoDetail> queryWrapper = new QueryWrapper();
        queryWrapper.eq("order_id", orderId).orderByDesc("create_time");
        PageUtils pageUtils = new PageUtils(baseMapper.selectPage(pages,queryWrapper));
        return Result.success().put("data", pageUtils);
    }

    @Override
    public Result insertPrintInfoDetail(PrintInfoDetail printInfoDetail) {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        printInfoDetail.setCreateTime(format);
        printInfoDetail.setDeleteFlag(0);
        int result = baseMapper.insert(printInfoDetail);
        return result > 0 ? Result.success() :  Result.error();
    }
}
