excel导入

master
litao 3 years ago
parent aea5a8bbd1
commit c811ee5f96
  1. 20
      src/main/java/org/springblade/modules/business/controller/ReportController.java
  2. 56
      src/main/java/org/springblade/modules/business/excel/AppealExcel.java
  3. 3
      src/main/java/org/springblade/modules/business/service/ILargeScreenService.java
  4. 107
      src/main/java/org/springblade/modules/business/service/impl/LargeScreenServiceImpl.java

@ -16,22 +16,31 @@
*/
package org.springblade.modules.business.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.TenantDS;
import org.springblade.core.tool.api.R;
import org.springblade.modules.business.excel.AppealExcel;
import org.springblade.modules.business.service.ILargeScreenService;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.UserImporter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
/**
* 控制器
@ -41,7 +50,6 @@ import java.util.Date;
@TenantDS
@RestController
@RequestMapping(CommonConstant.APPLICATION_NAME_BUSINESS + "/report")
//@RequestMapping("/report")
@AllArgsConstructor
@ApiSort(1)
@Api(value = "统计报表", tags = "统计报表接口")
@ -128,4 +136,14 @@ public class ReportController extends BladeController {
public R getAppealHot() {
return R.data(largeScreenService.getAppealHot());
}
/**
* 导入
*/
@PostMapping("importAppeal")
public R importAppeal(MultipartFile file) {
List<AppealExcel> excels = ExcelUtil.read(file, AppealExcel.class);
largeScreenService.importAppeal(excels);
return R.success("操作成功");
}
}

@ -0,0 +1,56 @@
package org.springblade.modules.business.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class AppealExcel implements Serializable {
private static final long serialVersionUID = 1L;
@ExcelProperty("矛盾纠纷类型")
private String disputeName;
@ExcelProperty("上报人")
private String username;
@ExcelProperty("上报时间")
private String firstRegTime;
// @ExcelProperty("事件来源")
// private String disputeName;
@ExcelProperty("事件等级")
private String disputeLevel;
@ExcelProperty("所属镇街")
private String streetId;
// @ExcelProperty("地点")
// private String disputeName;
// @ExcelProperty("坐标")
// private String disputeName;
@ExcelProperty("矛盾 纠纷详情")
private String problemDesc;
@ExcelProperty("状态")
private String status;
// @ExcelProperty("调解员")
// private String disputeName;
@ExcelProperty("所属部门")
private String handleDept;
}

@ -20,6 +20,7 @@ package org.springblade.modules.business.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.business.entity.Appeal;
import org.springblade.modules.business.entity.DataEntity;
import org.springblade.modules.business.excel.AppealExcel;
import java.text.ParseException;
import java.util.Date;
@ -52,4 +53,6 @@ public interface ILargeScreenService {
Map<String, List<DataEntity>> getAppealHot();
IPage<Appeal> getImmediateList(String streetId, IPage<Appeal> page);
void importAppeal(List<AppealExcel> excels);
}

@ -19,18 +19,27 @@ package org.springblade.modules.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springblade.common.cache.DictBizCache;
import org.springblade.common.enums.DictBizEnum;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.business.entity.Appeal;
import org.springblade.modules.business.entity.AppealVisitor;
import org.springblade.modules.business.entity.DataEntity;
import org.springblade.modules.business.excel.AppealExcel;
import org.springblade.modules.business.service.IAppealService;
import org.springblade.modules.business.service.IAppealVisitorService;
import org.springblade.modules.business.service.ILargeScreenService;
import org.springblade.modules.business.utils.LocalDateTimeUtils;
import org.springblade.modules.system.entity.Dict;
import org.springblade.modules.system.entity.DictBiz;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IDictBizService;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.DecimalFormat;
import java.text.ParseException;
@ -57,6 +66,8 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
private final IUserService userService;
private final IDictBizService dictBizService;
@Override
public Map<String, Object> getMediateFinish() {
Map<String, Object> map = new HashMap<>();
@ -197,11 +208,14 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
Map<String, Object> hashMap = new HashMap<>();
DecimalFormat df = new DecimalFormat("#0.0");
// 如果类型小于5,正常计算
if (list.size() <= 5) {
for (Map.Entry<String, Integer> entry : list) {
hashMap.put(entry.getKey(), df.format((double) entry.getValue() / (double) appeals.size() * 100) + "%");
}
} else {
}
// 如果类型大于5,前五正常计算,其余全部按照其他纠纷计算
else {
for (int i = 0; i < 5; i++) {
Map.Entry<String, Integer> entry = list.get(i);
hashMap.put(entry.getKey(), df.format((double) entry.getValue() / (double) appeals.size() * 100) + "%");
@ -212,7 +226,6 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
size += entry.getValue();
}
hashMap.put("其他纠纷", df.format((double) size / (double) appeals.size() * 100) + "%");
}
return hashMap;
@ -334,6 +347,96 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
return iPage;
}
@Override
@Transactional
public void importAppeal(List<AppealExcel> excels) {
if (CollectionUtils.isNotEmpty(excels)) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<Appeal> appeals = new ArrayList<>();
List<AppealVisitor> visitors = new ArrayList<>();
excels.forEach(excel -> {
if (StringUtils.isNotBlank(excel.getDisputeName())) {
Appeal appeal = Objects.requireNonNull(BeanUtil.copy(excel, Appeal.class));
appeal.setId(IdWorker.getId());
// 所属街道字典id
if (StringUtils.isNotBlank(excel.getStreetId())) {
List<DictBiz> street = dictBizService.list(new LambdaQueryWrapper<DictBiz>().eq(DictBiz::getCode, "street").like(DictBiz::getDictValue, excel.getStreetId()));
if (CollectionUtils.isNotEmpty(street)) {
appeal.setStreetId(street.get(0).getId());
}
}
// 纠纷字典id
if (StringUtils.isNotBlank(appeal.getDisputeName())) {
List<DictBiz> values = dictBizService.list(new LambdaQueryWrapper<DictBiz>().eq(DictBiz::getCode, "dispute_type").like(DictBiz::getDictValue, appeal.getDisputeName()));
if (CollectionUtils.isNotEmpty(values)) {
appeal.setDisputeId(values.get(0).getId());
}
}
// 数据录入时, 处理部门
if (StringUtils.isNotBlank(excel.getHandleDept())) {
List<User> users = userService.list(new LambdaQueryWrapper<User>().like(User::getName, excel.getHandleDept()));
if (CollectionUtils.isNotEmpty(users)) {
appeal.setHandleDept(users.get(0).getId());
}
}
// 纠纷等级(事件等级), 0:简单, 1:一般, 2:重大, 3:疑难
if (StringUtils.isNotBlank(excel.getDisputeLevel())) {
if ("简单".equals(excel.getDisputeLevel())) {
appeal.setDisputeLevel(0);
} else if ("一般".equals(excel.getDisputeLevel())) {
appeal.setDisputeLevel(1);
} else if ("重大".equals(excel.getDisputeLevel())) {
appeal.setDisputeLevel(2);
} else if ("疑难".equals(excel.getDisputeLevel())) {
appeal.setDisputeLevel(3);
}
}
// 首次登记时间
if (StringUtils.isNotBlank(excel.getFirstRegTime())) {
try {
appeal.setFirstRegTime(dateFormat.parse(excel.getFirstRegTime()));
} catch (ParseException e) {
e.printStackTrace();
}
}
// 诉求状态(办理状态)
if (StringUtils.isNotBlank(excel.getStatus())) {
if ("正在处理".equals(excel.getStatus())) {
appeal.setStatus(1);
} else if ("达成协议".equals(excel.getStatus())) {
appeal.setStatus(2);
} else if ("调解成功".equals(excel.getStatus()) || "完成归档".equals(excel.getStatus())) {
appeal.setStatus(3);
}
}
// 是否越级上报
appeal.setSkipGrant(0);
// 数据来源 0:系统添加, 1:数据导入
appeal.setSourceType(1);
// 上访人员
if (StringUtils.isNotBlank(excel.getUsername())) {
AppealVisitor visitor = new AppealVisitor();
visitor.setAppealId(appeal.getId());
visitor.setSort(1);
visitor.setUsername(excel.getUsername());
visitors.add(visitor);
}
appeals.add(appeal);
}
});
appealService.saveBatch(appeals);
appealVisitorService.saveBatch(visitors);
}
}
@Override
public Map<String, List<DataEntity>> getAppealHot() {
Map<String, List<DataEntity>> map = new HashMap();

Loading…
Cancel
Save