|
@@ -6,10 +6,16 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import cn.com.crbank.ommo.bean.ResultMessage;
|
|
|
import cn.com.crbank.ommo.esclient.ElasticsearchRunner;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.util.ListUtils;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.szwl.common.aop.LogAnnotation;
|
|
@@ -20,11 +26,9 @@ import com.szwl.model.bean.*;
|
|
|
import com.szwl.model.bo.JsonMessage;
|
|
|
import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.bo.ResponseModel;
|
|
|
+import com.szwl.model.dto.OrderDto;
|
|
|
import com.szwl.model.entity.*;
|
|
|
-import com.szwl.model.excel.CoinOrderTarget;
|
|
|
-import com.szwl.model.excel.OrderByAdminTarget;
|
|
|
-import com.szwl.model.excel.OrderByClientidTarget;
|
|
|
-import com.szwl.model.excel.OrderTarget;
|
|
|
+import com.szwl.model.excel.*;
|
|
|
import com.szwl.model.query.*;
|
|
|
import com.szwl.model.utils.DateUtils;
|
|
|
import com.szwl.model.utils.FgObjectUtil;
|
|
@@ -32,7 +36,9 @@ import com.szwl.model.utils.JsonUtils;
|
|
|
import com.szwl.service.*;
|
|
|
import com.szwl.service.es.EsTEquipmentService;
|
|
|
import com.szwl.service.es.EsTOrderService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
@@ -58,6 +64,7 @@ import java.util.*;
|
|
|
* @since 2022-06-14
|
|
|
*/
|
|
|
@Slf4j
|
|
|
+@Api(value = "/tOrder", tags = {"订单管理"})
|
|
|
@RestController
|
|
|
@RequestMapping("/tOrder")
|
|
|
public class TOrderController {
|
|
@@ -1357,7 +1364,6 @@ public class TOrderController {
|
|
|
String startDate, String endDate, String companyType, String machineType,
|
|
|
long current, long size) throws ParseException {
|
|
|
current = 1L;
|
|
|
-// size = 1000L;
|
|
|
size = 5000L;
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
Date begin = null;
|
|
@@ -1554,64 +1560,6 @@ public class TOrderController {
|
|
|
|
|
|
//1,线下
|
|
|
if (type.equals("1")) {
|
|
|
-// LambdaQueryWrapper<TCoinOrder> query = Wrappers.lambdaQuery();
|
|
|
-// if (StringUtils.isNotEmpty(userName) && !userName.equals("admin")) {
|
|
|
-// ResponseModel<TAdmin> adminByUsername = szwlFeign.getAdminByUsername(userName);
|
|
|
-// TAdmin data = adminByUsername.getData();
|
|
|
-// if (data == null || data.getId() == null) {
|
|
|
-// return R.fail(ResponseCodesEnum.A0001, "找不到商家");
|
|
|
-// }
|
|
|
-// query.eq(TCoinOrder::getAdminId, data.getId());
|
|
|
-// } else if (StringUtils.isEmpty(userName)) {
|
|
|
-// //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
|
|
|
-// if (StringUtils.isNotEmpty(adminType)) {
|
|
|
-// if (admin.getIsAdmined() && admin.getType() > 1) {
|
|
|
-// if (admin.getType() > 1) {
|
|
|
-// if (adminType.equals("all")) {
|
|
|
-// //查找所有下级
|
|
|
-// List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(adminId));
|
|
|
-// query.in(TCoinOrder::getAdminId, admidIdList);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// if (admin.getType() > 1) {
|
|
|
-// //登录账户为子账户 不查下级 只查对应机器的订单
|
|
|
-// TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
|
|
|
-// if (adminEquipment.getType().equals("0")) {
|
|
|
-// //全部机器
|
|
|
-// TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
|
|
|
-// query.eq(TCoinOrder::getAdminId, upAdmin.getId());
|
|
|
-// } else {
|
|
|
-// String equipmentIds = adminEquipment.getEquipmentIds();
|
|
|
-// List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
|
|
|
-// query.in(TCoinOrder::getClientId, equipmentIdList);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// } else {
|
|
|
-// //判断当前账号状态 公司还是商家
|
|
|
-// if (admin.getType() > 1) {
|
|
|
-// //商家 判断是否子账户
|
|
|
-// if (admin.getIsAdmined()) {
|
|
|
-// //商家自己
|
|
|
-// query.eq(TCoinOrder::getAdminId, adminId);
|
|
|
-// } else {
|
|
|
-// //商家 子账户
|
|
|
-// //登录账户为子账户 不查下级 只查对应机器的订单
|
|
|
-// TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
|
|
|
-// if (adminEquipment.getType().equals("0")) {
|
|
|
-// //全部机器
|
|
|
-// TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
|
|
|
-// query.eq(TCoinOrder::getAdminId, upAdmin.getId());
|
|
|
-// } else {
|
|
|
-// String equipmentIds = adminEquipment.getEquipmentIds();
|
|
|
-// List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
|
|
|
-// query.in(TCoinOrder::getClientId, equipmentIdList);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
LambdaQueryWrapper<TCoinOrder> query = Wrappers.lambdaQuery();
|
|
|
if (!userName.equals("admin")) {
|
|
|
// 如果为账户
|
|
@@ -1746,6 +1694,248 @@ public class TOrderController {
|
|
|
return R.ok("同步es成功");
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("订单明细导出")
|
|
|
+ @PostMapping("/newOrderExport")
|
|
|
+ public void newOrderExport(HttpServletResponse response, @RequestBody OrderDto orderDto) {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date begin = null;
|
|
|
+ Date end = null;
|
|
|
+ try {
|
|
|
+ begin = simpleDateFormat.parse(orderDto.getStartDate());
|
|
|
+ end = simpleDateFormat.parse(orderDto.getEndDate());
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ long time = end.getTime() - begin.getTime();
|
|
|
+ if (time > 183 * 24 * 60 * 60 * 1000L) {
|
|
|
+ log.error("导出订单明细时间范围不能超过半年");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //类型
|
|
|
+ //0,线上
|
|
|
+ if (orderDto.getType().equals("0")) {
|
|
|
+ try {
|
|
|
+ orderService.dataExport(orderDto, begin, end, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+// LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
|
|
|
+// if (!orderDto.getUserName().equals("admin")) {
|
|
|
+// if (StringUtils.isNotEmpty(orderDto.getUserName())) {
|
|
|
+// TAdmin data = R.getDataIfSuccess(szwlFeign.getAdminByUsername(orderDto.getUserName()));
|
|
|
+// if (data == null || data.getId() == null) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// if (data.getIsAdmined()) {
|
|
|
+// query.eq(TOrder::getAdminId, data.getId());
|
|
|
+// } else {
|
|
|
+// if (data.getParentId() != 1) {
|
|
|
+// query.eq(TOrder::getAdminId, data.getParentId());
|
|
|
+// //查找子账户所管理的机器
|
|
|
+// TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(orderDto.getAdminId()));
|
|
|
+// if (!adminEquipment.getType().equals("0")) {
|
|
|
+// List<String> list = R.getDataIfSuccess(szwlFeign.getClientIds(orderDto.getAdminId()));
|
|
|
+// if (list == null || list.size() == 0) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// query.in(TOrder::getClientId, list);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// //adminType="all"时,代表查全部下级 子账户没有这个权限 公司人员默认查所有人
|
|
|
+// if (StringUtils.isNotEmpty(orderDto.getAdminType())) {
|
|
|
+// if (admin.getIsAdmined() && admin.getType() > 1) {
|
|
|
+// if (admin.getType() > 1) {
|
|
|
+// if (orderDto.getAdminType().equals("all")) {
|
|
|
+// //查找所有下级
|
|
|
+// List<Long> admidIdList = R.getDataIfSuccess(szwlFeign.getAdminIdList(orderDto.getAdminId()));
|
|
|
+// query.in(TOrder::getAdminId, admidIdList);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if (admin.getType() > 1) {
|
|
|
+// //登录账户为子账户 不查下级 只查对应机器的订单
|
|
|
+// TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
|
|
|
+// if (adminEquipment.getType().equals("0")) {
|
|
|
+// //全部机器
|
|
|
+// TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
|
|
|
+// query.eq(TOrder::getAdminId, upAdmin.getId());
|
|
|
+// } else {
|
|
|
+// String equipmentIds = adminEquipment.getEquipmentIds();
|
|
|
+// List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
|
|
|
+// query.in(TOrder::getClientId, equipmentIdList);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// //判断当前账号状态 公司还是商家
|
|
|
+// if (admin.getType() > 1) {
|
|
|
+// //商家 判断是否子账户
|
|
|
+// if (admin.getIsAdmined()) {
|
|
|
+// //商家自己
|
|
|
+// query.eq(TOrder::getAdminId, orderDto.getAdminId());
|
|
|
+// } else {
|
|
|
+// //商家 子账户
|
|
|
+// //登录账户为子账户 不查下级 只查对应机器的订单
|
|
|
+// TAdminEquipment adminEquipment = R.getDataIfSuccess(szwlFeign.getClientIdList(String.valueOf(admin.getParentId())));
|
|
|
+// if (adminEquipment.getType().equals("0")) {
|
|
|
+// //全部机器
|
|
|
+// TAdmin upAdmin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(admin.getParentId())));
|
|
|
+// query.eq(TOrder::getAdminId, upAdmin.getId());
|
|
|
+// } else {
|
|
|
+// String equipmentIds = adminEquipment.getEquipmentIds();
|
|
|
+// List<String> equipmentIdList = JSON.parseArray(equipmentIds, String.class);
|
|
|
+// query.in(TOrder::getClientId, equipmentIdList);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotEmpty(orderDto.getPayType())) {
|
|
|
+// query.eq(TOrder::getFrpCode, orderDto.getPayType());
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotEmpty(orderDto.getClientId())) {
|
|
|
+// TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(orderDto.getClientId()));
|
|
|
+// //判断机器是否属于这个登陆账号
|
|
|
+// if (admin.getType() > 1) {
|
|
|
+// //商家
|
|
|
+// if (equipment.getAdminId().toString().equals(admin.getId().toString())) {
|
|
|
+// query.eq(TOrder::getEquipmentId, equipment.getId());
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// query.eq(TOrder::getEquipmentId, equipment.getId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotEmpty(orderDto.getEquipmentId())) {
|
|
|
+// query.eq(TOrder::getEquipmentId, orderDto.getEquipmentId());
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotEmpty(orderDto.getStatus())) {
|
|
|
+// query.eq(TOrder::getStatus, orderDto.getStatus());
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotEmpty(orderDto.getDateType())) {
|
|
|
+// if (orderDto.getDateType().equals("0")) {
|
|
|
+// //创建时间
|
|
|
+// if (begin != null && end != null) {
|
|
|
+// query.gt(TOrder::getCreateDate, begin);
|
|
|
+// query.lt(TOrder::getCreateDate, end);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (orderDto.getDateType().equals("1")) {
|
|
|
+// //退款时间
|
|
|
+// if (begin != null && end != null) {
|
|
|
+// query.gt(TOrder::getRefundDate, begin);
|
|
|
+// query.lt(TOrder::getRefundDate, end);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 公司平台
|
|
|
+// // 申泽平台管理员
|
|
|
+// String companyType = orderDto.getCompanyType();
|
|
|
+// if (admin.getId() == 2738) {
|
|
|
+// companyType = "0";
|
|
|
+// }
|
|
|
+// // 七云平台管理员
|
|
|
+// if (admin.getId() == 2739) {
|
|
|
+// companyType = "1";
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotEmpty(companyType)) {
|
|
|
+// if (companyType.equals("0")) {
|
|
|
+// String finalCompanyType = companyType;
|
|
|
+// query.nested(q -> q.isNull(TOrder::getCompanyType).or()
|
|
|
+// .eq(TOrder::getCompanyType, finalCompanyType));
|
|
|
+// } else {
|
|
|
+// query.eq(TOrder::getCompanyType, companyType);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// String machineType = orderDto.getMachineType();
|
|
|
+// if (StringUtils.isNotEmpty(machineType)) {
|
|
|
+// if (machineType.equals("0")) {
|
|
|
+// query.nested(q -> q.isNull(TOrder::getMachineType).or()
|
|
|
+// .eq(TOrder::getMachineType, machineType));
|
|
|
+// } else {
|
|
|
+// query.eq(TOrder::getMachineType, machineType);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 查询总数
|
|
|
+// total = orderService.count(query);
|
|
|
+// // 总页数
|
|
|
+// int totalPages = (total + pageSize - 1) / pageSize;
|
|
|
+// // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
|
|
|
+// response.setContentType("application/octet-stream; charset=UTF-8");
|
|
|
+// response.setCharacterEncoding("utf-8");
|
|
|
+// // 这里URLEncoder.encode可以防止中文乱码
|
|
|
+// String fileName = URLEncoder.encode("订单记录-" + System.currentTimeMillis(), "UTF-8").replaceAll("\\+", "%20");
|
|
|
+// response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+// // 创建ExcelWriter对象
|
|
|
+// ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), NewOrderTarget.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
|
|
|
+// // 创建 Sheet 对象
|
|
|
+// WriteSheet writeSheet = EasyExcel.writerSheet(0, "订单").build();
|
|
|
+// // 创建 CountDownLatch 对象
|
|
|
+// CountDownLatch countDownLatch = new CountDownLatch(totalPages);
|
|
|
+// // 创建线程池
|
|
|
+// ExecutorService executorService = Executors.newFixedThreadPool(10);
|
|
|
+// // 循环写入数据
|
|
|
+// for (int i = 1; i <= totalPages; i++) {
|
|
|
+// int page = i;
|
|
|
+// executorService.submit(() -> {
|
|
|
+// try {
|
|
|
+// Page<TOrder> orderPage = new Page<>(page, pageSize);
|
|
|
+// Page<TOrder> pageList = orderService.page(orderPage, query);
|
|
|
+// List<TOrder> list = pageList.getRecords();
|
|
|
+// // 写入数据
|
|
|
+// List<NewOrderTarget> orderTargetList = orderService.exportOrderData(admin, list);
|
|
|
+// synchronized (excelWriter) {
|
|
|
+// excelWriter.write(orderTargetList, writeSheet);
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// // 异常处理
|
|
|
+// e.printStackTrace();
|
|
|
+// } finally {
|
|
|
+// // 计数器减一
|
|
|
+// countDownLatch.countDown();
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// // 等待所有线程执行完毕
|
|
|
+// try {
|
|
|
+// countDownLatch.await();
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// while (hasNextPage) {
|
|
|
+// Page<TOrder> orderPage = new Page<>(pageNum, pageSize);
|
|
|
+// Page<TOrder> page = orderService.page(orderPage, query);
|
|
|
+// List<TOrder> list = page.getRecords();
|
|
|
+// if (CollectionUtils.isEmpty(list)) {
|
|
|
+// hasNextPage = false;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// // 写入数据
|
|
|
+// List<NewOrderTarget> orderTargetList = orderService.exportOrderData(admin, list);
|
|
|
+// excelWriter.write(orderTargetList, EasyExcel.writerSheet("订单").build());
|
|
|
+// // 更新起始位置
|
|
|
+// pageNum++;
|
|
|
+// }
|
|
|
+ // 关闭 ExcelWriter 对象
|
|
|
+// excelWriter.finish();
|
|
|
+//
|
|
|
+// // 关闭线程池
|
|
|
+// executorService.shutdown();
|
|
|
+ }
|
|
|
+
|
|
|
+ //1,线下
|
|
|
+ if (orderDto.getType().equals("1")) {
|
|
|
+ try {
|
|
|
+ coinOrderService.dataExport(orderDto, begin, end, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation(value = "线上通过时间分组")
|
|
|
@RequestMapping(value = "/getStatisticsByClientId", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
|
|
|
@ResponseBody
|