• 恒合仓库 - 采购单管理模块


    采购单管理模块

    一、添加采购单(核心)

    1.1 采购流程

    类似进货

    采购流程

    • 在商品列表针对具体的商品添加采购单

      image-20230819193051386

      向buy_list表中添加一条记录。添加的采购单表示预买的商品(还没有买,is_in字段的值是0)

      image-20230819185218636

    • 当商品采购到之后进行入库

      在采购单列表做入库操作,向in_store表添加记录(状态是0未入库),同时修改采购单表buy_list表由0改为1入库(这个入库是表示准备入库)

    image-20230819191554350

    ​ 下面是in_store表

    image-20230819191805399

    • 商品真正的入库

      在入库单列表做确认入库操作

      image-20230819191905348

      将入库单表in_store表的入库单状态由0改为1入库

    1.2 采购单实体类

    /**
     * 采购单表buy_list表的实体类:
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @ToString
    public class Purchase {
    
        private Integer buyId;//采购单id
    
        private Integer productId;//采购单采购的商品id
    
        private Integer storeId;//采购单采购的商品所在仓库id
    
        private Integer buyNum;//预计采购的商品数量
    
        private Integer factBuyNum;//实际采购的商品数量
    
        @JsonFormat(pattern = "yyyy-MM-dd")
        private Date buyTime;//采购时间
    
        private Integer supplyId;//采购单采购的商品的供应商id
    
        private Integer placeId;//采购单采购的商品的产地id
    
        private String buyUser;//采购人
    
        private String phone;//采购人联系电话
    
        private String isIn;//是否生成入库单,1.是,0.否
    
        //---------------追加属性---------------------------
    
        private String productName;//商品名称
    
        private String storeName;//仓库名称
    
        private String startTime;//搜索起始时间
    
        private String endTime;//搜索结束时间
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    1.3 添加采购单

    image-20230819193441082

    采购单数据库表buy_list如下所示

    image-20230819193636735

    image-20230819194050277

    1.3.1 Mapper

    @Mapper
    public interface PurchaseMapper {
    //   添加采购单
        public int insertPurchase(Purchase purchase);
        
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    <insert id="insertPurchase">
        insert into buy_list
        values (null, #{productId}, #{storeId}, #{buyNum}, null, now(),
                #{supplyId}, #{placeId}, #{buyUser}, #{phone}, 0)
    insert>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    1.3.2 Service

    @Service
    public class PurchaseServiceImpl implements PurchaseService {
    
        @Autowired
        private PurchaseMapper purchaseMapper;
    
        @Override
        public Result savePurchase(Purchase purchase) {
    //      初始化时,实际采购数量要和预计采购数量一致
            purchase.setFactBuyNum(purchase.getBuyNum());
            int success = purchaseMapper.insertPurchase(purchase);
    
            return success>0 ? Result.ok("添加采购单成功") : Result.err(501,"添加采购单失败");
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    1.3.3 Controller

    @RestController
    @RequestMapping("/purchase")
    public class PurchaseController {
    
        @Autowired
        private PurchaseService purchaseService;
    
        @RequestMapping("/purchase-add")
        public Result addPurchase(@RequestBody Purchase purchase){
    
            return purchaseService.savePurchase(purchase);
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    1.3.4 效果图

    image-20230819201233500

    image-20230819201346600

    二、采购单管理模块

    1.采购列表

    2.删除采购单

    3.修改采购单

    4.生成入库单

    image-20230822192440479

    2.1 仓库数据回显

    2.1.1 Mapper

    //  查询所有仓库的方法
        public List<Store> findAllStore();
    
    • 1
    • 2
    <mapper namespace="com.pn.mapper.StoreMapper">
    
        <select id="findAllStore" resultType="com.pn.entity.Store">
            select *
            from store
        select>
    
    mapper>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2.1.2 Service

    @CacheConfig(cacheNames = "com.pn.service.impl.StoreServiceImpl")
    @Service
    public class StoreServiceImpl implements StoreService {
        @Autowired
        private StoreMapper storeMapper;
    
    
        @Cacheable(key = "'all:store'")
        @Override
        public List<Store> queryAllStore() {
            return storeMapper.findAllStore();
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    2.1.3 Controller

    //  仓库数据回显 - 查询所有仓库
        @RequestMapping("/store-list")
        public Result storeList(){
            return Result.ok(storeService.queryAllStore());
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.1.4 效果图

    image-20230822193510247

    2.2 采购单列表

    我们需要将下面的数据显示出来。

    查询所有采购单并分页或者是根据仓库id、起止时间、商品名称、采购员、是否入库查询采购单并分页

    image-20230822213529276

    2.1.1 Mapper

    //  查询采购单行数的方法
        public Integer findPurchaseCount(Purchase purchase);
    
    //  分页查询采购单的方法
        public List<Purchase> findPurchasePage(@Param("page") Page page,@Param("purchase") Purchase purchase);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    <select id="findPurchaseCount" resultType="java.lang.Integer">
        select count(*) from buy_list t1, product t2, store t3
        where t1.product_id = t2.product_id and t1.store_id = t3.store_id
        <if test="storeId != null">
            and t1.store_id = #{storeId}
        </if>
        <if test="productName != null and productName != ''">
            and t2.product_name like concat('%', #{productName}, '%')
        </if>
        <if test="buyUser != null and buyUser != ''">
            and t1.buy_user like concat('%', #{buyUser}, '%')
        </if>
        <if test="isIn != null and isIn != ''">
            and t1.is_in = #{isIn}
        </if>
        <if test="startTime != null and startTime != ''">
            and t1.buy_time &gt;= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and t1.buy_time &lt;= #{endTime}
        </if>
    </select>
    
    <select id="findPurchasePage" resultType="com.pn.entity.Purchase">
        select t1.*, t2.product_name, t3.store_name
        from buy_list t1, product t2, store t3
        where t1.product_id = t2.product_id and t1.store_id = t3.store_id
        <if test="purchase.storeId != null">
            and t1.store_id = #{purchase.storeId}
        </if>
        <if test="purchase.productName != null and purchase.productName != ''">
            and t2.product_name like concat('%', #{purchase.productName}, '%')
        </if>
        <if test="purchase.buyUser != null and purchase.buyUser != ''">
            and t1.buy_user like concat('%', #{purchase.buyUser}, '%')
        </if>
        <if test="purchase.isIn != null and purchase.isIn != ''">
            and t1.is_in = #{purchase.isIn}
        </if>
        <if test="purchase.startTime != null and purchase.startTime != ''">
            and t1.buy_time &gt;= #{purchase.startTime}
        </if>
        <if test="purchase.endTime != null and purchase.endTime != ''">
            and t1.buy_time &lt;= #{purchase.endTime}
        </if>
        order by t1.buy_time desc
        limit #{page.limitIndex}, #{page.pageSize}
    </select>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    2.1.2 Service

        @Override
        public Page queryPurchasePage(Page page, Purchase purchase) {
    
    //      查询采购单行数
            Integer count = purchaseMapper.findPurchaseCount(purchase);
    
    //      分页查询采购单
            List<Purchase> purchasePage = purchaseMapper.findPurchasePage(page, purchase);
    
    //      组装分页信息
            page.setTotalNum(count);
            page.setResultList(purchasePage);
            return page;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    2.1.3 Controller

    //分页查询采购单的url
    @RequestMapping("/purchase-page-list")
    public Result purchaseListPage(Page page, Purchase purchase) {
        return Result.ok(purchaseService.queryPurchasePage(page,purchase));
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.1.4 效果图

    image-20230822224905377

    2.3 删除采购单

    已经入库的采购单不能被删除

    2.3.1 Mapper

    //  根据id删除采购单的方法
        public int removerPurchaseById(@Param("buyId") Integer buyId);
    
    • 1
    • 2
    <delete id="removerPurchaseById">
       delete from buy_list where buy_id =#{buyId}
    delete>
    
    • 1
    • 2
    • 3

    2.3.2 Service

        @Override
        public Result deletePurchaseById(Integer buyId) {
            int success = purchaseMapper.removerPurchaseById(buyId);
            return success>0 ? Result.ok("删除采购单成功") : Result.err(501,"删除采购单失败");
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.3.3 Controller

    //  删除采购单
        @RequestMapping("/purchase-delete/{buyId}")
        public Result deletePurchase(@PathVariable Integer buyId){
            return Result.ok(purchaseService.deletePurchaseById(buyId));
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.4 修改采购单

    只能修改采购单的“预计采购数量”和“实际采购数量”

    image-20230829211605364

    2.4.1 Mapper

    //  根据id修改预计采购数量和实际采购数量的方法
        public int setNumberById(Purchase purchase);
    
    • 1
    • 2
    <update id="setNumberById">
        update buy_list
        set buy_num = #{buyNum} ,fact_buy_num = #{factBuyNum}
        where buy_id = #{buyId}
    </update>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.4.2 Service

    @Override
    public Result updatePurchaseById(Purchase purchase) {
        int success = purchaseMapper.setNumberById(purchase);
        return success>0 ? Result.ok("删除采购单成功") : Result.err(501,"删除采购单失败");
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.4.3 Controller

    //  修改采购单的业务方法
        @RequestMapping("/purchase-update")
        public Result updatePurchase(@RequestBody Purchase purchase){
            return Result.ok(purchaseService.updatePurchaseById(purchase));
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.5 生成入库单

    image-20230829220825978

    当我们商品采购到后,我们要进行入库操作

    image-20230829220013380

    2.5.1 入库单表实体类

    /**
     * 入库单表in_store表的实体类:
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public class InStore {
    
        private Integer insId;//入库单id
    
        private Integer storeId;//仓库id
    
        private Integer productId;//商品id
    
        private Integer inNum;//入库数量
    
        private Integer createBy;//创建入库单的用户id
    
        @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
        private Date createTime;//创建时间
    
        private Integer isIn;//是否入库,1.是,0.否
    
        //-----------------追加的属性--------------------
    
        private String productName;//商品名称
    
        private String startTime;//起始时间
    
        private String endTime;//结束时间
    
        private String storeName;//仓库名称
    
        private String userCode;//创建入库单的用户的名称
    
        private BigDecimal inPrice;//商品入库价格
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    2.5.2 Mapper

    //  根据id修改采购单状态为已入库 (采购表buy_list)
        public int setIsInById(Integer buyId);
    
    • 1
    • 2
    <update id="setIsInById">
        update buy_list
        set is_in =1
        where buy_id = #{buyId}
    update>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    //添加入库单的方法
    public int insertInStore(InStore inStore);
    
    • 1
    • 2

    2.5.3 Service

    @Service
    public class InStoreServiceImpl implements InStoreService {
    
        //注入InStoreMapper
        @Autowired
        private InStoreMapper inStoreMapper;
    
        //注入PurchaseMapper
        @Autowired
        private PurchaseMapper purchaseMapper;
    
    //    //添加入库单的业务方法
        @Transactional//事务处理
        @Override
        public Result saveInStore(InStore inStore, Integer buyId) {
            //添加入库单
            int i = inStoreMapper.insertInStore(inStore);
            if(i>0){
                //根据id将采购单状态改为已入库
                int j = purchaseMapper.setIsInById(buyId);
                if(j>0){
                    return Result.ok("入库单添加成功!");
                }
                return Result.err(Result.CODE_ERR_BUSINESS, "入库单添加失败!");
            }
            return Result.err(Result.CODE_ERR_BUSINESS, "入库单添加失败!");
        }
        
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    2.5.4 Controller

    //  生成入库单的url接口
    @RequestMapping("/in-warehouse-record-add")
    public Result addInStore(@RequestBody Purchase purchase, @RequestHeader("Token") String token) {
        //获取当前登录的用户
        CurrentUser currentUser = tokenUtils.getCurrentUser(token);
    
        //获取当前登录的用户id 创建入库单的用户id
        int createBy = currentUser.getUserId();
    
        //创建InStore对象封装添加的入库单的信息
        InStore inStore = new InStore();
        inStore.setStoreId(purchase.getStoreId());
        inStore.setProductId(purchase.getProductId());
        inStore.setInNum(purchase.getFactBuyNum());
        inStore.setCreateBy(createBy);
    
        return inStoreService.saveInStore(inStore,purchase.getBuyId());
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    2.5.5 效果图

    image-20230829224201287

    三、入库单管理

    image-20230924102744290

    3.1 分页查询入库单

    我们要完成的就是下面这个功能

    3.1.1 Mapper

    //  分页查询的方法
    //  查询入库单行数的方法
        public Integer findInStoreCount(@Param("inStore")InStore inStore);
    
    //  分页查询入库单的方法
        public List<InStore> findInStorePage(@Param("page") Page page,@Param("inStore") InStore inStore);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    具体实现

    
    <select id="findInStoreCount" resultType="java.lang.Integer">
        select count(*)
        from in_store t1,
        product t2
        where t1.product_id = t2.product_id
        <if test="inStore.storeId !=null">
            and t1.store_id = #{inStore.storeId}
        if>
        <if test="inStore.productName !=null and inStore.productName !='' ">
            and t2.product_name like concat('%',#{inStore.productName},'%')
        if>
        <if test="inStore.startTime !=null and inStore.startTime!='' ">
            and t1.create_time > = #{inStore.startTime}
        if>
        <if test="inStore.endTime !=null and inStore.endTime!='' ">
            and t1.create_time < = #{inStore.endTime}
        if>
    select>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    
    <select id="findInStorePage" resultType="com.pn.entity.InStore">
        select t1.*,t2.product_name,t2.in_price,t3.store_name,t4.user_code
        from in_store t1,
        product t2,
        store t3,
        user_info t4
        where t1.product_id = t2.product_id
        and t1.store_id = t3.store_id
        and t1.create_by = t4.user_id
        <if test="inStore.storeId !=null">
            and t1.store_id = #{inStore.storeId}
        if>
        <if test="inStore.productName !=null and inStore.productName !='' ">
            and t2.product_name like concat('%',#{inStore.productName},'%')
        if>
        <if test="inStore.startTime !=null and inStore.startTime!='' ">
            and t1.create_time > = #{inStore.startTime}
        if>
        <if test="inStore.endTime !=null and inStore.endTime!='' ">
            and t1.create_time < = #{inStore.endTime}
        if>
        order by t1.create_time desc
        limit #{page.limitIndex},#{page.pageSize}
    select>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    3.1.2 Service

        @Override
        public Page queryInStore(Page page, InStore inStore) {
    //      查询入库单行数
            Integer count = inStoreMapper.findInStoreCount(inStore);
    
    //      分页查询入库单
            List<InStore> inStorePageList = inStoreMapper.findInStorePage(page, inStore);
            
            page.setResultList(inStorePageList);
            page.setTotalNum(count);
            
            return page;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3.1.3 Controller

    @RequestMapping("/instore-page-list")
    public Result inStoreListPage(Page page, InStore inStore) {
    
        return Result.ok(inStoreService.queryInStore(page, inStore));
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    3.1.4 效果图

    image-20230924113641134

    3.2 确认入库单

    image-20230924200345175

    image-20230924201341330

    入库流程

    • 将入库单状态改为已入库
    • 增加商品的库存

    3.1.1 Mapper

    将入库单的状态修改为已入库

    //  根据id修改入库单状态为已入库的方法
        public int  setIsInById(@Param("isStoreId") Integer isStoreId);
    
    • 1
    • 2
    <update id="setIsInById">
       update in_store set is_in = 1 where  ins_id = #{isStoreId}
    update>
    
    • 1
    • 2
    • 3

    修改product表中的库存数量

    //  根据id修改商品库存的方法
        public int setInventById(@Param("productId")Integer productId,@Param("invent")Integer invent);
    
    • 1
    • 2
    
    <update id="setInventById">
      update product set product_invent = product_invent+#{invent} where product_id = #{productId}
    update>
    
    • 1
    • 2
    • 3
    • 4

    3.1.2 Service

        @Override
        @Transactional
        public Result inStoreConfirm(InStore inStore) {
    //      修改入库单状态
            int success = inStoreMapper.setIsInById(inStore.getInsId());
            if (success>0){
    //          修改商品库存
    //          商品入库数量增加
                int successCount = productMapper.setInventById(inStore.getProductId(), inStore.getInNum());
                if (successCount>0){
                    return Result.ok("入库单确认成功!");
                }
            }
    
            return Result.err(Result.CODE_ERR_BUSINESS,"入库单确认失败!");
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    3.1.3 Controller

    //  确认入库的url
    @RequestMapping("/instore-confirm")
    public Result confirmInStore(@RequestBody InStore inStore) {
        return inStoreService.inStoreConfirm(inStore);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    四、出库单管理

    image-20230924212444875

    4.1 确认出库单

    • 将出库单状态修改为1,表示已出库
    • 修改商品的库存 – 减库存

    4.1.1 Mapper

    修改出库单状态

    //   根据id修改出库单状态为已出库的方法
        public int setIsOutById(@Param("outStoreId") Integer outStoreId);
    
    • 1
    • 2
    <update id="setIsOutById">
        update out_store
        set is_out =1
        where outs_id = #{outStoreId}
    update>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    根据商品id查询商品库存的方法

    //  根据商品id查询商品库存的方法
        public int findInventById(@Param("productId")Integer productId);
    
    • 1
    • 2
    <select id="findInventById" resultType="java.lang.Integer">
       select product_invent from product where product_id  =#{productId}
    </select>
    
    • 1
    • 2
    • 3

    修改商品库存数量

    依然是3.2.1中的Mapper

    4.1.2 Service

        @Override
        @Transactional
        public Result outStoreConfirm(OutStore outStore) {
    //      判断商品库存是否充足
            int productInvent = productMapper.findInventById(outStore.getProductId());
            if (productInvent < outStore.getOutNum()) {
               return  Result.err(Result.CODE_ERR_BUSINESS,"商品库存不足!");
            }
    //      修改出库单状态
            outStoreMapper.setIsOutById(outStore.getStoreId());
    //      修改商品库存
            productMapper.setInventById(outStore.getProductId(),-outStore.getOutNum());
            
            return Result.ok("确认出库成功");
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    4.1.3 Controller

    //  确认出库单url接口
    @RequestMapping("/outstore-confirm")
    public Result confirmOutStore(@RequestBody OutStore outStore) {
        return outStoreService.outStoreConfirm(outStore);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    C的char溢出
    JVM-Java字节码技术笔记
    [GitLab CI/CD]记录基于Docker的环境搭建实践
    计算机毕业设计Java广西科技大学第一附属医院陪护椅管理(源码+系统+mysql数据库+Lw文档)
    海外接单被没收百万收入并处以罚款,承德的这位程序员到底做了什么?
    「软考」复习方法+备考资料赠送
    4.5 Windows驱动开发:实现进程数据转储
    python绘制三维图
    docker.1-应用(Application)部署容器化演进之路
    跑在笔记本里的大语言模型 - GPT4All
  • 原文地址:https://blog.csdn.net/weixin_51351637/article/details/133255046