#
luxiaotao1123
2021-03-01 0497edd108397506301b181d7e934d546c092834
#
2个文件已修改
5个文件已添加
365 ■■■■■ 已修改文件
pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/zy/cloud/wms/common/service/MainService.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/zy/cloud/wms/common/service/erp/Result.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/zy/cloud/wms/common/service/erp/entity/GetDataResult.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/zy/cloud/wms/manager/controller/PakoutController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/zy/cloud/wms/manager/utils/HttpHandler.java 213 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -106,6 +106,12 @@
            <artifactId>aliyun-sdk-oss</artifactId>
            <version>2.8.3</version>
        </dependency>
        <!-- okHttp3 -->
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>3.10.0</version>
        </dependency>
    </dependencies>
    <build>
src/main/java/zy/cloud/wms/common/service/MainService.java
New file
@@ -0,0 +1,19 @@
package zy.cloud.wms.common.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * Created by vincent on 2021/3/1
 */
@Service("mainService")
public class MainService {
    @Transactional
    public void stockOutProcess() {
    }
}
src/main/java/zy/cloud/wms/common/service/erp/ErpScheduler.java
New file
@@ -0,0 +1,72 @@
package zy.cloud.wms.common.service.erp;
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import zy.cloud.wms.common.service.MainService;
import zy.cloud.wms.common.service.erp.entity.GetDataResult;
import zy.cloud.wms.manager.entity.Mat;
import zy.cloud.wms.manager.service.MatService;
import zy.cloud.wms.manager.utils.HttpHandler;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * erp任务控制器
 * Created by vincent on 2020/11/27
 */
@Slf4j
@Component
public class ErpScheduler {
    public static final String URI = "http://8.133.182.21:8080/api/";
    public static final String GET_ORDERS = "cM/basis/getOrders";
    @Autowired
    private MatService matService;
    @Autowired
    private MainService mainService;
    /**
     * 原材料
     */
//    @Scheduled(cron = "0/3 * * * * ? ")
    public void getOrdersExecute(){
        try {
            Map<String, Object> json = new HashMap<>();
            json.put("vchType", 41);
            String response = new HttpHandler.Builder()
                    .setUri(URI)
                    .setPath(GET_ORDERS)
                    .setJson(JSON.toJSONString(json))
                    .build()
                    .doPost();
            if (Cools.isEmpty(response)) {
                log.error("请求:{}\nError,响应结果为空!", URI + GET_ORDERS);
            } else {
                log.info(response);
                Result result = JSON.parseObject(response, Result.class);
                List<GetDataResult> datas = JSON.parseArray(result.getData(), GetDataResult.class);
                if (!Cools.isEmpty(datas)) {
                    for (GetDataResult data : datas) {
                        // 生成出库单
                        Mat mat = matService.selectByMatnr(data.getUserCode());
                        mainService.stockOutProcess();
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
src/main/java/zy/cloud/wms/common/service/erp/Result.java
New file
@@ -0,0 +1,18 @@
package zy.cloud.wms.common.service.erp;
import lombok.Data;
/**
 * Created by vincent on 2021/3/1
 */
@Data
public class Result {
    private Integer code;
    private String msg;
    private String data;
}
src/main/java/zy/cloud/wms/common/service/erp/entity/GetDataResult.java
New file
@@ -0,0 +1,35 @@
package zy.cloud.wms.common.service.erp.entity;
import lombok.Data;
/**
 * Created by vincent on 2021/3/1
 */
@Data
public class GetDataResult {
    // 销售单号
    private String number;
    // 单据日期 格式2020-01-02空则默认取当天日期
    private String billDate;
    // 客户编号 报损单,报溢单则忽略此参数
    private String bTypeID;
    // 经手人编号  可空
    private String eTypeID;
    // 商品编号 进销存系统中商品编码
    private String userCode;
    // 商品数量
    private Double qty;
    // 商品单价
    private Double Price;
    // 单行商品备注
    private String comment;
}
src/main/java/zy/cloud/wms/manager/controller/PakoutController.java
@@ -47,7 +47,7 @@
        return R.ok(pakoutService.selectPage(new Page<>(curr, limit), wrapper));
    }
    private void convert(Map<String, Object> map, EntityWrapper wrapper){
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
src/main/java/zy/cloud/wms/manager/utils/HttpHandler.java
New file
@@ -0,0 +1,213 @@
package zy.cloud.wms.manager.utils;
import okhttp3.*;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
 * Http协议客户端
 * @author luxiaotao
 * @date 2018-9-27
 */
public class HttpHandler {
    private static final Integer DEFAULT_TIMEOUT_SECONDS = 5;
    private static final MediaType MEDIA_TYPE = MediaType.parse("application/json;charset=utf-8");
    private String uri;
    private String path;
    private String json;
    private Map<String, Object> params;
    private Map<String, Object> headers;
    private boolean https;
    private Integer timeout;
    private TimeUnit timeUnit;
    public HttpHandler(Builder builder){
        this.uri = builder.uri;
        this.path = builder.path;
        this.json = builder.json;
        this.params = builder.params;
        this.headers = builder.headers;
        this.https = builder.https;
        this.timeout = builder.timeout;
        this.timeUnit = builder.timeUnit;
    }
    /**
     * GET请求执行
     * @return the HttpHandler response
     */
    public String doGet() throws IOException {
        String url = paramsToUrl(uri, path, params, https);
        Request.Builder headerBuilder = new Request.Builder();
        if (headers != null && headers.size()>0){
            for (Map.Entry<String, Object> entry : headers.entrySet()){
                headerBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
        Request request = headerBuilder.url(url).build();
        Response response = getClient(timeout, timeUnit).newCall(request).execute();
        return response.isSuccessful() ? response.body().string() : null;
    }
    /**
     * POST请求执行
     * @return the HttpHandler response
     */
    public String doPost() throws IOException {
        Request request;
        Request.Builder headerBuilder = new Request.Builder();
        if (headers != null && headers.size()>0){
            for (Map.Entry<String, Object> entry : headers.entrySet()){
                headerBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
        if (json == null || "".equals(json)){
            FormBody.Builder builder = new FormBody.Builder();
            for (Map.Entry<String, Object> entry : params.entrySet()){
                builder.add(entry.getKey(), String.valueOf(entry.getValue()));
            }
            FormBody body = builder.build();
            request = headerBuilder
                    .url((https?"https://":"http://")+uri+path)
                    .post(body)
                    .build();
        } else {
            RequestBody body = RequestBody.create(MEDIA_TYPE, json);
            Request.Builder builder = headerBuilder.url((https?"https://":"http://")+uri+path);
            builder.header("Content-Type", "application/json;charset=UTF-8");
            request = builder.post(body).build();
        }
        Call call = getClient(timeout, timeUnit).newCall(request);
        Response response = call.execute();
        return response.body().string();
    }
    /**
     * get请求参数拼接方法
     * @return 请求行
     */
    private String paramsToUrl(String uri, String path, Map<String, Object> params, boolean isHttps) {
        StringBuilder res = new StringBuilder();
        res.append(isHttps ? "https://" : "http://");
        res.append(uri);
        if (path.length() > 0 && !(path.charAt(0) == '/')){
            res.append("/");
        }
        res.append(path);
        Optional.ofNullable(params).ifPresent(
                args -> {
                    res.append("?");
                    args.forEach((key, value) -> {
                        res.append(key);
                        res.append("=");
                        res.append(value);
                        res.append("&");
                    });
                }
        );
        String url = res.toString();
        if ("&".equals(url.substring(url.length()-1, url.length()))){
            url = url.substring(0, url.length()-1);
        }
        return url;
    }
    /**
     * 获取 okHttpClient
     * @return the HttpHandler instance
     */
    private OkHttpClient getClient(Integer timeout, TimeUnit timeUnit){
        return new OkHttpClient
                .Builder()
                .connectTimeout(timeout, timeUnit)
                .readTimeout(timeout, timeUnit)
                .build();
    }
    /**
     * Http协议报文建造者
     */
    public static class Builder {
        private String uri;
        private String path;
        private String json;
        private Map<String, Object> params;
        private Map<String, Object> headers;
        private boolean https;
        private Integer timeout;
        private TimeUnit timeUnit;
        {
            // 默认5s超时
            timeout = DEFAULT_TIMEOUT_SECONDS;
            timeUnit = TimeUnit.SECONDS;
            path = "";
        }
        /**
         * 建造器
         * @return the HttpHandler instance
         */
        public HttpHandler build(){
            if (null == this.uri || "".equals(this.uri)){
                throw new RuntimeException("uri is null");
            }
            if (this.uri.startsWith("http://")){
                this.uri = this.uri.substring(6,uri.length());
            } else if (this.uri.startsWith("https://")){
                this.uri = this.uri.substring(7,uri.length());
            }
            return new HttpHandler(this);
        }
        public Builder setUri(String uri) {
            this.uri = uri;
            return this;
        }
        public Builder setPath(String path) {
            if (!path.startsWith("/")){
                path = "/" + path;
            }
            this.path = path;
            return this;
        }
        public Builder setTimeout(Integer timeout, TimeUnit timeUnit) {
            this.timeout = timeout;
            this.timeUnit = timeUnit;
            return this;
        }
        public Builder setParams(Map<String, Object> params) {
            this.params = params;
            return this;
        }
        public Builder setHeaders(Map<String, Object> headers) {
            this.headers = headers;
            return this;
        }
        public Builder setHttps(boolean https) {
            this.https = https;
            return this;
        }
        public Builder setJson(String json) {
            this.json = json;
            return this;
        }
    }
}