All Downloads are FREE. Search and download functionalities are using the official Maven repository.

k.e.book.ddh.service.CcItemService Maven / Gradle / Ivy


package k.e.book.ddh.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import k.e.book.common.enums.ItemStatus;
import k.e.book.ddh.entity.CcItemDO;
import k.e.book.ddh.entity.CcItemQueryDTO;
import k.e.book.ddh.mapper.CcItemMapper;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author kk
 * @date 2023-05-21 11:04
 */
@Service
public class CcItemService extends ServiceImpl {

    @Resource
    private RedissonClient redissonClient;

    public String getSN(Long itemId) {
        String key = "item:sn:" + itemId;

        Object o = redissonClient.getBucket(key).get();
        if (o != null) {
            return o.toString();
        }
        CcItemDO item = this.getById(itemId);
        if (item != null && StringUtils.isNotBlank(item.getSn())) {
            redissonClient.getBucket(key).set(item.getSn(), 1, TimeUnit.HOURS);
            return item.getSn();
        }
        return null;
    }

    /**
     * @param productId ,status=1
     * @return
     */
    public CcItemDO getByProduct(Long productId) {
        try {
            LambdaQueryWrapper qr = new LambdaQueryWrapper<>();
            qr.eq(CcItemDO::getProductId, productId).eq(CcItemDO::getStatus, ItemStatus.OPEN.ordinal());
//            qr.eq(CcItemDO::getProductId, productId).eq(CcItemDO::getStatus, ItemStatus.SOLD.ordinal());
            qr.last("limit 1");
            return getOne(qr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public IPage selectProductPage(CcItemQueryDTO dto) {
        LambdaQueryWrapper qr = new LambdaQueryWrapper<>();

        if (dto.getId() != null) {
            qr.eq(CcItemDO::getId, dto.getId());
        }
        if (dto.getSn() != null) {
            qr.eq(CcItemDO::getSn, dto.getSn());
        }
        if (dto.getNumber() != null) {
            qr.eq(CcItemDO::getNumber, dto.getNumber());
        }
        if (dto.getAuthorId() != null) {
            qr.eq(CcItemDO::getAuthorId, dto.getAuthorId());
        }
        if (dto.getProductId() != null) {
            qr.eq(CcItemDO::getProductId, dto.getProductId());
        }
        if (dto.getTokenId() != null) {
            qr.eq(CcItemDO::getTokenId, dto.getTokenId());
        }
        if (dto.getSubject() != null) {
            qr.eq(CcItemDO::getSubject, dto.getSubject());
        }
        if (dto.getImage() != null) {
            qr.eq(CcItemDO::getImage, dto.getImage());
        }
        if (dto.getAmount() != null) {
            qr.eq(CcItemDO::getAmount, dto.getAmount());
        }
        if (dto.getPriceunit() != null) {
            qr.eq(CcItemDO::getPriceunit, dto.getPriceunit());
        }
        if (dto.getCreatetime() != null) {
            qr.eq(CcItemDO::getCreatetime, dto.getCreatetime());
        }
        if (dto.getUpdatetime() != null) {
            qr.eq(CcItemDO::getUpdatetime, dto.getUpdatetime());
        }
        if (dto.getDeletetime() != null) {
            qr.eq(CcItemDO::getDeletetime, dto.getDeletetime());
        }
        if (dto.getStatus() != null) {
            qr.eq(CcItemDO::getStatus, dto.getStatus());
        }
        if (dto.getCreatedAt() != null) {
            qr.eq(CcItemDO::getCreatedAt, dto.getCreatedAt());
        }
        if (dto.getUpdatedAt() != null) {
            qr.eq(CcItemDO::getUpdatedAt, dto.getUpdatedAt());
        }
        if (dto.getDeletedAt() != null) {
            qr.eq(CcItemDO::getDeletedAt, dto.getDeletedAt());
        }

        qr.orderByDesc(CcItemDO::getId);
        IPage page = new Page<>();
        page.setCurrent(dto.getPage());
        page.setSize(dto.getLimit());
        return baseMapper.selectPage(page, qr);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy