inleft
2022-02-09 9bcb19959eeb9da9bde2561e7278f6d0a55eb151
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 ${packageName}.${modularName}.${busName}.service.impl;
26
27 import cn.hutool.core.bean.BeanUtil;
28 import cn.hutool.core.util.ObjectUtil;
29 import cn.hutool.core.util.StrUtil;
30 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
31 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
32 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
33 import vip.xiaonuo.core.consts.CommonConstant;
34 import vip.xiaonuo.core.enums.CommonStatusEnum;
35 import vip.xiaonuo.core.exception.ServiceException;
36 import vip.xiaonuo.core.factory.PageFactory;
37 import vip.xiaonuo.core.pojo.page.PageResult;
38 import vip.xiaonuo.core.util.PoiUtil;
39 import ${packageName}.${modularName}.${busName}.entity.${ClassName};
40 import ${packageName}.${modularName}.${busName}.enums.${ClassName}ExceptionEnum;
41 import ${packageName}.${modularName}.${busName}.mapper.${ClassName}Mapper;
42 import ${packageName}.${modularName}.${busName}.param.${ClassName}Param;
43 import ${packageName}.${modularName}.${busName}.service.${ClassName}Service;
44 import org.springframework.stereotype.Service;
45 import org.springframework.transaction.annotation.Transactional;
46 import javax.annotation.Resource;
47 import java.util.List;
48
49 /**
50  * ${functionName}service接口实现类
51  *
52  * @author ${authorName}
53  * @date ${createDateString}
54  */
55 @Service
56 public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements ${ClassName}Service {
57
58     @Override
59     public PageResult<${ClassName}> page(${ClassName}Param ${className}Param) {
60         QueryWrapper<${ClassName}> queryWrapper = new QueryWrapper<>();
61         if (ObjectUtil.isNotNull(${className}Param)) {
62
63 #foreach ($column in $tableField)
64 #if (${column.queryWhether} == "Y")
65             // 根据${column.columnComment} 查询
66             if (ObjectUtil.isNotEmpty(${className}Param.get${column.columnKeyName}())) {
67                 queryWrapper.lambda().${column.queryType}(${ClassName}::get${column.columnKeyName}, ${className}Param.get${column.columnKeyName}());
68             }
69 #end
70 #end
71         }
72         return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
73     }
74
75     @Override
76     public List<${ClassName}> list(${ClassName}Param ${className}Param) {
77         return this.list();
78     }
79
80     @Override
81     public void add(${ClassName}Param ${className}Param) {
82         ${ClassName} ${className} = new ${ClassName}();
83         BeanUtil.copyProperties(${className}Param, ${className});
84         this.save(${className});
85     }
86
87     @Transactional(rollbackFor = Exception.class)
88     @Override
89     public void delete(List<${ClassName}Param> ${className}ParamList) {
90         ${className}ParamList.forEach(${className}Param -> {
91 #foreach ($column in $tableField)
92 #if (${column.columnKey} == "PRI")
93             this.removeById(${className}Param.get${column.columnKeyName}());
94 #end
95 #end
96         });
97     }
98
99     @Transactional(rollbackFor = Exception.class)
100     @Override
101     public void edit(${ClassName}Param ${className}Param) {
102         ${ClassName} ${className} = this.query${ClassName}(${className}Param);
103         BeanUtil.copyProperties(${className}Param, ${className});
104         this.updateById(${className});
105     }
106
107     @Override
108     public ${ClassName} detail(${ClassName}Param ${className}Param) {
109         return this.query${ClassName}(${className}Param);
110     }
111
112     /**
113      * 获取${functionName}
114      *
115      * @author ${authorName}
116      * @date ${createDateString}
117      */
118     private ${ClassName} query${ClassName}(${ClassName}Param ${className}Param) {
119 #foreach ($column in $tableField)
120 #if (${column.columnKey} == "PRI")
121         ${ClassName} ${className} = this.getById(${className}Param.get${column.columnKeyName}());
122 #end
123 #end
124         if (ObjectUtil.isNull(${className})) {
125             throw new ServiceException(${ClassName}ExceptionEnum.NOT_EXIST);
126         }
127         return ${className};
128     }
129
130     @Override
131     public void export(${ClassName}Param ${className}Param) {
132         List<${ClassName}> list = this.list(${className}Param);
133         PoiUtil.exportExcelWithStream("Snowy${ClassName}.xls", ${ClassName}.class, list);
134     }
135
136 }