Commit 6dba9259 authored by tangwei's avatar tangwei

场站,模板下载,导入,导出

parent aa3add26
package com.yeejoin.amos.boot.module.jxiop.api.Enum;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ExcelEnums {
CZXX ("场站信息", "场站信息", "com.yeejoin.amos.boot.module.jxiop.api.dto.ExStationBasicDto","CZXX");
//RYXX("人员信息", "人员信息", "com.yeejoin.amos.boot.module.jcs.api.dto.OrgUsrSafeReportExcelDto","RYXX");
private String fileName;
private String sheetName;
private String classUrl;
private String type;
public static ExcelEnums getByKey(String type) {
for (ExcelEnums status : ExcelEnums.values())
{
if (status.getType().equals(type))
{
return status;
}
}
return null;
}
}
package com.yeejoin.amos.boot.module.jxiop.api.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.yeejoin.amos.boot.biz.common.excel.CommonExplicitConstraint;
import com.yeejoin.amos.boot.biz.common.excel.ExplicitConstraint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @description:
* @author: tw
* @createDate: 2023/4/24
*/
@Data
@ApiModel(value = "ExStationBasicDto", description = "")
public class ExStationBasicDto {
@ExcelProperty(value = "场站名称", index = 0)
@ApiModelProperty(value = "场站名称")
private String stationName;
@ExcelProperty(value = "场站编号", index = 1)
@ApiModelProperty(value = "场站编号")
private String stationCode;
@ExplicitConstraint(indexNum = 2, source = {"建设方","总承包方","分包方"}) //固定下拉内容
@ExcelProperty(value = "场站类型", index = 2)
@ApiModelProperty(value = "场站类型")
private String stationType;
@ExplicitConstraint(indexNum = 3, source = {"开发","策划","在建","停建","完工","结算","尾款","关闭","终止","运维","测试"}) //固定下拉内容
@ExcelProperty(value = "项目状态", index = 3)
@ApiModelProperty(value = "项目状态")
private String stationFlag;
@ExcelProperty(value = "地址", index = 4)
@ApiModelProperty("地址")
private String address;
@ExcelProperty(value = "站长", index = 5)
@ApiModelProperty(value = "站长")
private String stationMasterName;
@ExcelProperty(value = "紧急联系方式(手机)", index = 6)
@ApiModelProperty(value = "紧急联系方式(手机)")
private String mobilePhone;
@ExcelProperty(value = "电话", index = 7)
@ApiModelProperty(value = "电话")
private String phone;
@ExcelProperty(value = "邮箱", index = 8)
@ApiModelProperty(value = "邮箱")
private String email;
@ExcelProperty(value = "运维开始时间", index = 9)
@ApiModelProperty(value = "运维开始时间")
private String devopsTime;
@ExcelProperty(value = "业主单位", index = 10)
@ApiModelProperty(value = "业主单位")
private String ownerUnit;
@ExcelProperty(value = "简介", index = 11)
@ApiModelProperty(value = "简介")
private String briefIntroduction;
@ExplicitConstraint(indexNum = 12, sourceClass = CommonExplicitConstraint.class, method = "getArea") //固定下拉内容
@ExcelProperty(value = "所属片区", index = 12)
@ApiModelProperty(value = "所属片区")
private String area;
}
package com.yeejoin.amos.boot.module.jxiop.api.mapper; package com.yeejoin.amos.boot.module.jxiop.api.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jxiop.api.dto.ExStationBasicDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.StationBasicDto; import com.yeejoin.amos.boot.module.jxiop.api.dto.StationBasicDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic; import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
...@@ -14,20 +15,22 @@ import java.util.List; ...@@ -14,20 +15,22 @@ import java.util.List;
* @date 2023-04-20 * @date 2023-04-20
*/ */
public interface StationBasicMapper extends BaseMapper<StationBasic> { public interface StationBasicMapper extends BaseMapper<StationBasic> {
//分页
List<StationBasicDto> queryPage(Long current, Long size, List<StationBasicDto> queryPage(Long current, Long size,
String stationMasterName, String stationMasterName,
String stationName, String stationName,
String stationType); String stationType);
//统计
List<StationBasicDto> queryPagecount( List<StationBasicDto> queryPagecount(
String stationMasterName, String stationMasterName,
String stationName, String stationName,
String stationType); String stationType);
//删除
int deleteList(String[] ids); int deleteList(String[] ids);
//导出
List<ExStationBasicDto> getExStationBasicDto(String stationMasterName,
String stationName,
String stationType);
} }
...@@ -62,6 +62,37 @@ ...@@ -62,6 +62,37 @@
</delete> </delete>
<select id="getExStationBasicDto" resultType="com.yeejoin.amos.boot.module.jxiop.api.dto.ExStationBasicDto">
select
station_basic.station_name stationName ,
station_basic.station_code stationCode,
station_basic.station_type stationType,
station_basic.station_flag stationFlag,
station_basic.address address,
station_basic.station_master_name stationMasterName ,
station_basic.mobile_phone mobilePhone ,
station_basic.phone phone,
station_basic.email email,
station_basic.devops_time devopsTime,
station_basic.owner_unit ownerUnit,
station_basic.brief_introduction briefIntroduction,
station_basic.area_name area
from station_basic
<where>
is_delete=0
<if test="stationMasterName != null and stationMasterName != ''">
AND station_basic.station_master_name like concat('%',#{stationMasterName},'%')
</if>
<if test="stationName != null and stationName != ''">
AND station_basic.station_name like concat('%',#{stationName},'%')
</if>
<if test="stationType != null and stationType != ''">
AND station_basic.station_type = #{stationType}
</if>
</where>
ORDER BY station_basic.rec_date DESC
</select>
</mapper> </mapper>
package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.common.api.dto.ExcelDto;
import com.yeejoin.amos.boot.module.jxiop.api.Enum.ExcelEnums;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.ExcelServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
@RestController
@Api(tags = "导出")
@RequestMapping(value = "/excel")
public class ExcelController extends BaseController {
@Autowired
ExcelServiceImpl excelService;
@Autowired
RedisUtils redisUtils;
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "下载模板")
@GetMapping("/download/template/{type}")
public void downloadTemplate(HttpServletResponse response, @PathVariable(value = "type") String type) {
try {
ExcelEnums excelEnums = ExcelEnums.getByKey(type);
ExcelDto excelDto = new ExcelDto(excelEnums.getFileName(), excelEnums.getSheetName(),
excelEnums.getClassUrl(), excelEnums.getType());
excelService.templateExport(response, excelDto);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("系统异常!");
}
}
@TycloudOperation(needAuth = false,ApiLevel = UserType.AGENCY)
@ApiOperation(value = "导出公用类")
@GetMapping("/export/{type}")
public void getFireStationFile(HttpServletResponse response, @PathVariable(value = "type") String type,
@RequestParam Map par) {
try {
ExcelEnums excelEnums = ExcelEnums.getByKey(type);
ExcelDto excelDto = new ExcelDto(excelEnums.getFileName(), excelEnums.getSheetName(),
excelEnums.getClassUrl(), excelEnums.getType());
excelService.commonExport(response, excelDto, par);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("系统异常!");
}
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "导入公用")
@PostMapping("/upload/{type}")
public ResponseModel<Object> upload(@RequestPart("file") MultipartFile multipartFile,
@PathVariable(value = "type") String type) {
try {
ExcelEnums excelEnums = ExcelEnums.getByKey(type);
ExcelDto excelDto = new ExcelDto(excelEnums.getFileName(), excelEnums.getSheetName(),
excelEnums.getClassUrl(), excelEnums.getType());
excelService.commonUpload(multipartFile, excelDto);
return ResponseHelper.buildResponse(null);
} catch (RuntimeException e) {
e.printStackTrace();
throw new BadRequest("文件格式不正确或excel 模板不匹配");
} catch (Exception e) {
throw new BadRequest("文件格式不正确或excel 模板不匹配!");
}
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.yeejoin.amos.boot.biz.common.excel.DataSources;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/4/24
*/
@Service
public class ExDataSourcesImpl implements DataSources {
@Override
public String[] selectList(String type, String method) throws Exception {
String[] str = {};
switch (method) {
case "getArea":
str = getArea();
break;
}
return str;
}
private String[] getArea() {
FeignClientResult<Collection<CompanyModel>> de = Privilege.companyClient.queryAgencyTree(null);
// FeignClientResult<List<DictionarieValueModel>> lidt=Systemctl.dictionarieClient.dictValues(dictCode)
Collection<CompanyModel> listco = new ArrayList<>();
String[] str = null;
if (!ObjectUtils.isEmpty(de)) {
if (de.getStatus() == 200) {
listco = de.getResult();
List<String> collect = this.getCompanyModel(listco);
str = collect.toArray(new String[collect.size()]);
} else {
throw new RuntimeException(de.getMessage());
}
}
return str;
}
public List<String> getCompanyModel(Collection<CompanyModel> data) {
List<String> datas = new ArrayList<>();
if (!data.isEmpty()) {
for (CompanyModel datum : data) {
datas.add(datum.getCompanyName() + "@" + datum.getSequenceNbr());
if (datum.getChildren() != null) {
this.getCompanyModelchildren((List<LinkedHashMap<String,Object>> ) datum.getChildren(),datas);
}
}
}
return datas;
}
public void getCompanyModelchildren(List<LinkedHashMap<String,Object>> data, List<String> datas) {
if (!data.isEmpty()) {
for (LinkedHashMap<String,Object> datum : data) {
datas.add(datum.get("companyName") + "@" + datum.get("sequenceNbr"));
if (datum.get("children")!= null) {
this.getCompanyModelchildren((List<LinkedHashMap<String,Object>> ) datum.get("children"),datas);
}
}
}
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.yeejoin.amos.boot.biz.common.excel.ExcelUtil;
import com.yeejoin.amos.boot.module.common.api.dto.*;
import com.yeejoin.amos.boot.module.common.api.entity.FireChemical;
import com.yeejoin.amos.boot.module.jxiop.api.dto.ExStationBasicDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.utils.Bean;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
@Service
public class ExcelServiceImpl {
@Autowired
ExDataSourcesImpl dataSourcesImpl;
@Autowired
StationBasicMapper stationBasicMapper;
@Autowired
StationBasicServiceImpl stationBasicServiceImpl;
public void templateExport(HttpServletResponse response, ExcelDto excelDto) throws ClassNotFoundException {
String url = excelDto.getClassUrl();
Class<?> clz = Class.forName(url);
ExcelUtil.createTemplate(response, excelDto.getFileName(), excelDto.getSheetName(), null, clz, dataSourcesImpl,
true);
}
public void commonExport(HttpServletResponse response, ExcelDto excelDto, Map par) {
switch (excelDto.getType()) {
case "CZXX":
List<ExStationBasicDto> data=this.getExStationBasicDto(par);
ExcelUtil.createTemplate(response, excelDto.getFileName(), excelDto.getSheetName(), data,
WaterResourceDto.class, dataSourcesImpl, false);
default:
break;
}
}
@Transactional
public void commonUpload(MultipartFile multipartFile, ExcelDto excelDto) throws Exception {
switch (excelDto.getType()) {
case "CZXX":
this.addExStationBasicDto(multipartFile);
break;
}
return;
}
//场站信息导出
public List<ExStationBasicDto> getExStationBasicDto(Map<String,Object> map){
List<ExStationBasicDto> data=null;
if(!map.isEmpty()){
data=stationBasicMapper.getExStationBasicDto(map.get("stationMasterName").toString(),map.get("stationName").toString(),map.get("stationType").toString());
}
return data;
}
//场站导入
private void addExStationBasicDto(MultipartFile multipartFile) throws Exception {
List<ExStationBasicDto> excelDtoList = com.yeejoin.amos.boot.module.common.api.excel.ExcelUtil.readFirstSheetExcel(multipartFile, ExStationBasicDto.class, 1);
List<StationBasic> excelEntityList = new ArrayList<>();
excelDtoList.forEach(item -> {
StationBasic fireChemical = new StationBasic();
fireChemical = Bean.toPo(item, fireChemical);
if (fireChemical.getArea() != null) {
String[] type = fireChemical.getArea().split("@");
fireChemical.setAreaName(type[0]);
fireChemical.setArea(type[1]);
}
excelEntityList.add(fireChemical);
});
stationBasicServiceImpl.saveBatch(excelEntityList);
}
}
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