diff --git a/fuintAdmin/src/main.js b/fuintAdmin/src/main.js index 43b4aa1..828b5b9 100644 --- a/fuintAdmin/src/main.js +++ b/fuintAdmin/src/main.js @@ -12,7 +12,7 @@ import store from './store' import router from './router' import directive from './directive' // directive import plugins from './plugins' // plugins -import { download } from '@/utils/request' +import { download,download1,download2 } from '@/utils/request' import './assets/icons' // icon import './permission' // permission control @@ -42,14 +42,19 @@ import Print from 'vue-print-nb' import TreeSelect from '@/components/TreeSelect' // 会员选择组件 import UserSelect from '@/components/UserSelect' +import { selectDictLabel, selectDictLabels} from "@/utils/ruoyi"; // 全局方法挂载 Vue.prototype.getConfigKey = getConfigKey +Vue.prototype.selectDictLabel = selectDictLabel +Vue.prototype.selectDictLabels = selectDictLabels Vue.prototype.parseTime = parseTime Vue.prototype.resetForm = resetForm Vue.prototype.addDateRange = addDateRange Vue.prototype.getName = getName Vue.prototype.download = download +Vue.prototype.download1 = download1 +Vue.prototype.download2 = download2 Vue.prototype.handleTree = handleTree // 全局组件挂载 diff --git a/fuintAdmin/src/utils/request.js b/fuintAdmin/src/utils/request.js index 178388b..8836f6a 100644 --- a/fuintAdmin/src/utils/request.js +++ b/fuintAdmin/src/utils/request.js @@ -1,14 +1,15 @@ import axios from 'axios' -import { Notification, MessageBox, Message } from 'element-ui' +import { Notification, MessageBox, Message, Loading } from 'element-ui' import store from '@/store' import { getToken } from '@/utils/auth' import errorCode from '@/utils/errorCode' import { tansParams } from "@/utils/fuint"; import cache from '@/plugins/cache' - +import request from '@/utils/request' +import { blobValidate } from "@/utils/ruoyi"; // 是否显示重新登录 export let isRelogin = { show: false }; - +let downloadLoadingInstance; axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' // 创建axios实例 const service = axios.create({ @@ -135,6 +136,42 @@ export function download(url, params) { window.open(url, '_blank') } +// 通用下载方法 +export function download1(url, params) { + return request({ + url: url + '?token='+ getToken() + '&'+ param(params), + method: 'get' + }) + // url = process.env.VUE_APP_BASE_API + url + '?token='+ getToken() + '&'+ param(params) + // window.open(url, '_blank') +} +// 通用下载方法 +export function download2(url, params, filename, config) { + downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", }) + return service.post(url, params, { + transformRequest: [(params) => { return tansParams(params) }], + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + responseType: 'blob', + ...config + }).then(async (data) => { + const isBlob = blobValidate(data); + if (isBlob) { + const blob = new Blob([data]) + saveAs(blob, filename) + } else { + const resText = await data.text(); + const rspObj = JSON.parse(resText); + const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'] + Message.error(errMsg); + } + downloadLoadingInstance.close(); + }).catch((r) => { + console.error(r) + Message.error('下载文件出现错误,请联系管理员!') + downloadLoadingInstance.close(); + }) +} + // 组织参数 export function param(data) { let url = '' diff --git a/fuintAdmin/src/views/order/index.vue b/fuintAdmin/src/views/order/index.vue index aa1a7a5..d10a9bc 100644 --- a/fuintAdmin/src/views/order/index.vue +++ b/fuintAdmin/src/views/order/index.vue @@ -91,6 +91,13 @@ 查询 重置 + 导入 @@ -387,6 +394,32 @@ + + + + +
将文件拖到此处,或点击上传
+
+ 仅允许导入xls、xlsx格式文件。 + 下载模板 +
+
+ +
@@ -395,6 +428,7 @@ import { getName } from "@/utils/fuint"; import { getOrderList, updateOrderStatus, getOrderInfo, saveOrder, deleteOrder, verifyOrder, delivered } from "@/api/order"; import { doRefund } from "@/api/refund"; import orderPrintDialog from '../cashier/components/orderPrintDialog' +import { getToken } from "@/utils/auth"; export default { name: "OrderIndex", components: { @@ -486,7 +520,22 @@ export default { { required: true, message: "退款金额不能为空", trigger: "blur" }, { pattern: /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/, message: `请输入正确的退款金额`, trigger: 'blur' } ] - } + }, + // 用户导入参数 + upload: { + // 是否显示弹出层(用户导入) + open: false, + // 弹出层标题(用户导入) + title: "", + // 是否禁用上传 + isUploading: false, + // 是否更新已经存在的用户数据 + updateSupport: 0, + // 设置上传的请求头部 + headers: { 'Access-Token': getToken() }, + // 上传的地址 + url: process.env.VUE_APP_BASE_API + "/backendApi/order/importData" + }, }; }, created() { @@ -768,6 +817,32 @@ export default { break; } }, + /** 导入按钮操作 */ + handleImport() { + this.upload.title = "用户导入"; + this.upload.open = true; + }, + /** 下载模板操作 */ + importTemplate() { + this.download2('/backendApi/order/exportTemplate', { + }, `订单模板${new Date().getTime()}.xlsx`) + }, + // 文件上传中处理 + handleFileUploadProgress(event, file, fileList) { + this.upload.isUploading = true; + }, + // 文件上传成功处理 + handleFileSuccess(response, file, fileList) { + this.upload.open = false; + this.upload.isUploading = false; + this.$refs.upload.clearFiles(); + this.$alert("
" + response.msg + "
", "导入结果", { dangerouslyUseHTMLString: true }); + this.getList(); + }, + // 提交上传文件 + submitFileForm() { + this.$refs.upload.submit(); + } } }; diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderModeEnum.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderModeEnum.java index 03a8286..18d09e1 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderModeEnum.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderModeEnum.java @@ -34,4 +34,34 @@ public enum OrderModeEnum { public void setValue(String value) { this.value = value; } + + /** + * 根据key获取value + * + * @param key + * @return + */ + public static String getName(String key) { + final OrderModeEnum[] values = OrderModeEnum.values(); + for (OrderModeEnum value : values) { + if (key.equals(value.getKey())) { + return value.getValue(); + } + } + return null; + } + /** + * 根据value获取key + * + * @return + */ + public static String getKeyName(String value) { + final OrderModeEnum[] values = OrderModeEnum.values(); + for (OrderModeEnum order : values) { + if (value.equals(order.getValue())) { + return order.getKey(); + } + } + return null; + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderTypeEnum.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderTypeEnum.java index cff5bcb..ff22559 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderTypeEnum.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/OrderTypeEnum.java @@ -53,4 +53,18 @@ public enum OrderTypeEnum { } return null; } + /** + * 根据value获取key + * + * @return + */ + public static String getKeyName(String value) { + final OrderTypeEnum[] values = OrderTypeEnum.values(); + for (OrderTypeEnum order : values) { + if (value.equals(order.getValue())) { + return order.getKey(); + } + } + return null; + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/PayTypeEnum.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/PayTypeEnum.java index 5215143..e4c068d 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/PayTypeEnum.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/enums/PayTypeEnum.java @@ -37,4 +37,34 @@ public enum PayTypeEnum { public void setValue(String value) { this.value = value; } + + /** + * 根据key获取value + * + * @param key + * @return + */ + public static String getName(String key) { + final PayTypeEnum[] values = PayTypeEnum.values(); + for (PayTypeEnum value : values) { + if (key.equals(value.getKey())) { + return value.getValue(); + } + } + return null; + } + /** + * 根据value获取key + * + * @return + */ + public static String getKeyName(String value) { + final PayTypeEnum[] values = PayTypeEnum.values(); + for (PayTypeEnum order : values) { + if (value.equals(order.getValue())) { + return order.getKey(); + } + } + return null; + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/excelDto/UserOrderExcelDto.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/excelDto/UserOrderExcelDto.java new file mode 100644 index 0000000..6b7d07d --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/excelDto/UserOrderExcelDto.java @@ -0,0 +1,74 @@ +package com.fuint.common.excelDto; + +import com.fuint.common.dto.*; +import com.fuint.repository.model.MtRefund; +import com.fuint.repository.model.MtStore; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * 会员订单实体类 + * + * Created by FSQ + * CopyRight https://www.fuint.cn + */ +@Getter +@Setter +public class UserOrderExcelDto implements Serializable { + + @ApiModelProperty("订单类型") + private String type; + + @ApiModelProperty("支付类型") + private String payType; + + @ApiModelProperty("订单模式") + private String orderMode; + + @ApiModelProperty("订单号") + private String orderSn; + + @ApiModelProperty("所属商户") + private String merchantName; + + @ApiModelProperty("所属店铺") + private String storeName; + + @ApiModelProperty("用户手机号") + private String userName; + + @ApiModelProperty("是否游客") + private String isVisitor; + + @ApiModelProperty("订单金额") + private BigDecimal amount; + + @ApiModelProperty("支付金额") + private BigDecimal payAmount; + + @ApiModelProperty("使用积分数量") + private Integer usePoint; + + @ApiModelProperty("积分金额") + private BigDecimal pointAmount; + + @ApiModelProperty("折扣金额") + private BigDecimal discount; + + @ApiModelProperty("配送费用") + private BigDecimal deliveryFee; + + @ApiModelProperty("支付时间") + private Date payTime; + + @ApiModelProperty("操作员工") + private String staffName; + +} + diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/OrderService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/OrderService.java index 740613e..9473837 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/OrderService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/OrderService.java @@ -9,6 +9,8 @@ import com.fuint.framework.exception.BusinessCheckException; import com.fuint.framework.pagination.PaginationResponse; import com.fuint.repository.model.MtCart; import com.fuint.repository.model.MtOrder; +import org.springframework.web.multipart.MultipartFile; + import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.Date; @@ -239,4 +241,20 @@ public interface OrderService extends IService { * @return * */ List getTobeCommissionOrderList(String dateTime) throws BusinessCheckException; + + /** + * 保存文件 + * + * @param file excel文件 + * @param request 操作者 + * */ + String saveExcelFile(MultipartFile file, HttpServletRequest request) throws Exception; + + /** + * 导入发券列表 + * + * @param file excel文件 + * @param operator 操作者 + * */ + String importSendCoupon(MultipartFile file, String operator, String filePath) throws BusinessCheckException; } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java index 4b9bcf5..ac0b79c 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java @@ -1,5 +1,6 @@ package com.fuint.common.service.impl; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -7,13 +8,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fuint.common.Constants; import com.fuint.common.dto.*; import com.fuint.common.enums.*; +import com.fuint.common.excelDto.UserOrderExcelDto; import com.fuint.common.param.OrderListParam; import com.fuint.common.param.SettlementParam; import com.fuint.common.service.*; -import com.fuint.common.util.CommonUtil; -import com.fuint.common.util.DateUtil; -import com.fuint.common.util.SeqUtil; -import com.fuint.common.util.TokenUtil; +import com.fuint.common.util.*; import com.fuint.framework.annoation.OperationServiceLog; import com.fuint.framework.exception.BusinessCheckException; import com.fuint.framework.pagination.PaginationResponse; @@ -30,14 +29,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.context.annotation.Lazy; +import org.springframework.core.env.Environment; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ResourceUtils; +import org.springframework.web.multipart.MultipartFile; import weixin.popular.util.JsonUtil; import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.IOException; import java.math.BigDecimal; import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -169,6 +174,11 @@ public class OrderServiceImpl extends ServiceImpl implem * */ private PaymentService paymentService; + /** + * 系统环境变量 + * */ + private Environment env; + /** * 获取用户订单列表 * @param orderListParam @@ -2116,4 +2126,153 @@ public class OrderServiceImpl extends ServiceImpl implem public List getTobeCommissionOrderList(String dateTime) { return mtOrderMapper.getTobeCommissionOrderList(dateTime); } + + /** + * 保存文件 + * + * @param file excel文件 + * @param request + * */ + public String saveExcelFile(MultipartFile file, HttpServletRequest request) throws Exception { + String fileName = file.getOriginalFilename(); + + String imageName = fileName.substring(fileName.lastIndexOf(".")); + String pathRoot = env.getProperty("images.root"); + if (pathRoot == null || StringUtil.isEmpty(pathRoot)) { + pathRoot = ResourceUtils.getURL("classpath:").getPath(); + } + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + + String filePath = "/static/uploadFiles/"+ DateUtil.formatDate(new Date(), "yyyyMMdd")+"/"; + String path = filePath + uuid + imageName; + + try { + File tempFile = new File(pathRoot + path); + if (!tempFile.getParentFile().exists()) { + tempFile.getParentFile().mkdirs(); + } + CommonUtil.saveMultipartFile(file, pathRoot + path); + } catch (Exception e) { + //empty + } + + return path; + } + + /** + * 导入订单列表 + * + * @param file excel文件 + * @param operator 操作者 + * */ + @Override + @Transactional(rollbackFor = Exception.class) + @OperationServiceLog(description = "导入订单列表") + public String importSendCoupon(MultipartFile file, String operator, String filePath) throws BusinessCheckException { + String originalFileName = file.getOriginalFilename(); + boolean isExcel2003 = XlsUtil.isExcel2003(originalFileName); + boolean isExcel2007 = XlsUtil.isExcel2007(originalFileName); + + if (!isExcel2003 && !isExcel2007) { + logger.error("importSendCouponController->uploadFile:{}", "文件类型不正确"); + throw new BusinessCheckException("文件类型不正确"); + } + + List> content = new ArrayList<>(); + try { + content = XlsUtil.readExcelContent(file.getInputStream(), isExcel2003, 1, null, null, null); + } catch (IOException e) { + logger.error("CouponGroupServiceImpl->parseExcelContent{}", e); + throw new BusinessCheckException("导入失败"+e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + + StringBuffer errorMsg = new StringBuffer(); + StringBuffer errorMsgNoGroup = new StringBuffer(); + StringBuffer errorMsgNoNum = new StringBuffer(); + StringBuffer errorMsgNoRegister = new StringBuffer(); + + List rows = new ArrayList<>(); + + for (int i = 0; i < content.size(); i++) { + List groupIdArr = new ArrayList<>(); + List numArr = new ArrayList<>(); + + List rowContent = content.get(i); + MtOrder order = new MtOrder(); + String type = rowContent.get(0); + if(StringUtil.isNotEmpty(type)){ + String keyName = OrderTypeEnum.getKeyName(type); + if(StringUtil.isNotEmpty(keyName)){ + type = keyName; + } + } + order.setType(type); + String payType = rowContent.get(1); + if(StringUtil.isNotEmpty(payType)){ + String keyName = PayTypeEnum.getKeyName(payType); + if(StringUtil.isNotEmpty(keyName)){ + payType = keyName; + } + } + order.setPayType(payType); + String orderMode = rowContent.get(2); + if(StringUtil.isNotEmpty(orderMode)){ + String keyName = OrderModeEnum.getKeyName(orderMode); + if(StringUtil.isNotEmpty(keyName)){ + orderMode = keyName; + } + } + order.setOrderMode(orderMode); + String orderSn = rowContent.get(3); + order.setOrderSn(orderSn); + String merchantName = rowContent.get(4); +// order.setMerchantId(); + String storeName = rowContent.get(5); + if(StringUtil.isNotEmpty(storeName)){ + StoreDto storeDto = storeService.queryStoreByName(storeName); + if(ObjectUtil.isNotEmpty(storeDto)){ + order.setStoreId(storeDto.getId()); + } + } + String userName = rowContent.get(6); + String isVisitor = rowContent.get(7); + order.setIsVisitor(isVisitor); + String amount = rowContent.get(8); + if(StringUtil.isNotEmpty(amount)){ + order.setAmount(new BigDecimal(amount)); + } + String payAmount = rowContent.get(9); + if(StringUtil.isNotEmpty(payAmount)){ + order.setPayAmount(new BigDecimal(payAmount)); + } + String usePoint = rowContent.get(10); + if(StringUtil.isNotEmpty(usePoint)){ + order.setUsePoint(Integer.valueOf(usePoint)); + } + String pointAmount = rowContent.get(11); + if(StringUtil.isNotEmpty(pointAmount)){ + order.setPointAmount(new BigDecimal(pointAmount)); + } + String discount = rowContent.get(12); + if(StringUtil.isNotEmpty(discount)){ + order.setDiscount(new BigDecimal(discount)); + } + String deliveryFee = rowContent.get(13); + if(StringUtil.isNotEmpty(deliveryFee)){ + order.setDeliveryFee(new BigDecimal(deliveryFee)); + } + String payTime = rowContent.get(14); + String staffName = rowContent.get(15); +// order.setStaffId(); + mtOrderMapper.insert(order); + } + + + // 导入批次 + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + + return uuid; + } } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendOrderController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendOrderController.java index a4b6835..d591330 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendOrderController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendOrderController.java @@ -585,7 +585,7 @@ public class BackendOrderController extends BaseController { * @throws BusinessCheckException */ @ApiOperation(value = "导出模板文件") - @RequestMapping(value = "/exportTemplate", method = RequestMethod.GET) + @RequestMapping(value = "/exportTemplate", method = RequestMethod.POST) @CrossOrigin public void exportTemplate(HttpServletRequest request, HttpServletResponse response) throws BusinessCheckException { ClassLoader classLoader = this.getClass().getClassLoader(); @@ -594,9 +594,9 @@ public class BackendOrderController extends BaseController { ExcelExportDto excelExportDto = new ExcelExportDto(); excelExportDto.setSrcPath(srcTemplateFilePath); - excelExportDto.setSrcTemplateFileName("template" + File.separator + "importTemplate.xlsx"); + excelExportDto.setSrcTemplateFileName("template" + File.separator + "订单导入模板.xlsx"); - String filename = "订单模板" + ".xlsx"; + String filename = "订单导入模板" + ".xlsx"; try { OutputStream out = response.getOutputStream(); XlsUtil.setXlsHeader(request, response, filename); @@ -608,45 +608,25 @@ public class BackendOrderController extends BaseController { } } + /** + * 上传文件 + * + * @param request + * @throws + */ + @ApiOperation(value = "上传文件") + @RequestMapping(value = "/importData", method = RequestMethod.POST, produces = "text/html;charset=UTF-8") + @CrossOrigin + public ResponseObject uploadFile(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws Exception { + String token = request.getHeader("Access-Token"); + AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token); + if (accountInfo == null) { + return getFailureResult(1001, "请先登录"); + } -// @PreAuthorize("@ss.hasPermi('system:user:import')") -// @PostMapping("/importData") -// public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception -// { -// ExcelUtil util = new ExcelUtil(SysUser.class); -// List userList = util.importExcel(file.getInputStream()); -// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); -// String operName = loginUser.getUsername(); -// String message = userService.importUser(userList, updateSupport, operName); -// return AjaxResult.success(message); -// } -// -// @GetMapping("/importTemplate") -// public AjaxResult importTemplate() -// { -// ExcelUtil util = new ExcelUtil(SysUser.class); -// return util.importTemplateExcel("用户数据"); -// } - -// /** -// * 上传文件 -// * -// * @param request -// * @throws -// */ -// @ApiOperation(value = "上传文件") -// @RequestMapping(value = "/upload/", method = RequestMethod.POST, produces = "text/html;charset=UTF-8") -// @CrossOrigin -// public ResponseObject uploadFile(HttpServletRequest request, @RequestParam("fileInput") MultipartFile file) throws Exception { -// String token = request.getHeader("Access-Token"); -// AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token); -// if (accountInfo == null) { -// return getFailureResult(1001, "请先登录"); -// } -// -// String filePath = couponGroupService.saveExcelFile(file, request); -// String uuid = couponGroupService.importSendCoupon(file, accountInfo.getAccountName(), filePath); -// return getSuccessResult(uuid); -// } + String filePath = orderService.saveExcelFile(file, request); + String uuid = orderService.importSendCoupon(file, accountInfo.getAccountName(), filePath); + return getSuccessResult(uuid); + } } diff --git a/fuintBackend/fuint-application/src/main/resources/template/订单导入模板.xlsx b/fuintBackend/fuint-application/src/main/resources/template/订单导入模板.xlsx new file mode 100644 index 0000000..8b93e03 Binary files /dev/null and b/fuintBackend/fuint-application/src/main/resources/template/订单导入模板.xlsx differ