From c81e1267ee71da9bbf345ab2788deb3a65dbcd8c Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期一, 02 九月 2024 16:39:35 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TApplyChargingPileController.java | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 106 insertions(+), 7 deletions(-) diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TApplyChargingPileController.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TApplyChargingPileController.java index f600d99..8e85f92 100644 --- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TApplyChargingPileController.java +++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TApplyChargingPileController.java @@ -5,18 +5,24 @@ import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.builder.ExcelWriterBuilder; import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.chargingPile.api.dto.ApplyChargingQuery; import com.ruoyi.chargingPile.api.dto.ApplyChargingRemarkDto; +import com.ruoyi.chargingPile.api.dto.TApplyChargingPileDTO; import com.ruoyi.chargingPile.api.model.TApplyChargingPile; import com.ruoyi.chargingPile.dto.TApplyChargingPileExportDto; import com.ruoyi.chargingPile.service.TApplyChargingPileService; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.OperatorType; +import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.service.TokenService; import io.swagger.annotations.ApiOperation; import org.apache.commons.codec.CharEncoding; @@ -32,6 +38,7 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; /** * <p> @@ -47,11 +54,13 @@ private final TApplyChargingPileService applyChargingPileService; private final TokenService tokenService; + private final RedisService redisService; @Autowired - public TApplyChargingPileController(TApplyChargingPileService applyChargingPileService, TokenService tokenService) { + public TApplyChargingPileController(TApplyChargingPileService applyChargingPileService, TokenService tokenService, RedisService redisService) { this.applyChargingPileService = applyChargingPileService; this.tokenService = tokenService; + this.redisService = redisService; } /** @@ -60,7 +69,15 @@ @Log(title = "建桩申请", businessType = BusinessType.INSERT,operatorType = OperatorType.MOBILE) @ApiOperation(tags = {"小程序-建桩申请"},value = "建桩申请") @PostMapping(value = "/add") - public AjaxResult<Boolean> add(@RequestBody TApplyChargingPile dto) { + public AjaxResult<Boolean> add(@RequestBody TApplyChargingPileDTO dto) { + // 验证验证码 + String code = redisService.getCacheObject(dto.getLandlordPhone() + Constants.APPLY_CHARGING); + if(StringUtils.isEmpty(code)){ + return AjaxResult.error("验证码已过期,请重新获取验证码!"); + } + if(!code.equals(dto.getCode())){ + return AjaxResult.error("验证码错误!"); + } // 用户id Long userId = tokenService.getLoginUserApplet().getUserId(); dto.setAppUserId(userId); @@ -79,7 +96,7 @@ @PostMapping(value = "/page") public AjaxResult<Page<TApplyChargingPile>> page(ApplyChargingQuery applyChargingQuery) { Page<TApplyChargingPile> page = applyChargingPileService.lambdaQuery() - .like(applyChargingQuery.getName() != null && !applyChargingQuery.getName().equals(""), TApplyChargingPile::getAgentPhone, applyChargingQuery.getName()) + .like(applyChargingQuery.getLandlordPhone() != null && !applyChargingQuery.getLandlordPhone().equals(""), TApplyChargingPile::getLandlordPhone, applyChargingQuery.getLandlordPhone()) .page(Page.of(applyChargingQuery.getPageCurr(), applyChargingQuery.getPageSize())); return AjaxResult.ok(page); } @@ -87,7 +104,7 @@ @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "导出") @PutMapping(value = "/export") - public R export(HttpServletResponse response) { + public R export(String landlordPhone,HttpServletResponse response) { try { response.setCharacterEncoding(Constants.UTF8); response.setContentType("application/vnd.ms-excel"); @@ -98,13 +115,87 @@ return R.fail("excel导出失败!"); } try { - List<TApplyChargingPile> list = applyChargingPileService.lambdaQuery().list(); + List<TApplyChargingPile> list = applyChargingPileService.lambdaQuery().like(landlordPhone != null && !landlordPhone.equals(""), TApplyChargingPile::getLandlordPhone, landlordPhone).list(); List<TApplyChargingPileExportDto> exportDtos =new ArrayList<>(); for (TApplyChargingPile tApplyChargingPile : list) { TApplyChargingPileExportDto applyChargingPileExportDto = new TApplyChargingPileExportDto(); BeanUtils.copyProperties(tApplyChargingPile,applyChargingPileExportDto); - applyChargingPileExportDto.setImage(new URL("https://img-blog.csdnimg.cn/direct/c11088e1790049a5b84a0fda21a271b1.png")); + JSONArray p1 = JSON.parseArray(tApplyChargingPile.getLandlordFrontIdCard()); + if (!p1.isEmpty()) { + applyChargingPileExportDto.setLandlordFrontIdCard(new URL((String) p1.get(0))); + } + JSONArray p2 = JSON.parseArray(tApplyChargingPile.getLandlordBackIdCard()); + if (!p2.isEmpty()){ + applyChargingPileExportDto.setLandlordBackIdCard(new URL((String)p2.get(0)));} + JSONArray p3 = JSON.parseArray(tApplyChargingPile.getAgentBackIdCard()); + if (!p3.isEmpty()) + applyChargingPileExportDto.setAgentBackIdCard(new URL((String)p3.get(0))); + JSONArray p4 = JSON.parseArray(tApplyChargingPile.getAgentFrontIdCard()); + if (!p4.isEmpty()) { + applyChargingPileExportDto.setAgentFrontIdCard(new URL((String)p4.get(0))); + } + + if (tApplyChargingPile.getChargingPileUser()==1){ + JSONArray pics1 = JSON.parseArray(tApplyChargingPile.getFixedParkingPropertyRights()); + if (!pics1.isEmpty()) { + applyChargingPileExportDto.setPics1(new URL((String)pics1.get(0))); + } + JSONArray pics2 = JSON.parseArray(tApplyChargingPile.getConstructionCertificate()); + if (!pics1.isEmpty()) { + applyChargingPileExportDto.setPics2(new URL((String)pics2.get(0))); + } + }else { + JSONArray pics1 = JSON.parseArray(tApplyChargingPile.getTitleCertificate()); + if (!pics1.isEmpty()) { + applyChargingPileExportDto.setPics1(new URL((String)pics1.get(0))); + } + JSONArray pics2 = JSON.parseArray(tApplyChargingPile.getBusinessLicense()); + if (!pics1.isEmpty()) { + applyChargingPileExportDto.setPics2(new URL((String)pics2.get(0))); + } + } + + JSONArray objects1 = JSON.parseArray(tApplyChargingPile.getFurtherInformation()); + for (int i = 0; i < objects1.size(); i++) { + JSONObject jsonObject = JSON.parseObject(objects1.get(i).toString()); + System.err.println("==================="+jsonObject.get("url")); + + boolean isImage = isImageUrl(jsonObject); + if (!isImage){ + continue; + } + System.err.println("Is image: " + isImage); + if (i==0){ + applyChargingPileExportDto.setUrl1(new URL((String)jsonObject.get("url"))); + }else if (i==1){ + applyChargingPileExportDto.setUrl2(new URL((String)jsonObject.get("url"))); + }else if (i==2){ + applyChargingPileExportDto.setUrl3(new URL((String)jsonObject.get("url"))); + }else if (i==3){ + applyChargingPileExportDto.setUrl4(new URL((String)jsonObject.get("url"))); + }else if (i==4){ + applyChargingPileExportDto.setUrl5(new URL((String)jsonObject.get("url"))); + }else if (i==5){ + applyChargingPileExportDto.setUrl6(new URL((String)jsonObject.get("url"))); + } + } + + if (tApplyChargingPile.getLandlordHandling()==1){ + applyChargingPileExportDto.setIs1("是"); + }else { + applyChargingPileExportDto.setIs1("否"); + } + if (tApplyChargingPile.getChargingPileUser()==1){ + applyChargingPileExportDto.setIs2("是"); + }else { + applyChargingPileExportDto.setIs2("否"); + } + if (tApplyChargingPile.getChargingPile()==1){ + applyChargingPileExportDto.setIs3("是"); + }else { + applyChargingPileExportDto.setIs3("否"); + } exportDtos.add(applyChargingPileExportDto); } @@ -115,7 +206,7 @@ // 自动释放资源 try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) { WriteSheet writeSheet = EasyExcelFactory.writerSheet().build(); - excelWriter.fill(list, writeSheet); + excelWriter.fill(exportDtos, writeSheet); excelWriter.finish(); } catch (Exception e) { return R.fail("excel导出失败!"); @@ -126,6 +217,14 @@ return R.ok(); } + public static boolean isImageUrl(JSONObject jsonObject) { + String url = jsonObject.getString("url"); + Pattern pattern = Pattern.compile( + "^.*\\.(?i)(jpg|jpeg|png|gif|bmp|webp)$" + ); + return pattern.matcher(url).matches(); + } + @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "详情") @PostMapping(value = "/detail/{id}") public AjaxResult<TApplyChargingPile> detail(@PathVariable Integer id) { -- Gitblit v1.7.1