2.1入库单保存:
stockincomebill --入库主单表
package cn.itsource.aisell.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Entity
@Table(name = "stockincomebill")
public class StockIncomeBill extends BaseDomain {
private Date vdate;// 交易时间 -> 需要录入(时间set的时候加上@DateTimeFormat(pattern = "yyyy-MM-dd"))
private BigDecimal totalAmount; //总金额 -> 明细计算
private BigDecimal totalNum; //总数量 -> 明细计算
private Date inputTime = new Date(); //录入时间 ->系统自动生成 当前系统时间
private Date auditorTime; //审核时间 -> 可以为空,审核时自己生成
/**
* 0待审,1已审,-1作废
*/
private Integer status = 0; //单据状态 -> 默认待审
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "supplier_id")
private Supplier supplier;// 多对一,optional非空 供应商(需要选择)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "auditor_id")
private Employee auditor;// 多对一,可以为空
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "inputUser_id")
private Employee inputUser;// 多对一,非空 录入人 -> 登录用户就是录入人
/* @ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "buyer_id")
private Employee buyer;// 多对一,非空 采购员 -> 需要*/
//仓库员
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "keeper_id")
private Employee keeper;// 多对一,非空 仓管员 -> 需要
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "depot_id")
private Depot depot;// 仓库
@OneToMany(cascade = CascadeType.ALL, mappedBy = "bill", fetch = FetchType.LAZY, orphanRemoval = true)
private List<StockIncomeBillItem> items = new ArrayList<StockIncomeBillItem>();
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
public Date getVdate() {
return vdate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setVdate(Date vdate) {
this.vdate = vdate;
}
public BigDecimal getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
}
public BigDecimal getTotalNum() {
return totalNum;
}
public void setTotalNum(BigDecimal totalNum) {
this.totalNum = totalNum;
}
public Date getInputTime() {
return inputTime;
}
public void setInputTime(Date inputTime) {
this.inputTime = inputTime;
}
public Date getAuditorTime() {
return auditorTime;
}
public void setAuditorTime(Date auditorTime) {
this.auditorTime = auditorTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Supplier getSupplier() {
return supplier;
}
public void setSupplier(Supplier supplier) {
this.supplier = supplier;
}
public Employee getAuditor() {
return auditor;
}
public void setAuditor(Employee auditor) {
this.auditor = auditor;
}
public Employee getInputUser() {
return inputUser;
}
public void setInputUser(Employee inputUser) {
this.inputUser = inputUser;
}
/* public Employee getBuyer() {
return buyer;
}
public void setBuyer(Employee buyer) {
this.buyer = buyer;
}*/
public Employee getKeeper() {
return keeper;
}
public void setKeeper(Employee keeper) {
this.keeper = keeper;
}
public Depot getDepot() {
return depot;
}
public void setDepot(Depot depot) {
this.depot = depot;
}
public List<StockIncomeBillItem> getItems() {
return items;
}
public void setItems(List<StockIncomeBillItem> items) {
this.items = items;
}
}
stockincomebillitem--入库的子单表
package cn.itsource.aisell.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.math.BigDecimal;
//产品明细
@Entity
@Table(name = "stockincomebillitem")
public class StockIncomeBillItem extends BaseDomain {
private BigDecimal price; //价格
private BigDecimal num; //数量
private BigDecimal amount; //小计 = 价格*数量
private String descs; //描述
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "product_id")
private Product product;// 多对一,非空 产品
//和订单的关系
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "bill_id")
//@JsonIgnore //生成json的时候忽略这个属性
private StockIncomeBill bill;// 组合关系,非空
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getNum() {
return num;
}
public void setNum(BigDecimal num) {
this.num = num;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public String getDescs() {
return descs;
}
public void setDescs(String descs) {
this.descs = descs;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public StockIncomeBill getBill() {
return bill;
}
public void setBill(StockIncomeBill bill) {
this.bill = bill;
}
}
录入:保存到这两个表–和以前采购模块类型 --级联保存
2.2入库单审核
入库审核设计表 – stockincomebill这个审核人 审核状态 审核时间变化
仓库表 -depot 数量要加上 金额加上
产品即时库存表 – productstock这个表 (对应同一个商品和同一个仓库 --加权的平均法)
第一个加入产品,productstock新增数据
第二个加入同样的产品,并且同一个仓库 --通过加权平均法算 价格
OpenSymphony Quartz 任务调度**
applicationContext.xml
<!-- 引入其他的配置文件 -->
<import resource="classpath:plugin/applicationContext-*.xml"/>
Spirng配置
<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- cron表达式:在每天早上8点到晚上8点期间每1分钟触发一次 -->
<!--value>0 0/1 8-20 * * ?</value -->
<!-- cron表达式:每5分钟触发一次 -->
<!-- <value>0 0/5 * * * ?</value> -->
<task:scheduled-tasks>
<!-- 执行quartzJob里面的work方法,执行频率是cron表达式 -->
<task:scheduled ref="quartzJob" method="work" cron="0 0/1 * * * ?" />
</task:scheduled-tasks>
</beans>
9.8.3.代码
把预警消息发送给相关人员
@Service("QzJob")
public class QuartzJobServiceImpl implements IQuartzJobService {
@Autowired
private IProductstockService productstockService;
@Override
public void work() {
System.out.println(productstockService);
System.out.println("---------------------------------");
String jpql ="select o from Productstock o where o.id = ?";
List list = productstockService.findByJpql(jpql, 1L);
if(list.size() > 0 ){
System.out.println("库存不足");
}else{
System.out.println("库存很足...");
}
}
}
9.9.1.pom.xml添加jar文件
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
9.9.2.spring配置文件
<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<!-- 163邮箱,smtp.163.com -->
<!-- admin@163.com 用户名:admin 授权码:xxx -->
<!-- smtp邮件发送协议 -->
<!-- pop3收邮件协议 -->
<property name="host" value="smtp.163.com" />
<property name="username" value="123456" />
<property name="password" value="xxxxxxx" />
<property name="javaMailProperties">
<props>
<!-- 必须进行授权认证,它的目的就是阻止他人任意乱发邮件 -->
<prop key="mail.smtp.auth">true</prop>
<!-- SMTP加密方式:连接到一个TLS保护连接 -->
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
</beans>
9.9.3.开启smtp协议
登录网易163/126邮箱,在获取授权码(百度一下)
9.9.4.简单邮件和复杂邮件
public class MailTest extends BaseServiceTest {
@Autowired
JavaMailSender mailSender;
@Test
public void testName() throws Exception {
//JavaMailSenderImpl xxx = (JavaMailSenderImpl)mailSender
// 简单邮件对象
SimpleMailMessage msg = new SimpleMailMessage();
// 发送人:和配置一致
msg.setFrom("[email protected]");
// 收件人
msg.setTo("[email protected]");
// 主题
msg.setSubject("牛皮大学录取通知书");
// 内容
msg.setText("你已经被录取了");
// 设置固定回邮地址
//msg.setReplyTo("[email protected]");
// 发送
mailSender.send(msg);
}
/**
* 发送复杂邮件
*/
@Test
public void testSendMsg2() throws MessagingException {
//创建复杂的邮件发送
MimeMessage mimeMessage = mailSender.createMimeMessage();
//复杂邮件的工具类
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"UTF-8");
helper.setFrom("[email protected]");
helper.setTo("[email protected]");
helper.setSubject("测试一把");
helper.setText("男男女女
",true);
//发送附件
helper.addAttachment("美女.jpg",new File("E:/timg.jpg"));
helper.addAttachment("java.docx",new File("E:/新建文本文档 (2).txt"));
mailSender.send(mimeMessage);
}
}