package com.cool.store.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.dao.AssessmentTemplateDAO;
import com.cool.store.entity.AssessmentTemplateDO;
import com.cool.store.service.AssessmentTemplateService;
import com.cool.store.utils.poi.StringUtils;
import com.cool.store.vo.AssessmentTemplateVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2024/4/25 11:25
 * @Version 1.0
 */
@Service
public class AssessmentTemplateServiceImpl implements AssessmentTemplateService {

    @Resource
    AssessmentTemplateDAO assessmentTemplateDAO;

    @Override
    public List<AssessmentTemplateVO> listByType(Integer type) {
        List<AssessmentTemplateDO> assessmentTemplateDOS = assessmentTemplateDAO.listByType(type);
        List<AssessmentTemplateVO> result = new ArrayList<>();
        assessmentTemplateDOS.forEach(x->{
            AssessmentTemplateVO assessmentTemplateVO = new AssessmentTemplateVO();
            BeanUtil.copyProperties(x,assessmentTemplateVO);
            x.getTemplateRemark();
            if (StringUtils.isNotEmpty(x.getTemplateRemark())){
                String[] split = x.getTemplateRemark().replaceAll("[\\[\\]\\s]", "").split(",");
                assessmentTemplateVO.setTemplateRemarkList(Arrays.asList(split));
            }
            result.add(assessmentTemplateVO);
        });
        return result;
    }
}
