package cn.com.ctop.common.module.service.impl;

import cn.com.ctop.common.module.entity.MaterialAscription;
import cn.com.ctop.common.module.mapper.MaterialAscriptionMapper;
import cn.com.ctop.common.module.service.IMaterialAscriptionService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 素材归属标
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2019-11-23
 */
@Service
@Primary
public class MaterialAscriptionServiceImpl extends ServiceImpl<MaterialAscriptionMapper, MaterialAscription> implements IMaterialAscriptionService {
    @Resource
    private MaterialAscriptionMapper ascriptionMapper;

    @Override
    public JSONObject getDetailByCode(String code) {
        return ascriptionMapper.selectByMaterialId(code);
    }

    @Override
    public MaterialAscription getInfoByCode(String code) {
        QueryWrapper<MaterialAscription> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("material_id", code);
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);

    }
}
