Product data push demo

accept parameter

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

/**
 * product parameter demo
 */
@Getter
@Setter
public class DemoProductParam {

    /**
     * product code
     */
    private String skuCode;

    /**
     * product name
     */
    private String skuName;

    /**
     * factory product code
     */
    private String factorySkuCode;

    /**
     * factory product name
     */
    private String factorySkuName;

    /**
     * brade
     */
    private String brand;

    /**
     * unit name
     */
    private String unitName;

    /**
     * pack
     */
    private String pack;

    /**
     * price including tax
     */
    private BigDecimal taxPrice;

    /**
     * pre-tax
     */
    private BigDecimal noTaxPrice;

    /**
     * on sale status
     */
    private Boolean onSale;
}

return data

import lombok.Getter;
import lombok.Setter;

/**
 * return data demo
 */
@Getter
@Setter
public class DemoResponse {

    /**
     * status
     */
    private Boolean ok;

    /**
     * message
     */
    private String msg;

    /**
     * reserved field
     */
    private Object data;

    public DemoResponse(Boolean ok, String msg) {
        this.ok = ok;
        this.msg = msg;
    }

    public static DemoResponse success(String msg) {
        return new DemoResponse(Boolean.TRUE, msg);
    }

    public static DemoResponse error(String msg) {
        return new DemoResponse(Boolean.FALSE, msg);
    }
}

interface

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class DemoController {

    /**
     * product data receive demo
     */
    @PostMapping("/receiveProduct")
    public DemoResponse receiveProduct(@RequestBody List<DemoProductParam> list) {
        log.info("received product data:{}", JsonUtils.toJSONString(list));
        // save to database
        // ...
        return DemoResponse.success("success");
    }
}

Remarks

  • If authentication is required, the authentication information in the request header needs to be obtained for authentication.
  • The interface URL supports customization.
  • It is not recommended to perform business operations directly after receiving data at the interface. Instead, it is recommended to store the data in the database and return it to reduce interface waiting time.
  • The ‘data’ field in the response body is a reserved field for future business expansion. If there are no special business requirements, it can be ignored.
文档更新时间: 2024-06-25 06:17   作者:林贤涛