yangys
2024-04-01 86cdd920b68274185233383f69ddb974052b6b6f
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package com.qianwen.smartman.modules.system.controller;
 
import java.util.List;
 
import javax.validation.Valid;
 
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.cache.utils.CacheUtil;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.log.annotation.ApiLog;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.secure.BladeUser;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.tenant.annotation.NonDS;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.ExtCacheConstant;
import com.qianwen.smartman.common.validator.ValidatorGroup;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.resource.enums.TemplateEnum;
import com.qianwen.smartman.modules.resource.service.ISystemResourceService;
import com.qianwen.smartman.modules.system.convert.PostConvert;
import com.qianwen.smartman.modules.system.entity.Post;
import com.qianwen.smartman.modules.system.excel.PostExcel;
import com.qianwen.smartman.modules.system.excel.PostImport;
import com.qianwen.smartman.modules.system.service.IPostService;
import com.qianwen.smartman.modules.system.vo.PostDetailVO;
import com.qianwen.smartman.modules.system.vo.PostSelectVO;
import com.qianwen.smartman.modules.system.vo.PostVO;
import com.qianwen.smartman.modules.system.wrapper.PostWrapper;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
@Api(value = "岗位", tags = {"岗位"})
@RestController
@ApiResource({"blade-system/post"})
@NonDS
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/controller/PostController.class */
public class PostController extends BladeController {
    private final IPostService postService;
    private final OssBuilder ossBuilder;
    private final ISystemResourceService systemResourceService;
 
    public PostController(final IPostService postService, final OssBuilder ossBuilder, final ISystemResourceService systemResourceService) {
        this.postService = postService;
        this.ossBuilder = ossBuilder;
        this.systemResourceService = systemResourceService;
    }
 
    @ApiOperationSupport(order = 1)
    @ApiLog("岗位详情")
    @GetResource({"/detail"})
    @ApiOperation(value = "详情", notes = "传入post")
    public R<PostVO> detail(Post post) {
        Post detail = (Post) this.postService.getOne(Condition.getQueryWrapper(post));
        return R.data(PostWrapper.build().entityVO(detail));
    }
 
    @ApiOperationSupport(order = 2)
    @ApiLog("岗位分页列表")
    @GetResource({"/list"})
    @ApiOperation(value = "分页", notes = "传入post")
    public R<IPage<PostVO>> list(Post post, Query query) {
        IPage<Post> pages = this.postService.page(Condition.getPage(query), Condition.getQueryWrapper(post).lambda().orderByAsc(Post::getSort));
        /*
        IPage<Post> pages = this.postService.page(Condition.getPage(query), (Wrapper) Condition.getQueryWrapper(post).lambda().orderByAsc((v0) -> {
            return v0.getSort();
        }));*/
        return R.data(PostWrapper.build().pageVO(pages));
    }
 
    @ApiOperationSupport(order = 3)
    @ApiLog("岗位分页列表")
    @GetResource({"/page"})
    @ApiOperation(value = "分页", notes = "传入post")
    @PreAuth
    public R<IPage<PostDetailVO>> page(PostSelectVO postSelectVO, Query query) {
        if (postSelectVO.getStatus() == null) {
            postSelectVO.setStatus(CommonConstant.ENABLE);
        }
        IPage<PostDetailVO> pages = this.postService.selectPostPage(Condition.getPage(query), postSelectVO);
        return R.data(pages);
    }
 
    @ApiOperationSupport(order = 4)
    @PostResource({"/save"})
    @ApiLog("新增岗位")
    @ApiOperation(value = "新增", notes = "传入post")
    public R save(@RequestBody @Validated({ValidatorGroup.add.class}) Post post) {
        CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
        this.postService.checkExistPostNameOrCode(post);
        return R.status(this.postService.save(post));
    }
 
    @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
    @PostResource({"/update"})
    @ApiLog("修改岗位")
    @ApiOperation(value = "修改", notes = "传入post")
    @PreAuth
    public R update(@Valid @RequestBody Post post) {
        CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
        this.postService.checkExistPostNameOrCode(post);
        return R.status(this.postService.updateById(post));
    }
 
    @ApiOperationSupport(order = 6)
    @PostResource({"/submit"})
    @ApiLog("新增或修改岗位")
    @ApiOperation(value = "新增或修改", notes = "传入post")
    @PreAuth
    public R<Post> submit(@Valid @RequestBody Post post) {
        CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
        this.postService.checkExistPostNameOrCode(post);
        this.postService.insertNewPost(post);
        return R.data(post);
    }
 
    @ApiOperationSupport(order = 7)
    @PostResource({"/remove"})
    @ApiLog("删除岗位")
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    @PreAuth
    public R remove(@RequestParam @ApiParam(value = "主键集合", required = true) String ids, @RequestParam("type") @ApiParam("删除传0 停用传1") Integer type) {
        return R.status(this.postService.removePost(Func.toLongList(ids), type).booleanValue());
    }
 
    @ApiOperationSupport(order = 8)
    @GetResource({"/select"})
    @ApiOperation(value = "下拉数据源", notes = "传入post")
    public R<List<Post>> select(String tenantId, BladeUser bladeUser) {
        List<Post> list = this.postService.list(Wrappers.<Post>query().lambda().eq(Post::getTenantId, Func.toStrWithEmpty(tenantId, bladeUser.getTenantId())));
        /*
        List<Post> list = this.postService.list((Wrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, Func.toStrWithEmpty(tenantId, bladeUser.getTenantId())));*/
        return R.data(list);
    }
 
    @ApiOperationSupport(order = 9)
    @GetResource({"/export-template"})
    @ApiOperation("导出模板")
    @PreAuth
    public R<BladeFile> exportTemplate() {
        return R.data(this.systemResourceService.getBusinessTemplateInfo(TemplateEnum.POST));
    }
 
    @ApiOperationSupport(order = 10)
    @PostResource({"/import-post"})
    @ApiOperation("导入岗位")
    @PreAuth
    public R<BladeFile> importPost(MultipartFile file) {
        List<PostImport> data = ExcelUtil.read(file, 0, 2, PostImport.class);
        return R.data(this.postService.importPost(data));
    }
 
    @ApiOperationSupport(order = 11)
    @GetResource({"/export-post"})
    @ApiOperation("导出岗位")
    @PreAuth
    public R<BladeFile> exportPost(PostSelectVO postSelectVO) {
        IPage<PostDetailVO> pages = this.postService.selectPostPage(Condition.getPage(new Query().setCurrent(1).setSize(-1)), postSelectVO);
        List<PostDetailVO> records = pages.getRecords();
        String fileName = String.format("%s-%s.xlsx", "岗位数据", DateUtil.time());
        MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, "岗位数据表", PostConvert.INSTANCE.convert(records), PostExcel.class);
        BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
        return R.data(bladeFile);
    }
}