购销合同模块-需求分析
- (1)购销合同模块的需求
- (2)表的介绍
- (3)表与表之间的关系
购销合同模块的需求:
1)购销合同管理:出口企业 与 海外客户 之间签订的买卖合同
2)货物管理:管理出口企业需要出口的货物 ,例如 玻璃杯
3)附件管理:管理货物周边的附件,例如 包装玻璃杯的纸箱
4)工厂管理: 生成货物和附件的工厂,工厂负责生产,出口企业负责销售
-- contract 合同
-- 购销合同表
select * from co_contract;
-- 货物表
select * from co_contract_product;
-- 附件表
select * from co_ext_cproduct;
-- 工厂表
select * from co_factory;
关系:
1)购销合同 与 货物: 一对多的关系
一个购销合同下面可能存在多种出口货物
2)货物 与 附件:一对多的关系
一种货物下 可能存在多种附件。例如 玻璃杯 需要纸箱和泡沫两种附件。
购销合同模块-分散计算
- (1)什么是分散计算?
将一次集中计算的工作量分散到平时的多次计算过程中 - (2)有什么特点?
优点:提高了页面数据的检索速度
缺点:就是代码的编写量和维护工作量急剧上升
购销合同的总金额 = 货物金额 + 附件金额
- 新建购销合同,总金额 = 0
- 操作货物
新建货物, 购销合同总金额 += 货物金额
删除货物, 购销合同总金额 -= 货物金额
修改货物, 购销合同总金额 = 购销合同总金额 + 修改后 - 修改前 - 操作附件
…
domain实体类
- (1)四个表对应四个类
- (2)BaseEntity类
- (3)使用步骤
》打开资料
》引入BaseEntity到项目中
BaseEntity用来抽取所有domain公用的字段
》把实体类中的子目录cargo中的文件,引入到项目中
Contract.java 合同
ContractExample.java
ContractProduct.java 货物
ContractProductExample.java
ExtCproduct.java 附件
ExtCproductExample.java
Factory.java 工厂
FactoryExample.java
dao数据访问层
- (1)将dao文件夹下面的.java文件,与.xml文件分别复制到
java文件夹,resource文件夹 - (2)注意 位置
创建service接口工程
- (1)步骤
》1 创建项目:export_cargo_interface
》2 添加依赖:domain
》3 编写业务服务接口 - (2)实现
》1 业务接口说明
》2 业务接口方法说明
<!--指定父工程 -->
<parent>
<artifactId>export_parent</artifactId>
<groupId>com.wzx</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<dependencies>
<!--依赖domain-->
<dependency>
<artifactId>export_domain</artifactId>
<groupId>com.wzx</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
创建service接口实现工程
- (1)步骤
》1 创建项目:export_cargo_service
》2 添加依赖:依赖dao、service接口工程、dubbo依赖
》3 配置web.xml
》4 配置applicationContext-dubbo.xml
》5 编写ContractServiceImpl, 服务实现类
》6 编写ContractProvided, 启动服务 - (2)实现
pom.xml
<!-- 指定parent-->
<parent>
<groupId>com.wzx</groupId>
<artifactId>export_parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<!-- 依赖接口工程-->
<dependency>
<groupId>com.wzx</groupId>
<artifactId>export_cargo_interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 依赖dao工程-->
<dependency>
<groupId>com.wzx</groupId>
<artifactId>export_dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 依赖dubbo-->
<!--添加依赖:dubbo相关-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.6</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.32.Final</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.7</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
web.xml
<!--main 加载dubbo配置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/applicationContext-dubbo.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
spring/applicationContext-dubbo.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--Dubbo服务提供方-->
<!--1.dubbo服务名称-->
<dubbo:application name="export_cargo_service"/>
<!--2.注册中心配置-->
<dubbo:registry address="zookeeper://localhost:2181"/>
<!--3.dubbo协议-->
<dubbo:protocol name="dubbo" port="20882"/>
<!--4.扫描dubbo注解-->
<dubbo:annotation package="com.wzx.service"/>
</beans>
ContractServiceImpl
@Service//rpc功能的@Service
public class ContractServiceImpl implements ContractService {
//调用Dao
@Autowired
ContractDao dao;
@Override
public PageInfo<Contract> findByPage(ContractExample contractExample, int pageNum, int pageSize) {
//当前第几页,每页多少条
PageHelper.startPage(pageNum, pageSize);
List<Contract> list = dao.selectByExample(contractExample);
PageInfo<Contract> pi = new PageInfo<>(list);
return pi;
}
@Override
public List<Contract> findAll(ContractExample contractExample) {
return dao.selectByExample(contractExample);
}
@Override
public Contract findById(String id) {
return dao.selectByPrimaryKey(id);
}
@Override
public void save(Contract contract) {
//当前有三个值是必须
//uuid
contract.setId(UUID.randomUUID().toString());
//create_time
contract.setCreateTime(new Date());
//update_time
contract.setUpdateTime(new Date());
dao.insertSelective(contract);
}
@Override
public void update(Contract contract) {
dao.updateByPrimaryKeySelective(contract);
}
@Override
public void delete(String id) {
dao.deleteByPrimaryKey(id);
}
}
Provider
public class Provider {
public static void main(String[] args) throws IOException {
//1.加载配置文件
ClassPathXmlApplicationContext
cxt = new ClassPathXmlApplicationContext("classpath*:spring/applicationContext-*.xml");
//2.启动
cxt.start();
//3.阻塞
System.in.read();
}
}
SaasExport后台系统
- (1) 准备dubbo运行环境
》添加依赖: 依赖货运的service接口工程
》检查web.xml配置(已经完成)
》检查dubbo配置(已经完成) - (2)编写控制器ContractController, 调用服务接口
ContractController
@Controller
@RequestMapping("/cargo/contract")
public class ContractController extends BaseController{
//注入远程接口
@Reference
private ContractService contractService;
}
购销合同状态
- (1)实现查看购销合同
- (2)实现修改购销合同状态:
已报运2
提交1
取消0 ,已默认为草稿0
@RequestMapping(path = "/toView", method = {RequestMethod.GET, RequestMethod.POST})
public String toView(String id) {// location.href="${path}/cargo/contract/toView.do?id="+id;
Contract contract = service.findById(id);
request.setAttribute("contract",contract);
return "cargo/contract/contract-view";
}
@RequestMapping(path = "/submit", method = {RequestMethod.GET, RequestMethod.POST})
public String submit(String id) {// // location.href="${path}/cargo/contract/submit.do?id="+id;
Contract contract = new Contract();
contract.setId(id);
contract.setState(1);//1提交
service.update(contract);
return "redirect:/cargo/contract/toList.do";
}
@RequestMapping(path = "/cancel", method = {RequestMethod.GET, RequestMethod.POST})
public String cancel(String id) {// //location.href="${path}/cargo/contract/cancel.do?id="+id;
//取消
Contract contract = new Contract();
contract.setId(id);
contract.setState(0);//0 草稿
service.update(contract);
return "redirect:/cargo/contract/toList.do";
}