| | |
| | | package com.ruoyi.order.controller; |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.dto.ChargingOrderGroup; |
| | | import com.ruoyi.common.core.dto.ChargingPercentProvinceDto; |
| | | import com.ruoyi.common.core.utils.WebUtils; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.dto.GetImportOrderDTO; |
| | | import com.ruoyi.order.export.ChargeOrderExport; |
| | | import com.ruoyi.order.model.ChargeOrder; |
| | | import com.ruoyi.order.service.ChargeOrderService; |
| | | import com.ruoyi.other.api.domain.TIntegralRule; |
| | | import com.ruoyi.system.api.domain.SysConfig; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Api(tags = "充电订单") |
| | |
| | | public class ChargeOrderController { |
| | | @Resource |
| | | private ChargeOrderService chargeOrderService; |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | @PostMapping(value = "/getBySiteIdAndTime") |
| | | public R<List<ChargingOrderGroup>> getBySiteIdAndTime(@RequestBody ChargingPercentProvinceDto chargingPercentProvinceDto) { |
| | | |
| | |
| | | * 导入充电信息 |
| | | */ |
| | | @PostMapping("/importExpress") |
| | | @ApiOperation(value = "导入充电信息", tags = "后台-充电订单-导入充电信息") |
| | | public R importExpress(@RequestParam("file") MultipartFile file) { |
| | | /* JSONObject jsonObject = JSONObject.parseObject(url); |
| | | String url2 = jsonObject.getString("url");*/ |
| | | if (file.isEmpty()) { |
| | | return R.fail("请选择要上传的文件"); |
| | | } |
| | | |
| | | return chargeOrderService.importExpress(file); |
| | | } |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | /** |
| | | * 获取导入订单列表 |
| | | */ |
| | |
| | | @PostMapping("/getImportData") |
| | | @ApiOperation(value = "获取导入订单列表", tags = "后台-充电订单") |
| | | public R<PageInfo<ChargeOrder>> getUserPointPageList(@RequestBody GetImportOrderDTO getImportOrderDTO) { |
| | | |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | R<SysUser> sysUser = sysUserClient.getSysUser(loginUser.getUserid()); |
| | | SysUser data = sysUser.getData(); |
| | | if (data.getRoleType() == 2){ |
| | | // 只查询当前站点数据 |
| | | getImportOrderDTO.setSiteId(data.getSiteId()); |
| | | } |
| | | PageInfo<ChargeOrder> pageInfo=chargeOrderService.getUserPointPageList(getImportOrderDTO); |
| | | |
| | | return R.ok(pageInfo); |
| | | } |
| | | |
| | | @ApiOperation(value = "充电订单导入模板下载", tags = "后台-充电订单") |
| | | @GetMapping("/importChargeOrder") |
| | | public void importChargeOrder() { |
| | | List<ChargeOrderExport> chargeOrderExports = new ArrayList<>(); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ChargeOrderExport.class, chargeOrderExports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("充电订单导入模板.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | System.out.println("充电订单导入模板下载失败!"); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |