From 5e1cf8e0e94b42a94c3a3d3ccda5147fe6ce94f0 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 22 八月 2024 09:42:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TApplyChargingPileController.java |   81 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 73 insertions(+), 8 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 8fe2dbc..f60dca5 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
@@ -1,23 +1,32 @@
 package com.ruoyi.chargingPile.controller;
 
 
+import com.alibaba.excel.EasyExcelFactory;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.builder.ExcelWriterBuilder;
+import com.alibaba.excel.write.metadata.WriteSheet;
 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.model.TApplyChargingPile;
-import com.ruoyi.chargingPile.api.model.TCarport;
-import com.ruoyi.chargingPile.api.vo.TCarportVO;
 import com.ruoyi.chargingPile.service.TApplyChargingPileService;
-import com.ruoyi.chargingPile.service.TCarportService;
-import com.ruoyi.chargingPile.service.TVehicleRampService;
+import com.ruoyi.common.core.constant.Constants;
+import com.ruoyi.common.core.domain.R;
 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.security.service.TokenService;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.codec.CharEncoding;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.List;
 
 /**
@@ -33,10 +42,12 @@
 public class TApplyChargingPileController {
 
     private final TApplyChargingPileService applyChargingPileService;
+    private final TokenService tokenService;
 
     @Autowired
-    public TApplyChargingPileController(TApplyChargingPileService applyChargingPileService) {
+    public TApplyChargingPileController(TApplyChargingPileService applyChargingPileService, TokenService tokenService) {
         this.applyChargingPileService = applyChargingPileService;
+        this.tokenService = tokenService;
     }
 
     /**
@@ -46,21 +57,61 @@
     @ApiOperation(tags = {"小程序-建桩申请"},value = "建桩申请")
     @PostMapping(value = "/add")
     public AjaxResult<Boolean> add(@RequestBody TApplyChargingPile dto) {
-        // TODO 用户id
-        dto.setAppUserId(null);
+        // 用户id
+        Long userId = tokenService.getLoginUserApplet().getUserId();
+        dto.setAppUserId(userId);
+        return AjaxResult.ok(applyChargingPileService.save(dto));
+    }
+
+    @Log(title = "建桩申请", businessType = BusinessType.INSERT,operatorType = OperatorType.MOBILE)
+    @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "建桩申请")
+    @PostMapping(value = "/manage/add")
+    public AjaxResult<Boolean> manageAdd(@RequestBody TApplyChargingPile dto) {
+
         return AjaxResult.ok(applyChargingPileService.save(dto));
     }
 
     @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "列表")
     @PostMapping(value = "/page")
     public AjaxResult<Page<TApplyChargingPile>> page(ApplyChargingQuery applyChargingQuery) {
-        // TODO 用户id
         Page<TApplyChargingPile> page = applyChargingPileService.lambdaQuery()
                 .like(applyChargingQuery.getName() != null && !applyChargingQuery.getName().equals(""), TApplyChargingPile::getAgentPhone, applyChargingQuery.getName())
                 .page(Page.of(applyChargingQuery.getPageCurr(), applyChargingQuery.getPageSize()));
         return AjaxResult.ok(page);
     }
 
+
+    @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "导出")
+    @PutMapping(value = "/export")
+    public R export(HttpServletResponse response) {
+        try {
+        response.setCharacterEncoding(Constants.UTF8);
+        response.setContentType("application/vnd.ms-excel");
+        response.setHeader("Access-Control-Expose-Headers", "Content-disposition");
+        response.setHeader("Content-Disposition", "attachment;filename=" +
+                URLEncoder.encode("申请建桩数据", CharEncoding.UTF_8) + ".xlsx");
+        } catch (UnsupportedEncodingException e) {
+            return R.fail("excel导出失败!");
+        }
+        try {
+            List<TApplyChargingPile> list = applyChargingPileService.lambdaQuery().list();
+
+            // excel模板封装
+            ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream());
+            InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" +"充电桩申请记录" + ".xlsx");
+            // 自动释放资源
+            try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) {
+                WriteSheet writeSheet = EasyExcelFactory.writerSheet().build();
+                excelWriter.fill(list, writeSheet);
+                excelWriter.finish();
+            } catch (Exception e) {
+                return R.fail("excel导出失败!");
+            }
+        } catch (IOException e) {
+            return R.fail("excel导出失败!");
+        }
+        return R.ok();
+    }
 
     @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "详情")
     @PostMapping(value = "/detail/{id}")
@@ -77,9 +128,23 @@
         applyChargingPileService.updateById(byId);
         return AjaxResult.success();
     }
+    @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "删除")
+    @DeleteMapping(value = "/remark")
+    public AjaxResult remark(String ids) {
+
+        String[] split = ids.split(",");
+        for (String s : split) {
+            applyChargingPileService.removeById(s);
+
+        }
+        return AjaxResult.success();
+
+    }
 
 
 
 
+    
+    
 }
 

--
Gitblit v1.7.1