jiangping
2025-02-19 dfafe88917bd344d570277f14b7ea7bf03fa93d4
server/services/src/main/java/com/doumee/service/business/impl/LocksServiceImpl.java
@@ -26,6 +26,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.business.SitesService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.models.auth.In;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.lang3.StringUtils;
@@ -143,7 +144,7 @@
        if (!CollectionUtils.isEmpty(locksList)){
            // 检查是否有图片信息没有更新保存图片
            locksList.forEach(s-> {
                if (StringUtils.isBlank(s.getInfo())){
                if (Constants.equalsInteger(locks.getFource(),Constants.ONE) ||StringUtils.isBlank(s.getInfo())){
                    try {
                        wxMiniUtilService.generateWXMiniCode(s, WxMiniConfig.wxMaService.getAccessToken(),prePath,code);
                    }catch (Exception e){
@@ -158,21 +159,59 @@
        }
        return new ArrayList<>();
    }
    /**
     * 获取所有电测小程序二维码
     * @param force 0不强制刷新 1强制刷新
     * @return
     */
    @Override
    public    Bikes findBikeBase(String bikeId) {
        Locks re = new Locks();
    public     List<Bikes> findAllBikeBase(Integer force) {
        List<Bikes> bikesList = bikesMapper.selectList(new QueryWrapper<Bikes>().lambda()
                .eq(Bikes::getIsdeleted,Constants.ZERO)
                .eq(Bikes::getType,Constants.ONE)
        );
        if(bikesList!=null && bikesList.size()>0){
            LoginUserInfo loginUserInfo =  (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
            String fullPath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode() +
                    systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode() ;
            String code = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
            String prePath = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.IMG_DIR).getCode();
            bikesList.forEach(bikes-> {
                if (Constants.equalsInteger(force,Constants.ONE) || StringUtils.isBlank(bikes.getImgurl())){
                    try {
                        wxMiniUtilService.generateEbikeWXMiniCode(bikes, WxMiniConfig.wxMaService.getAccessToken(),prePath,code);
                    }catch (Exception e){
                    }
                    if (StringUtils.isNotBlank(bikes.getImgurl())){
                        bikes.setEditor(loginUserInfo.getId());
                        bikes.setEditDate(new Date());
                        bikesMapper.updateById(bikes);
                    }
                    if (StringUtils.isNotBlank(bikes.getImgurl())){
                        bikes.setImgurl(fullPath+bikes.getImgurl());
                    }
                }
            });
        }
        return bikesList;
    }
    @Override
    public    Bikes findBikeBase(String bikeId, Integer force) {
       Bikes bikes = bikesMapper.selectById(bikeId);
       if(bikes == null
               || Constants.equalsInteger(bikes.getIsdeleted(),Constants.ONE)
               || !Constants.equalsInteger(bikes.getType(),Constants.ONE)){
           throw new BusinessException(ResponseStatus.DATA_EMPTY);
       }
        LoginUserInfo loginUserInfo =  (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        String fullPath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode() +
                systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode() ;
       Bikes bikes = bikesMapper.selectById(bikeId);
       if(bikes == null){
           throw new BusinessException(ResponseStatus.DATA_EMPTY);
       }
        String code = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prePath = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.IMG_DIR).getCode();
            // 检查是否有图片信息没有更新保存图片
        if (StringUtils.isBlank(bikes.getImgurl())){
        if (Constants.equalsInteger(force,Constants.ONE) || StringUtils.isBlank(bikes.getImgurl())){
            try {
                wxMiniUtilService.generateEbikeWXMiniCode(bikes, WxMiniConfig.wxMaService.getAccessToken(),prePath,code);
            }catch (Exception e){
@@ -183,9 +222,10 @@
                bikesMapper.updateById(bikes);
            }
        }
        if (StringUtils.isNotBlank(bikes.getImgurl())){
            bikes.setImgurl(fullPath+bikes.getInfo());
        if (StringUtils.isBlank(bikes.getImgurl())){
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"获取小程序码失败,请稍后重试!");
        }
        bikes.setImgurl(fullPath+bikes.getImgurl());
        return bikes;
    }
@@ -267,6 +307,41 @@
            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
    }
    @Override
    public void exportEbikeImages(String bikeid, HttpServletResponse response){
        try {
            List<File> fileList = new ArrayList<>();
            List<Bikes> bikesList = bikesMapper.selectList(new QueryWrapper<Bikes>().lambda()
                    .eq(Bikes::getIsdeleted,Constants.ZERO)
                    .eq(StringUtils.isNotBlank(bikeid) ,Bikes::getId,bikeid)
                    .eq(Bikes::getType,Constants.ONE)
            );
            if(bikesList== null || bikesList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.IMG_DIR).getCode()+systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
            for(Bikes l : bikesList){
                if(StringUtils.isNotBlank(l.getInfo())){
                    File file = new File(path + l.getImgurl());
                    if(file!=null && file.isFile()){
                        fileList.add(file);
                    }
                }
            }
            if(fileList == null || fileList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String fileName =  "电车小程序码批量导出_"+System.currentTimeMillis()+".zip" ;
            String encodeFileName = URLEncoder.encode(fileName);
            response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
            response.setContentType("application/octet-stream");
            response.setHeader("eva-opera-type", "download");
            response.setHeader("eva-download-filename", encodeFileName);
            packFilesToZip(fileList,response.getOutputStream());
        } catch (IOException e) {
            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
    }
}