Compare commits
2 Commits
ebbd29c990
...
abfbf54d8a
Author | SHA1 | Date |
---|---|---|
zk | abfbf54d8a | 1 month ago |
zk | 8d081a3adc | 1 month ago |
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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("请求成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue