package cn.ey.biz.module.system.service.category;

import cn.ey.biz.module.system.controller.admin.category.vo.CategoryTplColumnsVO;
import cn.ey.biz.module.system.controller.admin.category.vo.CategoryTplRespVO;
import cn.ey.biz.module.system.convert.category.CategoryTplConvert;
import cn.ey.biz.module.system.dal.dataobject.category.CategoryTplDO;
import cn.ey.biz.module.system.dal.mapper.category.CategoryTplMapper;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;

/**
 *  字典tpl Service 实现类
 */
@Service
@Validated
public class CategoryTplServiceImpl implements CategoryTplService {

    @Resource
    private  CategoryTplMapper categoryTplMapper;

    @Override
    public CategoryTplRespVO getTpl(String categoryCode){
        LambdaQueryWrapper<CategoryTplDO> wrappers = Wrappers.lambdaQuery(CategoryTplDO.class)
                .eq(CategoryTplDO::getCategoryCode, categoryCode);
        List<CategoryTplDO> fileDOList=categoryTplMapper.selectList(wrappers);
        if(CollectionUtil.isNotEmpty(fileDOList)){
            CategoryTplDO categoryTplDO=fileDOList.get(0);
            CategoryTplRespVO   categoryTplRespVO=CategoryTplConvert.INSTANCE.convert(categoryTplDO);
            List<CategoryTplColumnsVO> listdd = JSONArray.parseArray(categoryTplRespVO.getColumns(), CategoryTplColumnsVO.class);
            categoryTplRespVO.setColumnsList(listdd);
            return  categoryTplRespVO;
        }
        return null;
    }

}
