EasyExcel 行业清单导入 及 接口调整

EasyExcel 企业导入 30%
This commit is contained in:
79493 2022-12-16 11:56:22 +08:00
parent a4167a5ad6
commit 543e337533
23 changed files with 268 additions and 121 deletions

View File

@ -65,4 +65,6 @@ public interface BaseInClassMapper {
/*最小工作单元行业*/
List<BaseInClass> workIndustry();
BaseInClass selectBaseInClassByName(@Param("industryClassName") String industryClassName);
}

View File

@ -2,6 +2,7 @@ package com.rzyc.mapper.ent;
import com.rzyc.model.ent.InEntList;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rzyc.model.ent.InListItem;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -25,4 +26,12 @@ public interface InEntListMapper extends BaseMapper<InEntList> {
* */
List<InEntList> selectByEnterpriseId(@Param("enterpriseId") String enterpriseId);
/**
* 插入清单项到企业清单项表
* @param inListItems 行业清单项
* @return int
* */
int insertList(@Param("list")List<InEntList>inListItems);
}

View File

@ -19,14 +19,15 @@ import java.util.List;
@Repository
public interface InListItemMapper extends BaseMapper<InListItem> {
List<String> SelectContents();
List<InListItem> SelectContents(@Param("industryId") String industryId,@Param("listId")String listId);
/*通过行业查询清单信息*/
List<InListItem> findByIndustryId(@Param("industryId") String industryId);
/**
*
*
*导入清单项
* @param list
* @return int
* */
int insertItem(List<EasyExcelInList>easyExcelInLists);
int insertItem(@Param("list") List<EasyExcelInList>list);
}

View File

@ -19,7 +19,7 @@ import java.util.List;
@Repository
public interface InListMapper extends BaseMapper<InList> {
/*查询所有*/
List<InList> findAll();
List<InList> findAll(String industry);
/**

View File

@ -0,0 +1,35 @@
package com.rzyc.model.EasyExcel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@EqualsAndHashCode
/**
* EasyExcel导入企业
* @author Xuwanxin
* @date 2022/12/16
* */
public class EasyExcelEnterprise {
private String address;
private String industry;
private String legalPerson;
private String legalPersonPhone;
private String safeChangePerson;
private String safeChangePersonPhone;
private Integer staffNumber;
private String dateOfIncorporation;
private String businessScope;
}

View File

@ -8,6 +8,11 @@ import lombok.Setter;
@Getter
@Setter
@EqualsAndHashCode
/**
* EasyExcel导入行业清单
* @author Xuwanxin
* @date 2022/12/15
* */
public class EasyExcelInList {
private String industry;
private String listName;
@ -16,6 +21,9 @@ public class EasyExcelInList {
private Integer standard;
private Integer frequency;
private String remark;
private Integer sortId;
private String industryId;
private String listId;
private String itemId;
}

View File

@ -16,10 +16,20 @@ public class InListAddDto {
@TableId("name")
private String name;
@ApiModelProperty(value = "行业id")
private String industryId;
@ApiModelProperty(value = "清单排序")
@TableId("sort_id")
private Integer sortId;
public String getIndustryId() {
return industryId;
}
public void setIndustryId(String industryId) {
this.industryId = industryId;
}
public String getName() {
return name;
}

View File

@ -5,46 +5,46 @@ import io.swagger.annotations.ApiModelProperty;
public class InListItemDto {
@ApiModelProperty(value = "清单项id")
private String item_id;
private String itemId;
@ApiModelProperty(value = "行业清单id")
private String list_id;
private String listId;
@ApiModelProperty(value = "行业id")
private String industry_id;
private String industryId;
@ApiModelProperty(value = "清单内容")
private String item_content;
private String itemContent;
public String getItem_content() {
return item_content;
public String getItemContent() {
return itemContent;
}
public void setItem_content(String item_content) {
this.item_content = item_content;
public void setItemContent(String itemContent) {
this.itemContent = itemContent;
}
public String getItem_id() {
return item_id;
public String getItemId() {
return itemId;
}
public void setItem_id(String item_id) {
this.item_id = item_id;
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getList_id() {
return list_id;
public String getListId() {
return listId;
}
public void setList_id(String list_id) {
this.list_id = list_id;
public void setListId(String listId) {
this.listId = listId;
}
public String getIndustry_id() {
return industry_id;
public String getIndustryId() {
return industryId;
}
public void setIndustry_id(String industry_id) {
this.industry_id = industry_id;
public void setIndustryId(String industryId) {
this.industryId = industryId;
}
}

View File

@ -360,7 +360,7 @@
</select>
<select id="findAll" resultMap="BaseResultMap">
select * from BaseInClass bc
select * from BaseInClass bc where hidden = 1
</select>
<select id="findByInType" resultMap="BaseResultMap">
@ -455,4 +455,11 @@
WHERE bc.`in_type` = 2 AND bc.`SuperInId` IS NOT NULL AND bc.`SuperInId` != ''
</select>
<select id="selectBaseInClassByName" resultMap="BaseResultMap">
SELECT * FROM `BaseInClass` bc
WHERE bc.`IndustryClassName` = #{industryClassName}
limit 1
</select>
</mapper>

View File

@ -30,8 +30,26 @@
item_basis, item_proof, item_law, sort_id,del_state, create_time, create_by, modify_time, modify_by
</sql>
<select id="selectByEnterpriseId" resultMap="BaseResultMap">
select * from in_ent_list where enterprise_id = #{enterpriseId}
</select>
<insert id="insertList">
insert into in_ent_list (ent_list_id,item_id,list_id,item_title,item_content,standard,frequency,sort_id,del_state,create_time,create_by,enterprise_id)values
<foreach collection="list" item="list" separator=",">
(#{list.entListId},
#{list.itemId},
#{list.listId},
#{list.itemTitle},
#{list.itemContent},
#{list.standard},
#{list.frequency},
#{list.sortId},
1,
#{list.createTime},
#{list.createBy},
#{list.enterpriseId})
</foreach>
</insert>
</mapper>

View File

@ -30,11 +30,29 @@ item_basis, item_proof, item_law, sort_id, del_state,create_time, create_by, mod
</sql>
<insert id="insertItem">
insert into in_list_item (item_id,list_id,industry_id, item_title,item_content,standard,frequency, del_state,sort_id)values
<foreach collection="list" item="list" separator=",">
(#{list.itemId},
#{list.listId},
#{list.industryId},
#{list.listItem},
#{list.listContent},
#{list.standard},
#{list.frequency},
1,
#{list.sortId})
</foreach>
</insert>
<select id="SelectContents" resultMap="BaseResultMap">
select item_content from in_list_item;
select * from in_list_item where del_state = 1
<if test="null != industryId and '' != industryId">
and industry_id = #{industryId}
</if>
<if test="null != listId and '' != listId">
and list_id = #{listId}
</if>
order by sort_id asc
</select>
<!--通过行业查询清单信息-->

View File

@ -22,18 +22,23 @@
<!--查询清单列-->
<select id="findAll" resultMap="BaseResultMap">
select * from in_list il order by il.sort_id asc
select * from in_list il where del_state = 1
<if test="null != industry and '' != industry">
and industry_id = #{industry}
</if>
order by il.sort_id asc
</select>
<insert id="insertList">
insert into in_list (list_id, name, del_state, create_by,create_time,industry_id)values
insert into in_list (list_id, name, del_state, create_by,create_time,industry_id,sort_id)values
<foreach collection="list" item="list" separator=",">
(#{list.listId},
#{list.name},
1,
#{list.createBy},
#{list.createTime},
#{list.industryId})
#{list.industryId},
#{list.sortId})
</foreach>
</insert>

View File

@ -306,11 +306,11 @@ public class UploadController extends com.rzyc.controller.BaseController {
/**
* EasyExcel读取
* EasyExcel读取行业清单
* @return
* @throws Exception
*/
@ApiOperation(value = "EasyExcel读取", notes = "EasyExcel读取")
@ApiOperation(value = "EasyExcel读取行业清单", notes = "EasyExcel读取行业清单")
@ResponseBody
@RequestMapping(value = "/readEasyExcel", method = RequestMethod.GET)
public String readEasyExcel(MultipartFile file)throws Exception{
@ -318,6 +318,19 @@ public class UploadController extends com.rzyc.controller.BaseController {
return "success";
}
/**
* EasyExcel读取企业
* @return
* @throws Exception
*/
@ApiOperation(value = "EasyExcel读取企业", notes = "EasyExcel读取企业")
@ResponseBody
@RequestMapping(value = "/readEasyExcelOfEnterprise", method = RequestMethod.GET)
public String readEasyExcelOfEnterprise(MultipartFile file)throws Exception{
pcBusinessService.readEasyExcelOfEnterprise(file);
return "success";
}

View File

@ -1202,4 +1202,10 @@ public class PcBusinessService extends BaseController {
return singleResult;
}
public SingleResult readEasyExcelOfEnterprise(MultipartFile file)throws IOException{
SingleResult singleResult = new SingleResult();
EasyExcel.read(file.getInputStream(), EasyExcelInList.class, new InListListener(inListMapper,inListItemMapper,baseInClassMapper)).doReadAll();
return singleResult;
}
}

View File

@ -45,6 +45,8 @@ public class InListListener implements ReadListener<EasyExcelInList> {
private String industryId = null;
private Integer listSort = 1;
private InListMapper inListMapper;
private InListItemMapper inListItemMapper;
@ -66,19 +68,26 @@ public class InListListener implements ReadListener<EasyExcelInList> {
@Override
public void invoke(EasyExcelInList data, AnalysisContext context) {
log.info("解析到一条数据:{}", JSON.toJSONString(data));
if (data.getListName() != null){
BaseInClass base = baseInClassMapper.selectByName(data.getListName());
industryId = base.getBaseinclassid();
BaseInClass base = null;
if (null == data.getIndustry()) {
}else {
base = baseInClassMapper.selectBaseInClassByName(data.getIndustry());
industryId = base.getBaseinclassid();
}
listName = data.getListName();
InList inList = new InList();
inList.setName(data.getListName());
listId = RandomNumber.getUUid();
inList.setListId(RandomNumber.getUUid());
inList.setIndustryId(base.getBaseinclassid());
inList.setListId(listId);
inList.setIndustryId(industryId);
inList.setCreateBy("系统导入");
inList.setCreateTime(new Date());
inList.setSortId(listSort);
queryList.add(inList);
listSort++;
}
if (data.getIndustry() != null){
industry = data.getIndustry();
@ -87,6 +96,7 @@ public class InListListener implements ReadListener<EasyExcelInList> {
data.setIndustry(industry);
data.setListId(listId);
data.setIndustryId(industryId);
data.setItemId(RandomNumber.getUUid());
cachedDataList.add(data);
// 达到BATCH_COUNT了需要去存储一次数据库防止数据几万条数据在内存容易OOM
if (cachedDataList.size() >= BATCH_COUNT) {
@ -109,6 +119,8 @@ public class InListListener implements ReadListener<EasyExcelInList> {
public void doAfterAllAnalysed(AnalysisContext context) {
//这里也要保存数据确保最后遗留的数据也存储到数据库
saveList();
// 存储完成清理 list
queryList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
log.info("所有数据解析完成!");
}
@ -128,8 +140,6 @@ public class InListListener implements ReadListener<EasyExcelInList> {
private void saveList() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
int result = inListMapper.insertList(queryList);
//清空list
queryList = new ArrayList<>();
log.info("存储数据库成功!");
}
}

View File

@ -20,35 +20,5 @@ import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
public class ReadTest {
@Autowired
InListMapper inListMapper;
@Autowired
InListItemMapper inListItemMapper;
@Autowired
BaseInClassMapper baseInClassMapper;
@Test
public void repeatedRead() {
String fileName = "导入模板.xlsx";
// 读取全部sheet
// 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次然后所有sheet都会往同一个DemoDataListener里面写
EasyExcel.read(fileName, EasyExcelInList.class, new InListListener(inListMapper,inListItemMapper,baseInClassMapper)).doReadAll();
// 读取部分sheet
// fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
//
// // 写法1
// try (ExcelReader excelReader = EasyExcel.read(fileName).build()) {
// // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener
// ReadSheet readSheet1 =
// EasyExcel.readSheet(0).head(DemoData.class).registerReadListener(new DemoDataListener()).build();
// ReadSheet readSheet2 =
// EasyExcel.readSheet(1).head(DemoData.class).registerReadListener(new DemoDataListener()).build();
// // 这里注意 一定要把sheet1 sheet2 一起传进去不然有个问题就是03版的excel 会读取多次浪费性能
// excelReader.read(readSheet1, readSheet2);
// }
}
}

View File

@ -33,6 +33,7 @@ import com.rzyc.model.check.BookEntHT;
import com.rzyc.model.check.ChkPerson;
import com.rzyc.model.ent.*;
import com.rzyc.model.user.*;
import com.rzyc.utils.ObjectConversion;
import org.apache.ibatis.annotations.Param;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
@ -2728,6 +2729,27 @@ public class BaseController {
}
}
/**
* @author Xu wanxin
* @param industryId
* @param companyId
* @throws Exception
*/
public void saveEntInList(String industryId,String companyId)throws Exception{
List<InListItem> inListItem = inListItemMapper.SelectContents(industryId,null);
List<InEntList> entLists = ObjectConversion.copy(inListItem,InEntList.class);
for (InEntList in:entLists) {
in.setEnterpriseId(companyId);
in.setEntListId(RandomNumber.getUUid());
in.setCreateBy(getUserId());
in.setCreateTime(new Date());
in.setEnterpriseId(companyId);
}
int result = inEntListMapper.insertList(entLists);
}
/**
* 获取政府机构的管辖区域的id
* @param userId

View File

@ -4,9 +4,7 @@ package com.rzyc.controller;
import com.common.utils.DateUtils;
import com.common.utils.RandomNumber;
import com.common.utils.StringUtils;
import com.common.utils.model.MultiResult;
import com.common.utils.model.Pager;
import com.common.utils.model.SingleResult;
import com.common.utils.model.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzyc.model.dto.*;
@ -47,17 +45,11 @@ public class IndustryListController extends BaseController{
@ApiOperation(value = "父级行业列表", notes = "行业清单列表")
@GetMapping("/industrySelect")
@ResponseBody
public MultiResult<String> industrySelect(){
public MultiResult<BaseInClass> industrySelect(){
MultiResult<String> result = new MultiResult<>();
ArrayList<String> nameList = new ArrayList<>();
MultiResult<BaseInClass> result = new MultiResult<>();
List<BaseInClass> baseInClassList = baseInClassMapper.findAll();
//取出对象的name字段放入集合
for (BaseInClass baseInClass : baseInClassList) {
String industryClassName = baseInClass.getIndustryclassname();
nameList.add(industryClassName);
}
result.setData(nameList);
result.setData(baseInClassList);
return result;
}
@ -71,49 +63,33 @@ public class IndustryListController extends BaseController{
@ApiOperation(value = "行业清单列表", notes = "行业清单列表")
@GetMapping("/industryListSelect")
@ResponseBody
public MultiResult<String> industryListSelect()throws Exception{
MultiResult<String> result = new MultiResult<>();
ArrayList<String> nameList = new ArrayList<>();
List<InList> inLists = inListMapper.findAll();
//取出对象的name字段放入集合
if(inLists.size() > 0){
for (InList inList : inLists) {
String name = inList.getName();
nameList.add(name);
}
}
result.setData(nameList);
public MultiResult<InList> industryListSelect(String industry)throws Exception{
MultiResult<InList> result = new MultiResult<>();
List<InList> inLists = inListMapper.findAll(industry);
result.setData(inLists);
return result;
}
@ApiOperation(value = "新增行业清单分类", notes = "新增行业清单分类")
@PostMapping("/industryListAdd")
@ResponseBody
public MultiResult<String> industryListAdd(@Valid @RequestBody InListAddDto inListAddDto){
public MultiResult<String> industryListAdd(@Valid @RequestBody InListAddDto inListAddDto) throws Exception {
MultiResult<String> result = new MultiResult<>();
InList inList = new InList();
//前端数据拷贝至对象
BeanUtils.copyProperties(inListAddDto,inList);
//industryId设null表示共有清单
if(StringUtils.isBlank(inList.getListId())){
//补全对象其余字段
inList.setListId(RandomNumber.getUUid());
inList.setDelState(1);
inList.setCreateTime(new Date());
inList.setIndustryId(null);
inList.setCreateBy(getUserId());
}
//industryId不设Null表示公有清单
if(StringUtils.isBlank(inList.getListId())){
//补全对象其余字段
inList.setListId(RandomNumber.getUUid());
inList.setDelState(1);
inList.setCreateTime(new Date());
//暂时设定危化品父级下
inList.setIndustryId("01c2afc4-cb18-4ac1-9560-b4708877db26");
int num = inListMapper.insert(inList);
if (num <= 0){
result.setCode(Code.ERROR.getCode());
result.setMessage(Message.ERROR);
}
return result;
}
@ -127,13 +103,13 @@ public class IndustryListController extends BaseController{
* @throws Exception
*/
@ApiOperation(value = "所属清单项列表分页", notes = "所属清单项列表分页")
@GetMapping("/industryListItemSelect")
@PostMapping("/industryListItemSelect")
@ResponseBody
public SingleResult<Pager<String>> industryListItemSelect(@RequestBody InListPageDto inListPageDto) throws Exception {
SingleResult<Pager<String>> result = new SingleResult<>();
Pager<String> pager = new Pager<>();
PageHelper.startPage(inListPageDto.getPage(),inListPageDto.getPageSize());
Page<String> page = (Page<String>)inListItemMapper.SelectContents();
Page<InListItem> page = (Page<InListItem>)inListItemMapper.SelectContents(inListPageDto.getIndustryId(),inListPageDto.getListId());
getDatePage(pager,page);
result.setData(pager);
return result;
@ -149,7 +125,7 @@ public class IndustryListController extends BaseController{
@PostMapping("/deleteInListItem")
@ResponseBody
public SingleResult<String> deleteInListItem(@Valid @RequestBody InListItemDto inListItemDto)throws Exception{
inListItemMapper.deleteById(inListItemDto.getItem_id());
inListItemMapper.deleteById(inListItemDto.getItemId());
return new SingleResult<String>();
}
@ -169,7 +145,7 @@ public class IndustryListController extends BaseController{
BaseInClass baseInClass = baseInClassMapper.selectByPrimaryKey(inListItemAddDto.getIndustryId());
if(null == inList){
result.setCode(0);
result.setMessage("用户不存在");
result.setMessage("清单不存在");
return result;
}
if(StringUtils.isBlank(inListItem.getItemId())){
@ -187,11 +163,8 @@ public class IndustryListController extends BaseController{
inListItem.setModifyBy(inList.getListId());
//inListItem.setIndustryId(baseInClass.getBaseinclassid());
inListItemMapper.updateById(inListItem);
}
return result;
}

View File

@ -2126,7 +2126,8 @@ public class MinWorkController extends BaseController{
//生成最小工作单元
saveEntWork(sysEnterprise.getSysenterpriseid());
//生成行业对应的企业责任清单
saveEntInList(sysEnterprise.getBaseinclassid(),sysEnterprise.getSysenterpriseid());
//创建或者修改企业用户
createEntUser(sysEnterprise,sysUser.getChinaname(),sysUser);
if (result > 0){

View File

@ -1221,7 +1221,7 @@ public class PcPersonalController extends com.rzyc.controller.BaseController {
public SingleResult<String> changePerformRecord(@Valid @RequestBody AddPerformRecordDto addPerformRecordDto)throws Exception{
SingleResult<String> result = new SingleResult<>();
ListDetailWithBLOBs listDetail = new ListDetailWithBLOBs();
BeanUtils.copyProperties(listDetail,addPerformRecordDto);
org.springframework.beans.BeanUtils.copyProperties(addPerformRecordDto,listDetail);
//处理时间
listDetail.setStarttime(DateUtils.parseString2Date(addPerformRecordDto.getStartTime(),"yyyy-MM-dd"));

View File

@ -540,7 +540,7 @@ public class PcCompanyController extends com.rzyc.controller.BaseController {
* 报错No value specified for Date
* */
ConvertUtils.register(new DateConverter(null), Date.class);
BeanUtils.copyProperties(sysEnterprise,sysEnterpriseDo);
org.springframework.beans.BeanUtils.copyProperties(sysEnterpriseDo,sysEnterprise);
String token = servletRequest.getHeader("userToken");
String userId = JwtUtil.getTokenMsg(token);
if (StringUtils.isBlank(userId)){
@ -591,7 +591,8 @@ public class PcCompanyController extends com.rzyc.controller.BaseController {
//生成最小工作单元
saveEntWork(sysEnterprise.getSysenterpriseid());
//生成行业对应的企业责任清单
saveEntInList(sysEnterprise.getWorkClassId(),sysEnterprise.getSysenterpriseid());
//创建或者修改企业用户
createEntUser(sysEnterprise,sysUser.getChinaname(),sysUser);

View File

@ -0,0 +1,38 @@
package com.rzyc.utils;
import java.util.List;
import com.alibaba.fastjson.JSON;
/**
* 两个对象或集合同名属性赋值
* @author Xu wanxin
*/
public class ObjectConversion {
/**
* 从List<A> copy到List<B>
* @param list List<B>
* @param clazz B
* @return List<B>
*/
public static <T> List<T> copy(List<?> list,Class<T> clazz){
String oldOb = JSON.toJSONString(list);
return JSON.parseArray(oldOb, clazz);
}
/**
* 从对象A copy到 对象B
* @param ob A
* @param clazz B.class
* @return B
*/
public static <T> T copy(Object ob,Class<T> clazz){
String oldOb = JSON.toJSONString(ob);
return JSON.parseObject(oldOb, clazz);
}
}

View File

@ -1,6 +1,6 @@
spring:
profiles:
active: dev #设定打包配置文件
active: prod #设定打包配置文件