“djh”
13 小时以前 c1628ae5526ffae9cb12e70778cac8195c405382
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
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.PurchaseApply;
import com.gkhy.exam.system.domain.PurchaseApplyPlan;
import com.gkhy.exam.system.mapper.PurchaseApplyMapper;
import com.gkhy.exam.system.mapper.PurchaseApplyPlanMapper;
import com.gkhy.exam.system.service.PurchaseApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.List;
 
@Service
public class PurchaseApplyServiceImpl extends ServiceImpl<PurchaseApplyMapper, PurchaseApply> implements PurchaseApplyService {
 
    @Autowired
    private PurchaseApplyMapper applyMapper;
 
    @Autowired
    private PurchaseApplyPlanMapper applyPlanMapper;
 
    @Override
    public CommonPage selectApplyList(PurchaseApply purchaseApply) {
        if (!SecurityUtils.adminUser()){
            if (purchaseApply.getCompanyId()==null){
                throw new ApiException("非管理员操作,企业id不可为空");
            }
        }
        PageUtils.startPage();
        List<PurchaseApply> purchaseApplies = applyMapper.selectApplyList(purchaseApply);
        for (PurchaseApply apply : purchaseApplies) {
            List<PurchaseApplyPlan> purchaseApplyPlans = applyPlanMapper.selectByApplyId(apply.getId());
            apply.setPurchaseApplyPlans(purchaseApplyPlans);
        }
        return CommonPage.restPage(purchaseApplies);
    }
 
    @Override
    public CommonResult insertApply(PurchaseApply purchaseApply) {
        purchaseApply.setCreateTime(LocalDateTime.now());
        purchaseApply.setCreateBy(SecurityUtils.getUsername());
        applyMapper.insert(purchaseApply);
        List<PurchaseApplyPlan> purchaseApplyPlans = purchaseApply.getPurchaseApplyPlans();
        for (PurchaseApplyPlan purchaseApplyPlan : purchaseApplyPlans) {
            purchaseApplyPlan.setApplyId(purchaseApply.getId());
        }
        applyPlanMapper.insertPlans(purchaseApplyPlans);
        return CommonResult.success();
    }
 
    @Override
    public CommonResult updateApply(PurchaseApply purchaseApply) {
        purchaseApply.setUpdateTime(LocalDateTime.now());
        purchaseApply.setUpdateBy(SecurityUtils.getUsername());
        applyMapper.updateById(purchaseApply);
        List<PurchaseApplyPlan> purchaseApplyPlans = purchaseApply.getPurchaseApplyPlans();
        applyPlanMapper.deletedByIds(purchaseApply.getId());
        applyPlanMapper.insertPlans(purchaseApplyPlans);
        return CommonResult.success();
    }
 
    @Override
    public CommonResult deletedApply(Integer applyId) {
        PurchaseApply purchaseApply = new PurchaseApply();
        purchaseApply.setId(applyId);
        purchaseApply.setUpdateBy(SecurityUtils.getUsername());
        purchaseApply.setUpdateTime(LocalDateTime.now());
        purchaseApply.setDelFlag(2);
        applyMapper.updateById(purchaseApply);
        return CommonResult.success();
    }
}