PriceServiceImpl.java
3.1 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.lhcredit.project.business.price.service;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.project.business.price.domain.Price;
import com.lhcredit.project.business.price.mapper.PriceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.util.*;
@Service
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public class PriceServiceImpl implements PriceService{
@Value("${crm.url}")
private String apiUrl;
@Value("${crm.token}")
private String token;
@Autowired
private PriceMapper priceMapper;
/**
* 添加用户报告价格
* @param contractId 合同号
*/
@Override
public AjaxResult addPrice(String contractId) {
String priceUrl = apiUrl+"/contract/client/web/selectBusinessTypeByContractId?id="+contractId;
Map<String, String> map = new HashMap<>();
map.put("token", token);
List<Price> priceByContractId = priceMapper.findPriceByContractId(contractId);
if (!ObjectUtils.isEmpty(priceByContractId)){
return AjaxResult.error("已经存在价格数据");
}
String result = HttpRequest.get(priceUrl).addHeaders(map).execute().body();
if(!"".equals(result)||null!=result){
JSONObject obj= (JSONObject) JSONObject.parse(result);
if(obj.getIntValue("code")==200){
JSONArray array = obj.getJSONArray("data");
if(array.size()>0) {
array.forEach(a->{
JSONObject obj1 = (JSONObject) a;
//先查一遍是否存在
List<Price> price = new ArrayList<>();
if (obj1.get("isCheck").toString().equals("Y")){
Price price1 = new Price();
price1.setContractId(obj1.get("contractId").toString());
price1.setTypePrice(obj1.get("typePrice").toString());
price1.setDeliveryDays(obj1.get("deliveryDays").toString());
price1.setDataStatus(obj1.get("dataStatus").toString());
price1.setClientType(obj1.get("clientType").toString());
price.add(price1);
}
priceMapper.addPrice(price);
});
}
}
}
return AjaxResult.success("添加价格成功");
}
/**
* 根据合同单号查找 价格
* @param contractId
* @return
*/
@Override
public List<Price> findPriceByContractId(String contractId) {
return priceMapper.findPriceByContractId(contractId);
}
}