inleft
2024-05-18 2ddbd99aa5b2e396f96c6daba60fe1ac2573d9fb
commit | author | age
9bcb19 1 /*
I 2 Copyright [2020] [https://www.xiaonuo.vip]
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
17
18 1.请不要删除和修改根目录下的LICENSE文件。
19 2.请不要删除和修改Snowy源码头部的版权声明。
20 3.请保留源码和相关描述文件的项目出处,作者声明等。
21 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
22 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
23 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
24  */
25 package vip.xiaonuo.generate.modular.service.impl;
26
27 import cn.hutool.core.bean.BeanUtil;
28 import cn.hutool.core.util.ObjectUtil;
29 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
30 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
31 import org.springframework.stereotype.Service;
32 import org.springframework.transaction.annotation.Transactional;
33 import vip.xiaonuo.core.enums.YesOrNotEnum;
34 import vip.xiaonuo.core.exception.ServiceException;
35 import vip.xiaonuo.generate.core.consts.GenConstant;
36 import vip.xiaonuo.generate.core.enums.QueryTypeEnum;
37 import vip.xiaonuo.generate.core.enums.TableFilteredFieldsEnum;
38 import vip.xiaonuo.generate.core.tool.JavaEffTool;
39 import vip.xiaonuo.generate.core.tool.JavaSqlTool;
40 import vip.xiaonuo.generate.core.tool.NamingConTool;
41 import vip.xiaonuo.generate.modular.entity.CodeGenerate;
42 import vip.xiaonuo.generate.modular.entity.SysCodeGenerateConfig;
43 import vip.xiaonuo.generate.modular.enums.SysCodeGenerateConfigExceptionEnum;
44 import vip.xiaonuo.generate.modular.mapper.SysCodeGenerateConfigMapper;
45 import vip.xiaonuo.generate.modular.param.SysCodeGenerateConfigParam;
46 import vip.xiaonuo.generate.modular.result.InforMationColumnsResult;
47 import vip.xiaonuo.generate.modular.service.SysCodeGenerateConfigService;
48
49 import java.util.List;
50
51 /**
52  * 代码生成详细配置service接口实现类
53  *
54  * @author yubaoshan
55  * @date 2021-02-06 20:19:49
56  */
57 @Service
58 public class SysCodeGenerateConfigServiceImpl extends ServiceImpl<SysCodeGenerateConfigMapper, SysCodeGenerateConfig> implements SysCodeGenerateConfigService {
59
60     @Override
61     public List<SysCodeGenerateConfig> list(SysCodeGenerateConfigParam sysCodeGenerateConfigParam) {
62         LambdaQueryWrapper<SysCodeGenerateConfig> queryWrapper = new LambdaQueryWrapper<>();
63         if (ObjectUtil.isNotNull(sysCodeGenerateConfigParam)) {
64
65             // 根据代码生成主表ID 模糊查询
66             if (ObjectUtil.isNotEmpty(sysCodeGenerateConfigParam.getCodeGenId())) {
67                 queryWrapper.eq(SysCodeGenerateConfig::getCodeGenId, sysCodeGenerateConfigParam.getCodeGenId());
68             }
69         }
70         return this.list(queryWrapper);
71     }
72
73     @Override
74     public void add(SysCodeGenerateConfigParam sysCodeGenerateConfigParam) {
75         SysCodeGenerateConfig sysCodeGenerateConfig = new SysCodeGenerateConfig();
76         BeanUtil.copyProperties(sysCodeGenerateConfigParam, sysCodeGenerateConfig);
77         this.save(sysCodeGenerateConfig);
78     }
79
80     @Override
81     public void addList(List<InforMationColumnsResult> inforMationColumnsResultList, CodeGenerate codeGenerate) {
82         for (InforMationColumnsResult inforMationColumnsResult : inforMationColumnsResultList) {
83             SysCodeGenerateConfig sysCodeGenerateConfig = new SysCodeGenerateConfig();
84
85             String YesOrNo = YesOrNotEnum.Y.getCode();
86             if (ObjectUtil.isNotNull(inforMationColumnsResult.getColumnKey())
87                     && inforMationColumnsResult.getColumnKey().equals(GenConstant.DB_TABLE_COM_KRY) ||
88                     TableFilteredFieldsEnum.contains(inforMationColumnsResult.getColumnName())) {
89                 YesOrNo = YesOrNotEnum.N.getCode();
90             }
91             if (TableFilteredFieldsEnum.contains(inforMationColumnsResult.getColumnName())) {
92                 sysCodeGenerateConfig.setWhetherCommon(YesOrNotEnum.Y.getCode());
93             } else {
94                 sysCodeGenerateConfig.setWhetherCommon(YesOrNotEnum.N.getCode());
95             }
96
97             sysCodeGenerateConfig.setCodeGenId(codeGenerate.getId());
98             sysCodeGenerateConfig.setColumnName(inforMationColumnsResult.getColumnName());
99             sysCodeGenerateConfig.setColumnComment(inforMationColumnsResult.getColumnComment());
100             sysCodeGenerateConfig.setJavaName(NamingConTool.UnderlineToHump(inforMationColumnsResult.getColumnName(), codeGenerate.getTablePrefix()));
101             sysCodeGenerateConfig.setJavaType(JavaSqlTool.sqlToJava(inforMationColumnsResult.getDataType()));
102             sysCodeGenerateConfig.setWhetherRetract(YesOrNotEnum.N.getCode());
103
104             sysCodeGenerateConfig.setWhetherRequired(YesOrNo);
105             sysCodeGenerateConfig.setQueryWhether(YesOrNo);
106             sysCodeGenerateConfig.setWhetherAddUpdate(YesOrNo);
107             sysCodeGenerateConfig.setWhetherTable(YesOrNo);
108
109             sysCodeGenerateConfig.setColumnKey(inforMationColumnsResult.getColumnKey());
110
111             // 设置get set方法使用的名称
112             String columnName = NamingConTool.UnderlineToHump(sysCodeGenerateConfig.getColumnName(),"");
113             sysCodeGenerateConfig.setColumnKeyName(columnName.substring(0,1).toUpperCase() + columnName.substring(1,columnName.length()));
114
115             sysCodeGenerateConfig.setDataType(inforMationColumnsResult.getDataType());
116             sysCodeGenerateConfig.setEffectType(JavaEffTool.javaToEff(sysCodeGenerateConfig.getJavaType()));
117             sysCodeGenerateConfig.setQueryType(QueryTypeEnum.eq.getCode());
118
119             this.save(sysCodeGenerateConfig);
120         }
121     }
122
123     @Transactional(rollbackFor = Exception.class)
124     @Override
125     public void delete(SysCodeGenerateConfigParam sysCodeGenerateConfigParam) {
126         LambdaQueryWrapper<SysCodeGenerateConfig> queryWrapper = new LambdaQueryWrapper<>();
127         queryWrapper.eq(SysCodeGenerateConfig::getCodeGenId, sysCodeGenerateConfigParam.getCodeGenId());
128         this.remove(queryWrapper);
129     }
130
131     @Transactional(rollbackFor = Exception.class)
132     @Override
133     public void edit(List<SysCodeGenerateConfigParam> sysCodeGenerateConfigParamList) {
134         for (SysCodeGenerateConfigParam sysCodeGenerateConfigParam : sysCodeGenerateConfigParamList) {
135             SysCodeGenerateConfig sysCodeGenerateConfig = this.querySysCodeGenerateConfig(sysCodeGenerateConfigParam);
136             BeanUtil.copyProperties(sysCodeGenerateConfigParam, sysCodeGenerateConfig);
137             this.updateById(sysCodeGenerateConfig);
138         }
139     }
140
141     @Override
142     public SysCodeGenerateConfig detail(SysCodeGenerateConfigParam sysCodeGenerateConfigParam) {
143         return this.querySysCodeGenerateConfig(sysCodeGenerateConfigParam);
144     }
145
146     /**
147      * 获取代码生成详细配置
148      *
149      * @author yubaoshan
150      * @date 2021-02-06 20:19:49
151      */
152     private SysCodeGenerateConfig querySysCodeGenerateConfig(SysCodeGenerateConfigParam sysCodeGenerateConfigParam) {
153         SysCodeGenerateConfig sysCodeGenerateConfig = this.getById(sysCodeGenerateConfigParam.getId());
154         if (ObjectUtil.isNull(sysCodeGenerateConfig)) {
155             throw new ServiceException(SysCodeGenerateConfigExceptionEnum.NOT_EXIST);
156         }
157         return sysCodeGenerateConfig;
158     }
159 }