wuxw
2019-04-23 b933bf8cfb7e0b3d231e7bc721b749fae54e911a
CodeService/src/main/java/com/java110/code/api/CodeApi.java
@@ -10,9 +10,15 @@
import com.java110.core.context.CodeDataFlow;
import com.java110.core.factory.DataFlowFactory;
import com.java110.core.factory.DataTransactionFactory;
import com.java110.feign.code.ICodeApi;
import com.java110.core.smo.code.ICodeApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
@@ -26,22 +32,37 @@
@RestController
public class CodeApi extends BaseController implements ICodeApi {
    protected static Logger logger = LoggerFactory.getLogger(CodeApi.class);
    @Autowired
    IPrimaryKeyServiceSMO primaryKeyServiceSMOImpl;
    /**
     * 生成编码服务器 不支持Get方法请求
     * @param request http 请求对象
     * @return 不支持Get方法请求
     */
    @Deprecated
    @RequestMapping(path = "/codeApi/generate", method = RequestMethod.GET)
    public String generateGet(HttpServletRequest request) {
        return DataTransactionFactory.createCodeResponseJson(ResponseConstant.NO_TRANSACTION_ID, "-1",
                ResponseConstant.RESULT_CODE_ERROR, "不支持Get方法请求").toJSONString();
    }
    /**
     * 生成编码服务器 不支持Get方法请求
     * @param orderInfo 请求信息
     * @param request http 请求对象
     * @return 不支持Get方法请求
     */
    @RequestMapping(path = "/codeApi/generate", method = RequestMethod.POST)
    public String generatePost(@RequestBody String orderInfo, HttpServletRequest request) {
        Map<String, String> headers = new HashMap<String, String>();
        try {
            getRequestInfo(request, headers);
            //预校验
            preValiateOrderInfo(orderInfo, headers);
            preValidateOrderInfo(orderInfo, headers);
            CodeDataFlow dataFlow = DataFlowFactory.newInstance(CodeDataFlow.class).builder(orderInfo, null);
            primaryKeyServiceSMOImpl.generateCode(dataFlow);
            return dataFlow.getResJson().toJSONString();
@@ -54,9 +75,9 @@
    /**
     * 获取请求信息
     *
     * @param request
     * @param headers
     * @throws RuntimeException
     * @param request 请求信息封装
     * @param headers 请求头信息
     * @throws Exception 处理数据失败会返回Exception异常
     */
    private void getRequestInfo(HttpServletRequest request, Map headers) throws Exception {
        try {
@@ -71,9 +92,10 @@
    /**
     * 这里预校验,请求报文中不能有 dataFlowId
     *
     * @param orderInfo
     * @param orderInfo 请求信息封装
     * @param headers  请求头信息
     */
    private void preValiateOrderInfo(String orderInfo, Map<String, String> headers) {
    private void preValidateOrderInfo(String orderInfo, Map<String, String> headers) {
        Assert.jsonObjectHaveKey(orderInfo, "prefix", "没有包含prefix");
@@ -97,7 +119,7 @@
     * @return
     */
    @Override
    @RequestMapping(value = "/codeApi/generateCode",method = RequestMethod.POST)
    @RequestMapping(value = "/codeApi/generateCode", method = RequestMethod.POST)
    public String generateCode(@RequestParam("prefix") String prefix) {
        try {