From b8a7dbe5382ba0db9d7a10ed9b3e3d9df560948d Mon Sep 17 00:00:00 2001 From: mahuandong <752432958@qq.com> Date: Thu, 15 Aug 2019 17:58:13 +0800 Subject: [PATCH] 添加容器导入和导出导入模板 --- .idea/workspace.xml | 42 +++++++++++++++++++++++------------------- src/main/java/com/huaheng/pc/general/container/controller/ContainerController.java | 21 +++++++++++++++++++++ src/main/java/com/huaheng/pc/general/container/domain/Container.java | 8 ++++++++ src/main/java/com/huaheng/pc/general/container/service/ContainerService.java | 5 ++++- src/main/java/com/huaheng/pc/general/container/service/ContainerServiceImpl.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/huaheng/pc/general/material/service/MaterialService.java | 2 +- 6 files changed, 103 insertions(+), 21 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e1bf9f0..7174ea4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,22 +2,11 @@ <project version="4"> <component name="ChangeListManager"> <list default="true" id="9ff7b25e-dc1a-4859-8a0c-00039489e359" name="Default Changelist" comment=""> - <change afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/config/excelTemplate/controller/excelTemplateController.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/config/excelTemplate/domain/ExcelTemplate.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/config/excelTemplate/mapper/ExcelTemplateMapper.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/config/excelTemplate/service/ExcelTemplateService.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/config/excelTemplate/service/ExcelTemplateServiceImpl.java" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/resources/mybatis/config/ExcelTemplateMapper.xml" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/resources/templates/config/excelTemplate/add.html" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/resources/templates/config/excelTemplate/edit.html" afterDir="false" /> - <change afterPath="$PROJECT_DIR$/src/main/resources/templates/config/excelTemplate/excelTemplate.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/MyBatisCodeHelperDatasource.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/MyBatisCodeHelperDatasource.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/dataSources.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/shipment/shipmentDetail/controller/ShipmentDetailController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/shipment/shipmentDetail/controller/ShipmentDetailController.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/resources/templates/config/receiptType/edit.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/templates/config/receiptType/edit.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/resources/templates/config/receiptType/receiptType.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/templates/config/receiptType/receiptType.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/resources/templates/tool/import/import.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/templates/tool/import/import.html" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/controller/ContainerController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/controller/ContainerController.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/domain/Container.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/domain/Container.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/service/ContainerService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/service/ContainerService.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/service/ContainerServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/container/service/ContainerServiceImpl.java" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/material/service/MaterialService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/huaheng/pc/general/material/service/MaterialService.java" afterDir="false" /> </list> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="SHOW_DIALOG" value="false" /> @@ -52,6 +41,13 @@ <item name="schemas" type="d4e8921:DatabaseStructure$FamilyGroup" /> <item name="wms_v2: schema" type="76f4a085:MysqlImplModel$Schema" /> </path> + <path> + <item name="Database" type="3277223f:DatabaseStructure$DbRootGroup" /> + <item name="@172.16.29.45" type="feb32156:DbDataSourceImpl" /> + <item name="schemas" type="d4e8921:DatabaseStructure$FamilyGroup" /> + <item name="wms_v2: schema" type="76f4a085:MysqlImplModel$Schema" /> + <item name="container: table" type="285a2a93:MysqlImplModel$Table" /> + </path> </expand> <select /> </component> @@ -212,7 +208,7 @@ <workItem from="1565829438280" duration="3502000" /> <workItem from="1565832950552" duration="86000" /> <workItem from="1565833039573" duration="288000" /> - <workItem from="1565833342181" duration="18527000" /> + <workItem from="1565833342181" duration="20192000" /> </task> <task id="LOCAL-00001" summary="添加库位、库位类型增删改查接口"> <created>1565226427512</created> @@ -312,7 +308,14 @@ <option name="project" value="LOCAL" /> <updated>1565856453372</updated> </task> - <option name="localTasksCounter" value="15" /> + <task id="LOCAL-00015" summary="添加导入模板列表"> + <created>1565861068194</created> + <option name="number" value="00015" /> + <option name="presentableId" value="LOCAL-00015" /> + <option name="project" value="LOCAL" /> + <updated>1565861068194</updated> + </task> + <option name="localTasksCounter" value="16" /> <servers /> </component> <component name="TypeScriptGeneratedFilesManager"> @@ -360,7 +363,8 @@ <MESSAGE value="添加承运商" /> <MESSAGE value="添加物料导入、导出模板,添加Excel导入导出配置文件" /> <MESSAGE value="添加承运商页面,入库单类型" /> - <option name="LAST_COMMIT_MESSAGE" value="添加承运商页面,入库单类型" /> + <MESSAGE value="添加导入模板列表" /> + <option name="LAST_COMMIT_MESSAGE" value="添加导入模板列表" /> </component> <component name="XDebuggerManager"> <breakpoint-manager> diff --git a/src/main/java/com/huaheng/pc/general/container/controller/ContainerController.java b/src/main/java/com/huaheng/pc/general/container/controller/ContainerController.java index d7107e9..09859f6 100644 --- a/src/main/java/com/huaheng/pc/general/container/controller/ContainerController.java +++ b/src/main/java/com/huaheng/pc/general/container/controller/ContainerController.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.huaheng.common.support.Convert; import com.huaheng.common.utils.StringUtils; +import com.huaheng.common.utils.poi.ExcelUtil; import com.huaheng.common.utils.security.ShiroUtils; import com.huaheng.framework.aspectj.lang.annotation.Log; import com.huaheng.framework.aspectj.lang.constant.BusinessType; @@ -16,6 +17,7 @@ import com.huaheng.framework.web.page.TableDataInfo; import com.huaheng.framework.web.page.TableSupport; import com.huaheng.pc.general.container.domain.Container; import com.huaheng.pc.general.container.service.ContainerService; +import com.huaheng.pc.general.material.domain.Material; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -23,6 +25,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.List; @@ -155,4 +158,22 @@ public class ContainerController extends BaseController { } return AjaxResult.success("删除成功!"); } + + @PostMapping("/importData") + @ResponseBody + public AjaxResult importData(MultipartFile file) throws Exception { + ExcelUtil<Material> util = new ExcelUtil<>(Material.class); + List<Material> materialList = util.importExcel(file.getInputStream()); + String operName = ShiroUtils.getLoginName(); + Boolean updateSupport = false; + String message = containerService.importMaterial(materialList, updateSupport, operName); + return AjaxResult.success(message); + } + + @GetMapping("/importTemplate") + @ResponseBody + public AjaxResult importTemplate() { + ExcelUtil<Material> util = new ExcelUtil<>(Material.class); + return util.importTemplateExcel("容器"); + } } diff --git a/src/main/java/com/huaheng/pc/general/container/domain/Container.java b/src/main/java/com/huaheng/pc/general/container/domain/Container.java index 7aaea79..76607d0 100644 --- a/src/main/java/com/huaheng/pc/general/container/domain/Container.java +++ b/src/main/java/com/huaheng/pc/general/container/domain/Container.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.huaheng.framework.aspectj.lang.annotation.Excel; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -20,6 +21,7 @@ public class Container implements Serializable { */ @TableId(value = "id", type = IdType.AUTO) @ApiModelProperty(value="内部号") + @Excel(name = "内部号", type = Excel.Type.EXPORT) private Integer id; /** @@ -27,6 +29,7 @@ public class Container implements Serializable { */ @TableField(value = "name") @ApiModelProperty(value="容器名字") + @Excel(name = "容器名字") private String name; /** @@ -34,6 +37,7 @@ public class Container implements Serializable { */ @TableField(value = "code") @ApiModelProperty(value="容器编码") + @Excel(name = "容器编码") private String code; /** @@ -41,6 +45,7 @@ public class Container implements Serializable { */ @TableField(value = "warehouseCode") @ApiModelProperty(value="仓库代码") + @Excel(name = "仓库编码") private String warehouseCode; /** @@ -48,6 +53,7 @@ public class Container implements Serializable { */ @TableField(value = "companyCode") @ApiModelProperty(value="货主编码") + @Excel(name = "货主编码") private String companyCode; @TableField(value = "locationCode") @@ -59,6 +65,7 @@ public class Container implements Serializable { */ @TableField(value = "containerType") @ApiModelProperty(value="容器类型") + @Excel(name = "容器类型") private String containerType; /** @@ -101,6 +108,7 @@ public class Container implements Serializable { */ @TableField(value = "enable") @ApiModelProperty(value="启用;0—禁用") + @Excel(name = "是否启用", prompt = "启用;0 禁用:1") private Integer enable; /** diff --git a/src/main/java/com/huaheng/pc/general/container/service/ContainerService.java b/src/main/java/com/huaheng/pc/general/container/service/ContainerService.java index 43ed4dc..257230a 100644 --- a/src/main/java/com/huaheng/pc/general/container/service/ContainerService.java +++ b/src/main/java/com/huaheng/pc/general/container/service/ContainerService.java @@ -3,10 +3,13 @@ package com.huaheng.pc.general.container.service; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.general.container.domain.Container; import com.baomidou.mybatisplus.extension.service.IService; +import com.huaheng.pc.general.material.domain.Material; import java.util.List; public interface ContainerService extends IService<Container>{ - public AjaxResult<List<Container>> insertContainer(String type, Integer quantity); + AjaxResult<List<Container>> insertContainer(String type, Integer quantity); + + String importMaterial(List<Container> containerList, Boolean updateSupport, String operName); } diff --git a/src/main/java/com/huaheng/pc/general/container/service/ContainerServiceImpl.java b/src/main/java/com/huaheng/pc/general/container/service/ContainerServiceImpl.java index bd1de7e..7218c24 100644 --- a/src/main/java/com/huaheng/pc/general/container/service/ContainerServiceImpl.java +++ b/src/main/java/com/huaheng/pc/general/container/service/ContainerServiceImpl.java @@ -2,12 +2,15 @@ package com.huaheng.pc.general.container.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.huaheng.common.exception.BusinessException; import com.huaheng.common.exception.service.ServiceException; +import com.huaheng.common.utils.StringUtils; import com.huaheng.common.utils.security.ShiroUtils; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.config.containerType.domain.ContainerType; import com.huaheng.pc.config.containerType.service.ContainerTypeService; import com.huaheng.pc.general.container.domain.ContainerStatus; +import com.huaheng.pc.general.material.domain.Material; import org.apache.commons.collections.functors.ConstantFactory; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -65,4 +68,47 @@ public class ContainerServiceImpl extends ServiceImpl<ContainerMapper, Container return 0; } } + + public String importMaterial(List<Container> containerList, Boolean updateSupport, String operName){ + if (StringUtils.isNull(containerList) || containerList.size() == 0) { + throw new BusinessException("导入数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + for (Container container : containerList) { + try { + LambdaQueryWrapper<Container> lambdaQueryWrapper = Wrappers.lambdaQuery(); + lambdaQueryWrapper.eq(Container::getCode, container.getCode()); + // 验证是否存在这个容器 + Container m = this.getOne(lambdaQueryWrapper); + + if (StringUtils.isNull(m)) { + System.out.println(ShiroUtils.getLoginName()); + container.setCreatedBy(ShiroUtils.getUser().getLoginName()); + container.setLastUpdatedBy(ShiroUtils.getLoginName()); + this.save(container); + successNum++; + successMsg.append("<br/>" + successNum + "、编码 " + container.getCode() + " 导入成功"); + } else { + String msg = "<br/>" + failureNum + "、编码" + container.getCode() + " 已存在:"; + failureMsg.append(msg); + log.error(msg); + } + } catch (Exception e) { + failureNum++; + String msg = "<br/>" + failureNum + "、编码" + container.getCode() + " 导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new BusinessException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } } diff --git a/src/main/java/com/huaheng/pc/general/material/service/MaterialService.java b/src/main/java/com/huaheng/pc/general/material/service/MaterialService.java index 5f30d34..9f15bbc 100644 --- a/src/main/java/com/huaheng/pc/general/material/service/MaterialService.java +++ b/src/main/java/com/huaheng/pc/general/material/service/MaterialService.java @@ -11,7 +11,7 @@ public interface MaterialService extends IService<Material>{ AjaxResult removeByIds(String ids); - public String importMaterial(List<Material> materialList, Boolean updateSupport,String operName); + String importMaterial(List<Material> materialList, Boolean updateSupport,String operName); } -- libgit2 0.22.2