Commit 646629fe authored by lixiaolei's avatar lixiaolei

submit

parent 4ed5004e
......@@ -17,6 +17,10 @@ import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.enums.BusinessType;
import com.dsk.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 项目详情Controller
......@@ -31,11 +35,17 @@ public class BusinessInfoController extends BaseController
@Autowired
private IBusinessInfoService businessInfoService;
/**
* 项目批量导入
*/
@PostMapping("/upload")
public AjaxResult batchUpload(@RequestParam(value="file",required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response){
return businessInfoService.batchUpload(file,response);
}
/**
* 查询所有项目名称(支持模糊查询)
*/
// @PreAuthorize("@ss.hasPermi('system:info:list')")
@PostMapping("/query/project")
public AjaxResult queryprojectName(@RequestBody BusinessListDto dto){
return AjaxResult.success(businessInfoService.selectProjectName(dto));
......@@ -44,7 +54,7 @@ public class BusinessInfoController extends BaseController
/**
* 查询项目列表
*/
// @PreAuthorize("@ss.hasPermi('system:info:list')")
// @PreAuthorize("@ss.hasPermi('system:business:list')")
@GetMapping("/list")
public TableDataInfo list(@RequestBody BusinessListDto dto)
{
......@@ -56,7 +66,7 @@ public class BusinessInfoController extends BaseController
/**
* 查询项目速览
*/
// @PreAuthorize("@ss.hasPermi('system:info:list')")
// @PreAuthorize("@ss.hasPermi('system:business:query')")
@GetMapping("/browse/{businessId}")
public AjaxResult browse(@PathVariable Integer id)
{
......@@ -66,7 +76,7 @@ public class BusinessInfoController extends BaseController
/**
* 获取项目建设内容
*/
// @PreAuthorize("@ss.hasPermi('system:info:query')")
// @PreAuthorize("@ss.hasPermi('system:business:query')")
@GetMapping(value = "/construction/{id}")
public AjaxResult getConstruction(@PathVariable("id") Integer id)
{
......@@ -76,8 +86,8 @@ public class BusinessInfoController extends BaseController
/**
* 删除项目列表
*/
// @PreAuthorize("@ss.hasPermi('system:info:remove')")
// @Log(title = "项目详情", businessType = BusinessType.DELETE)
// @PreAuthorize("@ss.hasPermi('system:business:remove')")
@Log(title = "项目管理", businessType = BusinessType.DELETE)
@DeleteMapping("/remove/{ids}")
public AjaxResult remove(@PathVariable(value = "ids",required=false) Long[] ids)
{
......@@ -87,8 +97,8 @@ public class BusinessInfoController extends BaseController
/**
* 新增项目详情
*/
// @PreAuthorize("@ss.hasPermi('system:info:add')")
// @Log(title = "项目详情", businessType = BusinessType.INSERT)
// @PreAuthorize("@ss.hasPermi('system:business:add')")
@Log(title = "项目管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@RequestBody BusinessAddDto dto)
{
......@@ -98,8 +108,8 @@ public class BusinessInfoController extends BaseController
/**
* 修改项目详情
*/
// @PreAuthorize("@ss.hasPermi('system:info:edit')")
// @Log(title = "项目详情", businessType = BusinessType.UPDATE)
// @PreAuthorize("@ss.hasPermi('system:business:edit')")
@Log(title = "项目管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
public AjaxResult edit(@RequestBody BusinessInfo businessInfo)
{
......
package com.dsk.system.domain;
import com.dsk.common.utils.StringUtils;
import lombok.Data;
/**
......@@ -60,6 +61,6 @@ public class BusinessAddDto {
private String customerId;
public Double getInvestmentAmount() {
return Double.parseDouble(investmentAmount);
return StringUtils.isEmpty(investmentAmount) ? 0 :Double.parseDouble(investmentAmount);
}
}
package com.dsk.system.domain;
import com.dsk.common.utils.StringUtils;
import lombok.Data;
/**
* @author lxl
* @Description:
* @Date 2023/6/1 下午 6:41
**/
@Data
public class BusinessExcelDto {
/**
* 项目名称
*/
private String projectName;
/**
* 投资估算(万元)
*/
private String investmentAmount;
/**
* 业主单位
*/
private String ownerCompany;
}
......@@ -2,6 +2,8 @@ package com.dsk.system.domain;
import lombok.Data;
import java.util.List;
/**
* @author lxl
* @Description:
......@@ -28,17 +30,17 @@ public class BusinessListDto {
/**
* 省id
*/
private Integer provinceId;
private List<Integer> provinceId;
/**
* 市id
*/
private Integer cityId;
private List<Integer> cityId;
/**
* 区id
*/
private Integer districtId;
private List<Integer> districtId;
/**
* 项目类型
......
......@@ -26,17 +26,17 @@ public class BusinessListVo {
/**
* 省
*/
private Integer provinceName;
private String provinceName;
/**
* 市
*/
private Integer cityName;
private String cityName;
/**
* 区
*/
private Integer districtName;
private String districtName;
/**
* 投资估算
......
......@@ -8,7 +8,9 @@ import com.dsk.system.domain.customer.dto.CustomerBusinessSearchDto;
import com.dsk.system.domain.customer.vo.CustomerBusinessListVo;
import com.dsk.system.domain.vo.BusinessBrowseVo;
import com.dsk.system.domain.vo.BusinessListVo;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
......@@ -56,6 +58,11 @@ public interface IBusinessInfoService
*/
List<String> selectProjectName(BusinessListDto dto);
/**
* 项目批量导入
*/
AjaxResult batchUpload(MultipartFile file, HttpServletResponse response);
/**
* 新增项目详情
*
......
package com.dsk.system.service.impl;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dsk.common.constant.HttpStatus;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.core.domain.entity.BusinessInfo;
import com.dsk.common.core.domain.entity.BusinessLabel;
import com.dsk.common.core.domain.entity.BusinessRelateCompany;
import com.dsk.common.core.domain.entity.BusinessUser;
import com.dsk.common.dtos.BusinessInfoDto;
import com.dsk.common.utils.DateUtils;
import com.dsk.common.utils.SecurityUtils;
import com.dsk.system.domain.BusinessExcelDto;
import com.dsk.system.domain.BusinessAddDto;
import com.dsk.system.domain.BusinessListDto;
import com.dsk.system.domain.customer.dto.CustomerBusinessSearchDto;
......@@ -24,11 +27,13 @@ import com.dsk.system.mapper.BusinessLabelMapper;
import com.dsk.system.mapper.BusinessRelateCompanyMapper;
import com.dsk.system.mapper.BusinessUserMapper;
import com.dsk.system.service.IBusinessInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
/**
* 项目详情Service业务层处理
......@@ -37,6 +42,7 @@ import javax.annotation.Resource;
* @date 2023-05-17
*/
@Service
@Slf4j
public class BusinessInfoServiceImpl implements IBusinessInfoService {
@Resource
private BusinessInfoMapper businessInfoMapper;
......@@ -46,6 +52,8 @@ public class BusinessInfoServiceImpl implements IBusinessInfoService {
private BusinessRelateCompanyMapper businessRelateCompanyMapper;
@Resource
private BusinessLabelMapper businessLabelMapper;
@Resource
private ReadBusinessInfoExcel readBusinessInfoExcel;
/**
* 查询项目详情
......@@ -97,6 +105,37 @@ public class BusinessInfoServiceImpl implements IBusinessInfoService {
return businessInfoMapper.selectProjectName(dto);
}
@Override
public AjaxResult batchUpload(MultipartFile file, HttpServletResponse response) {
int row=3;//起始行数
int rowSuccess=0;//成功条数
Integer errorCount=0;//失败条数
List<String> result = new LinkedList();//导入结果汇总
List<BusinessExcelDto> businessInfoList = readBusinessInfoExcel.getExcelInfo(file);
for (BusinessExcelDto businessInfo : businessInfoList) {
//查询已有的项目名称
Integer count = businessInfoMapper.selectCount(Wrappers.<BusinessInfo>lambdaQuery().eq(BusinessInfo::getProjectName, businessInfo.getProjectName()));
row++;
if(count > 0){
//如果存在,跳过该项目,不保存
result.add("第"+row+"行的"+businessInfo.getProjectName()+"的项目已存在,跳过该项目,保存下一条");
errorCount++;
}else {
//保存到数据库
BusinessAddDto businessAddDto = new BusinessAddDto();
BeanUtil.copyProperties(businessInfo,businessAddDto);
//获取当前登录用户id
businessAddDto.setUserId(SecurityUtils.getLoginUser().getUserId().intValue());
businessAddDto.setCompanyId(0);
AjaxResult add = insertBusinessInfo(businessAddDto);
if(add.get("code").equals(HttpStatus.SUCCESS))rowSuccess++;
}
}
result.add("导入项目成功条数"+rowSuccess);
result.add("导入项目失败条件"+errorCount);
return errorCount == businessInfoList.size() ? AjaxResult.error(String.join("\n",result),response) : AjaxResult.success(String.join("\n",result),response);
}
/**
* 新增项目详情
*
......@@ -106,6 +145,9 @@ public class BusinessInfoServiceImpl implements IBusinessInfoService {
@Override
@Transactional
public AjaxResult insertBusinessInfo(BusinessAddDto dto) {
//新增前查询是否已存在
BusinessInfo selectOne = businessInfoMapper.selectOne(Wrappers.<BusinessInfo>lambdaQuery().eq(BusinessInfo::getProjectName, dto.getProjectName()));
if(ObjectUtil.isNotEmpty(selectOne)) return AjaxResult.error("项目名称已存在");
//新增项目主信息
BusinessInfo businessInfo = new BusinessInfo();
BeanUtil.copyProperties(dto, businessInfo);
......
package com.dsk.system.service.impl;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import com.dsk.system.domain.BusinessExcelDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
* @author lxl
* @Description:
* @Date 2023/6/1 下午 4:30
**/
@Slf4j
@Service
public class ReadBusinessInfoExcel {
// 总行数
private int totalRows = 0;
// 总条数
private int totalCells = 0;
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public int getTotalCells() {
return totalCells;
}
public void setTotalCells(int totalCells) {
this.totalCells = totalCells;
}
/**
* 读EXCEL文件,获取信息集合
*
* @param mFile
* @return
*/
public List<BusinessExcelDto> getExcelInfo(MultipartFile mFile) {
String fileName = mFile.getOriginalFilename();// 获取文件名
try {
// 验证文件名是否合格
if (!validateExcel(fileName)) return null;
// 根据文件名判断文件是2003版本还是2007版本
boolean isExcel2003 = true;
if (isExcel2007(fileName)) isExcel2003 = false;
return createExcel(mFile.getInputStream(), isExcel2003);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 根据excel里面的内容读取信息
*
* @param is 输入流
* @param isExcel2003 excel是2003还是2007版本
* @return
*/
public List<BusinessExcelDto> createExcel(InputStream is, boolean isExcel2003) {
try {
Workbook wb = null;
// 当excel是2003时,创建excel2003
if (isExcel2003) {
wb = new HSSFWorkbook(is);
} else {
// 当excel是2007时,创建excel2007
wb = new XSSFWorkbook(is);
}
return readExcelValue(wb);// 读取Excel里面客户的信息
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 读取Excel内容
*
* @param wb
* @return
*/
private List<BusinessExcelDto> readExcelValue(Workbook wb) {
//得到第一个shell
Sheet sheet = wb.getSheetAt(0);
//得到Excel的行数
this.totalRows = sheet.getPhysicalNumberOfRows();
//得到Excel的列数(前提是有行数)
if (totalRows > 1 && sheet.getRow(0) != null) {
this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
}
// List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
ArrayList<BusinessExcelDto> list = new ArrayList<>();
//循环Excel行数
for (int r = 1; r < totalRows; r++) {
Row row = sheet.getRow(r);
if (row == null) {
continue;
}
//循环Excel的列
// Map<String, Object> map = new HashMap<String, Object>();
BusinessExcelDto businessExcelDto = new BusinessExcelDto();
for (int c = 3; c < this.totalCells; c++) {
Cell cell = row.getCell(c);
if (null != cell) {
if (c == 0) {
//如果是纯数字,比如你写的是25,cell.getNumericCellValue()获得是25.0,通过截取字符串去掉.0获得25
if (cell.getCellType() == CellType.NUMERIC) {
String name = String.valueOf(cell.getNumericCellValue());
businessExcelDto.setProjectName(name.substring(0, name.length() - 2 > 0 ? name.length() - 2 : 1));//项目名称
} else {
businessExcelDto.setProjectName(cell.getStringCellValue());//名称
}
} else if (c == 1) {
if (cell.getCellType() == CellType.NUMERIC) {
String company = String.valueOf(cell.getNumericCellValue());
businessExcelDto.setOwnerCompany(company.substring(0, company.length() - 2 > 0 ? company.length() - 2 : 1));//业主单位
} else {
businessExcelDto.setOwnerCompany(cell.getStringCellValue());//性别
}
} else if (c == 2) {
if (cell.getCellType() == CellType.NUMERIC) {
String amount = String.valueOf(cell.getNumericCellValue());
businessExcelDto.setInvestmentAmount(amount.substring(0, amount.length() - 2 > 0 ? amount.length() - 2 : 1));//投资估算(万元)
} else {
businessExcelDto.setInvestmentAmount(cell.getStringCellValue());
}
}
}
}
//添加到list
list.add(businessExcelDto);
}
return list;
}
/**
* 验证EXCEL文件
* @param filePath
* @return
*/
public boolean validateExcel(String filePath) {
if (filePath == null || !(isExcel2003(filePath) || isExcel2007(filePath))) {
log.info("文件不是excel格式");
return false;
}
return true;
}
// @描述:是否是2003的excel,返回true是2003
public static boolean isExcel2003(String filePath) {
return filePath.matches("^.+\\.(?i)(xls)$");
}
// @描述:是否是2007的excel,返回true是2007
public static boolean isExcel2007(String filePath) {
return filePath.matches("^.+\\.(?i)(xlsx)$");
}
}
......@@ -80,15 +80,6 @@
LEFT JOIN business_user bu on bu.business_id = i.id
LEFT JOIN sys_user u on u.user_id = f.user_id
<where>
<if test="provinceId != null">
and i.province_id = #{provinceId}
</if>
<if test="cityId != null">
and i.city_id = #{cityId}
</if>
<if test="districtId != null">
and i.district_id = #{districtId}
</if>
<if test="projectType != null and projectType != ''">
and i.project_type = #{projectType}
</if>
......@@ -116,6 +107,77 @@
<if test="deptId != null">
and bu.dept_id = #{deptId} and i.is_private = 1
</if>
<if test="provinceId != null and provinceId.size > 0 and cityId == null and districtId == null">
and i.province_id in
<foreach collection="provinceId" item="provinceId" open="(" separator="," close=")">
#{provinceId}
</foreach>
</if>
<if test="cityId != null and cityId.size > 0 and provinceId == null and districtId == null">
and i.city_id in
<foreach collection="cityId" item="cityId" open="(" separator="," close=")">
#{cityId}
</foreach>
</if>
<if test="districtId != null and districtId.size > 0 and provinceId == null and cityId == null">
and i.district_id in
<foreach collection="districtId" item="districtId" open="(" separator="," close=")">
#{districtId}
</foreach>
</if>
<if test="provinceId != null and provinceId.size > 0 and cityId != null and cityId.size > 0 and districtId == null">
and (
i.province_id in
<foreach collection="provinceId" item="provinceId" open="(" separator="," close=")">
#{provinceId}
</foreach>
or i.city_id in
<foreach collection="cityId" item="cityId" open="(" separator="," close=")">
#{cityId}
</foreach>
)
</if>
<if test="provinceId != null and provinceId.size > 0 and districtId != null and districtId.size > 0 and cityId == null">
and (
i.province_id in
<foreach collection="provinceId" item="provinceId" open="(" separator="," close=")">
#{provinceId}
</foreach>
or i.district_id in
<foreach collection="districtId" item="districtId" open="(" separator="," close=")">
#{districtId}
</foreach>
)
</if>
<if test="cityId != null and cityId.size > 0 and districtId != null and districtId.size > 0 and provinceId ==null">
and (
i.city_id in
<foreach collection="cityId" item="cityId" open="(" separator="," close=")">
#{cityId}
</foreach>
or i.district_id in
<foreach collection="districtId" item="districtId" open="(" separator="," close=")">
#{districtId}
</foreach>
)
</if>
<if test="provinceId != null and provinceId.size > 0 and cityId != null and cityId.size > 0 and districtId != null and districtId.size > 0">
and (
i.province_id in
<foreach collection="provinceId" item="provinceId" open="(" separator="," close=")">
#{provinceId}
</foreach>
or i.city_id in
<foreach collection="cityId" item="cityId" open="(" separator="," close=")">
#{cityId}
</foreach>
or i.district_id in
<foreach collection="districtId" item="districtId" open="(" separator="," close=")">
#{districtId}
</foreach>
)
</if>
</where>
GROUP BY i.id
ORDER BY i.create_time DESC
......
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