Commit b4b85e94 authored by lisong's avatar lisong

添加应急救援小组相关接口

parent 8ab1cb2e
package com.yeejoin.amos.boot.module.jcs.api.dto;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.Data;
@Data
public class OrganizationExportDto {
@ColumnWidth(40)
@ExcelProperty(value = "*应急救援小组名称", index = 0)
private String emergencyTeamName;
@ColumnWidth(25)
@ExcelProperty(value = "小组职责", index = 1)
private String duty;
@ColumnWidth(25)
@ExcelProperty(value = "*组长", index = 2)
private String groupLeader;
@ColumnWidth(25)
@ExcelProperty(value = "组长电话", index = 3)
private String groupLeaderTel;
@ColumnWidth(25)
@ExcelProperty(value = "副组长", index = 4)
private String deputyGroupLeader;
@ColumnWidth(25)
@ExcelProperty(value = "副组长电话", index = 5)
private String deputyGroupLeaderTel;
}
package com.yeejoin.amos.boot.module.jcs.api.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.Data;
@Data
public class OrganizationUserExportDto {
@ColumnWidth(40)
@ExcelProperty(value = "*应急救援小组名称", index = 0)
private String emergencyTeamName;
@ColumnWidth(25)
@ExcelProperty(value = "*组员姓名", index = 1)
private String memberName;
@ColumnWidth(25)
@ExcelProperty(value = "组员岗位", index = 2)
private String postName;
@ColumnWidth(25)
@ExcelProperty(value = "*组员电话", index = 3)
private String telephone;
}
...@@ -3,9 +3,12 @@ package com.yeejoin.amos.boot.module.jcs.api.mapper; ...@@ -3,9 +3,12 @@ package com.yeejoin.amos.boot.module.jcs.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.common.api.entity.Firefighters; import com.yeejoin.amos.boot.module.common.api.entity.Firefighters;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationExportDto;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationUserExportDto;
import com.yeejoin.amos.boot.module.jcs.api.entity.Organization; import com.yeejoin.amos.boot.module.jcs.api.entity.Organization;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -13,4 +16,16 @@ public interface OrganizationMapper extends BaseMapper<Organization> { ...@@ -13,4 +16,16 @@ public interface OrganizationMapper extends BaseMapper<Organization> {
Page<Map<String, Object>> getOrganizationInfo(Page<Map<String, Object>> page, @Param("bizOrgCode") String bizOrgCode); Page<Map<String, Object>> getOrganizationInfo(Page<Map<String, Object>> page, @Param("bizOrgCode") String bizOrgCode);
Page<Map<String, Object>> getOrganizationList(Page<Map<String, Object>> page, @Param("bizOrgCode") String bizOrgCode);
Page<Map<String, Object>> getOrganizationGroup(Page<Map<String, Object>> page, @Param("bizOrgCode") String bizOrgCode);
List<OrganizationExportDto> selectOrganization(@Param("bizOrgCode") String bizOrgCode);
List<OrganizationUserExportDto> selectOrganizationUserList(@Param("bizOrgCode") String bizOrgCode);
int selectMaxSort();
} }
package com.yeejoin.amos.boot.module.jcs.api.service; package com.yeejoin.amos.boot.module.jcs.api.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationExportDto;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationUserExportDto;
import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -9,4 +12,11 @@ public interface OrganizationService { ...@@ -9,4 +12,11 @@ public interface OrganizationService {
Page<Map<String, Object>> getOrganizationInfo(Page<Map<String, Object>> page, String bizOrgCode); Page<Map<String, Object>> getOrganizationInfo(Page<Map<String, Object>> page, String bizOrgCode);
Page<Map<String, Object>> getOrganizationList(Page<Map<String, Object>> page, String bizOrgCode);
List<OrganizationExportDto> selectOrganization(String bizOrgCode);
List<OrganizationUserExportDto> selectOrganizationUserList(String bizOrgCode);
void saveOrganization(List<OrganizationExportDto> data, List<OrganizationUserExportDto> userData, String bizOrgCode);
} }
...@@ -67,4 +67,55 @@ ...@@ -67,4 +67,55 @@
LIMIT 4 LIMIT 4
) )
</select> </select>
<select id="getOrganizationList" resultType="java.util.Map">
SELECT
co.emergency_team_id as groupId,
co.emergency_team_name as emergencyTeamName,
cou.member_name as memberName ,
cou.post_name as postName,
cou.telephone,
co.duty
FROM
cb_organization co
LEFT JOIN cb_organization_user cou ON co.sequence_nbr = cou.emergency_team_id
where co.biz_org_code like concat(#{bizOrgCode}, '%')
</select>
<select id="getOrganizationGroup" resultType="java.util.Map">
SELECT
co.sequence_nbr as id,
co.duty
FROM
cb_organization co
LEFT JOIN cb_organization_user cou ON co.sequence_nbr = cou.emergency_team_id
where co.biz_org_code like concat(#{bizOrgCode}, '%')
GROUP BY co.sequence_nbr
</select>
<select id="selectOrganization" resultType="com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationExportDto">
SELECT
co.emergency_team_name AS emergencyTeamName,
co.duty,
co.group_leader AS groupLeader,
co.group_leader_tel AS groupLeaderTel,
co.deputy_group_leader AS deputyGroupLeader,
co.deputy_group_leader_tel AS deputyGroupLeaderTel
FROM
cb_organization co
WHERE
co.biz_org_code LIKE concat( #{bizOrgCode}, '%' )
</select>
<select id="selectOrganizationUserList" resultType="com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationUserExportDto">
SELECT
cou.emergency_team_name AS emergencyTeamName,
cou.member_name as memberName,
cou.post_name AS postName,
cou.telephone
FROM
cb_organization_user cou
</select>
<select id="selectMaxSort" resultType="java.lang.Integer">
SELECT MAX(sort) FROM cb_organization
</select>
</mapper> </mapper>
package com.yeejoin.amos.boot.module.jcs.biz.controller; package com.yeejoin.amos.boot.module.jcs.biz.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams; import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.controller.BaseController; import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.excel.ExcelUtil;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.common.api.core.framework.PersonIdentify; import com.yeejoin.amos.boot.module.common.api.core.framework.PersonIdentify;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationExportDto;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationUserExportDto;
import com.yeejoin.amos.boot.module.jcs.api.service.OrganizationService; import com.yeejoin.amos.boot.module.jcs.api.service.OrganizationService;
import com.yeejoin.amos.boot.module.common.biz.utils.CommonResponseUtil; import com.yeejoin.amos.boot.module.common.biz.utils.CommonResponseUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
...@@ -56,5 +72,108 @@ public class OrganizationController extends BaseController { ...@@ -56,5 +72,108 @@ public class OrganizationController extends BaseController {
return CommonResponseUtil.success(organizationService.getOrganizationInfo(mapPage, bizOrgCode)); return CommonResponseUtil.success(organizationService.getOrganizationInfo(mapPage, bizOrgCode));
} }
@PersonIdentify
@GetMapping(value = "/getOrganizationList")
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "四横八纵", notes = "四横八纵-组织列表")
public ResponseModel getOrganizationList(@RequestParam(value = "pageNumber") int pageNumber,
@RequestParam(value = "pageSize") int pageSize) {
ReginParams reginParam = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
String bizOrgCode = null;
if (null != reginParam) {
bizOrgCode = reginParam.getPersonIdentity().getBizOrgCode();
if (StringUtils.isEmpty(bizOrgCode)) {
return CommonResponseUtil.success(null);
}
} else {
return CommonResponseUtil.success(null);
}
Page<Map<String, Object>> mapPage = new Page<>(pageNumber, pageSize);
return CommonResponseUtil.success(organizationService.getOrganizationList(mapPage, bizOrgCode));
}
@PersonIdentify
@GetMapping(value = "/export")
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "四横八纵", notes = "四横八纵-组织机构导出")
public void export(HttpServletResponse response) {
String file_name = null;
try {
file_name = new String("组织机构信息".getBytes(), "ISO-8859-1");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + file_name + ".xlsx");
List<OrganizationExportDto> firstSheetVOS = new ArrayList<>();
List<OrganizationUserExportDto> secondSheetVOS = new ArrayList<>();
// 表一写入
ExcelWriter writer = EasyExcel.write(response.getOutputStream(), OrganizationExportDto.class).build();
WriteSheet sheet = EasyExcel.writerSheet(0, "应急救援小组").build();
writer.write(firstSheetVOS, sheet);
// 表二写入
WriteSheet sheet2 = EasyExcel.writerSheet(1, "组员").head(OrganizationUserExportDto.class).build();
writer.write(secondSheetVOS, sheet2);
// 关闭流
writer.finish();
} catch (Exception e) {
e.printStackTrace();
}
}
@PersonIdentify
@GetMapping(value = "/exportData")
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "四横八纵", notes = "四横八纵-组织机构导出")
public void exportData(@RequestParam("bizOrgCode") String bizOrgCode
, HttpServletResponse response) {
String file_name = null;
try {
file_name = new String("组织机构信息".getBytes(), "ISO-8859-1");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + file_name + ".xlsx");
// 应急小组信息
List<OrganizationExportDto> organizationList = organizationService.selectOrganization(bizOrgCode);
// 应急小组人员信息
List<OrganizationUserExportDto> organizationUserList = organizationService.selectOrganizationUserList(bizOrgCode);
// 应急小组写入
ExcelWriter writer = EasyExcel.write(response.getOutputStream(), OrganizationExportDto.class).build();
WriteSheet sheet = EasyExcel.writerSheet(0, "应急救援小组").build();
writer.write(organizationList, sheet);
// 组员写入
WriteSheet sheet2 = EasyExcel.writerSheet(1, "组员").head(OrganizationUserExportDto.class).build();
writer.write(organizationUserList, sheet2);
// 关闭流
writer.finish();
} catch (Exception e) {
e.printStackTrace();
}
}
@PersonIdentify
@GetMapping(value = "/upload")
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "四横八纵", notes = "四横八纵-组织机构导入")
public ResponseModel upload(@RequestParam("bizOrgCode") String bizOrgCode
, MultipartFile file) {
try {
ExcelReader reader = EasyExcel.read(file.getInputStream()).build();
List<OrganizationExportDto> organizationList = ExcelUtil.readExcel(reader, OrganizationExportDto.class, 0);
List<OrganizationUserExportDto> organizationUserList = ExcelUtil.readExcel(reader, OrganizationUserExportDto.class, 1);
organizationService.saveOrganization(organizationList, organizationUserList, bizOrgCode);
} catch (IOException e) {
e.printStackTrace();
return CommonResponseUtil.failure();
}
return CommonResponseUtil.success();
}
} }
package com.yeejoin.amos.boot.module.jcs.biz.service.impl; package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationExportDto;
import com.yeejoin.amos.boot.module.jcs.api.dto.OrganizationUserExportDto;
import com.yeejoin.amos.boot.module.jcs.api.entity.Organization;
import com.yeejoin.amos.boot.module.jcs.api.entity.OrganizationUser;
import com.yeejoin.amos.boot.module.jcs.api.mapper.OrganizationMapper; import com.yeejoin.amos.boot.module.jcs.api.mapper.OrganizationMapper;
import com.yeejoin.amos.boot.module.jcs.api.mapper.OrganizationUserMapper;
import com.yeejoin.amos.boot.module.jcs.api.service.OrganizationService; import com.yeejoin.amos.boot.module.jcs.api.service.OrganizationService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
...@@ -15,8 +25,60 @@ public class OrganizationImpl implements OrganizationService { ...@@ -15,8 +25,60 @@ public class OrganizationImpl implements OrganizationService {
@Autowired @Autowired
private OrganizationMapper organizationMapper; private OrganizationMapper organizationMapper;
@Autowired
private OrganizationUserMapper organizationUserMapper;
@Override @Override
public Page<Map<String, Object>> getOrganizationInfo(Page<Map<String, Object>> page, String bizOrgCode) { public Page<Map<String, Object>> getOrganizationInfo(Page<Map<String, Object>> page, String bizOrgCode) {
return organizationMapper.getOrganizationInfo(page, bizOrgCode); return organizationMapper.getOrganizationInfo(page, bizOrgCode);
} }
@Override
public Page<Map<String, Object>> getOrganizationList(Page<Map<String, Object>> page, String bizOrgCode) {
Page<Map<String, Object>> groupPage = new Page<>();
Page<Map<String, Object>> group = organizationMapper.getOrganizationGroup(groupPage, bizOrgCode);
Page<Map<String, Object>> mapPage = organizationMapper.getOrganizationList(page, bizOrgCode);
List<Map<String, Object>> records = group.getRecords();
ArrayList<Map<String, Object>> result = new ArrayList<>();
for (Map<String, Object> record : records) {
List<Map<String, Object>> collect = mapPage.getRecords().stream().filter(item -> String.valueOf(record.get("id")).equals(String.valueOf(item.get("groupId")))).collect(Collectors.toList());
record.put("persons", collect);
result.add(record);
}
mapPage.setRecords(result);
return mapPage;
}
@Override
public List<OrganizationExportDto> selectOrganization(String bizOrgCode) {
return organizationMapper.selectOrganization(bizOrgCode);
}
@Override
public List<OrganizationUserExportDto> selectOrganizationUserList(String bizOrgCode) {
return organizationMapper.selectOrganizationUserList(bizOrgCode);
}
@Override
@Transactional
public void saveOrganization(List<OrganizationExportDto> data, List<OrganizationUserExportDto> userData, String bizOrgCode) {
int sort = organizationMapper.selectMaxSort();
for (OrganizationExportDto dto : data) {
Organization organization = new Organization();
BeanUtils.copyProperties(dto, organization);
sort = sort + 1;
organization.setSort(sort);
organization.setBizOrgCode(bizOrgCode);
organizationMapper.insert(organization);
List<OrganizationUserExportDto> collect = userData.stream().filter(item -> item.getEmergencyTeamName().equals(dto.getEmergencyTeamName())).collect(Collectors.toList());
for (OrganizationUserExportDto userExportDto : collect) {
OrganizationUser organizationUser = new OrganizationUser();
BeanUtils.copyProperties(userExportDto, organizationUser);
organizationUser.setEmergencyTeamId(String.valueOf(organization.getSequenceNbr()));
organizationUserMapper.insert(organizationUser);
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment