|
@@ -3,21 +3,33 @@ package com.ims.eval.service.impl;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ims.eval.dao.MultipleBrandMapper;
|
|
|
import com.ims.eval.entity.Indicator;
|
|
|
import com.ims.eval.entity.MultipleBrand;
|
|
|
-import com.ims.eval.dao.MultipleBrandMapper;
|
|
|
+import com.ims.eval.entity.dto.result.R;
|
|
|
import com.ims.eval.service.IMultipleBrandService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ims.eval.util.ExcelUtil;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author wang
|
|
@@ -27,28 +39,175 @@ import java.util.stream.Collectors;
|
|
|
public class MultipleBrandServiceImpl extends ServiceImpl<MultipleBrandMapper, MultipleBrand> implements IMultipleBrandService {
|
|
|
|
|
|
@Override
|
|
|
- public IPage<MultipleBrand> getMultipleBranTree(Integer pageNum, Integer pageSize,String id, String parentId,String binSection,String checkCycle,String year,String month) {
|
|
|
+ public IPage<MultipleBrand> getMultipleBranTree(Integer pageNum, Integer pageSize, String id, String parentId, String binSection, String checkCycle, String year, String month) {
|
|
|
Page<Indicator> page = new Page<>(pageNum, pageSize);
|
|
|
- IPage<MultipleBrand> list = baseMapper.selectMultipleBranTree(page,id,"0",binSection,checkCycle,year,month);
|
|
|
- List<MultipleBrand> list2 = baseMapper.selectMultipleBranList(id,"","",checkCycle,year,month);
|
|
|
+ IPage<MultipleBrand> list = baseMapper.selectMultipleBranTree(page, id, "0", binSection, checkCycle, year, month);
|
|
|
+ List<MultipleBrand> list2 = baseMapper.selectMultipleBranList(id, "", "", checkCycle, year, month);
|
|
|
|
|
|
- List<MultipleBrand> tree = convert(list.getRecords(),list2);
|
|
|
+ List<MultipleBrand> tree = convert(list.getRecords(), list2);
|
|
|
list.setRecords(tree);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<MultipleBrand> getMultipleBranList(String id, String parentId,String binSection,String checkCycle,String year,String month) {
|
|
|
- List<MultipleBrand> list = baseMapper.selectMultipleBranList(id,parentId,binSection,checkCycle,year,month);
|
|
|
+ public List<MultipleBrand> getMultipleBranList(String id, String parentId, String binSection, String checkCycle, String year, String month) {
|
|
|
+ List<MultipleBrand> list = baseMapper.selectMultipleBranList(id, parentId, binSection, checkCycle, year, month);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<MultipleBrand> getMultipleBranList2( String organizationId, String parentId, String binSection, String checkCycle, String year, String month) {
|
|
|
- List<MultipleBrand> list = baseMapper.selectMultipleBranList2(organizationId,parentId,binSection,checkCycle,year,month);
|
|
|
+ public List<MultipleBrand> getMultipleBranList2(String organizationId, String parentId, String binSection, String checkCycle, String year, String month) {
|
|
|
+ List<MultipleBrand> list = baseMapper.selectMultipleBranList2(organizationId, parentId, binSection, checkCycle, year, month);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void exportExcel(String binSection, String checkCycle, String year, HttpServletResponse response) throws IOException {
|
|
|
+ // 设置响应头信息,以附件形式下载
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=multiple_brand.xlsx");
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+
|
|
|
+ // 创建新的Excel工作簿
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+
|
|
|
+ // 创建新的工作表
|
|
|
+ Sheet sheet = workbook.createSheet("Sheet1");
|
|
|
+
|
|
|
+ // 创建表头
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
+ List<String> headers = Arrays.asList("ID", "单位名称", "业务属性", "考评周期", "利润金额", "分数", "年", "月", "备注");
|
|
|
+ for (int i = 0; i < headers.size(); i++) {
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ //行数据
|
|
|
+ List<MultipleBrand> firstOrderList = baseMapper.selectMultipleBranList("", "0", binSection, checkCycle, year, "");
|
|
|
+ List<MultipleBrand> secondLevelList = baseMapper.selectMultipleBranList("", "", "", checkCycle, year, "");
|
|
|
+ List<MultipleBrand> multipleBrandList = convert(firstOrderList, secondLevelList);
|
|
|
+
|
|
|
+ // 填充数据到工作表
|
|
|
+ int rowIndex = 1; // 从第二行开始填充数据(第一行是表头)
|
|
|
+ for (MultipleBrand multipleBrand : multipleBrandList) {
|
|
|
+ Row row = sheet.createRow(rowIndex++);
|
|
|
+
|
|
|
+ // 设置ID
|
|
|
+ row.createCell(0).setCellValue(multipleBrand.getId());
|
|
|
+
|
|
|
+ // 设置其他数据
|
|
|
+ row.createCell(1).setCellValue(multipleBrand.getOrganizationName());
|
|
|
+ row.createCell(2).setCellValue(multipleBrand.getBinSectionName());
|
|
|
+ if ("NDKP".equals(multipleBrand.getCheckCycle())) {
|
|
|
+ checkCycle = "年度考评";
|
|
|
+ } else if ("JDKP".equals(multipleBrand.getCheckCycle())) {
|
|
|
+ checkCycle = "季度考评";
|
|
|
+ } else if ("YDKP".equals(multipleBrand.getCheckCycle())) {
|
|
|
+ checkCycle = "月度考评";
|
|
|
+ }
|
|
|
+ row.createCell(3).setCellValue(checkCycle);
|
|
|
+ row.createCell(4).setCellValue(multipleBrand.getProfit());
|
|
|
+ row.createCell(5).setCellValue(multipleBrand.getScore());
|
|
|
+ row.createCell(6).setCellValue(multipleBrand.getYear());
|
|
|
+ row.createCell(7).setCellValue(multipleBrand.getMonth());
|
|
|
+ row.createCell(8).setCellValue(multipleBrand.getRemark());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 隐藏第一列(ID列)
|
|
|
+ sheet.setColumnHidden(0, true);
|
|
|
+
|
|
|
+ // 将工作簿写入到输出流
|
|
|
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
+ workbook.write(outputStream);
|
|
|
+ response.getOutputStream().write(outputStream.toByteArray());
|
|
|
+ response.getOutputStream().flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭工作簿
|
|
|
+ workbook.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void importTemplate(HttpServletResponse response) throws IOException {
|
|
|
+ // 设置响应头信息,以附件形式下载
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=multiple_brand.xlsx");
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+
|
|
|
+ // 创建新的Excel工作簿
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+
|
|
|
+ // 创建新的工作表
|
|
|
+ Sheet sheet = workbook.createSheet("Sheet1");
|
|
|
+
|
|
|
+ // 创建表头
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
+ List<String> headers = Arrays.asList("单位名称", "业务属性", "考评周期", "利润金额", "分数", "年", "月", "备注");
|
|
|
+ for (int i = 0; i < headers.size(); i++) {
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
+ cell.setCellValue(headers.get(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将工作簿写入到输出流
|
|
|
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
|
|
+ workbook.write(outputStream);
|
|
|
+ response.getOutputStream().write(outputStream.toByteArray());
|
|
|
+ response.getOutputStream().flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭工作簿
|
|
|
+ workbook.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R importExcel(MultipartFile file) {
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ try {
|
|
|
+ //获取原始的文件名
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ //获取文件类型
|
|
|
+ String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
|
|
|
+ //默认从第一行开始读取
|
|
|
+ int startRows = 1;
|
|
|
+ //获取输入流
|
|
|
+ InputStream is = file.getInputStream();
|
|
|
+ List<MultipleBrand> multipleBrandList = new ArrayList<>();
|
|
|
+ //Excel导入导出的单元类
|
|
|
+ List<String[]> strings = ExcelUtil.readData(fileType, startRows, true, is);
|
|
|
+ //遍历Excel表每一行的数据
|
|
|
+ for (String[] str : strings) {
|
|
|
+ MultipleBrand multipleBrand = new MultipleBrand();
|
|
|
+ if (OrganizationEvaluationRuleServiceImpl.verifyID(str[0])) {
|
|
|
+ multipleBrand.setId(str[0]);
|
|
|
+ multipleBrand.setProfit(Double.valueOf(str[4]));
|
|
|
+ multipleBrand.setScore(Double.valueOf(str[5]));
|
|
|
+ multipleBrand.setRemark(str[8]);
|
|
|
+ multipleBrandList.add(multipleBrand);
|
|
|
+ } else {
|
|
|
+ /*multipleBrand.setOrganizationId();
|
|
|
+ multipleBrand.setOrganizationName();
|
|
|
+ multipleBrand.setParentId();
|
|
|
+ multipleBrand.setProfit();
|
|
|
+ multipleBrand.setScore();
|
|
|
+ multipleBrand.setBinSection();
|
|
|
+ multipleBrand.setCheckCycle();
|
|
|
+ multipleBrand.setYear();
|
|
|
+ multipleBrand.setMonth();
|
|
|
+ multipleBrand.setRemark();*/
|
|
|
+ multipleBrandList.add(multipleBrand);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ boolean b = super.saveOrUpdateBatch(multipleBrandList);
|
|
|
+ if (b) {
|
|
|
+ return R.ok().data(b);
|
|
|
+ } else {
|
|
|
+ return R.error("导入失败!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.customError(e.getMessage()).data("失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.error("上传文件为空!");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 转换为有树形结构的列表
|
|
@@ -56,24 +215,24 @@ public class MultipleBrandServiceImpl extends ServiceImpl<MultipleBrandMapper, M
|
|
|
* @param brands 源数据所有数据
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<MultipleBrand> convert(List<MultipleBrand> result,List<MultipleBrand> brands) {
|
|
|
+ public List<MultipleBrand> convert(List<MultipleBrand> result, List<MultipleBrand> brands) {
|
|
|
if (CollectionUtil.isEmpty(brands)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
- brands = brands.stream().filter(f->!"0".equals(f.getParentId())).collect(Collectors.toList());
|
|
|
+ brands = brands.stream().filter(f -> !"0".equals(f.getParentId())).collect(Collectors.toList());
|
|
|
// Map<String ,List<MultipleBrand>> brandMap = brands.stream().collect(Collectors.groupingBy(MultipleBrand::getParentId));
|
|
|
|
|
|
// Map<String, List<MultipleBrand>> groupedBrands = brands.stream()
|
|
|
// .collect(Collectors.groupingBy(brand -> brand.getParentId() + "_" + brand.getCheckCycle()));
|
|
|
for (MultipleBrand brandsVO : result) {
|
|
|
// 循环一级之后子级
|
|
|
- List<MultipleBrand> newbrands = null;
|
|
|
- if("NDKP".equals(brandsVO.getCheckCycle())){
|
|
|
+ List<MultipleBrand> newbrands = null;
|
|
|
+ if ("NDKP".equals(brandsVO.getCheckCycle())) {
|
|
|
|
|
|
- newbrands = brands.stream().filter(f->brandsVO.getOrganizationId().equals(f.getParentId()) && brandsVO.getCheckCycle().equals(f.getCheckCycle())).collect(Collectors.toList());
|
|
|
- }else{
|
|
|
- newbrands = brands.stream().filter(f->brandsVO.getOrganizationId().equals(f.getParentId()) && brandsVO.getCheckCycle().equals(f.getCheckCycle()) && brandsVO.getMonth().equals(f.getMonth())).collect(Collectors.toList());
|
|
|
+ newbrands = brands.stream().filter(f -> brandsVO.getOrganizationId().equals(f.getParentId()) && brandsVO.getCheckCycle().equals(f.getCheckCycle())).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ newbrands = brands.stream().filter(f -> brandsVO.getOrganizationId().equals(f.getParentId()) && brandsVO.getCheckCycle().equals(f.getCheckCycle()) && brandsVO.getMonth().equals(f.getMonth())).collect(Collectors.toList());
|
|
|
}
|
|
|
brandsVO.setChildren(newbrands);
|
|
|
}
|