mpk
潘志宝
2024-09-20 b425df38b434f1eaf4762690905cd7affcf4c7b6
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
93
94
95
96
97
package com.iailab.module.model.mcs.sche.service.impl;
 
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.model.mcs.sche.dao.StScheduleModelDao;
import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity;
import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService;
import com.iailab.module.model.mcs.sche.service.StScheduleModelService;
import com.iailab.module.model.mcs.sche.service.StScheduleModelSettingService;
import com.iailab.module.model.mcs.sche.vo.StScheduleModelPageReqVO;
import com.iailab.module.model.mcs.sche.vo.StScheduleModelSaveReqVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
 
/**
 * @author PanZhibao
 * @date 2021年07月20日 14:23
 */
@Service
public class StScheduleModelServiceImpl implements StScheduleModelService {
 
    @Resource
    private StScheduleModelDao stScheduleModelDao;
 
    @Autowired
    private StScheduleModelParamService stScheduleModelParamService;
 
    @Autowired
    private StScheduleModelSettingService stScheduleModelSettingService;
 
    @Override
    public PageResult<StScheduleModelEntity> page(StScheduleModelPageReqVO reqVO) {
        return stScheduleModelDao.selectPage(reqVO);
    }
 
    @Override
    public List<StScheduleModelEntity> list() {
 
        return stScheduleModelDao.selectList(null);
    }
 
    @Override
    @DSTransactional(rollbackFor = Exception.class)
    public void create(StScheduleModelSaveReqVO reqVO) {
        StScheduleModelEntity entity = BeanUtils.toBean(reqVO, StScheduleModelEntity.class);
        entity.setId(UUID.randomUUID().toString());
        stScheduleModelDao.insert(entity);
        stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList());
        stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList());
    }
 
    @Override
    @DSTransactional(rollbackFor = Exception.class)
    public void update(StScheduleModelSaveReqVO reqVO) {
        StScheduleModelEntity entity = BeanUtils.toBean(reqVO, StScheduleModelEntity.class);
        stScheduleModelDao.updateById(entity);
        stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList());
        stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList());
    }
 
    @Override
    public StScheduleModelEntity get(String id) {
        return stScheduleModelDao.selectById(id);
    }
 
    @Override
    @DSTransactional(rollbackFor = Exception.class)
    public void delete(String id) {
        stScheduleModelDao.deleteById(id);
        stScheduleModelParamService.deleteByModelId(id);
        stScheduleModelSettingService.deleteByModelId(id);
    }
 
    @Override
    public Long check(StScheduleModelSaveReqVO reqVO) {
        String id = reqVO.getId();
        String modelname = reqVO.getModelName();
        QueryWrapper<StScheduleModelEntity> scheduleModelWrapper = new QueryWrapper<>();
        scheduleModelWrapper.ne(StringUtils.isNotBlank(id), "id", id);
        scheduleModelWrapper.and(wrapper -> wrapper.eq("model_name", modelname));
        return stScheduleModelDao.selectCount(scheduleModelWrapper);
    }
 
    @Override
    public Long count() {
        QueryWrapper<StScheduleModelEntity> wrapper = new QueryWrapper<>();
        return stScheduleModelDao.selectCount(wrapper);
    }
}