智慧农业后台管理
guoshilong
2022-08-02 9c1e4091094c6b588c3fd998dbad3dc4fbd04a57
新增加工产品库存,删除加工记录表中数据,农产品和加工产品数据回滚
8 files modified
8 files added
632 ■■■■■ changed files
src/main/java/org/springblade/modules/InventoryLoss/controller/InventoryController.java 27 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farmplant/mapper/FarmProductStockMapper.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farmplant/mapper/FarmProductStockMapper.xml 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farmplant/service/FarmProductStockService.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/farmplant/service/impl/FarmProductStockServiceImpl.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/process/controller/ProcessController.java 34 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/process/mapper/ProcessMapper.xml 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/controller/ProcessInvController.java 127 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/dto/ProcessInvDTO.java 34 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/entity/ProcessInv.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.java 52 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.xml 62 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/service/IProcessInvService.java 61 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/service/impl/ProcessInvServiceImpl.java 79 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/processInv/vo/ProcessInvVO.java 46 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/sale/controller/SaleController.java 27 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/InventoryLoss/controller/InventoryController.java
@@ -33,9 +33,12 @@
import org.springblade.modules.InventoryLoss.service.InventoryService;
import org.springblade.modules.InventoryLoss.vo.InventoryVO;
import org.springblade.modules.process.service.IProcessService;
import org.springblade.modules.processInv.entity.ProcessInv;
import org.springblade.modules.processInv.service.IProcessInvService;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Date;
/**
 * 库存损耗记录表 控制器
@@ -51,8 +54,8 @@
    private final InventoryService inventoryService;
    private final FarmProductStockService farmProductStockService;
    private final IProcessService processService;
//    private final IProcessService processService;
    private final IProcessInvService processInvService;
    /**
     * 详情
     */
@@ -124,18 +127,32 @@
    }
    /**
     * 新增或修改 库存损耗记录表
     * 新增或修改 库存损耗记录表(加工产品)
     */
    @PostMapping("/submitProcess")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "新增或修改", notes = "传入sale")
    public R submitProcess(@Valid @RequestBody InventoryVO inventory) {
        boolean res = processService.stockCompare(inventory.getSaleNum(),inventory.getProid());
//        boolean res = processService.stockCompare(inventory.getSaleNum(),inventory.getProid());
//        if (!res){
//            throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
//        }else {
//            //库存充足,减去相应库存
//            processService.stockReduce(inventory.getSaleNum(),inventory.getProid());
//        }
//        return R.status(inventoryService.saveOrUpdate(inventory));
        boolean res = processInvService.stockCompare(inventory.getSaleNum(),inventory.getProid());
        if (!res){
            throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
        }else {
            //库存充足,减去相应库存
            processService.stockReduce(inventory.getSaleNum(),inventory.getProid());
            processInvService.stockReduce(inventory.getSaleNum(),inventory.getProid());
            //更新updateTIme 和 updateUser
            ProcessInv processInv = new ProcessInv();
            processInv.setUpdateUser(inventory.getCreateUser());
            processInv.setUpdateTime(new Date());
            processInv.setId(Long.parseLong(inventory.getProid()));
            processInvService.updateById(processInv);
        }
        return R.status(inventoryService.saveOrUpdate(inventory));
    }
src/main/java/org/springblade/modules/farmplant/mapper/FarmProductStockMapper.java
@@ -45,4 +45,12 @@
    List<Map<String, Double>> statisticsYield(String year,String deptId);
    boolean stockCompare(double sale,String id);
    boolean stockReduce(double sale,String id);
    /**
     * 查找对应数据
     * @param strainId 品种id
     * @param landId 地块id
     * @return
     */
    FarmProductStock selectBy2Id(@Param("strainId") String strainId, @Param("landId") String landId);
}
src/main/java/org/springblade/modules/farmplant/mapper/FarmProductStockMapper.xml
@@ -382,10 +382,17 @@
        WHERE
            id = #{id}
    </select>
    <!--减去对应库存-->
    <update id="stockReduce">
        UPDATE sys_farm_product_stock SET weight = weight - #{sale}
        WHERE
            id = #{id}
    </update>
    <select id="selectBy2Id" resultType="org.springblade.modules.farmplant.entity.FarmProductStock">
        SELECT id,strain_id,weight,leaves,time,operator,remark,
               create_time,farm_plant_id,dept_id,tenant_id,recovery,land_id
        FROM sys_farm_product_stock  WHERE strain_id = #{strainId} AND land_id = #{landId}
    </select>
</mapper>
src/main/java/org/springblade/modules/farmplant/service/FarmProductStockService.java
@@ -45,4 +45,12 @@
    boolean stockCompare(double sale,String id);
    //减去相应库存
    boolean stockReduce(double sale,String id);
    /**
     * 查找对应数据
     * @param strainId 品种id
     * @param landId 地块id
     * @return
     */
    FarmProductStock selectBy2Id(String strainId, String landId);
}
src/main/java/org/springblade/modules/farmplant/service/impl/FarmProductStockServiceImpl.java
@@ -109,4 +109,9 @@
    public boolean stockReduce(double sale,String id) {
        return baseMapper.stockReduce(sale,id);
    }
    @Override
    public FarmProductStock selectBy2Id(String strainId, String landId) {
        return baseMapper.selectBy2Id(strainId,landId);
    }
}
src/main/java/org/springblade/modules/process/controller/ProcessController.java
@@ -28,7 +28,10 @@
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.farmplant.entity.FarmProductStock;
import org.springblade.modules.farmplant.service.FarmProductStockService;
import org.springblade.modules.processInv.entity.ProcessInv;
import org.springblade.modules.processInv.service.IProcessInvService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -36,6 +39,8 @@
import org.springblade.modules.process.vo.ProcessVO;
import org.springblade.modules.process.service.IProcessService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.Date;
/**
 * 加工记录表 控制器
@@ -51,6 +56,7 @@
    private final IProcessService processService;
    private final FarmProductStockService farmProductStockService;
    private final IProcessInvService processInvService;
    /**
     * 详情
     */
@@ -117,6 +123,13 @@
        }else {
            //库存充足,减去相应库存
            farmProductStockService.stockReduce(process.getSaleNum(),process.getProid());
            //向加工产品库存表中添加数据
            ProcessInv processInv = new ProcessInv();
            processInv.setProductId(Long.parseLong(process.getProcessId()));
            processInv.setProductInventoryNum(process.getProcessNum());
            processInv.setStrainId(Long.parseLong(process.getStrainId()));
            processInv.setUpdateUser(process.getCreateUser());
            processInvService.insertOrUpdate(processInv);
        }
        return R.status(processService.saveOrUpdate(process));
    }
@@ -129,6 +142,27 @@
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        //对加工产品库存和农产品库存进行回滚
        Process process = processService.getById(Long.parseLong(ids));
        //通过strainId和landId 确定是由哪一个品种库存加工而来
        FarmProductStock farmProductStock = farmProductStockService.selectBy2Id(process.getStrainId(),process.getLandId());
        //通过strainId和processId(processId为产品id)确定对应的加工库存
        ProcessInv processInv = processInvService.selectBy2Id(process.getStrainId(),process.getProcessId());
        //农产品增加相应库存
        Double weight = Double.parseDouble(farmProductStock.getWeight())+process.getSaleNum();
        farmProductStock.setWeight(weight.toString());
        farmProductStockService.updateById(farmProductStock);
        //加工产品减少对应库存
        Double num = processInv.getProductInventoryNum()-process.getProcessNum();
        if (num<=0){
            //删除对应库存
//            processInvService.del(processInv.getId());
            throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足,不能删除数据!"));
        }else {
            //更新库存
            processInv.setProductInventoryNum(num);
            processInvService.updateById(processInv);
        }
        return R.status(processService.deleteLogic(Func.toLongList(ids)));
    }
src/main/java/org/springblade/modules/process/mapper/ProcessMapper.xml
@@ -39,7 +39,7 @@
        <if test="process.strainId !=null and process.strainId !=''">
            and p.strain_id = #{process.strainId}
        </if>
        GROUP BY p.strain_id,m.machining_type,m.machining_tp,p.land_id,sale_time,sale_num,process_id,p.id
        GROUP BY p.strain_id,m.machining_type,m.machining_tp,p.land_id,sale_time,sale_num,process_id,p.id ORDER BY p.create_time DESC
    </select>
    <select id="stockCompare" resultType="boolean">
src/main/java/org/springblade/modules/processInv/controller/ProcessInvController.java
New file
@@ -0,0 +1,127 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.processInv.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.processInv.entity.ProcessInv;
import org.springblade.modules.processInv.service.IProcessInvService;
import org.springblade.modules.processInv.vo.ProcessInvVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.boot.ctrl.BladeController;
/**
 * 加工库存表 控制器
 *
 * @author BladeX
 * @since 2022-08-01
 */
@RestController
@AllArgsConstructor
@RequestMapping("/processinv/processinv")
@Api(value = "加工库存表", tags = "加工库存表接口")
public class ProcessInvController extends BladeController {
    private final IProcessInvService processInvService;
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入processInv")
    public R<ProcessInv> detail(ProcessInv processInv) {
        ProcessInv detail = processInvService.getOne(Condition.getQueryWrapper(processInv));
        return R.data(detail);
    }
    /**
     * 分页 加工库存表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入processInv")
    public R<IPage<ProcessInv>> list(ProcessInv processInv, Query query) {
        IPage<ProcessInv> pages = processInvService.page(Condition.getPage(query), Condition.getQueryWrapper(processInv));
        return R.data(pages);
    }
    /**
     * 自定义分页 加工库存表
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入processInv")
    public R<IPage<ProcessInvVO>> page(ProcessInvVO processInv, Query query) {
        IPage<ProcessInvVO> pages = processInvService.selectProcessInvPage(Condition.getPage(query), processInv);
        return R.data(pages);
    }
    /**
     * 新增 加工库存表
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入processInv")
    public R save(@Valid @RequestBody ProcessInv processInv) {
        return R.status(processInvService.save(processInv));
    }
    /**
     * 修改 加工库存表
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入processInv")
    public R update(@Valid @RequestBody ProcessInv processInv) {
        return R.status(processInvService.updateById(processInv));
    }
    /**
     * 新增或修改 加工库存表
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入processInv")
    public R submit(@Valid @RequestBody ProcessInv processInv) {
        return R.status(processInvService.saveOrUpdate(processInv));
    }
    /**
     * 删除 加工库存表
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(processInvService.deleteLogic(Func.toLongList(ids)));
    }
}
src/main/java/org/springblade/modules/processInv/dto/ProcessInvDTO.java
New file
@@ -0,0 +1,34 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.processInv.dto;
import org.springblade.modules.processInv.entity.ProcessInv;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * 加工库存表数据传输对象实体类
 *
 * @author BladeX
 * @since 2022-08-01
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ProcessInvDTO extends ProcessInv {
    private static final long serialVersionUID = 1L;
}
src/main/java/org/springblade/modules/processInv/entity/ProcessInv.java
New file
@@ -0,0 +1,53 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.processInv.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import org.springblade.core.mp.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * 加工库存表实体类
 *
 * @author BladeX
 * @since 2022-08-01
 */
@Data
@TableName("sys_process_inv")
@EqualsAndHashCode(callSuper = true)
public class ProcessInv extends BaseEntity {
    private static final long serialVersionUID = 1L;
    /**
    * 品种id
    */
    private Long strainId;
    /**
    * 产品id 关联sys_machining加工管理表
    */
    private Long productId;
    /**
    * 产品库存数量
    */
    private Double productInventoryNum;
}
src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.java
New file
@@ -0,0 +1,52 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.processInv.mapper;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.processInv.entity.ProcessInv;
import org.springblade.modules.processInv.vo.ProcessInvVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
/**
 * 加工库存表 Mapper 接口
 *
 * @author BladeX
 * @since 2022-08-01
 */
public interface ProcessInvMapper extends BaseMapper<ProcessInv> {
    /**
     * 自定义分页
     *
     * @param page
     * @param processInv
     * @return
     */
    List<ProcessInvVO> selectProcessInvPage(IPage page, ProcessInvVO processInv);
    ProcessInv selectBy2Id(@Param("strainId") Long strainId, @Param("productId") Long productId);
    Boolean add(@Param("processInv") ProcessInv processInv1);
    boolean stockCompare(@Param("saleNum") Double saleNum, @Param("proid") String proid);
    Boolean stockReduce(@Param("saleNum") Double saleNum, @Param("proid") String proid);
    Boolean del(Long id);
}
src/main/java/org/springblade/modules/processInv/mapper/ProcessInvMapper.xml
New file
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.processInv.mapper.ProcessInvMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="processInvResultMap" type="org.springblade.modules.processInv.vo.ProcessInvVO">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="strain_id" property="strainId"/>
        <result column="product_id" property="productId"/>
        <result column="product_inventory_num" property="productInventoryNum"/>
        <result column="machining_tp" property="tpurl"/>
        <result column="machining_type" property="processName"/>
        <result column="strain_name" property="strainName"/>
    </resultMap>
    <select id="selectProcessInvPage" resultMap="processInvResultMap">
        select inv.*,m.machining_tp,
               m.machining_type,strain_name
        from sys_process_inv inv
        LEFT JOIN sys_machining m ON m.id = inv.product_id
        LEFT JOIN sys_strain strain ON strain.id = inv.strain_id
        where inv.is_deleted = 0
    </select>
    <select id="selectBy2Id" resultType="org.springblade.modules.processInv.entity.ProcessInv">
        SELECT id,strain_id,product_id,product_inventory_num,create_time,update_user,update_time,status,is_deleted
        FROM sys_process_inv WHERE strain_id = #{strainId} AND product_id = #{productId}
    </select>
    <insert id="add">
        INSERT INTO sys_process_inv (strain_id,product_id,product_inventory_num,create_time,status,is_deleted)
        VALUES (#{processInv.strainId},#{processInv.productId},#{processInv.productInventoryNum},NOW(),1,0)
    </insert>
    <select id="stockCompare" resultType="java.lang.Boolean">
        SELECT
            CASE
                WHEN
                    product_inventory_num > #{saleNum} THEN
                    TRUE ELSE FALSE
                END result
        FROM
            sys_process_inv
        WHERE
            id = #{proid}
    </select>
    <update id="stockReduce">
        UPDATE sys_process_inv SET product_inventory_num = product_inventory_num - #{saleNum}
        WHERE
            id = #{proid}
    </update>
    <delete id="del">
        DELETE FROM sys_process_inv WHERE id = #{id}
    </delete>
</mapper>
src/main/java/org/springblade/modules/processInv/service/IProcessInvService.java
New file
@@ -0,0 +1,61 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.processInv.service;
import org.springblade.modules.processInv.entity.ProcessInv;
import org.springblade.modules.processInv.vo.ProcessInvVO;
import org.springblade.core.mp.base.BaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
/**
 * 加工库存表 服务类
 *
 * @author BladeX
 * @since 2022-08-01
 */
public interface IProcessInvService extends BaseService<ProcessInv> {
    /**
     * 自定义分页
     *
     * @param page
     * @param processInv
     * @return
     */
    IPage<ProcessInvVO> selectProcessInvPage(IPage<ProcessInvVO> page, ProcessInvVO processInv);
    Boolean insertOrUpdate(ProcessInv processInv);
    boolean stockCompare(Double saleNum, String proid);
    Boolean stockReduce(Double saleNum, String proid);
    /**
     * 查找对应数据
     * @param strainId 品种id
     * @param processId    产品id
     * @return
     */
    ProcessInv selectBy2Id(String strainId, String processId);
    /**
     * 彻底删除
     * @param id 主键
     * @return
     */
    Boolean del(Long id);
}
src/main/java/org/springblade/modules/processInv/service/impl/ProcessInvServiceImpl.java
New file
@@ -0,0 +1,79 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.processInv.service.impl;
import org.springblade.modules.processInv.entity.ProcessInv;
import org.springblade.modules.processInv.mapper.ProcessInvMapper;
import org.springblade.modules.processInv.service.IProcessInvService;
import org.springblade.modules.processInv.vo.ProcessInvVO;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.Date;
/**
 * 加工库存表 服务实现类
 *
 * @author BladeX
 * @since 2022-08-01
 */
@Service
public class ProcessInvServiceImpl extends BaseServiceImpl<ProcessInvMapper, ProcessInv> implements IProcessInvService {
    @Override
    public IPage<ProcessInvVO> selectProcessInvPage(IPage<ProcessInvVO> page, ProcessInvVO processInv) {
        return page.setRecords(baseMapper.selectProcessInvPage(page, processInv));
    }
    @Override
    public Boolean insertOrUpdate(ProcessInv processInv) {
        //通过strainId和productId查询对应数据
        ProcessInv processInv1 = baseMapper.selectBy2Id(processInv.getStrainId(),processInv.getProductId());
        if (processInv1 != null){
            //当存在该数据时,修改
            processInv1.setProductInventoryNum(processInv1.getProductInventoryNum()+processInv.getProductInventoryNum());
            processInv1.setUpdateTime(new Date());
            processInv1.setUpdateUser(processInv.getUpdateUser());
            return baseMapper.updateById(processInv1)>0;
        }else {
            //不存在该数据时添加
            return baseMapper.add(processInv);
        }
    }
    @Override
    public boolean stockCompare(Double saleNum, String proid) {
        return baseMapper.stockCompare(saleNum,proid);
    }
    @Override
    public Boolean stockReduce(Double saleNum, String proid) {
        return baseMapper.stockReduce(saleNum,proid);
    }
    @Override
    public ProcessInv selectBy2Id(String strainId, String processId) {
        return baseMapper.selectBy2Id(Long.parseLong(strainId),Long.parseLong(processId));
    }
    @Override
    public Boolean del(Long id) {
        return baseMapper.del(id);
    }
}
src/main/java/org/springblade/modules/processInv/vo/ProcessInvVO.java
New file
@@ -0,0 +1,46 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.processInv.vo;
import org.springblade.modules.processInv.entity.ProcessInv;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
 * 加工库存表视图实体类
 *
 * @author BladeX
 * @since 2022-08-01
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ProcessInvVO extends ProcessInv {
    private static final long serialVersionUID = 1L;
    /**
     * 加工产品图片
     */
    private String tpurl;
    /**
     * 加工产品名
     */
    private String processName;
    /**
     * 品种名
     */
    private String strainName;
}
src/main/java/org/springblade/modules/sale/controller/SaleController.java
@@ -31,6 +31,8 @@
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.farmplant.service.FarmProductStockService;
import org.springblade.modules.process.service.IProcessService;
import org.springblade.modules.processInv.entity.ProcessInv;
import org.springblade.modules.processInv.service.IProcessInvService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -38,6 +40,8 @@
import org.springblade.modules.sale.vo.SaleVO;
import org.springblade.modules.sale.service.ISaleService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.Date;
/**
 * 销售记录表 控制器
@@ -53,8 +57,8 @@
    private final ISaleService saleService;
    private final FarmProductStockService farmProductStockService;
    private final IProcessService processService;
//    private final IProcessService processService;
    private final IProcessInvService processInvService;
    /**
     * 详情
     */
@@ -132,13 +136,28 @@
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "新增或修改", notes = "传入sale")
    public R submitProcess(@Valid @RequestBody SaleVO sale) {
//        //对比加工表库存量
//        boolean res = processService.stockCompare(sale.getSaleNum(),sale.getProid());
//        if (!res){
//            throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
//        }else {
//            //库存充足,减去相应库存
//            processService.stockReduce(sale.getSaleNum(),sale.getProid());
//        }
//        return R.status(saleService.saveOrUpdate(sale));
        //对比加工表库存量
        boolean res = processService.stockCompare(sale.getSaleNum(),sale.getProid());
        boolean res = processInvService.stockCompare(sale.getSaleNum(),sale.getProid());
        if (!res){
            throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前库存不足!"));
        }else {
            //库存充足,减去相应库存
            processService.stockReduce(sale.getSaleNum(),sale.getProid());
            processInvService.stockReduce(sale.getSaleNum(),sale.getProid());
            //更新updateTIme 和 updateUser
            ProcessInv processInv = new ProcessInv();
            processInv.setUpdateUser(sale.getCreateUser());
            processInv.setUpdateTime(new Date());
            processInv.setId(Long.parseLong(sale.getProid()));
            processInvService.updateById(processInv);
        }
        return R.status(saleService.saveOrUpdate(sale));
    }