luodangjia
2024-08-22 a983092f3bd4f1b2ddc416a9e9260b5bac9e3672
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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.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.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.BeanUtils;
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.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-07
 */
@RestController
@RequestMapping("/t-apply-charging-pile")
public class TApplyChargingPileController {
 
    private final TApplyChargingPileService applyChargingPileService;
    private final TokenService tokenService;
 
    @Autowired
    public TApplyChargingPileController(TApplyChargingPileService applyChargingPileService, TokenService tokenService) {
        this.applyChargingPileService = applyChargingPileService;
        this.tokenService = tokenService;
    }
 
    /**
     * 建桩申请
     */
    @Log(title = "建桩申请", businessType = BusinessType.INSERT,operatorType = OperatorType.MOBILE)
    @ApiOperation(tags = {"小程序-建桩申请"},value = "建桩申请")
    @PostMapping(value = "/add")
    public AjaxResult<Boolean> add(@RequestBody TApplyChargingPile dto) {
        // 用户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) {
        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();
 
            List<TApplyChargingPileExportDto> exportDtos =new ArrayList<>();
            for (TApplyChargingPile tApplyChargingPile : list) {
                TApplyChargingPileExportDto applyChargingPileExportDto = new TApplyChargingPileExportDto();
                BeanUtils.copyProperties(tApplyChargingPile,applyChargingPileExportDto);
                applyChargingPileExportDto.setLandlordFrontIdCard(new URL(tApplyChargingPile.getLandlordFrontIdCard()));
                applyChargingPileExportDto.setLandlordBackIdCard(new URL(tApplyChargingPile.getLandlordBackIdCard()));
                applyChargingPileExportDto.setAgentBackIdCard(new URL(tApplyChargingPile.getAgentBackIdCard()));
                applyChargingPileExportDto.setAgentFrontIdCard(new URL(tApplyChargingPile.getAgentFrontIdCard()));
                List<URL> urls = new ArrayList<>();
                urls.add(new URL("https://img-blog.csdnimg.cn/direct/c11088e1790049a5b84a0fda21a271b1.png"));
                urls.add(new URL("https://img-blog.csdnimg.cn/direct/c11088e1790049a5b84a0fda21a271b1.png"));
                urls.add(new URL("https://img-blog.csdnimg.cn/direct/c11088e1790049a5b84a0fda21a271b1.png"));
                        applyChargingPileExportDto.setUrls(urls);
                exportDtos.add(applyChargingPileExportDto);
 
            }
 
            // 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}")
    public AjaxResult<TApplyChargingPile> detail(@PathVariable Integer id) {
 
        return AjaxResult.ok(applyChargingPileService.getById(id));
    }
 
    @ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "修改备注")
    @PostMapping(value = "/remark")
    public AjaxResult<TApplyChargingPile> remark(@RequestBody ApplyChargingRemarkDto applyChargingRemarkDt) {
        TApplyChargingPile byId = applyChargingPileService.getById(applyChargingRemarkDt.getId());
        byId.setRemark(applyChargingRemarkDt.getRemark());
        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();
 
    }
 
 
 
 
    
    
}