ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package jnpf.visualdata.service.impl;
 
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.SystemApi;
import jnpf.base.entity.SystemEntity;
import jnpf.base.service.SuperServiceImpl;
import jnpf.constant.MsgCode;
import jnpf.exception.DataException;
import jnpf.util.RandomUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import jnpf.util.context.RequestContext;
import jnpf.visualdata.entity.VisualConfigEntity;
import jnpf.visualdata.entity.VisualEntity;
import jnpf.visualdata.mapper.VisualMapper;
import jnpf.visualdata.model.visual.VisualPaginationModel;
import jnpf.visualdata.service.VisualConfigService;
import jnpf.visualdata.service.VisualService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
 
/**
 * 大屏基本信息
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2021年6月15日
 */
@Service
public class VisualServiceImpl extends SuperServiceImpl<VisualMapper, VisualEntity> implements VisualService {
 
 
    @Autowired
    private VisualConfigService configService;
    @Autowired
    private SystemApi systemApi;
 
 
    private void getSystemId(VisualEntity entity) {
        SystemEntity infoByEnCode = systemApi.getInfoByEnCode(RequestContext.getAppCode());
        entity.setSystemId(infoByEnCode.getId());
    }
    @Override
    public String getSystemIdByReq() {
        SystemEntity infoByEnCode = systemApi.getInfoByEnCode(RequestContext.getAppCode());
        return null==infoByEnCode.getId()?"":infoByEnCode.getId();
    }
 
    @Override
    public List<VisualEntity> getList(VisualPaginationModel pagination) {
        QueryWrapper<VisualEntity> queryWrapper = new QueryWrapper<>();
        SystemEntity infoByEnCode = systemApi.getInfoByEnCode(RequestContext.getAppCode());
        if(ObjectUtil.isNotEmpty(pagination.getTitle())){
            queryWrapper.lambda().like(VisualEntity::getTitle, pagination.getTitle());
        }
        queryWrapper.lambda().eq(VisualEntity::getCategory, pagination.getCategory());
        queryWrapper.lambda().eq(VisualEntity::getSystemId, infoByEnCode.getId());
        queryWrapper.lambda().orderByDesc(VisualEntity::getCreateTime);
        Page page = new Page(pagination.getCurrent(), pagination.getSize());
        IPage<VisualEntity> iPages = this.page(page, queryWrapper);
        return pagination.setData(iPages);
    }
 
    @Override
    public List<VisualEntity> getList() {
        QueryWrapper<VisualEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().orderByDesc(VisualEntity::getCreateTime);
        return this.list(queryWrapper);
    }
 
    @Override
    public VisualEntity getInfo(String id) {
        QueryWrapper<VisualEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(VisualEntity::getId, id);
        return this.getOne(queryWrapper);
    }
 
    @Override
    public void create(VisualEntity entity, VisualConfigEntity configEntity) {
        getSystemId(entity);
        entity.setId(RandomUtil.uuId());
        entity.setCreateTime(new Date());
        entity.setUpdateUser(UserProvider.getLoginUserId());
        entity.setStatus(1);
        entity.setIsDeleted(0);
        this.creUpdateCheck(entity,true);
        this.save(entity);
        configEntity.setVisualId(entity.getId());
        configService.create(configEntity);
    }
 
    @Override
    public boolean update(String id, VisualEntity entity, VisualConfigEntity configEntity) {
        getSystemId(entity);
        entity.setId(id);
        entity.setUpdateTime(new Date());
        entity.setUpdateUser(UserProvider.getLoginUserId());
        this.creUpdateCheck(entity,true);
        boolean flag = this.updateById(entity);
        if (configEntity != null) {
            configService.update(configEntity.getId(), configEntity);
        }
        return flag;
    }
 
    @Override
    public void delete(VisualEntity entity) {
        if (entity != null) {
            this.removeById(entity.getId());
            VisualConfigEntity config = configService.getInfo(entity.getId());
            configService.delete(config);
        }
    }
 
    @Override
    public void createImport(VisualEntity entity, VisualConfigEntity configEntity) throws DataException {
        try {
            getSystemId(entity);
            this.creUpdateCheck(entity,true);
            entity.setId(RandomUtil.uuId());
            this.save(entity);
            configService.create(configEntity);
        }catch (Exception e){
            throw new DataException(MsgCode.IMP003.get());
        }
 
    }
 
    public  void creUpdateCheck(VisualEntity entity, Boolean fullNameCheck) {
        String title = entity.getTitle();
        String systemId = entity.getSystemId();
 
        // 名称长度验证(假设长度限制为80)
        if (StringUtil.isNotEmpty(title)&&title.length() > 80) {
            throw new DataException(MsgCode.EXIST005.get());
        }
 
        // 动态构建查询条件
        LambdaQueryWrapper<VisualEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (fullNameCheck) {
            queryWrapper.eq(VisualEntity::getTitle, title)
                    .eq(VisualEntity::getSystemId, systemId);
            List<VisualEntity> list = this.list(queryWrapper);
            if (!list.isEmpty()) {
                if (StringUtil.isNotEmpty(entity.getId())&&list.get(0).getId().equals(entity.getId())) {
                    return;
                }
                throw new DataException(MsgCode.EXIST003.get());
            }
        }
    }
}