add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.iotechn.unimall.runner.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.dobbinsoft.fw.support.component.open.OpenPlatformUtil;
import com.iotechn.unimall.biz.client.erp.ErpClient;
import com.iotechn.unimall.data.dto.ErpStockNotifyDTO;
import com.iotechn.unimall.data.dto.ErpStockNotifyItemDTO;
import com.iotechn.unimall.data.properties.UnimallErpOpenPlatformProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Map;
 
/**
 * Created by rize on 2019/7/10.
 */
@RestController
@RequestMapping("/cb")
public class CallbackController {
 
    @Autowired
    private UnimallErpOpenPlatformProperties unimallErpOpenPlatformProperties;
 
    @Autowired
    private ErpClient erpClient;
 
    @RequestMapping("/erp/stock")
    @Transactional(rollbackFor = Exception.class)
    public Object stock(@RequestBody String body) throws Exception {
        JSONObject jsonObject = JSONObject.parseObject(body);
        String ciphertext = jsonObject.getString("ciphertext");
        // 验签
        String publicKey = unimallErpOpenPlatformProperties.getDobbinServerPublicKey();
        Map<String, String> map = OpenPlatformUtil.parseAndCheckSign(ciphertext, publicKey);
        String notify = map.get("notify");
        // 编辑库存
        ErpStockNotifyDTO erpStockNotifyDTO = JSONObject.parseObject(notify, ErpStockNotifyDTO.class);
        List<ErpStockNotifyItemDTO> items = erpStockNotifyDTO.getItems();
        for (ErpStockNotifyItemDTO item : items) {
            erpClient.invokeStockChange(item.getBarCode(), item.getQuantity());
        }
        return "ok";
    }
 
}