jiaosong
2023-09-19 7fc79e5c6c98fa7fe1e2279572251a45f0970c65
server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java
@@ -20,10 +20,12 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
@@ -289,7 +291,19 @@
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(baseDataMapper.selectPage(page, queryWrapper));
        IPage<BaseData> result =baseDataMapper.selectPage(page, queryWrapper);
        if(result!=null && result.getRecords()!=null){
            for(BaseData data :result.getRecords()){
                //多图,英文逗号隔开
                if(StringUtils.isNotBlank(data.getBgImg())){
                    String tImg =  data.getBgImg().replace(",", ",").replace(".avif", "");
                    String[] imgs =tImg.split(",");
                    data.setBgImgs(imgs);
                }
            }
        }
        return PageData.from(result);
    }
    @Override
@@ -300,6 +314,7 @@
    public static   boolean IS_RUNNING = false;
    @Override
    @Transactional
    @Async
    public   void dealBaseData() {
        if(IS_RUNNING){
            return;
@@ -393,7 +408,7 @@
        int i =0;
        //多图,英文逗号隔开
        if(StringUtils.isNotBlank(data.getBgImg())){
           String tImg =  data.getBgImg().replace(",", ",");
           String tImg =  data.getBgImg().replace(",", ",").replace(".avif", "");
            String[] imgs =tImg.split(",");
            for (int j = 0; j < imgs.length; j++) {
                if(StringUtils.isNotBlank(imgs[j])){
@@ -426,7 +441,8 @@
        return  0;
    }
    private OssModel initOssModel() {
    @Override
    public OssModel initOssModel() {
        OssModel model = new OssModel();
        model.setUrl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode());
        model.setEndpoint(systemDictDataBiz.queryByCode(Constants.OSS, Constants.ENDPOINT).getCode());
@@ -604,7 +620,8 @@
        return model;
    }
    private String getOssImgurl(OssModel ossModel, String folder,String img) {
    @Override
    public String getOssImgurl(OssModel ossModel, String folder,String img) {
        if(StringUtils.isBlank(img)){
            return null;
        }
@@ -625,4 +642,30 @@
        }
        return  null;
    }
    @Override
    public     String getOssImgurl(OssModel ossModel, String folder, File f) {
        if(f == null || !f.isFile()){
            return null;
        }
        try {
            String img = f.getPath();
            String nowDate = DateUtil.getNowShortDate();// 当前时间(年月日)
            String nfix  = img.lastIndexOf(".")>0?img.substring(img.lastIndexOf(".")):null;
            nfix = StringUtils.defaultString(nfix,".jpg");
            String fileName = UUID.randomUUID() + nfix;
            String tempFileName = nowDate + "/" + fileName;
            String key =folder+ tempFileName;// 文件名
            ALiYunUtil obs = new ALiYunUtil(ossModel.getEndpoint(), ossModel.getAccessId(), ossModel.getAccessKey());
            if (obs.uploadFile(ossModel.getBucket(), key,f,null)) {
                    return  tempFileName;
            }
        }catch (Exception e){
        }
        return  null;
    }
}