Commit d3d456cb authored by tianhongyang's avatar tianhongyang

Merge branch 'V20231129-中建一局二公司' of http://192.168.60.201/root/dsk-operate-sys...

Merge branch 'V20231129-中建一局二公司' of http://192.168.60.201/root/dsk-operate-sys into V20231129-中建一局二公司
parents a9f0d3ed 7f637f80
......@@ -3,6 +3,7 @@ package com.dsk.common.excel;
import cn.hutool.core.convert.Convert;
import com.dsk.common.annotation.Excel;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.exception.ServiceException;
import com.dsk.common.exception.UtilException;
import com.dsk.common.utils.DateUtils;
import com.dsk.common.utils.DictUtils;
......@@ -13,6 +14,7 @@ import com.dsk.common.utils.file.ImageUtils;
import com.dsk.common.utils.poi.ExcelHandlerAdapter;
import com.dsk.common.utils.poi.ExcelUtil;
import com.dsk.common.utils.reflect.ReflectUtils;
import org.apache.commons.collections4.list.CursorableLinkedList;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
......@@ -40,6 +42,8 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* Excel相关处理
......@@ -207,6 +211,7 @@ public class ExcelUtils<T> {
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol));
}
}
public void createExportMessage() {
if (dateStatus) {
subMergedFirstRowNum++;
......@@ -226,6 +231,7 @@ public class ExcelUtils<T> {
rownum++;
}
}
public void createExportDate() {
if (dateStatus) {
subMergedFirstRowNum++;
......@@ -330,8 +336,8 @@ public class ExcelUtils<T> {
exportExcel(response);
}
public ByteArrayOutputStream exportExcel( List<T> list, String sheetName, String title, boolean dateStatus) {
ByteArrayOutputStream ba= new ByteArrayOutputStream();
public ByteArrayOutputStream exportExcel(List<T> list, String sheetName, String title, boolean dateStatus) {
ByteArrayOutputStream ba = new ByteArrayOutputStream();
this.init(list, sheetName, title, Excel.Type.EXPORT, dateStatus);
try {
writeSheet();
......@@ -356,11 +362,11 @@ public class ExcelUtils<T> {
* @param dateStatus 是否添加导出时间
* @return
*/
public String localInit( List<T> list, String sheetName, String title, boolean dateStatus) {
public String localInit(List<T> list, String sheetName, String title, boolean dateStatus) {
String fileName = title + "-" + System.currentTimeMillis() + ".xlsx";
this.init(list, sheetName, title, Excel.Type.EXPORT, dateStatus);
writeSheet();
try (FileOutputStream fileOutputStream = new FileOutputStream(FILE_PATH.concat(fileName))){
try (FileOutputStream fileOutputStream = new FileOutputStream(FILE_PATH.concat(fileName))) {
wb.write(fileOutputStream);
return fileName;
} catch (Exception e) {
......@@ -1384,113 +1390,148 @@ public class ExcelUtils<T> {
public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception {
this.type = Excel.Type.IMPORT;
this.wb = WorkbookFactory.create(is);
List<T> list = new ArrayList<T>();
List<T> resList = new ArrayList<T>();
// 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
if (sheet == null) {
throw new IOException("文件sheet不存在");
}
boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook);
Map<String, PictureData> pictures;
if (isXSSFWorkbook) {
pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb);
} else {
pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb);
}
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
int rows = sheet.getLastRowNum();
if (rows > 0) {
// 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<String, Integer>();
// 获取表头
Row heard = sheet.getRow(titleNum);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) {
Cell cell = heard.getCell(i);
if (ObjectUtils.isEmpty(cell)) {
cellMap.put(null, i);
} else {
String value = this.getCellValue(heard, i).toString();
cellMap.put(value, i);
}
dealwithSheet(resList, sheet, titleNum);
return resList;
}
/**
* 对excel表单所有表格转换成list
*
* @param titleNum 标题占用行数
* @param is 输入流
* @return 转换后集合
*/
public List<T> importExcelAllSheet(InputStream is, int titleNum) throws Exception {
this.type = Excel.Type.IMPORT;
this.wb = WorkbookFactory.create(is);
List<T> resList = new ArrayList<>();
int sheetCount = wb.getNumberOfSheets();
System.out.println("工作表个数为:" + sheetCount);
IntStream.rangeClosed(0, sheetCount - 1).parallel().forEach(sheetNum -> {
Sheet sheet = wb.getSheetAt(sheetNum);
dealwithSheet(resList, sheet, titleNum);
});
return resList;
}
private void dealwithSheet(List<T> resList, Sheet sheet, int titleNum) {
try {
if (sheet == null) {
throw new IOException(sheet.getSheetName() + "为空表!");
}
// 有数据时才处理 得到类的所有field.
List<Object[]> fields = this.getFields();
Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
for (Object[] objects : fields) {
Excel attr = (Excel) objects[1];
Integer column = cellMap.get(attr.name());
if (column != null) {
fieldsMap.put(column, objects);
}
boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook);
Map<String, PictureData> pictures;
if (isXSSFWorkbook) {
pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb);
} else {
pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb);
}
for (int i = titleNum + 1; i <= rows; i++) {
// 从第2行开始取数据,默认第一行是表头.
Row row = sheet.getRow(i);
// 判断当前行是否是空行
if (isRowEmpty(row)) {
continue;
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
int rows = sheet.getLastRowNum();
if (rows > 0) {
// 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<String, Integer>();
// 获取表头
Row heard = sheet.getRow(titleNum);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) {
Cell cell = heard.getCell(i);
if (ObjectUtils.isEmpty(cell)) {
cellMap.put(null, i);
} else {
String value = this.getCellValue(heard, i).toString();
cellMap.put(value, i);
}
}
T entity = null;
for (Map.Entry<Integer, Object[]> entry : fieldsMap.entrySet()) {
Object val = this.getCellValue(row, entry.getKey());
// 如果不存在实例则新建.
entity = (entity == null ? clazz.newInstance() : entity);
// 从map中得到对应列的field.
Field field = (Field) entry.getValue()[0];
Excel attr = (Excel) entry.getValue()[1];
// 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType();
if (String.class == fieldType) {
String s = Convert.toStr(val);
if (StringUtils.endsWith(s, ".0")) {
val = StringUtils.substringBefore(s, ".0");
} else {
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
if (StringUtils.isNotEmpty(dateFormat)) {
val = parseDateToStr(dateFormat, val);
// 有数据时才处理 得到类的所有field.
List<Object[]> fields = this.getFields();
Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
for (Object[] objects : fields) {
Excel attr = (Excel) objects[1];
Integer column = cellMap.get(attr.name());
if (column != null) {
fieldsMap.put(column, objects);
}
}
for (int i = titleNum + 1; i <= rows; i++) {
// 从第2行开始取数据,默认第一行是表头.
Row row = sheet.getRow(i);
// 判断当前行是否是空行
if (isRowEmpty(row)) {
continue;
}
T entity = null;
for (Map.Entry<Integer, Object[]> entry : fieldsMap.entrySet()) {
Object val = this.getCellValue(row, entry.getKey());
// 如果不存在实例则新建.
entity = (entity == null ? clazz.newInstance() : entity);
// 从map中得到对应列的field.
Field field = (Field) entry.getValue()[0];
Excel attr = (Excel) entry.getValue()[1];
// 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType();
if (String.class == fieldType) {
String s = Convert.toStr(val);
if (StringUtils.endsWith(s, ".0")) {
val = StringUtils.substringBefore(s, ".0");
} else {
val = Convert.toStr(val);
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
if (StringUtils.isNotEmpty(dateFormat)) {
val = parseDateToStr(dateFormat, val);
} else {
val = Convert.toStr(val);
}
}
} else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
val = Convert.toInt(val);
} else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
val = Convert.toLong(val);
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
val = Convert.toDouble(val);
} else if (Float.TYPE == fieldType || Float.class == fieldType) {
val = Convert.toFloat(val);
} else if (BigDecimal.class == fieldType) {
val = Convert.toBigDecimal(val);
} else if (Date.class == fieldType) {
if (val instanceof String) {
val = DateUtils.parseDate(val);
} else if (val instanceof Double) {
val = DateUtil.getJavaDate((Double) val);
}
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
val = Convert.toBool(val, false);
}
} else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
val = Convert.toInt(val);
} else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
val = Convert.toLong(val);
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
val = Convert.toDouble(val);
} else if (Float.TYPE == fieldType || Float.class == fieldType) {
val = Convert.toFloat(val);
} else if (BigDecimal.class == fieldType) {
val = Convert.toBigDecimal(val);
} else if (Date.class == fieldType) {
if (val instanceof String) {
val = DateUtils.parseDate(val);
} else if (val instanceof Double) {
val = DateUtil.getJavaDate((Double) val);
if (!ObjectUtils.isEmpty(fieldType)) {
String propertyName = field.getName();
if (StringUtils.isNotEmpty(attr.targetAttr())) {
propertyName = field.getName() + "." + attr.targetAttr();
} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
} else if (StringUtils.isNotEmpty(attr.dictType())) {
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
} else if (!attr.handler().equals(ExcelHandlerAdapter.class)) {
val = dataFormatHandlerAdapter(val, attr);
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
val = Convert.toBool(val, false);
}
if (!ObjectUtils.isEmpty(fieldType)) {
String propertyName = field.getName();
if (StringUtils.isNotEmpty(attr.targetAttr())) {
propertyName = field.getName() + "." + attr.targetAttr();
} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
} else if (StringUtils.isNotEmpty(attr.dictType())) {
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
} else if (!attr.handler().equals(ExcelHandlerAdapter.class)) {
val = dataFormatHandlerAdapter(val, attr);
}
ReflectUtils.invokeSetter(entity, propertyName, val);
synchronized (resList){
resList.add(entity);
}
}
list.add(entity);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
......@@ -20,22 +20,26 @@ public interface CbProjectConstants {
* 成本阶段:转固
*/
Integer CB_STAGE_TO_SOLID = 2;
/**
* 项目文件状态:未上传
*/
Integer PROJECT_FILE_STATUS_NOT_UPLOAD = 0;
/**
* 项目文件状态:待解析
*/
Integer PROJECT_FILE_STATUS_NOT_PARSE = 0;
Integer PROJECT_FILE_STATUS_NOT_PARSE = 1;
/**
* 项目文件状态:解析中
*/
Integer PROJECT_FILE_STATUS_PARSING = 1;
Integer PROJECT_FILE_STATUS_PARSING = 2;
/**
* 项目文件状态:解析成功
*/
Integer PROJECT_FILE_STATUS_PARSE_SUCCESS = 2;
Integer PROJECT_FILE_STATUS_PARSE_SUCCESS = 3;
/**
* 项目文件状态:解析失败
*/
Integer PROJECT_FILE_STATUS_PARSE_FAIL = 3;
Integer PROJECT_FILE_STATUS_PARSE_FAIL = 4;
/**
* 删除状态:未删除
*/
......@@ -44,5 +48,43 @@ public interface CbProjectConstants {
* 删除状态:已删除
*/
Integer DELETE_FLAG_NOT_EXIST = 2;
/**
* 是否获取项目详情:是
*/
Integer IS_GET_PROJECT_DETAIL = 0;
/**
* 是否获取项目详情:否
*/
Integer NOT_GET_PROJECT_DETAIL = 1;
//成本类型(0:直接费成本、1:工料汇总、2:措施项目、3:其他项目、4:现场经费、5:成本汇总、6:未确定)
/**
* 成本类型:直接费成本
*/
Integer CB_TYPE_DIRECT_EXPENSE = 0;
/**
* 成本类型:工料汇总
*/
Integer CB_TYPE_QUANTITY_SUMMARY = 1;
/**
* 成本类型:措施项目
*/
Integer CB_TYPE_MEASURE_PROJECT = 2;
/**
* 成本类型:其他项目
*/
Integer CB_TYPE_OTHER_PROJECT = 3;
/**
* 成本类型:现场经费
*/
Integer CB_TYPE_SCENE_EXPENSE = 4;
/**
* 成本类型:成本汇总
*/
Integer CB_TYPE_ACCOUNT_SUMMARY = 5;
/**
* 成本类型:未确定
*/
Integer CB_TYPE_NOT_CONFIRM = 6;
}
......@@ -2,11 +2,23 @@ package com.dsk.cscec.controller;
import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.R;
import com.dsk.common.excel.ExcelUtils;
import com.dsk.common.exception.ServiceException;
import com.dsk.cscec.domain.CbQuantitySummary;
import com.dsk.cscec.domain.bo.CbProjectBaseBo;
import com.dsk.cscec.service.ICbQuantitySummaryService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dsk.system.domain.vo.SysUserImportVo;
import lombok.RequiredArgsConstructor;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.reflect.generics.tree.Tree;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
/**
* 成本-工料汇总基本表(CbQuantitySummary)表控制层
......@@ -15,14 +27,50 @@ import javax.annotation.Resource;
* @since 2024-02-05 11:06:56
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/cb/quantity/summary")
public class CbQuantitySummaryController extends BaseController {
private final ICbQuantitySummaryService baseService;
/**
* 工料汇总科目树
* @return
*/
@GetMapping(value = "/subjectTree")
public R<Map<String, Object>> subjectTree(@PathVariable CbProjectBaseBo bo){
return R.ok(baseService.subjectTree(bo));
}
/**
* 已记录月份集合
*/
@GetMapping(value = "/monthList")
public R<List<String>> monthList(@PathVariable CbProjectBaseBo bo){
return R.ok(baseService.monthList(bo));
}
/**
* 服务对象
* 数据导入
*/
@Resource
private ICbQuantitySummaryService baseService;
@PostMapping(value = "/importData")
public R<Void> importFile(@RequestPart("file") MultipartFile file) throws Exception {
//识别Excel内容
List<CbQuantitySummary> importList = new ExcelUtils<>(CbQuantitySummary.class).importExcelAllSheet(file.getInputStream(), 1);
if (importList.isEmpty()) {
throw new ServiceException("表格中不存在待导入数据!");
}
importList = importList.stream().parallel()
.filter(item -> !ObjectUtils.isEmpty(item.getCbName()))
.peek(item -> {
item.setProjectId(1L);
item.setCbStage(0);
}).collect(Collectors.toList());
if (importList.isEmpty()) {
throw new ServiceException("表格中不存在有效数据数据!");
}
return toAjax(baseService.saveBatch(importList));
}
}
......@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import com.dsk.common.annotation.Excel;
import lombok.Data;
/**
......@@ -30,6 +31,7 @@ public class CbQuantitySummary implements Serializable {
/**
* 序号
*/
@Excel(name = "序号")
private String number;
/**
* 成本阶段(0:标前成本 1:标后成本 2:转固成本)
......@@ -38,6 +40,7 @@ public class CbQuantitySummary implements Serializable {
/**
* 成本科目名称(合约规划)
*/
@Excel(name = "成本科目")
private String cbSubjectName;
/**
* 成本科目编号(合约规划编号)
......@@ -46,66 +49,82 @@ public class CbQuantitySummary implements Serializable {
/**
* 公司编码
*/
@Excel(name = "编码")
private String companyNo;
/**
* 集团编码
*/
@Excel(name = "集团编码")
private String orgNo;
/**
* 成本名称
*/
@Excel(name = "名称")
private String cbName;
/**
* 工作内容
*/
@Excel(name = "工作内容")
private String jobContent;
/**
* 计算规则
*/
@Excel(name = "计算规则")
private String calculationRule;
/**
* 计量单位
*/
@Excel(name = "单位")
private String unit;
/**
* 材料说明
*/
@Excel(name = "甲供材料说明")
private String materialDescription;
/**
* 指导价格
*/
@Excel(name = "指导价格")
private String guidePrice;
/**
* 投标选用单价(不含税)
*/
@Excel(name = "投标选用单价(不含税)")
private Double bidUnitPrice;
/**
* 单价差额
*/
@Excel(name = "单价差额")
private Double unitPriceDifference;
/**
* 数量
*/
@Excel(name = "数量")
private Double quantity;
/**
* 合价(不含税)
* 合价(不含税)
*/
@Excel(name = "合价(不含税)")
private Double combinedPrice;
/**
* 合价(含税)
*/
@Excel(name = "合价(含税)")
private Double combinedPriceTax;
/**
* 品牌名称
*/
@Excel(name = "品牌名称")
private String brandName;
/**
* 投标选用来源
*/
@Excel(name = "投标选用来源")
private String bidSource;
/**
* 备注
*/
@Excel(name = "备注")
private String remark;
/**
* 创建时间
......
package com.dsk.cscec.domain.bo;
import lombok.Data;
/**
* 项目成本基础参数
*
* @Author lcl
* @Data 2024/2/6 9:24
*/
@Data
public class CbProjectBaseBo {
/**
* 项目id
*/
private Long projectId;
/**
* 成本阶段(0:标前成本 1:标后成本 2:转固成本)
*/
private Integer cbStage;
}
package com.dsk.cscec.listener;
import cn.dev33.satoken.secure.BCrypt;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.dsk.common.excel.ExcelListener;
import com.dsk.common.excel.ExcelResult;
import com.dsk.common.exception.ServiceException;
import com.dsk.common.helper.LoginHelper;
import com.dsk.common.utils.ValidatorUtils;
import com.dsk.common.utils.spring.SpringUtils;
import com.dsk.cscec.domain.vo.ProjectMeasuresImportVo;
import com.dsk.system.domain.SysUser;
import com.dsk.system.domain.vo.SysUserImportVo;
import com.dsk.system.service.ISysConfigService;
import com.dsk.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* 系统用户自定义导入
*
* @author Lion Li
*/
@Slf4j
public class ProjectCostMeasureImportListener extends AnalysisEventListener<ProjectMeasuresImportVo> implements ExcelListener<ProjectMeasuresImportVo> {
// private final ISysUserService userService;
// private final String password;
private final Boolean isUpdateSupport;
private final String operName;
private int successNum = 0;
private int failureNum = 0;
private final StringBuilder successMsg = new StringBuilder();
private final StringBuilder failureMsg = new StringBuilder();
public ProjectCostMeasureImportListener(Boolean isUpdateSupport) {
// String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword");
// this.userService = SpringUtils.getBean(ISysUserService.class);
// this.password = BCrypt.hashpw(initPassword);
this.isUpdateSupport = isUpdateSupport;
this.operName = LoginHelper.getUsername();
}
@Override
public void invoke(ProjectMeasuresImportVo userVo, AnalysisContext context) {
// SysUser user = this.userService.selectUserByUserName(userVo.getUserName());
// try {
// // 验证是否存在这个用户
// if (ObjectUtil.isNull(user)) {
// user = BeanUtil.toBean(userVo, SysUser.class);
// ValidatorUtils.validate(user);
// user.setPassword(password);
// user.setCreateBy(operName);
// userService.insertUser(user);
// successNum++;
// successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
// } else if (isUpdateSupport) {
// Long userId = user.getUserId();
// user = BeanUtil.toBean(userVo, SysUser.class);
// user.setUserId(userId);
// ValidatorUtils.validate(user);
// userService.checkUserAllowed(user);
// userService.checkUserDataScope(user.getUserId());
// user.setUpdateBy(operName);
// userService.updateUser(user);
// successNum++;
// successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 更新成功");
// } else {
// failureNum++;
// failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(user.getUserName()).append(" 已存在");
//package com.dsk.cscec.listener;
//
//import cn.dev33.satoken.secure.BCrypt;
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.util.ObjectUtil;
//import com.alibaba.excel.context.AnalysisContext;
//import com.alibaba.excel.event.AnalysisEventListener;
//import com.dsk.common.excel.ExcelListener;
//import com.dsk.common.excel.ExcelResult;
//import com.dsk.common.exception.ServiceException;
//import com.dsk.common.helper.LoginHelper;
//import com.dsk.common.utils.ValidatorUtils;
//import com.dsk.common.utils.spring.SpringUtils;
//import com.dsk.cscec.domain.vo.ProjectMeasuresImportVo;
//import com.dsk.system.domain.SysUser;
//import com.dsk.system.domain.vo.SysUserImportVo;
//import com.dsk.system.service.ISysConfigService;
//import com.dsk.system.service.ISysUserService;
//import lombok.extern.slf4j.Slf4j;
//
//import java.util.List;
//
///**
// * 系统用户自定义导入
// *
// * @author Lion Li
// */
//@Slf4j
//public class ProjectCostMeasureImportListener extends AnalysisEventListener<ProjectMeasuresImportVo> implements ExcelListener<ProjectMeasuresImportVo> {
//
//// private final ISysUserService userService;
//
//// private final String password;
//
// private final Boolean isUpdateSupport;
//
// private final String operName;
//
// private int successNum = 0;
// private int failureNum = 0;
// private final StringBuilder successMsg = new StringBuilder();
// private final StringBuilder failureMsg = new StringBuilder();
//
// public ProjectCostMeasureImportListener(Boolean isUpdateSupport) {
//// String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword");
//// this.userService = SpringUtils.getBean(ISysUserService.class);
//// this.password = BCrypt.hashpw(initPassword);
// this.isUpdateSupport = isUpdateSupport;
// this.operName = LoginHelper.getUsername();
// }
//
// @Override
// public void invoke(ProjectMeasuresImportVo userVo, AnalysisContext context) {
//// SysUser user = this.userService.selectUserByUserName(userVo.getUserName());
//// try {
//// // 验证是否存在这个用户
//// if (ObjectUtil.isNull(user)) {
//// user = BeanUtil.toBean(userVo, SysUser.class);
//// ValidatorUtils.validate(user);
//// user.setPassword(password);
//// user.setCreateBy(operName);
//// userService.insertUser(user);
//// successNum++;
//// successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
//// } else if (isUpdateSupport) {
//// Long userId = user.getUserId();
//// user = BeanUtil.toBean(userVo, SysUser.class);
//// user.setUserId(userId);
//// ValidatorUtils.validate(user);
//// userService.checkUserAllowed(user);
//// userService.checkUserDataScope(user.getUserId());
//// user.setUpdateBy(operName);
//// userService.updateUser(user);
//// successNum++;
//// successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 更新成功");
//// } else {
//// failureNum++;
//// failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(user.getUserName()).append(" 已存在");
//// }
//// } catch (Exception e) {
//// failureNum++;
//// String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
//// failureMsg.append(msg).append(e.getMessage());
//// log.error(msg, e);
//// }
// }
//
// @Override
// public void doAfterAllAnalysed(AnalysisContext context) {
//
// }
//
// @Override
// public ExcelResult<ProjectMeasuresImportVo> getExcelResult() {
// return new ExcelResult<ProjectMeasuresImportVo>() {
//
// @Override
// public String getAnalysis() {
// if (failureNum > 0) {
// failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
// throw new ServiceException(failureMsg.toString());
// } else {
// successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
// }
// return successMsg.toString();
// }
// } catch (Exception e) {
// failureNum++;
// String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
// failureMsg.append(msg).append(e.getMessage());
// log.error(msg, e);
// }
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
@Override
public ExcelResult<ProjectMeasuresImportVo> getExcelResult() {
return new ExcelResult<ProjectMeasuresImportVo>() {
@Override
public String getAnalysis() {
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new ServiceException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
@Override
public List<ProjectMeasuresImportVo> getList() {
return null;
}
@Override
public List<String> getErrorList() {
return null;
}
};
}
}
//
// @Override
// public List<ProjectMeasuresImportVo> getList() {
// return null;
// }
//
// @Override
// public List<String> getErrorList() {
// return null;
// }
// };
// }
//}
......@@ -2,6 +2,12 @@ package com.dsk.cscec.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dsk.cscec.domain.CbQuantitySummary;
import com.dsk.cscec.domain.bo.CbProjectBaseBo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 成本-工料汇总基本表(CbQuantitySummary)表数据库访问层
......@@ -11,5 +17,10 @@ import com.dsk.cscec.domain.CbQuantitySummary;
*/
public interface CbQuantitySummaryMapper extends BaseMapper<CbQuantitySummary> {
List<Map<String, Object>> selectSubject(CbProjectBaseBo bo);
int selectOtherSubjectCount(CbProjectBaseBo bo);
}
......@@ -2,6 +2,10 @@ package com.dsk.cscec.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dsk.cscec.domain.CbQuantitySummary;
import com.dsk.cscec.domain.bo.CbProjectBaseBo;
import java.util.List;
import java.util.Map;
/**
* 成本-工料汇总基本表(CbQuantitySummary)表服务接口
......@@ -11,5 +15,9 @@ import com.dsk.cscec.domain.CbQuantitySummary;
*/
public interface ICbQuantitySummaryService extends IService<CbQuantitySummary> {
Map<String, Object> subjectTree(CbProjectBaseBo bo);
List<String> monthList(CbProjectBaseBo bo);
}
package com.dsk.cscec.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsk.cscec.mapper.CbQuantitySummaryMapper;
import com.dsk.cscec.domain.CbQuantitySummary;
import com.dsk.cscec.domain.bo.CbProjectBaseBo;
import com.dsk.cscec.mapper.CbQuantitySummaryMapper;
import com.dsk.cscec.service.ICbQuantitySummaryService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 成本-工料汇总基本表(CbQuantitySummary)表服务实现类
......@@ -15,5 +22,27 @@ import org.springframework.stereotype.Service;
@Service
public class CbQuantitySummaryServiceImpl extends ServiceImpl<CbQuantitySummaryMapper, CbQuantitySummary> implements ICbQuantitySummaryService {
@Override
public Map<String, Object> subjectTree(CbProjectBaseBo bo) {
Map<String, Object> resultMap = new HashMap<>();
List<Map<String, Object>> list = baseMapper.selectSubject(bo);
if (!ObjectUtils.isEmpty(list)) {
Map<String, Map<String, Map<String, List<Map<String, Object>>>>> map = list.stream().collect(
Collectors.groupingBy(item -> item.get("one").toString(),
Collectors.groupingBy(item -> item.get("two").toString(),
Collectors.groupingBy(item -> item.get("three").toString()))));
resultMap.put("房建类成本科目", map);
}
int otherSubjectCount = baseMapper.selectOtherSubjectCount(bo);
if (otherSubjectCount > 0) {
resultMap.put("未归类项目", "other");
}
return resultMap;
}
@Override
public List<String> monthList(CbProjectBaseBo bo) {
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dsk.cscec.mapper.CbQuantitySummaryMapper">
<select id="selectSubject" resultType="java.util.Map">
select
cs1.cb_subject_name as one, cs2.cb_subject_name as two, cs3.cb_subject_name as three
from cb_subject cs1
join cb_subject cs2 on (cs2.cb_subject_no like concat(cs1.cb_subject_no,'%') and cs2.`level` = 2 )
join cb_subject cs3 on (cs3.cb_subject_no like concat(cs2.cb_subject_no,'%') and cs3.`level` = 3 )
join cb_quantity_summary cqs on (cqs.cb_subject_name = cs3.cb_subject_name and cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage})
where cs1.`level` = 1
group by cs1.cb_subject_name,cs2.cb_subject_name,cs3.cb_subject_name
</select>
<select id="selectOtherSubjectCount" resultType="java.lang.Integer">
select
count(cqs.id)
from cb_quantity_summary cqs
left join cb_subject cs1 on cqs.cb_subject_name = cs1.cb_subject_name
where cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} and cs1.id is null
</select>
</mapper>
\ No newline at end of file
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