From 0fb38e938ff2f943a6b8cc5c3247a23fc1276d24 Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期一, 11 十月 2021 16:47:18 +0800
Subject: [PATCH] 爱心义仓代码提交

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActWarehouseApplyServiceImpl.java |   69 +++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActWarehouseApplyServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActWarehouseApplyServiceImpl.java
index 02cfb1e..508d282 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActWarehouseApplyServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActWarehouseApplyServiceImpl.java
@@ -1,13 +1,27 @@
 package com.panzhihua.service_community.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.panzhihua.common.model.dtos.property.CommonPage;
 import com.panzhihua.common.model.vos.R;
-import com.panzhihua.service_community.entity.ComActWarehouseApply;
+import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseApplyVO;
+import com.panzhihua.service_community.dao.ComActWarehouseDonatesDao;
+import com.panzhihua.service_community.dao.ComActWarehouseOperationDao;
+import com.panzhihua.service_community.dao.ComPbServiceTeamDao;
 import com.panzhihua.service_community.dao.ComActWarehouseApplyDao;
+import com.panzhihua.service_community.entity.ComActWarehouseApply;
+import com.panzhihua.service_community.entity.ComActWarehouseDonates;
+import com.panzhihua.service_community.entity.ComActWarehouseOperation;
+import com.panzhihua.service_community.entity.ComPbServiceTeam;
 import com.panzhihua.service_community.service.ComActWarehouseApplyService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.Date;
 
 /**
  * 物品申请表(ComActWarehouseApply)表服务实现类
@@ -18,9 +32,58 @@
 @Slf4j
 @Service
 public class ComActWarehouseApplyServiceImpl extends ServiceImpl<ComActWarehouseApplyDao, ComActWarehouseApply> implements ComActWarehouseApplyService {
-
+    @Resource
+    private ComActWarehouseApplyDao comActWarehouseApplyDao;
+    @Resource
+    private ComPbServiceTeamDao comPbServiceTeamDao;
+    @Resource
+    private ComActWarehouseDonatesDao comActWarehouseDonatesDao;
+    @Resource
+    private ComActWarehouseOperationDao comActWarehouseOperationDao;
     @Override
     public R pageList(CommonPage commonPage) {
-        return null;
+        IPage<ComActWarehouseApplyVO> iPage=this.comActWarehouseApplyDao.queryAll(new Page<>(commonPage.getPage(),commonPage.getSize()),commonPage);
+        return R.ok(iPage);
+    }
+
+    @Override
+    public R selectStatics(Long communityId) {
+        return R.ok(this.comActWarehouseApplyDao.selectStatics(communityId));
+    }
+
+    @Override
+    public R selectById(Integer id) {
+        return R.ok(this.comActWarehouseApplyDao.selectById(id));
+    }
+
+    @Override
+    public R check(String phone) {
+        Integer count=comPbServiceTeamDao.selectCount(new QueryWrapper<ComPbServiceTeam>().lambda().eq(ComPbServiceTeam::getPhone,phone));
+        return count>0? R.ok():R.fail("无权限");
+    }
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public R update(ComActWarehouseApply comActWarehouseApply) {
+        if(comActWarehouseApply.getStatus().equals(ComActWarehouseApplyVO.status.ylq)){
+            ComActWarehouseDonates comActWarehouseDonates=this.comActWarehouseDonatesDao.selectById(comActWarehouseApply.getGoodsId());
+            if(comActWarehouseDonates!=null&&comActWarehouseDonates.getSurplusQuantity()>0){
+                comActWarehouseDonates.setSurplusQuantity(comActWarehouseDonates.getSurplusQuantity()-1);
+                this.comActWarehouseDonatesDao.updateById(comActWarehouseDonates);
+                ComActWarehouseOperation comActWarehouseOperation=new ComActWarehouseOperation();
+                comActWarehouseOperation.setGoodsId(comActWarehouseApply.getGoodsId());
+                comActWarehouseOperation.setCreateTime(new Date());
+                comActWarehouseOperation.setContent("爱心传递给了"+comActWarehouseApply.getApplyName().charAt(0)+"**,"+"减少了"+comActWarehouseApply.getReason()+"的困难,谢谢你的帮助");
+                this.comActWarehouseOperationDao.insert(comActWarehouseOperation);
+            }
+            else {
+                return R.fail("库存不足");
+            }
+        }
+        return R.ok(this.comActWarehouseApplyDao.updateById(comActWarehouseApply));
+    }
+
+    @Override
+    public R export(CommonPage commonPage) {
+        return R.ok(this.comActWarehouseApplyDao.queryAll(commonPage));
     }
 }

--
Gitblit v1.7.1