| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.YwPatrolPointMapper; |
| | | import com.doumee.dao.business.model.Category; |
| | | import com.doumee.dao.business.model.YwDevice; |
| | | import com.doumee.dao.business.model.YwPatrolPoint; |
| | | import com.doumee.dao.system.MultifileMapper; |
| | | import com.doumee.dao.system.model.Multifile; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.YwPatrolPointService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.google.zxing.BarcodeFormat; |
| | | import com.google.zxing.EncodeHintType; |
| | | import com.google.zxing.MultiFormatWriter; |
| | | import com.google.zxing.client.j2se.MatrixToImageWriter; |
| | | import com.google.zxing.common.BitMatrix; |
| | | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; |
| | | import com.google.zxing.qrcode.encoder.ByteMatrix; |
| | | import com.google.zxing.qrcode.encoder.Encoder; |
| | | import com.google.zxing.qrcode.encoder.QRCode; |
| | | import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; |
| | | import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.Charset; |
| | | import java.nio.file.FileSystems; |
| | | import java.nio.file.Path; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 运维巡检点信息表Service实现 |
| | |
| | | |
| | | @Autowired |
| | | private YwPatrolPointMapper ywPatrolPointMapper; |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private MultifileMapper multifileMapper; |
| | | |
| | | @Override |
| | | public Integer create(YwPatrolPoint ywPatrolPoint) { |
| | | if(Objects.isNull(ywPatrolPoint) |
| | | // || Objects.isNull(ywPatrolPoint.getCode()) |
| | | || Objects.isNull(ywPatrolPoint.getName()) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | String pre = systemDictDataBiz.queryByCode(Constants.XUNJIAN,Constants.XJ_POINT_PREFIX).getCode(); |
| | | int length = 8; |
| | | try { |
| | | length = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.XUNJIAN,Constants.XJ_POINT_CODE_LENGTH).getCode()); |
| | | }catch (Exception e){ |
| | | } |
| | | long num = ywPatrolPointMapper.selectCount(new QueryWrapper<YwPatrolPoint>()); |
| | | |
| | | ywPatrolPoint.setCode(pre+Constants.formartNumString (length,(num+1))); |
| | | LoginUserInfo loginUserInfo = ywPatrolPoint.getLoginUserInfo(); |
| | | ywPatrolPoint.setCreateDate(new Date()); |
| | | ywPatrolPoint.setCreator(loginUserInfo.getId()); |
| | | ywPatrolPoint.setIsdeleted(Constants.ZERO); |
| | | ywPatrolPoint.setStatus(Constants.ZERO); |
| | | ywPatrolPointMapper.insert(ywPatrolPoint); |
| | | |
| | | |
| | | if(Objects.nonNull(ywPatrolPoint.getFileUrl())){ |
| | | Multifile multifile = new Multifile(); |
| | | multifile.setCreator(loginUserInfo.getId()); |
| | | multifile.setCreateDate(new Date()); |
| | | multifile.setIsdeleted(Constants.ZERO); |
| | | multifile.setObjType(Constants.MultiFile.FN_PATROL_POINT_FILE.getKey()); |
| | | multifile.setObjId(ywPatrolPoint.getId()); |
| | | multifile.setFileurl(ywPatrolPoint.getFileUrl()); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | |
| | | return ywPatrolPoint.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id, LoginUserInfo user) { |
| | | ywPatrolPointMapper.deleteById(id); |
| | | ywPatrolPointMapper.update(new UpdateWrapper<YwPatrolPoint>().lambda() |
| | | .set(YwPatrolPoint::getIsdeleted,Constants.ONE) |
| | | .set(YwPatrolPoint::getEditDate, DateUtil.getCurrDateTime()) |
| | | .set(YwPatrolPoint::getEditor,user.getId()) |
| | | .eq(YwPatrolPoint::getId,id) |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | |
| | | UpdateWrapper<YwPatrolPoint> deleteWrapper = new UpdateWrapper<>(ywPatrolPoint); |
| | | ywPatrolPointMapper.delete(deleteWrapper); |
| | | } |
| | | @Override |
| | | public void exportQrcodes(Integer id, HttpServletResponse response){ |
| | | try { |
| | | List<File> fileList = new ArrayList<>(); |
| | | List<YwPatrolPoint> bikesList = ywPatrolPointMapper.selectList(new QueryWrapper<YwPatrolPoint>().lambda() |
| | | .eq(YwPatrolPoint::getIsdeleted,Constants.ZERO) |
| | | .eq(id!=null,YwPatrolPoint::getId,id) |
| | | ); |
| | | if(bikesList== null || bikesList.size() == 0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | // 创建临时文件的前缀和后缀 |
| | | String path = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_AUTH_URL).getCode(); |
| | | String uri = systemDictDataBiz.queryByCode(Constants.XUNJIAN,Constants.XJ_RERIRECT_URI).getCode(); |
| | | String appId = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_APPID).getCode() ; |
| | | // 创建临时文件 |
| | | for(YwPatrolPoint l : bikesList){ |
| | | if(StringUtils.isNotBlank(l.getCode())){ |
| | | String redirectUri = uri.replace("${ywid}",l.getCode()); |
| | | String url = path.replace("${url}",URLEncoder.encode(redirectUri)).replace("${appid}",appId); |
| | | File file = generateQRCodeImage(url,100,100,l.getCode()+".png"); |
| | | if(file!=null && file.isFile()){ |
| | | fileList.add(file); |
| | | } |
| | | } |
| | | } |
| | | if(fileList == null || fileList.size() == 0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,下载内容为空,操作失败!"); |
| | | } |
| | | String fileName = "巡检点二维码导出_"+System.currentTimeMillis()+".zip" ; |
| | | String encodeFileName =URLEncoder.encode(fileName, Charset.forName("UTF-8").toString())+".zip"; |
| | | 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); |
| | | } |
| | | } |
| | | public static File generateQRCodeImage(String text, int width, int height, String fileName) { |
| | | try { |
| | | // 创建二维码数据矩阵 |
| | | Map<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); // 设置字符编码为UTF-8 |
| | | hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // 设置纠错等级为H |
| | | hints.put(EncodeHintType.MARGIN, 0); // 设置白边为0 |
| | | BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE , width, height, hints); |
| | | // 保存二维码图片到文件系统 |
| | | File f = new File("temp/"); |
| | | if(!f.exists()){ |
| | | f.mkdirs(); |
| | | } |
| | | // bitMatrix = renderResult(bitMatrix,width,height); |
| | | Path path = FileSystems.getDefault().getPath("temp/"+fileName); |
| | | MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path); // 保存为PNG格式的图片 |
| | | return path.toFile(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | File f =generateQRCodeImage("dj少时诵诗书少时诵诗书是撒是撒是撒",100,100,UUID.randomUUID().toString()+".png"); |
| | | System.out.println(f.getAbsolutePath()); |
| | | } |
| | | |
| | | private static BitMatrix renderResult(BitMatrix input, int width, int height) { |
| | | if (input == null) { |
| | | return null; |
| | | } |
| | | int inputWidth = input.getWidth(); |
| | | int inputHeight = input.getHeight(); |
| | | // 依据用户的输入宽高,计算最后的输出宽高 |
| | | int outputWidth = Math.max(width, inputWidth); |
| | | int outputHeight = Math.max(height, inputHeight); |
| | | |
| | | //计算缩放比例 |
| | | int multiple = Math.min(outputWidth / inputWidth, outputHeight / inputHeight); |
| | | |
| | | BitMatrix output = new BitMatrix(outputWidth, outputHeight); |
| | | int inputY = 0; |
| | | // 嵌套循环,将ByteMatrix的内容计算padding后转换成BitMatrix |
| | | for (int outputY = 0; inputY < inputHeight; outputY += multiple) { |
| | | int inputX = 0; |
| | | for (int outputX = 0; inputX < inputWidth; outputX += multiple) { |
| | | if (input.get(inputX, inputY)) { |
| | | output.setRegion(outputX, outputY, multiple, multiple); |
| | | } |
| | | inputX++; |
| | | } |
| | | inputY++; |
| | | } |
| | | |
| | | return output; |
| | | } |
| | | 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 deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | |
| | | |
| | | @Override |
| | | public void updateById(YwPatrolPoint ywPatrolPoint) { |
| | | if(Objects.isNull(ywPatrolPoint) |
| | | || Objects.isNull(ywPatrolPoint.getId()) |
| | | || Objects.isNull(ywPatrolPoint.getCode()) |
| | | || Objects.isNull(ywPatrolPoint.getName()) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(ywPatrolPointMapper.selectCount(new QueryWrapper<YwPatrolPoint>().lambda().eq(YwPatrolPoint::getIsdeleted,Constants.ZERO) |
| | | .eq(YwPatrolPoint::getCode,ywPatrolPoint.getCode()).ne(YwPatrolPoint::getId,ywPatrolPoint.getId()))>Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"巡检点编码重复!"); |
| | | } |
| | | LoginUserInfo loginUserInfo = ywPatrolPoint.getLoginUserInfo(); |
| | | ywPatrolPoint.setEditDate(new Date()); |
| | | ywPatrolPoint.setEditor(loginUserInfo.getId()); |
| | | ywPatrolPointMapper.updateById(ywPatrolPoint); |
| | | |
| | | multifileMapper.delete(new QueryWrapper<Multifile>().lambda() |
| | | .eq(Multifile::getObjId,ywPatrolPoint.getId()) |
| | | .eq(Multifile::getObjType,Constants.MultiFile.FN_PATROL_POINT_FILE.getKey()) |
| | | ); |
| | | |
| | | if(Objects.nonNull(ywPatrolPoint.getFileUrl())){ |
| | | Multifile multifile = new Multifile(); |
| | | multifile.setCreator(loginUserInfo.getId()); |
| | | multifile.setCreateDate(new Date()); |
| | | multifile.setIsdeleted(Constants.ZERO); |
| | | multifile.setObjType(Constants.MultiFile.FN_PATROL_POINT_FILE.getKey()); |
| | | multifile.setObjId(ywPatrolPoint.getId()); |
| | | multifile.setFileurl(ywPatrolPoint.getFileUrl()); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public YwPatrolPoint getDetail(Integer id) { |
| | | YwPatrolPoint ywPatrolPoint = ywPatrolPointMapper.selectById(id); |
| | | if(Objects.isNull(ywPatrolPoint)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getObjId,id) |
| | | .eq(Multifile::getObjType,Constants.MultiFile.FN_PATROL_POINT_FILE.getKey()).orderByDesc(Multifile::getId).last(" limit 1")); |
| | | if(Objects.nonNull(multifile) && StringUtils.isNotBlank(multifile.getFileurl())){ |
| | | String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() |
| | | +systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_PATROL).getCode(); |
| | | ywPatrolPoint.setFileFullUrl(path + multifile.getFileurl()); |
| | | ywPatrolPoint.setFileUrl(multifile.getFileurl()); |
| | | } |
| | | |
| | | return ywPatrolPoint; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public YwPatrolPoint findOne(YwPatrolPoint ywPatrolPoint) { |
| | | QueryWrapper<YwPatrolPoint> wrapper = new QueryWrapper<>(ywPatrolPoint); |
| | | return ywPatrolPointMapper.selectOne(wrapper); |
| | |
| | | |
| | | @Override |
| | | public List<YwPatrolPoint> findList(YwPatrolPoint ywPatrolPoint) { |
| | | QueryWrapper<YwPatrolPoint> wrapper = new QueryWrapper<>(ywPatrolPoint); |
| | | QueryWrapper<YwPatrolPoint> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda().eq(YwPatrolPoint::getIsdeleted,Constants.ZERO); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(ywPatrolPoint.getIdLists())){ |
| | | wrapper.lambda().notIn(YwPatrolPoint::getId,ywPatrolPoint.getIdLists()); |
| | | } |
| | | return ywPatrolPointMapper.selectList(wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<YwPatrolPoint> findPage(PageWrap<YwPatrolPoint> pageWrap) { |
| | | IPage<YwPatrolPoint> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | QueryWrapper<YwPatrolPoint> queryWrapper = new QueryWrapper<>(); |
| | | MPJLambdaWrapper<YwPatrolPoint> queryWrapper = new MPJLambdaWrapper<YwPatrolPoint>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getId, pageWrap.getModel().getId()); |
| | | } |
| | | if (pageWrap.getModel().getCreator() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getCreator, pageWrap.getModel().getCreator()); |
| | | } |
| | | if (pageWrap.getModel().getCreateDate() != null) { |
| | | queryWrapper.lambda().ge(YwPatrolPoint::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); |
| | | queryWrapper.lambda().le(YwPatrolPoint::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); |
| | | } |
| | | if (pageWrap.getModel().getEditor() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getEditor, pageWrap.getModel().getEditor()); |
| | | } |
| | | if (pageWrap.getModel().getEditDate() != null) { |
| | | queryWrapper.lambda().ge(YwPatrolPoint::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); |
| | | queryWrapper.lambda().le(YwPatrolPoint::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); |
| | | } |
| | | if (pageWrap.getModel().getIsdeleted() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getIsdeleted, pageWrap.getModel().getIsdeleted()); |
| | | } |
| | | if (pageWrap.getModel().getName() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getName, pageWrap.getModel().getName()); |
| | | } |
| | | if (pageWrap.getModel().getRemark() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getRemark, pageWrap.getModel().getRemark()); |
| | | } |
| | | if (pageWrap.getModel().getStatus() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getStatus, pageWrap.getModel().getStatus()); |
| | | } |
| | | if (pageWrap.getModel().getSortnum() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getSortnum, pageWrap.getModel().getSortnum()); |
| | | } |
| | | if (pageWrap.getModel().getImgurl() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getImgurl, pageWrap.getModel().getImgurl()); |
| | | } |
| | | if (pageWrap.getModel().getAreaId() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getAreaId, pageWrap.getModel().getAreaId()); |
| | | } |
| | | if (pageWrap.getModel().getAddr() != null) { |
| | | queryWrapper.lambda().eq(YwPatrolPoint::getAddr, pageWrap.getModel().getAddr()); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | return PageData.from(ywPatrolPointMapper.selectPage(page, queryWrapper)); |
| | | YwPatrolPoint model = pageWrap.getModel(); |
| | | queryWrapper.selectAll(YwPatrolPoint.class) |
| | | .selectAs(Category::getName,YwPatrolPoint::getAreaName) |
| | | .selectAs(YwDevice::getName,YwPatrolPoint::getDeviceName) |
| | | .leftJoin(Category.class,Category::getId,YwPatrolPoint::getAreaId) |
| | | .leftJoin(YwDevice.class,YwDevice::getId,YwPatrolPoint::getDeviceId) |
| | | .and(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getName()), |
| | | i->i.like(YwPatrolPoint::getName,model.getName()).or().like(YwPatrolPoint::getCode,model.getName())) |
| | | .eq(Objects.nonNull(model.getAreaId()),YwPatrolPoint::getAreaId,model.getAreaId()) |
| | | .eq(YwPatrolPoint::getIsdeleted,Constants.ZERO) |
| | | .orderByDesc(YwPatrolPoint::getCreateDate) |
| | | ; |
| | | IPage iPage = ywPatrolPointMapper.selectJoinPage(page,YwPatrolPoint.class,queryWrapper); |
| | | return PageData.from(iPage); |
| | | } |
| | | |
| | | @Override |