入库审核操作&入库预警定会调度+邮件发送

          入库审核操作&入库预警定会调度+邮件发送

模块分类:

组织机构模块:公司,部门,员工

系统模块: 角色,权限,菜单-- 使用系统之前的 这些就应该维护到系统

基础数据模块:(数据字典(下拉框) )产品,产品类型,供应商(采购),客户(销售)

 进销存核心模块:

 

(1)采购模块:采购订单,采购报表

 

(2)销售模块:销售订单,销售报表

 

     销售是面向批发

 

     销售订单公司销售人员下单,于客户进行沟通

 

     下销售订单:把采购里面的供应商变成客户,采购员变成销售员,查询库存数量,需要考虑

 

3)库存模块:入库单,出库单,报表

 

库存模块(今天)
入库数据: 保存(stockincomebill/stockincomebillitem)
出库数据:
入库审核:
审核完之后, 进入productstock(即时库存表)和 depot(仓库表) 同时 (stockincomebill)入库单据状态变成已审核
出库审核之后:
审核完之后, 进入productstock和 depot 同时 (stockincomebill)入库单据状态变成已审核

业务代码:


 

@Transactional
public void auditStockincomebill(Long billid, Employee auditor){

//需要审核单据
Stockincomebill bill = stockincomebillRepository.findOne(billid);
if(bill == null){
throw new RuntimeException("该单据不存在");
}
//0表示 待审 1 表示已审 -1表示作废
if(bill.getStatus() == 1){
throw new RuntimeException("该单据已审核");
}

if(bill.getStatus() == -1){
throw new RuntimeException("该单据已作废");
}

//单据里面 里面审核的时间 审核人 状态
bill.setAuditorTime(new Date());
bill.setAuditor(auditor);
bill.setStatus(1);

//保存数据 更新数据
stockincomebillRepository.save(bill);

// (2)仓库变化
Depot depot = bill.getDepot();
//当前容量
depot.setCurrentcapacity(depot.getCurrentcapacity().add(bill.getTotalNum()));
depot.setTotalamount(depot.getTotalamount().add(bill.getTotalAmount()));

//保存仓库
depotRepository.save(depot);

//(3)及时库存表变化 同一个仓库 同一个产品合并
// 第一次入及时库存 直接新增 如果不是第一次 需要进行合并
List<Stockincomebillitem> items = bill.getItems();
//查询当前这个产品在即时库存表离是否存在
String jpql = "select o from Productstock o where o.product=? and o.depot=?";
for (Stockincomebillitem item : items) {
Product product = item.getProduct();

List productStockList = productstockRepository.findByJpql(jpql, product, depot);
BigDecimal totalNum = new BigDecimal("0");
BigDecimal totalAmount = new BigDecimal("0");

if(productStockList.size() == 0){
//第一次 直接新增
Productstock productStock = new Productstock();
productStock.setDepot(depot);//仓库
productStock.setNum(item.getNum());
productStock.setPrice(item.getPrice());
productStock.setAmount(item.getAmount());
productStock.setIncomedate(new Date());//入即时库存时间
productStock.setProduct(product);//产品
productstockRepository.save(productStock);

}else if(productStockList.size() == 1){
//合并
Productstock productstock = (Productstock)productStockList.get(0);

totalNum = productstock.getNum().add(item.getNum());
totalAmount = productstock.getAmount().add(item.getAmount());
//总数量
productstock.setNum(productstock.getNum().add(item.getNum()));
//总金额
productstock.setAmount(productstock.getAmount().add(item.getAmount()));
//加权平均价格 --四舍五入
productstock.setPrice(totalAmount.divide(totalNum,2,BigDecimal.ROUND_HALF_EVEN));

productstockRepository.save(productstock);
}else{
throw new RuntimeException("仓库出问题");
}

}


}

 

定时报警:导包

 

<dependency>

<groupId>quartz</groupId>

<artifactId>quartz</artifactId>

<version>1.5.2</version>

</dependency>

测试代码:

@Test

public void time() throws Exception {

// 定时器

Timer timer = new Timer();

// 开启定时任务(子线程)

timer.schedule(new TimerTask() {

@Override

public void run() {

System.out.println(new Date().toLocaleString());

}

}, 0, 1000);// 0立即执行,1000间隔1

// 让主线程处于运行状态

Thread.sleep(5000);

}

配置 applicationContext.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: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>

库存不足时发送邮件给相应的人:

@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("库存很足...");
        }

    }
}

 

邮件导包:

 

<dependency>

 

<groupId>javax.mail</groupId>

 

<artifactId>mail</artifactId>

 

<version>1.4.1</version>

 

</dependency>

配置文件:

<?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 -->

<!-- [email protected] 用户名: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>

 

测试邮箱后 开启协议:

 邮箱的测试代码:

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);
   }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

猜你喜欢

转载自www.cnblogs.com/1999wang/p/11367041.html