Commit 6d660d59 by 王家辉

获取正确的sku并补推

parent 94e2fcbe
...@@ -108,12 +108,27 @@ ...@@ -108,12 +108,27 @@
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<!-- excel工具类开始 -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.apache.poi</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.7.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -41,4 +41,20 @@ public class OrdersController { ...@@ -41,4 +41,20 @@ public class OrdersController {
return JSON.toJSONString(list); return JSON.toJSONString(list);
} }
@PostMapping("/getRightSkuAndOrderPush")
@ResponseBody
public String getRightSkuAndOrderPush(@RequestBody OrderProductDTO orderProductDTO ){
String orderId = orderProductDTO.getOrderCode();
String sku = orderProductDTO.getSku();
Long id = orderProductDTO.getId();
String channel = orderProductDTO.getChannel();
ordersService.RepairByRightSku(id,sku);
ordersService.OrderPush(channel,orderId);
return null;
}
} }
...@@ -17,6 +17,7 @@ import com.freemud.Service.OrdersService; ...@@ -17,6 +17,7 @@ import com.freemud.Service.OrdersService;
import com.freemud.dto.OrderProductDTO; import com.freemud.dto.OrderProductDTO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.List; import java.util.List;
...@@ -26,9 +27,23 @@ public class OrdersServiceImpl implements OrdersService { ...@@ -26,9 +27,23 @@ public class OrdersServiceImpl implements OrdersService {
@Autowired @Autowired
private OrderProductMapper orderProductMapper; private OrderProductMapper orderProductMapper;
@Autowired
private RestTemplate restTemplate;
@Override @Override
public List<OrderProductDTO> getOrderProductDTOByOrderId(String orderId) { public List<OrderProductDTO> getOrderProductDTOByOrderId(String orderId) {
return orderProductMapper.getOrderProductDTOByOrderId(orderId); return orderProductMapper.getOrderProductDTOByOrderId(orderId);
} }
@Override
public void RepairByRightSku(Long id, String sku) {
// 请求修复接口
}
@Override
public void OrderPush(String channel, String orderId) {
// 补推订单
}
} }
...@@ -25,4 +25,7 @@ public interface OrdersService { ...@@ -25,4 +25,7 @@ public interface OrdersService {
*/ */
List<OrderProductDTO> getOrderProductDTOByOrderId(String orderId); List<OrderProductDTO> getOrderProductDTOByOrderId(String orderId);
void RepairByRightSku(Long id, String sku);
void OrderPush(String channel, String orderId);
} }
...@@ -23,6 +23,8 @@ public class OrderProductDTO { ...@@ -23,6 +23,8 @@ public class OrderProductDTO {
// 订单主键 // 订单主键
private String orderId; private String orderId;
private String channel;
// 订单号 // 订单号
private String orderCode; private String orderCode;
......
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: HandleExcelException
* @Package com.freemud.apps.promotion.exception
* @Description: 简单描述下这个类是做什么用的
* @author: jiahui.wang
* @date: 2019/1/30 17:31
* @version V1.0
* @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目的
*/
package com.freemud.exception;
public class HandleExcelException extends Exception {
public HandleExcelException(String message){
super(message);
}
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: FileOperationUtils
* @Package com.freemud.apps.promotion.util
* @Description: 文件上传下载工具类
* @author: jiahui.wang
* @date: 2019/1/29 10:50
* @version V1.0
* @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目的
*/
package com.freemud.utils;
import com.freemud.exception.HandleExcelException;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
public class FileOperationUtils {
private static final String SUFFIX_2007 = ".xlsx";
private static final String SUFFIX_2003 = ".xls";
// 日期的格式
private static final String DateFormate = "yyyy-MM-dd";
/**
* 读取 Excel 并解析对象工具类
* @param file
* @param aimClass
* @param map key-value key表示excel内字段,value表示我们的bean类字段
* @param <T>
* @return
*/
public static <T> List<T> ReadExcelToObj(MultipartFile file, Class<T> aimClass, Map<String,String> map) {
List<T> result = new ArrayList<>();
List<List<String>> rows = readExcel(file, 0);
try {
for (int k = 1; k < rows.size(); k++) {
T t = aimClass.newInstance();
for (int num = 0; num < rows.get(0).size(); num++) {
//循环bean字段(等同循环表头)
for (String header : map.keySet()) {
if (rows.get(0).get(num).equals(header)) {
PropertyDescriptor propertyDescriptor = BeanUtilsBean.getInstance()
.getPropertyUtils().getPropertyDescriptor(t, map.get(header).toString());
if (propertyDescriptor != null) {
BeanUtils.setProperty(t, map.get(header).toString(), changeType(rows.get(k).get(num), propertyDescriptor.getPropertyType()));
break;
}
}
}
}
result.add(t);
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return result;
}
private static Object changeType(String s, Class<?> propertyType) {
System.out.println(propertyType.getTypeName());
if (propertyType.getTypeName().equals("java.lang.String")){
return s;
} else if (propertyType.getTypeName().equals("java.lang.Long")){
return Long.parseLong(s);
} else if (propertyType.getTypeName().equals("java.lang.Float")){
return Float.parseFloat(s);
} else if (propertyType.getTypeName().equals("java.lang.Short")){
return Short.parseShort(s);
} else if (propertyType.getTypeName().equals("java.lang.Byte")){
return Byte.parseByte(s);
} else if (propertyType.getTypeName().equals("java.lang.Integer")){
return Integer.parseInt(s);
} else if (propertyType.getTypeName().equals("java.lang.Double")){
return Double.parseDouble(s);
} else {
return null;
}
}
private static List<List<String>> readExcel (MultipartFile file, int i) {
// 创建二位数组保存所有读取到的行列数据,外层存行数据,内存存单元格数据
List<List<String>> dataList = new ArrayList<List<String>>();
try {
Workbook workbook = getWorkbook(file);
int sheetNum = workbook.getNumberOfSheets();
for (int index = 0 ; index < sheetNum ; index ++){
Sheet sheet = workbook.getSheetAt(index);
if (sheet == null){
continue;
}
log.info("表单行数:{}",sheet.getLastRowNum());
for (int rowIndex = 0 ; rowIndex <= sheet.getLastRowNum() ; rowIndex ++){
Row row = sheet.getRow(rowIndex);
if (row == null){
continue;
}
// 遍历每一行的第一列,第三层遍历所有的单元格
List<String> cellList = new ArrayList<>();
for (int cellIndex = 0 ; cellIndex < row.getLastCellNum(); cellIndex ++){
Cell cell = row.getCell(cellIndex);
String CellValue = getCellValue(cell);
if (CellValue == null){
continue;
}
cellList.add(CellValue);
}
if (cellList.size() != 0){
dataList.add(cellList);
}
}
}
} catch (HandleExcelException e) {
log.error("输入的文件不是excel文件,请确认文件是否正确");
}
return dataList;
}
/**
* 获取cell中的值
* @param cell
* @return
*/
private static String getCellValue(Cell cell) {
CellType cellType = cell.getCellTypeEnum();
String cellValue = "";
if(cell==null || cell.toString().trim().equals("")){
return null;
}
if(cellType==CellType.STRING){
cellValue = cell.getStringCellValue().trim();
return cellValue = StringUtil.isEmpty(cellValue)?"":cellValue;
}
if(cellType==CellType.NUMERIC){
if (HSSFDateUtil.isCellDateFormatted(cell)) { //判断日期类型
SimpleDateFormat sdf = new SimpleDateFormat(DateFormate);
cellValue = sdf.format(cell.getDateCellValue().getTime());
} else {
// DecimalFormat 对数字进行格式化
// # 整数 #.## 取两位小数 #.##% 百分号计数取2位小数 todo 处理数值类型数据
cellValue = new DecimalFormat("#.##").format(cell.getNumericCellValue());
}
return cellValue;
}
if(cellType==CellType.BOOLEAN){
cellValue = String.valueOf(cell.getBooleanCellValue());
return cellValue;
}
return null;
}
/**
* 通过判断文件结尾封装 Workbook 类
* @param file
* @return
* @throws HandleExcelException
*/
private static Workbook getWorkbook(MultipartFile file) throws HandleExcelException{
Workbook wb = null;
try {
if (file.getOriginalFilename().endsWith(SUFFIX_2007)){
wb = new XSSFWorkbook(file.getInputStream());
} else if (file.getOriginalFilename().endsWith(SUFFIX_2003)){
wb = new HSSFWorkbook(file.getInputStream());
} else {
throw new HandleExcelException("输入的文件不是excel文件,请确认文件是否正确");
}
} catch (IOException e) {
log.error("读取Excel 异常,请确认文件是否正确");
}
return wb;
}
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<result column="order_code" property="orderCode" jdbcType="VARCHAR"/> <result column="order_code" property="orderCode" jdbcType="VARCHAR"/>
<result column="name" property="name" jdbcType="VARCHAR"/> <result column="name" property="name" jdbcType="VARCHAR"/>
<result column="sku" property="sku" jdbcType="VARCHAR" /> <result column="sku" property="sku" jdbcType="VARCHAR" />
<result column="channel" property="channel" jdbcType="VARCHAR" />
</resultMap> </resultMap>
<select id="getOrderProductDTOByOrderId" resultMap="OrderProductDTO"> <select id="getOrderProductDTOByOrderId" resultMap="OrderProductDTO">
...@@ -16,7 +17,8 @@ ...@@ -16,7 +17,8 @@
op.order_id, op.order_id,
o.order_id as order_code, o.order_id as order_code,
op.name, op.name,
op.sku op.sku,
o.channel
from orders o from orders o
left join order_product op on o.id = op.order_id left join order_product op on o.id = op.order_id
where o.order_id = #{orderId} where o.order_id = #{orderId}
......
function getOrder() {
var orderId = document.getElementById(orderid);
$ajax.
}
\ No newline at end of file
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script th:src="@{js/jquery-3.3.1.min.js}"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btn2").click(function () {
var orderId = $("#orderid").val();
$.ajax({
type: "POST",
dataType: "json",
url: "/getOrder/" + orderId,
success: function (result) {
console.log(result);//打印服务端返回的数据(调试用)
},
error : function() {
alert("异常!");
}
})
})
})
</script>
</head>
<body>
<div class="div1" style="text-align:center">
<span class="center" align="center">订单sku修复补推小工具</span>
<br />
<br />
<label>订单号:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" id="orderid" />
<br />
<button id="btn2">查询</button>
<br />
<br />
<textarea id="txta1" style="width:1120px;height:250px;"></textarea>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment