Browse Source

增加dubbo配置和调用案例

zyh
Loki 3 years ago
parent
commit
f1b8d3b47d
  1. 15
      yudao-server/src/main/java/cn/iocoder/yudao/server/YudaoServerApplication.java
  2. 12
      yudao-server/src/main/resources/application-dev.yaml
  3. 70
      zsw-farm/zsw-farm-api/src/main/java/dubbo/dto/BasMaterial.java
  4. 13
      zsw-farm/zsw-farm-api/src/main/java/dubbo/service/OpenErpService.java
  5. 14
      zsw-farm/zsw-farm-impl/pom.xml
  6. 9
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java

15
yudao-server/src/main/java/cn/iocoder/yudao/server/YudaoServerApplication.java

@ -1,16 +1,31 @@
package cn.iocoder.yudao.server;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.system.ApplicationHome;
import java.io.File;
@SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package}
@SpringBootApplication(scanBasePackages = {
"${yudao.info.base-package}.server", "${yudao.info.base-package}.module",
"co.yixiang", "com.zsw.erp"
})
@EnableDubbo
public class YudaoServerApplication {
public static void main(String[] args) {
ApplicationHome home = new ApplicationHome(YudaoServerApplication.class);
File jarFile = home.getSource();
String dirPath = jarFile.getParentFile().toString();
String filePath = dirPath + File.separator + ".dubbo";
System.out.println(filePath);
System.setProperty("dubbo.meta.cache.filePath", filePath);
System.setProperty("dubbo.mapping.cache.filePath",filePath);
SpringApplication.run(YudaoServerApplication.class, args);
}

12
yudao-server/src/main/resources/application-dev.yaml

@ -203,3 +203,15 @@ justauth:
type: REDIS
prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE::
timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟
dubbo:
registry:
id: zsw-farm
address: 192.168.10.250:8848
protocol: nacos
username: nacos
password: nacos
application:
name: zsw-farm

70
zsw-farm/zsw-farm-api/src/main/java/dubbo/dto/BasMaterial.java

@ -0,0 +1,70 @@
package dubbo.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* @Description: 物料
* @Author: jeecg-boot
* @Date: 2020-05-29
* @Version: V1.0
*/
@Data
@TableName("bas_material")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class BasMaterial implements Serializable {
private static final long serialVersionUID = 1L;
/**ID*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**编码*/
private String code;
/**名称*/
private String name;
/**分类*/
private String categoryId;
/**是否启用*/
private Integer isEnabled;
/**规格型号*/
private String model;
/**计量单位*/
private String unitId;
private BigDecimal stockAlarm;
private Integer validity;
/**销售价格*/
private BigDecimal salePrice;
/**税控编码*/
private String taxCode;
/**备注*/
private String remark;
/**创建人*/
private String createBy;
/**创建时间*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date createTime;
/**修改人*/
private String updateBy;
/**修改时间*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date updateTime;
/**版本*/
private Integer version;
}

13
zsw-farm/zsw-farm-api/src/main/java/dubbo/service/OpenErpService.java

@ -0,0 +1,13 @@
package dubbo.service;
import dubbo.dto.BasMaterial;
import java.util.List;
public interface OpenErpService {
// 把实现方法写在这里
String hello();
List<BasMaterial> list();
}

14
zsw-farm/zsw-farm-impl/pom.xml

@ -66,6 +66,20 @@
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-spring-boot-starter -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>3.0.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.nacos/nacos-client -->
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
</project>

9
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java

@ -38,6 +38,9 @@ import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper;
import cn.iocoder.yudao.module.system.service.CpUser.CpUserService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zsw.base.R;
import dubbo.service.OpenErpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -55,6 +58,7 @@ import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*;
*/
@Service
@Validated
@Slf4j
public class DiscussServiceImpl implements DiscussService {
@Resource
@ -78,6 +82,9 @@ public class DiscussServiceImpl implements DiscussService {
@Resource
private TaskCateMapper taskCateMapper;
@DubboReference
private OpenErpService openErpService;
@Override
public Long createDiscuss(DiscussCreateReqVO createReqVO) {
//只有所属任务进行中才可以添加活动
@ -279,6 +286,8 @@ public class DiscussServiceImpl implements DiscussService {
cropRecordMapper.insert(cropRecordDO);
//todo 调用ERP出入库接口
String hello = openErpService.hello();
log.error("hello:{}",hello);
}
}

Loading…
Cancel
Save