Commit 17a3e9d5 authored by 刘林's avatar 刘林

fix(96333):坐席添加导入导出接口

parent 5c17c54d
...@@ -3,7 +3,10 @@ package com.yeejoin.amos.boot.module.elevator.api.service; ...@@ -3,7 +3,10 @@ package com.yeejoin.amos.boot.module.elevator.api.service;
import com.yeejoin.amos.boot.module.elevator.api.entity.TzsCitInfo; import com.yeejoin.amos.boot.module.elevator.api.entity.TzsCitInfo;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
/** /**
...@@ -17,4 +20,7 @@ public interface ITzsCitInfoService extends IService<TzsCitInfo> { ...@@ -17,4 +20,7 @@ public interface ITzsCitInfoService extends IService<TzsCitInfo> {
String saveOrUpdateInfo(TzsCitInfo tzsCitInfo); String saveOrUpdateInfo(TzsCitInfo tzsCitInfo);
void export(HttpServletResponse response, List<String> list);
ResponseModel<Object> expertDataImport(MultipartFile file, AgencyUserModel userModel);
} }
package com.yeejoin.amos.boot.module.elevator.api.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* 案例列表
*/
@Data
public class TzsCitInfoVo {
@ExcelProperty(value = "坐席人员", index = 0)
private String ctiUserName;
@ExcelProperty(value = "坐席人员userId", index = 1)
private String ctiUserId;
@ExcelProperty(value = "登录坐席参数code", index = 2)
private String code;
@ExcelProperty(value = "登录坐席参数gid", index = 3)
private String gid;
@ExcelProperty(value = "坐席码机号", index = 4)
private String extphone;
@ExcelProperty(value = "坐席码职位", index = 5)
private String userRole;
@ExcelProperty(value = "值班日期", index = 6)
private String dutyDate;
}
...@@ -8,17 +8,17 @@ import com.yeejoin.amos.boot.biz.common.utils.NameUtils; ...@@ -8,17 +8,17 @@ import com.yeejoin.amos.boot.biz.common.utils.NameUtils;
import com.yeejoin.amos.boot.module.common.biz.utils.CommonResponseUtil; import com.yeejoin.amos.boot.module.common.biz.utils.CommonResponseUtil;
import com.yeejoin.amos.boot.module.elevator.api.entity.TzsCitInfo; import com.yeejoin.amos.boot.module.elevator.api.entity.TzsCitInfo;
import com.yeejoin.amos.boot.module.elevator.api.service.ITzsCitInfoService; import com.yeejoin.amos.boot.module.elevator.api.service.ITzsCitInfoService;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
...@@ -26,6 +26,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper; ...@@ -26,6 +26,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -170,6 +171,41 @@ public class TzsCitInfoController extends BaseController { ...@@ -170,6 +171,41 @@ public class TzsCitInfoController extends BaseController {
} }
return ResponseHelper.buildResponse("ok"); return ResponseHelper.buildResponse("ok");
} }
/**
*数据导出
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/ys/export")
@ApiOperation(httpMethod = "GET", value = "列表数据导出", notes = "列表数据导出")
public void expertDataExport(HttpServletResponse response, String ids) {
Assert.hasText(ids,"未选择导出数据");
iTzsCitInfoService.export(response,Arrays.asList(ids.split(",")));
}
/**
*数据导入
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/ys/import")
@ApiOperation(httpMethod = "POST", value = "坐席数据导入", notes = "坐席数据导入")
public ResponseModel<Object> expertDataImport(@RequestBody MultipartFile file) {
// 校验文件是否为空
if (file.isEmpty()) {
return ResponseHelper.buildResponse("文件不能为空");
}
// 校验文件类型为 Excel
String contentType = file.getContentType();
String fileExtension = FilenameUtils.getExtension(file.getOriginalFilename());
// 校验 Excel 文件的 MIME type 和扩展名
if (!("application/vnd.ms-excel".equals(contentType) ||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(contentType)) ||
!("xls".equalsIgnoreCase(fileExtension) || "xlsx".equalsIgnoreCase(fileExtension))) {
return ResponseHelper.buildResponse("文件类型必须是 Excel 文件");
}
AgencyUserModel userModel = getSelectedOrgInfo().getUserModel();
return iTzsCitInfoService.expertDataImport(file,userModel);
}
} }
package com.yeejoin.amos.boot.module.elevator.biz.service.impl; package com.yeejoin.amos.boot.module.elevator.biz.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.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.elevator.api.dto.TzsCitInfoDto; import com.yeejoin.amos.boot.module.elevator.api.dto.TzsCitInfoDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.TzsCitInfo; import com.yeejoin.amos.boot.module.elevator.api.entity.TzsCitInfo;
import com.yeejoin.amos.boot.module.elevator.api.mapper.TzsCitInfoMapper; import com.yeejoin.amos.boot.module.elevator.api.mapper.TzsCitInfoMapper;
import com.yeejoin.amos.boot.module.elevator.api.service.ITzsCitInfoService; import com.yeejoin.amos.boot.module.elevator.api.service.ITzsCitInfoService;
import com.yeejoin.amos.boot.module.elevator.api.vo.TzsCitInfoVo;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege; import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel; import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
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.io.InputStream;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -106,6 +122,66 @@ public class TzsCitInfoServiceImpl extends BaseService<TzsCitInfoDto, TzsCitInfo ...@@ -106,6 +122,66 @@ public class TzsCitInfoServiceImpl extends BaseService<TzsCitInfoDto, TzsCitInfo
} }
/** /**
* 列表数据导出
*
* @param response 响应
* @param ids 数据id
*/
@Override
public void export(HttpServletResponse response, List<String> ids) {
LambdaQueryWrapper<TzsCitInfo> lambda = new QueryWrapper<TzsCitInfo>().lambda();
lambda.in(TzsCitInfo::getSequenceNbr, ids);
List<TzsCitInfo> experts = this.baseMapper.selectList(lambda);
List<TzsCitInfoVo> exportData = JSON.parseArray(JSON.toJSONString(experts), TzsCitInfoVo.class);
ExcelUtil.createTemplate(response, "坐席数据", "坐席数据", exportData, TzsCitInfoVo.class, null, false);
}
@Transactional(rollbackFor = Exception.class)
@Override
public ResponseModel<Object> expertDataImport(MultipartFile file, AgencyUserModel userModel) {
try {
InputStream inputStream = file.getInputStream();
ExcelReader excelReader = EasyExcel.read(inputStream).build();
List<ReadSheet> sheetList = excelReader.excelExecutor().sheetList();
ReadSheet sheet = sheetList.get(0);
if (ValidationUtil.isEmpty(sheet)) {
throw new BadRequest("Excel导入模板有误,请重写下载导入!");
}
ArrayList<TzsCitInfo> dataList = new ArrayList<>();
EasyExcel.read(file.getInputStream(), TzsCitInfoVo.class, new AnalysisEventListener<TzsCitInfoVo>() {
@Override
public void invoke(TzsCitInfoVo data, AnalysisContext context) {
TzsCitInfo citInfo = JSON.parseObject(JSON.toJSONString(data), TzsCitInfo.class);
AgencyUserModel agencyUser = Privilege.agencyUserClient.queryByUserId(String.valueOf(data.getCtiUserId())).getResult();
if (agencyUser == null){
throw new BadRequest("导入坐席人员userId错误!");
}
citInfo.setCtiUserName(agencyUser.getRealName());
citInfo.setRegionCode(agencyUser.getCompanys().iterator().next().getCompanyCode());
citInfo.setRecDate(new Date());
dataList.add(citInfo);
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
}).headRowNumber(1).sheet().doRead();
excelReader.finish();
// 保存数据
this.saveOrUpdateBatch(dataList);
return ResponseHelper.buildResponse("success");
} catch (Exception e) {
throw new BadRequest(e.getMessage());
}
}
/**
* 用户单位信息redis获取 * 用户单位信息redis获取
**/ **/
public ReginParams getReginParams() { public ReginParams getReginParams() {
......
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