|
@@ -2,22 +2,38 @@ package com.keao.edu.user.controller;
|
|
|
|
|
|
|
|
|
import com.keao.edu.auth.api.client.SysUserFeignService;
|
|
|
+import com.keao.edu.auth.api.entity.SysRole;
|
|
|
import com.keao.edu.auth.api.entity.SysUser;
|
|
|
import com.keao.edu.common.controller.BaseController;
|
|
|
import com.keao.edu.common.entity.HttpResponseResult;
|
|
|
import com.keao.edu.common.page.PageInfo;
|
|
|
import com.keao.edu.common.tenant.TenantContextHolder;
|
|
|
+import com.keao.edu.user.dao.SysUserDao;
|
|
|
import com.keao.edu.user.entity.Organization;
|
|
|
+import com.keao.edu.user.enums.SettlementTypeEnum;
|
|
|
import com.keao.edu.user.page.OrganizationQueryInfo;
|
|
|
import com.keao.edu.user.service.OrganizationService;
|
|
|
+import com.keao.edu.util.collection.MapUtil;
|
|
|
+import com.keao.edu.util.date.DateUtil;
|
|
|
+import com.keao.edu.util.excel.POIUtil;
|
|
|
+import com.keao.edu.util.iniFile.IniFileEntity;
|
|
|
+import com.keao.edu.util.iniFile.IniFileUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.beans.IntrospectionException;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
/**
|
|
|
* 合作单位服务
|
|
|
*/
|
|
@@ -26,69 +42,176 @@ import java.util.List;
|
|
|
@RequestMapping(value = "organization")
|
|
|
public class OrganizationController extends BaseController {
|
|
|
|
|
|
- @Autowired
|
|
|
- private OrganizationService organizationService;
|
|
|
- @Autowired
|
|
|
- private SysUserFeignService sysUserFeignService;
|
|
|
+ @Autowired
|
|
|
+ private OrganizationService organizationService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserDao sysUserDao;
|
|
|
|
|
|
- @ApiOperation(value = "合作单位列表")
|
|
|
- @GetMapping(value = "list")
|
|
|
+ @ApiOperation(value = "合作单位列表")
|
|
|
+ @GetMapping(value = "list")
|
|
|
@PreAuthorize("@pcs.hasPermissions('organization/list')")
|
|
|
- public HttpResponseResult<PageInfo<Organization>> configList(OrganizationQueryInfo queryInfo) {
|
|
|
- SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- queryInfo.setParentId(sysUser.getId());
|
|
|
- if(queryInfo.getOrganId() != null){
|
|
|
- queryInfo.setOrganIds(organizationService.getChildOrganIds(queryInfo.getOrganId(),false));
|
|
|
- }
|
|
|
- return succeed(organizationService.queryPage(queryInfo));
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "修改合作单位")
|
|
|
- @PostMapping(value = "update")
|
|
|
+ public HttpResponseResult<PageInfo<Organization>> configList(OrganizationQueryInfo queryInfo) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ queryInfo.setParentId(sysUser.getId());
|
|
|
+ if (queryInfo.getOrganId() != null) {
|
|
|
+ queryInfo.setOrganIds(organizationService.getChildOrganIds(queryInfo.getOrganId(), false));
|
|
|
+ }
|
|
|
+ return succeed(organizationService.queryPage(queryInfo));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改合作单位")
|
|
|
+ @PostMapping(value = "update")
|
|
|
@PreAuthorize("@pcs.hasPermissions('organization/update')")
|
|
|
- public HttpResponseResult updateOrganization(@RequestBody Organization organization) {
|
|
|
- organizationService.updateOrganization(organization);
|
|
|
- return succeed();
|
|
|
- }
|
|
|
+ public HttpResponseResult updateOrganization(@RequestBody Organization organization) {
|
|
|
+ organizationService.updateOrganization(organization);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
|
|
|
- @ApiOperation(value = "新增合作单位")
|
|
|
- @PostMapping(value = "add")
|
|
|
+ @ApiOperation(value = "新增合作单位")
|
|
|
+ @PostMapping(value = "add")
|
|
|
@PreAuthorize("@pcs.hasPermissions('organization/add')")
|
|
|
- public HttpResponseResult addConfig(@RequestBody Organization organization) {
|
|
|
- organization.setTenantId(TenantContextHolder.getTenantId());
|
|
|
- organizationService.add(organization);
|
|
|
- return succeed();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询合作单位")
|
|
|
- @GetMapping(value = "get")
|
|
|
+ public HttpResponseResult addConfig(@RequestBody Organization organization) {
|
|
|
+ organization.setTenantId(TenantContextHolder.getTenantId());
|
|
|
+ organizationService.add(organization);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询合作单位")
|
|
|
+ @GetMapping(value = "get")
|
|
|
@PreAuthorize("@pcs.hasPermissions('organization/get')")
|
|
|
- public HttpResponseResult<Organization> getConfig(Integer id) {
|
|
|
- return succeed(organizationService.getOrganization(id));
|
|
|
- }
|
|
|
+ public HttpResponseResult<Organization> getConfig(Integer id) {
|
|
|
+ return succeed(organizationService.getOrganization(id));
|
|
|
+ }
|
|
|
|
|
|
- @ApiOperation(value = "删除合作单位")
|
|
|
- @PostMapping(value = "del")
|
|
|
+ @ApiOperation(value = "删除合作单位")
|
|
|
+ @PostMapping(value = "del")
|
|
|
@PreAuthorize("@pcs.hasPermissions('organization/del')")
|
|
|
- public HttpResponseResult del(Integer id) {
|
|
|
- organizationService.del(id);
|
|
|
- return succeed();
|
|
|
- }
|
|
|
+ public HttpResponseResult del(Integer id) {
|
|
|
+ organizationService.del(id);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
|
|
|
- @ApiOperation(value = "启用/停用合作单位")
|
|
|
- @PostMapping(value = "lock")
|
|
|
+ @ApiOperation(value = "启用/停用合作单位")
|
|
|
+ @PostMapping(value = "lock")
|
|
|
@PreAuthorize("@pcs.hasPermissions('organization/lock')")
|
|
|
- public HttpResponseResult lock(Integer id,Integer lockFlag) {
|
|
|
- organizationService.lock(id,lockFlag);
|
|
|
- return succeed();
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "获取当前分部及其所有子合作单位")
|
|
|
- @GetMapping(value = "getChildOrgans")
|
|
|
- @PreAuthorize("@pcs.hasPermissions('organization/getChildOrgans')")
|
|
|
- public HttpResponseResult<List<Organization>> getChildOrgans(Integer includeSelf){
|
|
|
- SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- Organization organization = organizationService.findByUserId(sysUser.getId());
|
|
|
- return succeed(organizationService.getChildOrgans(organization.getId(), includeSelf==1));
|
|
|
- }
|
|
|
+ public HttpResponseResult lock(Integer id, Integer lockFlag) {
|
|
|
+ organizationService.lock(id, lockFlag);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取当前分部及其所有子合作单位")
|
|
|
+ @GetMapping(value = "getChildOrgans")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('organization/getChildOrgans')")
|
|
|
+ public HttpResponseResult<List<Organization>> getChildOrgans(Integer includeSelf) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ Organization organization = organizationService.findByUserId(sysUser.getId());
|
|
|
+ return succeed(organizationService.getChildOrgans(organization.getId(), includeSelf == 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "导入合作单位")
|
|
|
+ @PostMapping(value = "importOrgan")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('organization/importOrgan')")
|
|
|
+ public HttpResponseResult importOrgan(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ String tenantId = TenantContextHolder.getTenantId();
|
|
|
+
|
|
|
+ Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(file.getInputStream(), 2, file.getOriginalFilename());
|
|
|
+
|
|
|
+ File columnFile = ResourceUtils.getFile("classpath:" + "columnMapper.ini");
|
|
|
+ List<IniFileEntity> organizationColumns = IniFileUtil.readIniFile(columnFile).get("organization");
|
|
|
+
|
|
|
+ List<SysRole> organRoles = sysUserDao.getOrganRole(Integer.parseInt(tenantId));
|
|
|
+
|
|
|
+
|
|
|
+ sheetsListMap.keySet().forEach(e -> {
|
|
|
+ List<Map<String, Object>> sheet = sheetsListMap.get(e);
|
|
|
+ for (Map<String, Object> row : sheet) {
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ Map<String, Object> objectMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (String s : row.keySet()) {
|
|
|
+ for (IniFileEntity organizationColumn : organizationColumns) {
|
|
|
+ if (!s.equals(organizationColumn.getKey())) continue;
|
|
|
+ objectMap.put(organizationColumn.getValue(), row.get(s));
|
|
|
+
|
|
|
+ if (organizationColumn.getValue().equals("contactPhone")) {
|
|
|
+ user.setPhone(row.get(s).toString());
|
|
|
+ }
|
|
|
+ if (organizationColumn.getValue().equals("shareProfitAmount")) {
|
|
|
+ objectMap.put(organizationColumn.getValue(),new BigDecimal(row.get(s).toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (organizationColumn.getValue().equals("roleName")) {
|
|
|
+ for (SysRole organRole : organRoles) {
|
|
|
+ if (organRole.getRoleName().equals(row.get(s).toString())) {
|
|
|
+ user.setRoles(organRole.getId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (organizationColumn.getValue().equals("settlementType")) {
|
|
|
+ for (SettlementTypeEnum settlementType : SettlementTypeEnum.values()) {
|
|
|
+ if (settlementType.getMsg().equals(row.get(s).toString())) {
|
|
|
+ objectMap.put("settlementType", settlementType);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Organization organization = MapUtil.mapToJavaBean(Organization.class, objectMap);
|
|
|
+ organization.setTenantId(tenantId);
|
|
|
+ organization.setSysUser(user);
|
|
|
+ organizationService.add(organization);
|
|
|
+ } catch (IllegalAccessException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ } catch (IntrospectionException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ } catch (InstantiationException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取导入模板")
|
|
|
+ @GetMapping(value = "getImportTemplate")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('organization/getImportTemplate')")
|
|
|
+ public void getImportTemplate(HttpServletResponse response) throws IOException {
|
|
|
+ File file = ResourceUtils.getFile("classpath:" + "columnMapper.ini");
|
|
|
+ Map<String, List<IniFileEntity>> stringListMap = IniFileUtil.readIniFile(file);
|
|
|
+ List<IniFileEntity> organizationColumns = stringListMap.get("organization");
|
|
|
+
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
+ try {
|
|
|
+ String[] header = organizationColumns.stream().map(IniFileEntity::getKey).toArray(String[]::new);
|
|
|
+
|
|
|
+ List<Organization> organizations = new ArrayList<>();
|
|
|
+
|
|
|
+ HSSFWorkbook workbook = POIUtil.exportExcel(header, null, organizations);
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=organization-" + DateUtil.getDate(new Date()) + ".xls");
|
|
|
+ response.flushBuffer();
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
+ workbook.write(outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|