feat(支持与O1系统进行数据同步):

main
zk 1 month ago
parent c6d32fdfe1
commit 8d081a3adc

@ -1,8 +1,10 @@
package com.currency.appengine.controller; package com.currency.appengine.controller;
import com.currency.appengine.domain.CustomerReq; import com.currency.appengine.domain.CustomerReq;
import com.currency.appengine.domain.SupplierReq;
import com.currency.appengine.service.common.CommonServices; import com.currency.appengine.service.common.CommonServices;
import com.currency.appengine.service.system.CustomerService; import com.currency.appengine.service.system.CustomerService;
import com.currency.appengine.service.system.SupplierService;
import com.currency.appengine.utils.Result; import com.currency.appengine.utils.Result;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -23,7 +25,8 @@ public class OpenController {
@Autowired @Autowired
private CustomerService customerService; private CustomerService customerService;
@Autowired @Autowired
private CommonServices commonServices; private SupplierService supplierService;
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Map<String, Object> obj) { public Result add(@RequestBody Map<String, Object> obj) {
@ -46,4 +49,23 @@ public class OpenController {
customerReq.setCreateBy("超级管理员"); customerReq.setCreateBy("超级管理员");
return Result.suc(customerService.AsynCustomer(customerReq)); return Result.suc(customerService.AsynCustomer(customerReq));
} }
@PostMapping("/add/supplier")
public Result addSupplier(@RequestBody Map<String, Object> obj) {
SupplierReq supplierReq = new SupplierReq();
supplierReq.setSupplierName(obj.get("name").toString());
if (Objects.nonNull(obj.get("phone"))) {
supplierReq.setContactPhone(obj.get("phone").toString());
}
if (Objects.nonNull(obj.get("address"))) {
supplierReq.setAddress(obj.get("address").toString());
}
supplierReq.setStatus(1);
supplierReq.setIsAuto(true);
supplierReq.setSettlementCurrency("CNY");
supplierReq.setTax("text2");
supplierReq.setIsTaxIncluded(1);
supplierReq.setCreateBy("超级管理员");
return Result.suc(supplierService.AsynSupplier(supplierReq));
}
} }

@ -4,8 +4,10 @@ import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha; import cn.hutool.captcha.LineCaptcha;
import com.currency.appengine.annotation.CheckToken; import com.currency.appengine.annotation.CheckToken;
import com.currency.appengine.domain.CustomerReq; import com.currency.appengine.domain.CustomerReq;
import com.currency.appengine.domain.SupplierReq;
import com.currency.appengine.domain.system.SysParam; import com.currency.appengine.domain.system.SysParam;
import com.currency.appengine.service.system.CustomerService; import com.currency.appengine.service.system.CustomerService;
import com.currency.appengine.service.system.SupplierService;
import com.currency.appengine.service.system.SysMenuService; import com.currency.appengine.service.system.SysMenuService;
import com.currency.appengine.service.system.SysParamService; import com.currency.appengine.service.system.SysParamService;
import com.currency.appengine.service.system.SysRoleService; import com.currency.appengine.service.system.SysRoleService;
@ -46,6 +48,8 @@ public class SystemController {
SysParamService sysParamService; SysParamService sysParamService;
@Autowired @Autowired
CustomerService customerService; CustomerService customerService;
@Autowired
SupplierService supplierService;
/* /*
* *
@ -333,7 +337,9 @@ public class SystemController {
return sysParamService.cacheUpdate(); return sysParamService.cacheUpdate();
} }
/**
*
*/
@PostMapping("/customer/add") @PostMapping("/customer/add")
@CheckToken @CheckToken
public Result addCustomer(HttpServletRequest request, @RequestBody CustomerReq customerReq) { public Result addCustomer(HttpServletRequest request, @RequestBody CustomerReq customerReq) {
@ -341,4 +347,14 @@ public class SystemController {
customerReq.setUserId(userId); customerReq.setUserId(userId);
return Result.suc(customerService.addCustomer(customerReq)); return Result.suc(customerService.addCustomer(customerReq));
} }
/**
*
*/
@PostMapping("/supplier/add")
@CheckToken
public Result addSupplier(HttpServletRequest request, @RequestBody SupplierReq supplierReq) {
String userId = StringUtil.objectToString(request.getAttribute("openid"));
supplierReq.setUserId(userId);
return Result.suc(supplierService.addSupplier(supplierReq));
}
} }

@ -0,0 +1,40 @@
package com.currency.appengine.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* VO
* @author zk
* @date 2024/9/30
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Builder
public class AysnSupplier {
/**
*
*/
private String name;
/**
*
*/
private String phone;
/**
*
*/
private String email;
/**
*
*/
private String creditCode;
/**
*
*/
private String address;
}

@ -0,0 +1,75 @@
package com.currency.appengine.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
*
*
* @author zk
* @date 2024/10/23
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class SupplierReq {
private Long id;
/**
*
*/
private String contactPerson;
/**
*
*/
private String contactPhone;
/**
*
*/
private String supplierCode;
/**
*
*/
private String supplierName;
/**
*
*/
private Boolean isAuto;
/**
*
*/
private Integer isTaxIncluded;
/**
*
*/
private String remarks;
/**
*
*/
private String settlementCurrency;
/**
*
*/
private Integer status;
/**
*
*/
private String tax;
/**
*
*/
private String createBy;
/**
* id
*/
private String userId;
/**
*
*/
private String address;
}

@ -0,0 +1,31 @@
package com.currency.appengine.mapper.system;
import com.currency.appengine.domain.CustomerReq;
import com.currency.appengine.domain.SupplierReq;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
* @author zk
* @date 2024/10/23
*/
public interface SupplierMapper {
@Insert(
"insert into mini_supplier_info(address,create_by, contact_person, contact_phone, supplier_name, is_tax_included, remarks, settlement_currency, status, tax) values(#{address},#{createBy}, #{contactPerson}, #{contactPhone}, #{supplierName}, #{isTaxIncluded}, #{remarks}, #{settlementCurrency}, #{status}, #{tax});"
)
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int insertSupplier(SupplierReq supplierReq);
@Select(
"SELECT user_name FROM sys_user WHERE user_id = #{userId}"
)
String selectUserById(String userId);
@Update(
"update mini_supplier_info set supplier_code = #{supplierCode} where id = #{id}"
)
void updateCodeById(SupplierReq supplierReq);
}

@ -1,6 +1,7 @@
package com.currency.appengine.service.system; package com.currency.appengine.service.system;
import com.currency.appengine.domain.CustomerReq; import com.currency.appengine.domain.CustomerReq;
import com.currency.appengine.domain.SupplierReq;
/** /**
* @author zk * @author zk

@ -0,0 +1,19 @@
package com.currency.appengine.service.system;
import com.currency.appengine.domain.CustomerReq;
import com.currency.appengine.domain.SupplierReq;
/**
* @author zk
* @date 2024/10/25
*/
public interface SupplierService {
/**
*
*/
int addSupplier(SupplierReq supplierReq);
/**
*
*/
int AsynSupplier(SupplierReq supplierReq);
}

@ -1,6 +1,7 @@
package com.currency.appengine.service.system.imp; package com.currency.appengine.service.system.imp;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
@ -47,6 +48,7 @@ public class CustomerServiceImpl implements CustomerService {
customerMapper.updateCodeById(customerReq); customerMapper.updateCodeById(customerReq);
try { try {
aysnO2(customerReq); aysnO2(customerReq);
aysnO1(customerReq);
} catch (Exception e) { } catch (Exception e) {
log.warn("同步客户信息异常", e); log.warn("同步客户信息异常", e);
} }
@ -107,4 +109,46 @@ public class CustomerServiceImpl implements CustomerService {
} }
} }
} }
/**
* O1
*/
private static void aysnO1(CustomerReq req) {
String property = SpringUtil.getProperty("o1.sync.enabled");
Boolean res = Boolean.valueOf(property);
if (Boolean.TRUE.equals(res)) {
String accessKey = SpringUtil.getProperty("o1.sync.access-key");
String secretKey = SpringUtil.getProperty("o1.sync.secret-key");
String url = SpringUtil.getProperty("o1.sync.create-url.customer");
Map<String, String> map = new HashMap<>();
AysnCustomer customer = new AysnCustomer();
customer.setName(req.getCustomerName());
customer.setPhone(req.getContactPhone());
customer.setRemark(req.getRemarks());
customer.setAddress(req.getAddress());
// customer.setCreateTime(crmCustomer.getCreateTime().getTime());
Map<String, Object> toMap = BeanUtil.beanToMap(customer, false, true);
long timestamp = System.currentTimeMillis();
map.put("time-stamp", String.valueOf(timestamp));
map.put("access-key", accessKey);
map.put("tenant-id", "1");
toMap.put("time-stamp", String.valueOf(timestamp));
toMap.put("access-key", accessKey);
String sign = SignUtil.getSign(toMap, secretKey);
map.put("sign", sign);
HttpResponse response = null;
try {
response = HttpRequest.post(url)
.addHeaders(map)
.body(JSONUtil.toJsonStr(customer))
.execute();
} catch (IORuntimeException e) {
log.warn("同步失败", e);
return;
}
String body = response.body();
if (response.isOk()) {
log.info("同步成功");
}
}
}
} }

@ -0,0 +1,113 @@
package com.currency.appengine.service.system.imp;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.currency.appengine.domain.AysnCustomer;
import com.currency.appengine.domain.AysnSupplier;
import com.currency.appengine.domain.CustomerReq;
import com.currency.appengine.domain.SupplierReq;
import com.currency.appengine.mapper.system.SupplierMapper;
import com.currency.appengine.service.common.CommonServices;
import com.currency.appengine.service.system.SupplierService;
import com.currency.appengine.utils.SignUtil;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author zk
* @date 2024/10/23
*/
@Slf4j
@Service
public class SupplierServiceImpl implements SupplierService {
@Autowired
private SupplierMapper supplierMapper;
@Autowired
private CommonServices commonServices;
/**
*
*
*/
@Override
public int addSupplier(SupplierReq supplierReq) {
if (Boolean.TRUE.equals(supplierReq.getIsAuto())){
supplierReq.setSupplierCode(commonServices.getCode("SupplierCode", null));
}
String user = supplierMapper.selectUserById(supplierReq.getUserId());
supplierReq.setCreateBy(user);
int i = supplierMapper.insertSupplier(supplierReq);
supplierReq.setSupplierCode(String.valueOf(supplierReq.getId()));
supplierMapper.updateCodeById(supplierReq);
try {
aysnO1(supplierReq);
} catch (Exception e) {
log.warn("同步客户信息异常", e);
}
return i;
}
/**
*
*
* @param customerReq
*/
@Override
public int AsynSupplier(SupplierReq supplierReq) {
int i = supplierMapper.insertSupplier(supplierReq);
supplierReq.setSupplierCode(String.valueOf(supplierReq.getId()));
supplierMapper.updateCodeById(supplierReq);
return i;
}
/**
*
*
* @param supplierCompany
*/
private void aysnO1(SupplierReq supplierCompany) {
String property = SpringUtil.getProperty("o1.sync.enabled");
Boolean res = Boolean.valueOf(property);
if (Boolean.TRUE.equals(res)) {
String accessKey = SpringUtil.getProperty("o1.sync.access-key");
String secretKey = SpringUtil.getProperty("o1.sync.secret-key");
String url = SpringUtil.getProperty("o1.sync.create-url.supplier");
Map<String, String> map = new HashMap<>();
AysnSupplier supplier = AysnSupplier.builder().address(supplierCompany.getAddress())
.name(supplierCompany.getSupplierName())
.phone(supplierCompany.getContactPhone())
.build();
// customer.setCreateTime(crmCustomer.getCreateTime().getTime());
Map<String, Object> toMap = BeanUtil.beanToMap(supplier,false,true);
long timestamp = System.currentTimeMillis();
map.put("time-stamp", String.valueOf(timestamp));
map.put("access-key", accessKey);
map.put("tenant-id", "1");
toMap.put("time-stamp", String.valueOf(timestamp));
toMap.put("access-key", accessKey);
String sign = SignUtil.getSign(toMap, secretKey);
map.put("sign", sign);
HttpResponse response = null;
try {
response = HttpRequest.post(url)
.addHeaders(map)
.body(JSONUtil.toJsonStr(supplier))
.execute();
} catch (Exception e) {
log.warn("同步失败", e);
return;
}
String body = response.body();
if (response.isOk()){
log.info("请求成功");
}
}
}
}

@ -1,8 +1,8 @@
spring: spring:
profiles: profiles:
# active: local # test 本地 active: local # test 本地
# active: dev # test 测试 # active: dev # test 测试
active: pro # pro 生产 # active: pro # pro 生产
# 通用配置 # 通用配置
servlet: servlet:
@ -69,3 +69,16 @@ o2:
enabled: true enabled: true
# 同步新增o2的客户api地址 # 同步新增o2的客户api地址
create-url: http://127.0.0.1:8182/open/api/add create-url: http://127.0.0.1:8182/open/api/add
# o1 同步配置
# o1 同步配置
o1:
sync:
access-key: 8ceeH0H6w4ZIR5nHSDB7
# 密钥
secret-key: alLv8CPzZjM6EAgvKqvVjf4kOuTPSmoQTbgK25jz
# 是否启用同步
enabled: true
# 同步新增o1的客户api地址
create-url:
customer: http://127.0.0.1:48080/admin-api/open/api/customerCompany/create
supplier: http://127.0.0.1:48080/admin-api/open/api/customerCompany/create/supplier
Loading…
Cancel
Save