| | |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.wx.WxMiniConfig; |
| | | import com.doumee.dao.business.BikesMapper; |
| | | import com.google.common.collect.Lists; |
| | | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | |
| | | 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; |
| | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private BikesMapper bikesMapper; |
| | | |
| | | @Override |
| | | public String create(Locks locks) { |
| | |
| | | if (!CollectionUtils.isEmpty(locksList)){ |
| | | // 检查是否有图片信息没有更新保存图片 |
| | | locksList.forEach(s-> { |
| | | if (StringUtils.isBlank(s.getInfo())){ |
| | | wxMiniUtilService.generateWXMiniCode(s,systemDictData,prePath,code); |
| | | if (Constants.equalsInteger(locks.getFource(),Constants.ONE) ||StringUtils.isBlank(s.getInfo())){ |
| | | try { |
| | | wxMiniUtilService.generateWXMiniCode(s, WxMiniConfig.wxMaService.getAccessToken(),prePath,code); |
| | | }catch (Exception e){ |
| | | } |
| | | s.setEditor(loginUserInfo.getId()); |
| | | s.setEditDate(new Date()); |
| | | updateById(s); |
| | |
| | | return locksList; |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有电测小程序二维码 |
| | | * @param force 0不强制刷新 1强制刷新 |
| | | * @return |
| | | */ |
| | | @Override |
| | | 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(); |
| | | for(Bikes bikes : bikesList){ |
| | | 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() ; |
| | | String code = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode(); |
| | | String prePath = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.IMG_DIR).getCode(); |
| | | // 检查是否有图片信息没有更新保存图片 |
| | | if (Constants.equalsInteger(force,Constants.ONE) || StringUtils.isBlank(bikes.getImgurl())){ |
| | | try { |
| | | wxMiniUtilService.generateEbikeWXMiniCode(bikes, WxMiniConfig.wxMaService.getAccessToken(),prePath,code); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | if (StringUtils.isNotBlank(bikes.getImgurl())){ |
| | | bikes.setEditor(loginUserInfo.getId()); |
| | | bikes.setEditDate(new Date()); |
| | | bikesMapper.updateById(bikes); |
| | | } |
| | | } |
| | | if (StringUtils.isBlank(bikes.getImgurl())){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"获取小程序码失败,请稍后重试!"); |
| | | } |
| | | bikes.setImgurl(fullPath+bikes.getImgurl()); |
| | | return bikes; |
| | | } |
| | | |
| | | |
| | |
| | | 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.getImgurl())){ |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | } |