package com.mvc.service.taizhang;

import com.mvc.dao.FileUploadTypeMapper;
import com.mvc.entity.FileUploadType;
import com.mvc.entity.FileUploadTypeExample;
import com.mvc.model.FileUploadTypeModel;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Transactional
public class FileUploadTypeService {

    @Resource
    private FileUploadTypeMapper fileUploadTypeMapper;

    public List<FileUploadTypeModel> findAllFileUploadType() {
        List<FileUploadType> FileUploadTypes = fileUploadTypeMapper.selectByExample(null);
        List<FileUploadTypeModel> resList = new ArrayList<>();
        for (FileUploadType FileUploadType : FileUploadTypes) {
            FileUploadTypeModel model = new FileUploadTypeModel();
            BeanUtils.copyProperties(FileUploadType, model);
            resList.add(model);
        }
        return resList;
    }

    /**
     * 根据typeCode获取文件类型
     * @param typeCode
     * @return
     */
    public FileUploadTypeModel findFileUploadTypeByCode(String typeCode){
        FileUploadTypeExample example=new FileUploadTypeExample();
        FileUploadTypeExample.Criteria criteria=example.createCriteria();
        criteria.andFiletypecodeEqualTo(typeCode);
        List<FileUploadType> list = fileUploadTypeMapper.selectByExample(example);
        if(list!=null&&list.size()>0){
            FileUploadTypeModel model=new FileUploadTypeModel();
            BeanUtils.copyProperties(list.get(0),model);
            return model;
        }
        return null;
    }
}
