shiyunteng
8 天以前 cc59b65bc63b839127c29775bcd410dd407de66d
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
package com.by4cloud.platformx.device.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.by4cloud.platformx.common.security.util.SecurityUtils;
import com.by4cloud.platformx.device.constant.MaxSizeContant;
import com.by4cloud.platformx.device.dto.DevicePurchasePlanQueryDTO;
import com.by4cloud.platformx.device.entity.DevicePurchasePlan;
import com.by4cloud.platformx.device.entity.DevicePurchasePlanItem;
import com.by4cloud.platformx.device.mapper.DevicePurchasePlanItemMapper;
import com.by4cloud.platformx.device.mapper.DevicePurchasePlanMapper;
import com.by4cloud.platformx.device.service.DevicePurchasePlanService;
import com.by4cloud.platformx.device.service.JcMaxSizeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
 
/**
 * 设备采购计划
 *
 * @author syt
 * @date 2025-04-21 14:43:13
 */
@Service
@AllArgsConstructor
public class DevicePurchasePlanServiceImpl extends ServiceImpl<DevicePurchasePlanMapper, DevicePurchasePlan> implements DevicePurchasePlanService {
 
    private final JcMaxSizeService maxSizeService;
 
    private final DevicePurchasePlanItemMapper itemMapper;
 
    @Override
    public boolean saveNew(DevicePurchasePlan devicePurchasePlan) {
        devicePurchasePlan.setPlanCode(maxSizeService.nextNo(MaxSizeContant.DEVICE_PURCHASE_CODE));
        devicePurchasePlan.setReleaseCompId(SecurityUtils.getUser().getCompId());
        devicePurchasePlan.setReleaseId(SecurityUtils.getUser().getId());
        devicePurchasePlan.setReleaseTime(new Date());
        devicePurchasePlan.setStatus(0);
        baseMapper.insert(devicePurchasePlan);
        if (devicePurchasePlan.getPlanItemList() != null&&devicePurchasePlan.getPlanItemList().size()>0) {
            devicePurchasePlan.getPlanItemList().forEach(item->{
                item.setPlanId(devicePurchasePlan.getId());
                itemMapper.insert(item);
            });
        }
        return true;
    }
 
    @Override
    public IPage pageNew(Page page, DevicePurchasePlanQueryDTO queryDTO) {
        return baseMapper.page(page,queryDTO);
    }
 
    @Override
    public boolean approved(Long id) {
        DevicePurchasePlan plan = baseMapper.selectById(id);
        plan.setStatus(1);
        baseMapper.updateById(plan);
        return true;
    }
 
    @Override
    public DevicePurchasePlan getByIdNew(Long id) {
        DevicePurchasePlan plan = baseMapper.selectById(id);
        QueryWrapper<DevicePurchasePlanItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("plan_id",id);
        List<DevicePurchasePlanItem> planItemList = itemMapper.selectList(queryWrapper);
        plan.setPlanItemList(planItemList);
        return plan;
    }
 
    @Override
    public boolean updateByIdNew(DevicePurchasePlan devicePurchasePlan) {
        baseMapper.updateById(devicePurchasePlan);
        if (devicePurchasePlan.getPlanItemList() != null&&devicePurchasePlan.getPlanItemList().size()>0) {
            devicePurchasePlan.getPlanItemList().forEach(item->{
                item.setPlanId(devicePurchasePlan.getId());
                if (item.getId()==null) {
                    itemMapper.insert(item);
                }else {
                    itemMapper.updateById(item);
                }
            });
        }
        return true;
    }
}