mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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.common.model.vos.community.warehouse.ComActWarehouseApplyVO;
import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseOperationVO;
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)表服务实现类
 *
 * @author makejava
 * @since 2021-10-09 17:13:53
 */
@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) {
        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) {
        ComActWarehouseApply comActWarehouseApply1=this.comActWarehouseApplyDao.selectById(comActWarehouseApply.getId());
        if(comActWarehouseApply.getStatus().equals(ComActWarehouseApplyVO.status.ylq)){
            ComActWarehouseDonates comActWarehouseDonates=this.comActWarehouseDonatesDao.selectById(comActWarehouseApply1.getGoodsId());
            if(comActWarehouseDonates!=null&&comActWarehouseDonates.getSurplusQuantity()>=comActWarehouseApply1.getGoodsNum()){
                comActWarehouseDonates.setSurplusQuantity(comActWarehouseDonates.getSurplusQuantity()-comActWarehouseApply1.getGoodsNum());
                this.comActWarehouseDonatesDao.updateById(comActWarehouseDonates);
                ComActWarehouseOperation comActWarehouseOperation=new ComActWarehouseOperation();
                comActWarehouseOperation.setGoodsId(comActWarehouseApply1.getGoodsId());
                comActWarehouseOperation.setCreateTime(new Date());
                comActWarehouseOperation.setType(ComActWarehouseOperation.type.xs);
                comActWarehouseOperation.setApplyId(comActWarehouseApply.getId());
                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));
    }
}