| | |
| | | package com.doumee.service.business.impl; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.google.common.collect.Lists; |
| | | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.core.wx.WxMiniUtilService; |
| | | import com.doumee.dao.business.LocksMapper; |
| | | import com.doumee.dao.business.join.LocksJoinMapper; |
| | | import com.doumee.dao.business.model.BaseParam; |
| | | import com.doumee.dao.business.model.Bikes; |
| | | import com.doumee.dao.business.model.Locks; |
| | | import com.doumee.dao.business.model.Sites; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.service.business.LocksService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.service.business.SitesService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; |
| | | import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.Charset; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 锁头信息表Service实现 |
| | |
| | | |
| | | @Autowired |
| | | private LocksJoinMapper locksJoinMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private WxMiniUtilService wxMiniUtilService; |
| | | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Override |
| | | public String create(Locks locks) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Locks> findLockBase64List(Locks locks) { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | String fullPath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode() + |
| | | systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode() ; |
| | | |
| | | QueryWrapper<Locks> wrapper = new QueryWrapper<>(locks); |
| | | wrapper.lambda().orderByAsc(Locks::getCode); |
| | | List<Locks> locksList = locksMapper.selectList(wrapper); |
| | | SystemDictData systemDictData = systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.ACCESS_TOKEN); |
| | | String code = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode(); |
| | | String prePath = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.IMG_DIR).getCode(); |
| | | if (!CollectionUtils.isEmpty(locksList)){ |
| | | // 检查是否有图片信息没有更新保存图片 |
| | | locksList.forEach(s-> { |
| | | if (StringUtils.isBlank(s.getInfo())){ |
| | | wxMiniUtilService.generateWXMiniCode(s,systemDictData,prePath,code); |
| | | s.setEditor(loginUserInfo.getId()); |
| | | s.setEditDate(new Date()); |
| | | updateById(s); |
| | | } |
| | | s.setImgfullurl(fullPath+s.getInfo()); |
| | | }); |
| | | return locksList; |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PageData<Locks> findPage(PageWrap<Locks> pageWrap) { |
| | | IPage<Locks> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | MPJLambdaWrapper<Locks> queryWrapper = new MPJLambdaWrapper<>(); |
| | |
| | | QueryWrapper<Locks> wrapper = new QueryWrapper<>(locks); |
| | | return locksMapper.selectCount(wrapper); |
| | | } |
| | | public static void packFilesToZip(List<File> files, ServletOutputStream os) throws IOException { |
| | | try (ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(os)) { |
| | | for (File file : files) { |
| | | ZipArchiveEntry entry = new ZipArchiveEntry(file.getName()); |
| | | zipOutputStream.putArchiveEntry(entry); |
| | | try (FileInputStream fileInputStream = new FileInputStream(file)) { |
| | | byte[] buffer = new byte[1024]; |
| | | int length; |
| | | while ((length = fileInputStream.read(buffer)) > 0) { |
| | | zipOutputStream.write(buffer, 0, length); |
| | | } |
| | | } |
| | | zipOutputStream.closeArchiveEntry(); |
| | | } |
| | | } |
| | | } |
| | | @Override |
| | | public void exportImages(String siteId, HttpServletResponse response) { |
| | | try { |
| | | List<File> fileList = new ArrayList<>(); |
| | | List<Locks> locks = locksJoinMapper.selectList(new QueryWrapper<Locks>().lambda().eq(Locks::getSiteId,siteId).isNotNull(Locks::getInfo)); |
| | | if(locks== null || locks.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(Locks l : locks){ |
| | | if(StringUtils.isNotBlank(l.getInfo())){ |
| | | File file = new File(path + l.getInfo()); |
| | | if(file!=null && file.isFile()){ |
| | | fileList.add(file); |
| | | } |
| | | } |
| | | } |
| | | if(fileList == null || fileList.size() == 0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | String fileName = "站点【"+siteId+"】小程序码批量导出_"+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); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |