yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
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
package com.qianwen.smartman.modules.cps.controller;
 
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.scanner.modular.annotation.DeleteResource;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
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.node.ForestNodeMerger;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.smartman.modules.cps.convert.OrganizationConvert;
import com.qianwen.smartman.modules.cps.dto.OrganizationDTO;
import com.qianwen.smartman.modules.cps.excel.OrganizationExcel;
import com.qianwen.smartman.modules.cps.service.IOrganizationService;
import com.qianwen.smartman.modules.cps.vo.OrganizationSelectVO;
import com.qianwen.smartman.modules.cps.vo.OrganizationVO;
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 org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
@Api(value = "组织结构", tags = {"组织结构"})
@RestController
@ApiResource({"smis/organization"})
@NonDS
public class OrganizationController extends BladeController {
    private final IOrganizationService organizationService;
    private final OssBuilder ossBuilder;
    private final ISystemResourceService systemResourceService;
 
    public OrganizationController(final IOrganizationService organizationService, final OssBuilder ossBuilder, final ISystemResourceService systemResourceService) {
        this.organizationService = organizationService;
        this.ossBuilder = ossBuilder;
        this.systemResourceService = systemResourceService;
    }
 
    @ApiOperationSupport(order = 1)
    @GetResource({"/tree"})
    @ApiOperation("树形结构")
    public R<List<OrganizationVO>> tree(@Validated OrganizationSelectVO organizationSelectVO) {
        if (organizationSelectVO.getStatus() == null) {
            organizationSelectVO.setStatus(CommonConstant.ENABLE);
        }
        List<OrganizationDTO> list = this.organizationService.selectList(organizationSelectVO);
        return R.data(ForestNodeMerger.merge(OrganizationConvert.INSTANCE.convert(list)));
    }
 
    @ApiOperationSupport(order = 1)
    @GetResource({"/list"})
    @ApiOperation("列表")
    public R<List<OrganizationDTO>> list(@Validated OrganizationSelectVO organizationSelectVO) {
        if (organizationSelectVO.getStatus() == null) {
            organizationSelectVO.setStatus(CommonConstant.ENABLE);
        }
        List<OrganizationDTO> list = this.organizationService.selectList(organizationSelectVO);
        return R.data(list);
    }
 
    @ApiOperationSupport(order = 2)
    @ApiOperation("删除组织")
    @PreAuth
    @DeleteResource
    public R<Boolean> deleteOrganization(@RequestParam @ApiParam(value = "主键", required = true) String ids, @RequestParam("type") @ApiParam("删除传0 停用传1") Integer type) {
        return R.data(this.organizationService.deleteOrganization(ids, type));
    }
 
    @ApiOperationSupport(order = 3)
    @GetResource({"/export-template"})
    @ApiOperation("导出模板")
    @PreAuth
    public R<BladeFile> exportTemplate() {
        return R.data(this.systemResourceService.getBusinessTemplateInfo(TemplateEnum.ORGANIZATION));
    }
 
    @ApiOperationSupport(order = 4)
    @GetResource({"/export-organization"})
    @ApiOperation("导出组织")
    @PreAuth
    public R<BladeFile> exportOrganization(OrganizationSelectVO organizationSelectVO) {
        List<OrganizationExcel> list = this.organizationService.getExportOrganizationData(organizationSelectVO);
        String fileName = String.format("%s-%s.xlsx", "部门数据", DateUtil.time());
        MultipartFile multipartFile = ExcelUtil.exportToMultipartFile(fileName, "部门数据表", list, OrganizationExcel.class);
        BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
        return R.data(bladeFile);
    }
}