diff --git a/appengine/src/main/java/com/currency/appengine/controller/OpenController.java b/appengine/src/main/java/com/currency/appengine/controller/OpenController.java index e494ca2..7c0ea2e 100644 --- a/appengine/src/main/java/com/currency/appengine/controller/OpenController.java +++ b/appengine/src/main/java/com/currency/appengine/controller/OpenController.java @@ -1,8 +1,10 @@ package com.currency.appengine.controller; import com.currency.appengine.domain.CustomerReq; +import com.currency.appengine.domain.SupplierReq; import com.currency.appengine.service.common.CommonServices; import com.currency.appengine.service.system.CustomerService; +import com.currency.appengine.service.system.SupplierService; import com.currency.appengine.utils.Result; import java.util.Map; import java.util.Objects; @@ -23,7 +25,8 @@ public class OpenController { @Autowired private CustomerService customerService; @Autowired - private CommonServices commonServices; + private SupplierService supplierService; + @PostMapping("/add") public Result add(@RequestBody Map obj) { @@ -46,4 +49,23 @@ public class OpenController { customerReq.setCreateBy("超级管理员"); return Result.suc(customerService.AsynCustomer(customerReq)); } + + @PostMapping("/add/supplier") + public Result addSupplier(@RequestBody Map 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)); + } } diff --git a/appengine/src/main/java/com/currency/appengine/controller/SystemController.java b/appengine/src/main/java/com/currency/appengine/controller/SystemController.java index a9d7784..dbabddd 100644 --- a/appengine/src/main/java/com/currency/appengine/controller/SystemController.java +++ b/appengine/src/main/java/com/currency/appengine/controller/SystemController.java @@ -4,8 +4,10 @@ import cn.hutool.captcha.CaptchaUtil; import cn.hutool.captcha.LineCaptcha; import com.currency.appengine.annotation.CheckToken; import com.currency.appengine.domain.CustomerReq; +import com.currency.appengine.domain.SupplierReq; import com.currency.appengine.domain.system.SysParam; 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.SysParamService; import com.currency.appengine.service.system.SysRoleService; @@ -46,6 +48,8 @@ public class SystemController { SysParamService sysParamService; @Autowired CustomerService customerService; + @Autowired + SupplierService supplierService; /* * 获取图形验证码 @@ -333,7 +337,9 @@ public class SystemController { return sysParamService.cacheUpdate(); } - + /** + * 客户信息 + */ @PostMapping("/customer/add") @CheckToken public Result addCustomer(HttpServletRequest request, @RequestBody CustomerReq customerReq) { @@ -341,4 +347,14 @@ public class SystemController { customerReq.setUserId(userId); 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)); + } } diff --git a/appengine/src/main/java/com/currency/appengine/domain/AysnSupplier.java b/appengine/src/main/java/com/currency/appengine/domain/AysnSupplier.java new file mode 100644 index 0000000..1d341da --- /dev/null +++ b/appengine/src/main/java/com/currency/appengine/domain/AysnSupplier.java @@ -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; +} diff --git a/appengine/src/main/java/com/currency/appengine/domain/SupplierReq.java b/appengine/src/main/java/com/currency/appengine/domain/SupplierReq.java new file mode 100644 index 0000000..5c533e3 --- /dev/null +++ b/appengine/src/main/java/com/currency/appengine/domain/SupplierReq.java @@ -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; +} diff --git a/appengine/src/main/java/com/currency/appengine/mapper/system/SupplierMapper.java b/appengine/src/main/java/com/currency/appengine/mapper/system/SupplierMapper.java new file mode 100644 index 0000000..d6fb7c2 --- /dev/null +++ b/appengine/src/main/java/com/currency/appengine/mapper/system/SupplierMapper.java @@ -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); +} diff --git a/appengine/src/main/java/com/currency/appengine/service/system/CustomerService.java b/appengine/src/main/java/com/currency/appengine/service/system/CustomerService.java index bef6579..5136e1d 100644 --- a/appengine/src/main/java/com/currency/appengine/service/system/CustomerService.java +++ b/appengine/src/main/java/com/currency/appengine/service/system/CustomerService.java @@ -1,6 +1,7 @@ package com.currency.appengine.service.system; import com.currency.appengine.domain.CustomerReq; +import com.currency.appengine.domain.SupplierReq; /** * @author zk diff --git a/appengine/src/main/java/com/currency/appengine/service/system/SupplierService.java b/appengine/src/main/java/com/currency/appengine/service/system/SupplierService.java new file mode 100644 index 0000000..510697f --- /dev/null +++ b/appengine/src/main/java/com/currency/appengine/service/system/SupplierService.java @@ -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); +} diff --git a/appengine/src/main/java/com/currency/appengine/service/system/imp/CustomerServiceImpl.java b/appengine/src/main/java/com/currency/appengine/service/system/imp/CustomerServiceImpl.java index 79c8875..3811f49 100644 --- a/appengine/src/main/java/com/currency/appengine/service/system/imp/CustomerServiceImpl.java +++ b/appengine/src/main/java/com/currency/appengine/service/system/imp/CustomerServiceImpl.java @@ -1,6 +1,7 @@ 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; @@ -47,6 +48,7 @@ public class CustomerServiceImpl implements CustomerService { customerMapper.updateCodeById(customerReq); try { aysnO2(customerReq); + aysnO1(customerReq); } catch (Exception 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 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 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("同步成功"); + } + } + } } diff --git a/appengine/src/main/java/com/currency/appengine/service/system/imp/SupplierServiceImpl.java b/appengine/src/main/java/com/currency/appengine/service/system/imp/SupplierServiceImpl.java new file mode 100644 index 0000000..fd752e9 --- /dev/null +++ b/appengine/src/main/java/com/currency/appengine/service/system/imp/SupplierServiceImpl.java @@ -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 map = new HashMap<>(); + AysnSupplier supplier = AysnSupplier.builder().address(supplierCompany.getAddress()) + .name(supplierCompany.getSupplierName()) + .phone(supplierCompany.getContactPhone()) + .build(); +// customer.setCreateTime(crmCustomer.getCreateTime().getTime()); + Map 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("请求成功"); + } + } + } +} diff --git a/appengine/src/main/resources/application.yml b/appengine/src/main/resources/application.yml index 3ea4ce9..4cdc9f1 100644 --- a/appengine/src/main/resources/application.yml +++ b/appengine/src/main/resources/application.yml @@ -1,8 +1,8 @@ spring: profiles: -# active: local # test 本地 + active: local # test 本地 # active: dev # test 测试 - active: pro # pro 生产 +# active: pro # pro 生产 # 通用配置 servlet: @@ -69,3 +69,16 @@ o2: enabled: true # 同步新增o2的客户api地址 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 \ No newline at end of file