package com.ruoyi.chargingPile.controller;
|
import java.time.LocalDateTime;
|
import java.math.BigDecimal;
|
|
import com.ruoyi.chargingPile.api.feignClient.SiteClient;
|
import com.ruoyi.chargingPile.api.model.Partner;
|
import com.ruoyi.chargingPile.api.model.Site;
|
import com.ruoyi.common.core.utils.WebUtils;
|
import com.ruoyi.common.core.web.page.PageInfo;
|
import com.ruoyi.order.api.feignClient.OrderClient;
|
import com.ruoyi.order.api.model.TChargingOrder;
|
import com.ruoyi.order.api.model.TSettlementConfirm;
|
import com.ruoyi.order.api.vo.AccountListVO;
|
import com.ruoyi.order.api.vo.ChargingBillListVO;
|
|
|
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcelFactory;
|
import com.alibaba.excel.ExcelWriter;
|
import com.alibaba.excel.enums.WriteDirectionEnum;
|
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
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 com.ruoyi.order.api.feignClient.ChargingOrderClient;
|
import com.ruoyi.order.api.model.ChargingListQuery;
|
import com.ruoyi.order.api.vo.ChargingBillVO;
|
import com.ruoyi.order.api.vo.SettlementTotalVO;
|
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.annotation.Resource;
|
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.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.regex.Pattern;
|
|
/**
|
* <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;
|
private final RedisService redisService;
|
@Resource
|
private ChargingOrderClient chargingOrderClient;
|
@Resource
|
private OrderClient orderClient;
|
@Resource
|
private SiteClient siteClient;
|
|
@Autowired
|
public TApplyChargingPileController(TApplyChargingPileService applyChargingPileService, TokenService tokenService, RedisService redisService) {
|
this.applyChargingPileService = applyChargingPileService;
|
this.tokenService = tokenService;
|
this.redisService = redisService;
|
}
|
|
/**
|
* 建桩申请
|
*/
|
@Log(title = "建桩申请", businessType = BusinessType.INSERT,operatorType = OperatorType.MOBILE)
|
@ApiOperation(tags = {"小程序-建桩申请"},value = "建桩申请")
|
@PostMapping(value = "/add")
|
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);
|
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.getLandlordPhone() != null && !applyChargingQuery.getLandlordPhone().equals(""), TApplyChargingPile::getLandlordPhone, applyChargingQuery.getLandlordPhone())
|
.page(Page.of(applyChargingQuery.getPageCurr(), applyChargingQuery.getPageSize()));
|
return AjaxResult.ok(page);
|
}
|
|
|
@ApiOperation(tags = {"后台-申请表单-申请建桩"},value = "导出")
|
@PutMapping(value = "/export")
|
public R export(String landlordPhone,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().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);
|
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);
|
}
|
// 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(exportDtos, writeSheet);
|
excelWriter.finish();
|
} catch (Exception e) {
|
return R.fail("excel导出失败!");
|
}
|
} catch (IOException e) {
|
return R.fail("excel导出失败!");
|
}
|
return R.ok();
|
}
|
|
@ApiOperation(value = "下载-已出账", tags = {"管理后台-充电算账单"})
|
@GetMapping("/downloadBill")
|
public R downloadBill(String uid,HttpServletResponse response)
|
{
|
ChargingListQuery chargingListQuery = new ChargingListQuery();
|
chargingListQuery.setUid(uid);
|
chargingListQuery.setPageCurr(1);
|
chargingListQuery.setPageSize(99999);
|
ChargingBillVO data = chargingOrderClient.chargingBillListR(chargingListQuery).getData();
|
|
List<ChargingBillVO> chargingBillVOS = new ArrayList<>();
|
chargingBillVOS.add(data);
|
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("月账单-"+data.getCategory()+"-"+data.getBillWeek()+"-"+data.getSiteName(), CharEncoding.UTF_8) + ".xlsx");
|
} catch (UnsupportedEncodingException e) {
|
return R.fail("excel导出失败!");
|
}
|
try {
|
// excel模板封装
|
ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream());
|
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" +"充电算帐单已出账" + ".xlsx");
|
// 自动释放资源
|
try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) {
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
|
excelWriter.fill(new FillWrapper("data1", chargingBillVOS), fillConfig, writeSheet);
|
excelWriter.fill(new FillWrapper("data2", data.getExportList()), fillConfig, writeSheet);
|
excelWriter.finish();
|
} catch (Exception e) {
|
return R.fail("excel导出失败!");
|
}
|
} catch (IOException e) {
|
return R.fail("excel导出失败!");
|
}
|
return R.ok();
|
}
|
@ApiOperation(value = "下载", tags = {"管理后台-账户结算账单"})
|
@PutMapping("/downloadAccount")
|
public R downloadAccount(@RequestBody ChargingListQuery dto,HttpServletResponse response)
|
{
|
AccountListVO data = orderClient.accountBillList(dto).getData();
|
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 {
|
// excel模板封装
|
ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream());
|
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" +"账户结算账单" + ".xlsx");
|
// 自动释放资源
|
try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) {
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build();
|
excelWriter.fill(new FillWrapper("data1", data.getList().getRecords()), fillConfig, writeSheet);
|
excelWriter.finish();
|
} catch (Exception e) {
|
return R.fail("excel导出失败!");
|
}
|
} catch (IOException e) {
|
return R.fail("excel导出失败!");
|
}
|
return R.ok();
|
}
|
|
@ApiOperation(value = "导出", tags = {"管理后台-结算汇总表"})
|
@GetMapping("/downloadSettlementTotal")
|
public R downloadSettlementTotal(String time,HttpServletResponse response)
|
{
|
SettlementTotalVO data = chargingOrderClient.settlementTotalR(time).getData();
|
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 {
|
// excel模板封装
|
ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream());
|
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" +"运营商名称1-充电桩名称1-结算对账单明细-结算月份1" + ".xlsx");
|
// 自动释放资源
|
try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) {
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build();
|
excelWriter.fill(new FillWrapper("data1", data.getList1()), fillConfig, writeSheet);
|
excelWriter.fill(new FillWrapper("data2", data.getList2()), fillConfig, writeSheet);
|
excelWriter.finish();
|
} catch (Exception e) {
|
return R.fail("excel导出失败!");
|
}
|
} catch (IOException e) {
|
return R.fail("excel导出失败!");
|
}
|
return R.ok();
|
}
|
@ApiOperation(value = "下载", tags = {"管理后台-结算表记录"})
|
@GetMapping("/downloadSettlement")
|
public R downloadSettlement(String uid,HttpServletResponse response)
|
{
|
TSettlementConfirm data = chargingOrderClient.downloadSettlement(uid).getData();
|
List<Site> data1 = siteClient.getSiteByIds(Arrays.asList(data.getSiteId())).getData();
|
if (!data1.isEmpty()){
|
data.setSiteName(data1.get(0).getName());
|
}
|
Partner data2 = siteClient.getPartnerR(data.getPartnerId()).getData();
|
if (data2!=null){
|
data.setPartnerName(data2.getName());
|
}
|
List<TSettlementConfirm> chargingBillVOS = new ArrayList<>();
|
chargingBillVOS.add(data);
|
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 {
|
// excel模板封装
|
ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream());
|
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" +"运营商名称1-充电桩名称1-结算对账单明细-结算月份1" + ".xlsx");
|
// 自动释放资源
|
try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) {
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
WriteSheet writeSheet2 = EasyExcel.writerSheet().build();
|
WriteSheet writeSheet3 = EasyExcel.writerSheet().build();
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
|
excelWriter.fill(new FillWrapper("data1", chargingBillVOS), fillConfig, writeSheet);
|
excelWriter.fill(new FillWrapper("data2", chargingBillVOS), fillConfig, writeSheet2);
|
excelWriter.fill(new FillWrapper("data3", data.getList()), fillConfig, writeSheet3);
|
excelWriter.finish();
|
} catch (Exception e) {
|
return R.fail("excel导出失败!");
|
}
|
} catch (IOException e) {
|
return R.fail("excel导出失败!");
|
}
|
return R.ok();
|
}
|
|
|
|
|
|
|
@ApiOperation(value = "下载-未出账", tags = {"管理后台-充电算账单"})
|
@GetMapping("/download")
|
public R download(String uid,HttpServletResponse response)
|
{
|
ChargingListQuery chargingListQuery = new ChargingListQuery();
|
chargingListQuery.setUid(uid);
|
chargingListQuery.setPageCurr(1);
|
chargingListQuery.setPageSize(99999);
|
ChargingBillVO data = chargingOrderClient.chargingBillListR(chargingListQuery).getData();
|
|
List<ChargingBillVO> chargingBillVOS = new ArrayList<>();
|
chargingBillVOS.add(data);
|
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("月账单-"+data.getCategory()+data.getBillWeek()+data.getSiteName(), CharEncoding.UTF_8) + ".xlsx");
|
} catch (UnsupportedEncodingException e) {
|
return R.fail("excel导出失败!");
|
}
|
try {
|
// excel模板封装
|
ExcelWriterBuilder excelWriterBuilder = EasyExcelFactory.write(response.getOutputStream());
|
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("template/" +"充电算帐单已出账" + ".xlsx");
|
// 自动释放资源
|
try (ExcelWriter excelWriter = excelWriterBuilder.withTemplate(stream).build()) {
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
|
excelWriter.fill(new FillWrapper("data1", chargingBillVOS), fillConfig, writeSheet);
|
excelWriter.fill(new FillWrapper("data2", data.getExportList()), fillConfig, writeSheet);
|
excelWriter.finish();
|
} catch (Exception e) {
|
return R.fail("excel导出失败!");
|
}
|
} catch (IOException e) {
|
return R.fail("excel导出失败!");
|
}
|
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) {
|
|
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();
|
|
}
|
|
|
|
|
|
|
}
|