Commit b4acd6b2 by 王家辉

修改接口并接入生产环境

parent e50f2f21
......@@ -140,6 +140,8 @@
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.xls</include>
<include>**/*.xlsx</include>
</includes>
<filtering>false</filtering>
</resource>
......@@ -149,6 +151,8 @@
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.xls</include>
<include>**/*.xlsx</include>
</includes>
<filtering>false</filtering>
</resource>
......
......@@ -17,6 +17,7 @@ import com.freemud.Service.OrdersService;
import com.freemud.dto.OrderProductDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
......@@ -42,21 +43,20 @@ public class OrdersController {
@ApiOperation("根据正确的sku进行补推")
@PostMapping("/getRightSkuAndOrderPush")
@ResponseBody
public OrderProductDTO getRightSkuAndOrderPush(@RequestBody OrderProductDTO orderProductDTO){
String orderId = orderProductDTO.getOrderCode();
public Integer getRightSkuAndOrderPush(@RequestBody OrderProductDTO orderProductDTO){
String sku = orderProductDTO.getSku();
Long id = orderProductDTO.getId();
String channel = orderProductDTO.getChannel();
String id = orderProductDTO.getId();
// 修复sku
// boolean isMod = ordersService.RepairByRightSku(id,sku);
// if (isMod){
// return "修复成功";
// } else {
// return "修复失败";
// }
return orderProductDTO;
// ordersService.OrderPush(channel,orderId);
boolean isMod = ordersService.RepairByRightSku(id,sku);
if (isMod){
return 1;
} else {
return 0;
}
}
}
......@@ -12,6 +12,7 @@
*/
package com.freemud.Service.Impl;
import com.alibaba.fastjson.JSON;
import com.freemud.Mapper.OrderProductMapper;
import com.freemud.Service.OrdersService;
import com.freemud.dto.BaseResponse;
......@@ -19,12 +20,12 @@ import com.freemud.dto.OrderProductDTO;
import com.freemud.utils.ExcelOperationUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.ArrayList;
......@@ -40,44 +41,41 @@ public class OrdersServiceImpl implements OrdersService {
@Autowired
private RestTemplate restTemplate;
private String RequestUrl = "http://172.16.15.179:3017";
@Value("${order.RequestUrl}")
private String RequestUrl;
@Value("${order.FileDir}")
private String FileDir;
@Override
public List<OrderProductDTO> getOrderProductDTOByOrderId(String orderId) {
return orderProductMapper.getOrderProductDTOByOrderId(orderId);
List<OrderProductDTO> orderProductDTO = orderProductMapper.getOrderProductDTOByOrderId(orderId);
log.info("查询结果:{}", JSON.toJSONString(orderProductDTO));
return orderProductDTO;
}
@Override
public Boolean RepairByRightSku(Long id, String sku) {
public Boolean RepairByRightSku(String id, String sku) {
// 请求修复接口
String url = RequestUrl+"/order/repairByRightSku";
String titles[] = {"订单联合表主键","正确的sku"};
List<String> cells = new ArrayList <>();
cells.add(id+"");
cells.add(id);
cells.add(sku);
File file = ExcelOperationUtils.WriteExcel(titles,cells);
File file = ExcelOperationUtils.WriteExcel(titles,cells,FileDir);
if (!file.exists()){
log.error("文件不存在");
}
FileSystemResource resource = new FileSystemResource(file.getPath());
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("file",resource);
String code = restTemplate.postForObject(url,param,String.class);
if (code.equals("100")){
log.info("修改sku成功");
return true;
}
log.info("修改sku失败:{}");
return false;
}
@Override
public Boolean OrderPush(String channel, String orderId) {
// 补推订单
String checkAndPushUrl = RequestUrl+"/order/checkOrderPush";
BaseResponse baseResponse = restTemplate.getForObject(checkAndPushUrl, BaseResponse.class,channel,orderId);
if (baseResponse.getCode().equals("100")){
log.info("补推订单成功:{}",baseResponse.getResult());
log.info("修改sku成功{},{}",id,sku);
return true;
}
log.info("补推订单失败:{}",baseResponse.getResult());
log.info("修改sku失败:{},{}",id,sku);
return false;
}
......
......@@ -25,7 +25,6 @@ public interface OrdersService {
*/
List<OrderProductDTO> getOrderProductDTOByOrderId(String orderId);
Boolean RepairByRightSku(Long id, String sku);
Boolean RepairByRightSku(String id, String sku);
Boolean OrderPush(String channel, String orderId);
}
......@@ -15,11 +15,15 @@ package com.freemud.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class OrderProductDTO {
public class OrderProductDTO implements Serializable {
private static final long servialVersionUID = -1L;
@ApiModelProperty(value = "商品编号",required = true)
private Long id;
private String id;
@ApiModelProperty(value = "订单主键",required = true)
private String orderId;
......
......@@ -12,44 +12,58 @@
*/
package com.freemud.utils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
@Slf4j
public class ExcelOperationUtils {
public static File WriteExcel(String [] titles, List<String> cells){
public static File WriteExcel(String [] titles, List<String> cells,String FileDir){
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
HSSFCellStyle cellStyle2 = workbook.createCellStyle();
HSSFDataFormat format = workbook.createDataFormat();
cellStyle2.setDataFormat(format.getFormat("@"));
// 创建第一行 ( 表头 )
HSSFRow row = sheet.createRow(0);
HSSFCell cell = null;
for (int i = 0 ; i < titles.length ; i++){
cell = row.createCell(i);
cell.setCellStyle(cellStyle2);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(titles[i]);
}
//写入数据
HSSFRow nrow=sheet.createRow(1);
HSSFCell ncell=nrow.createCell(0);
ncell.setCellStyle(cellStyle2);
ncell.setCellType(HSSFCell.CELL_TYPE_STRING);
ncell.setCellValue(cells.get(0));
ncell=nrow.createCell(1);
ncell.setCellStyle(cellStyle2);
ncell.setCellType(HSSFCell.CELL_TYPE_STRING);
ncell.setCellValue(cells.get(1));
//创建excel文件
File file=new File("/opt/test.xls");
File file=new File(FileDir);
try {
file.createNewFile();
boolean result = file.createNewFile();
//将excel写入
FileOutputStream stream= new FileOutputStream(file);
FileOutputStream stream = new FileOutputStream(file);
workbook.write(stream);
stream.close();
} catch (IOException e) {
e.printStackTrace();
log.error("写入excel失败:{}"+cells);
}
return file;
}
......
......@@ -18,4 +18,7 @@ spring.datasource.druid.testOnBorrow=true
mybatis.mapper-locations=classpath:Mapper/*.xml
order.RequestUrl=http://172.16.15.179:3017
order.FileDir=D://test.xls
server.port=8778
spring.datasource.druid.url=jdbc:mysql://10.50.1.41:6630/fm_mg_order?useUnicode=true&characterEncoding=utf8
spring.datasource.druid.driver-class=com.mysql.jdbc.Driver
spring.datasource.druid.username=tech_support
spring.datasource.druid.password=(sS:9Z8Gnt%z
spring.datasource.druid.initial-size=1
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-active=100
spring.datasource.druid.maxWait=60000
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
spring.datasource.druid.minEvictableIdleTimeMillis=300000
spring.datasource.druid.validationQuery=SELECT 'x'
spring.datasource.druid.testWhileIdle=true
spring.datasource.druid.testOnReturn=false
spring.datasource.druid.testOnBorrow=true
mybatis.mapper-locations=classpath:Mapper/*.xml
order.RequestUrl=http://10.50.1.40:9929
order.FileDir=/data/smalltools/test.xls
spring.profiles.active=dev
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
spring.profiles.active=prod
......@@ -9,9 +9,9 @@
</appender>
<appender name="FREEMUD_API" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/data/log/familymart/takeoutjob/takeout-job.log</file>
<file>/data/smalltools/logs/repair-sku.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/data/log/familymart/takeoutjob/takeout-job-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>/data/smalltools/logs/repair-sku-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>20MB</maxFileSize>
</rollingPolicy>
<encoder>
......
package com.freemud.smalltools;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SmalltoolsApplicationTests {
@Test
public void contextLoads() {
}
}
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