Commit 9c4e14e4cecc7210ded90a4615f28f615bc39562

Authored by tongzhonghao
1 parent df96892a

增加 物料类别导入功能

修改 物料导入功能
src/main/java/com/huaheng/pc/config/material/domain/Material.java
... ... @@ -20,7 +20,6 @@ public class Material implements Serializable {
20 20 */
21 21 @TableId(value = "id", type = IdType.AUTO)
22 22 @ApiModelProperty(value="ID")
23   - @Excel(name = "ID")
24 23 private Integer id;
25 24  
26 25 /**
... ... @@ -80,11 +79,18 @@ public class Material implements Serializable {
80 79 private String type;
81 80  
82 81 /**
  82 + * 库区
  83 + */
  84 + @TableField(value = "zoneCode")
  85 + @ApiModelProperty(value="库区")
  86 + @Excel(name = "库区")
  87 + private String zoneCode;
  88 +
  89 + /**
83 90 * ABC分类
84 91 */
85 92 @TableField(value = "abcClass")
86 93 @ApiModelProperty(value="ABC分类")
87   - @Excel(name = "ABC分类")
88 94 private String abcClass;
89 95  
90 96 /**
... ... @@ -92,7 +98,6 @@ public class Material implements Serializable {
92 98 */
93 99 @TableField(value = "daysToExpire")
94 100 @ApiModelProperty(value="保质期(天)")
95   - @Excel(name = "保质期(天)")
96 101 private Integer daysToExpire;
97 102  
98 103 /**
... ... @@ -100,7 +105,6 @@ public class Material implements Serializable {
100 105 */
101 106 @TableField(value = "locatingRule")
102 107 @ApiModelProperty(value="定位规则")
103   - @Excel(name = "定位规则")
104 108 private String locatingRule;
105 109  
106 110 /**
... ... @@ -108,7 +112,6 @@ public class Material implements Serializable {
108 112 */
109 113 @TableField(value = "allocationRule")
110 114 @ApiModelProperty(value="分配规则")
111   - @Excel(name = "分配规则")
112 115 private String allocationRule;
113 116  
114 117 /**
... ... @@ -116,7 +119,6 @@ public class Material implements Serializable {
116 119 */
117 120 @TableField(value = "replenishmentRule")
118 121 @ApiModelProperty(value="补货规则")
119   - @Excel(name = "补货规则")
120 122 private String replenishmentRule;
121 123  
122 124 /**
... ... @@ -124,7 +126,6 @@ public class Material implements Serializable {
124 126 */
125 127 @TableField(value = "emptyLocRule")
126 128 @ApiModelProperty(value="空货位规则")
127   - @Excel(name = "空货位规则")
128 129 private String emptyLocRule;
129 130  
130 131 /**
... ... @@ -132,7 +133,6 @@ public class Material implements Serializable {
132 133 */
133 134 @TableField(value = "receivingFlow")
134 135 @ApiModelProperty(value="入库流程")
135   - @Excel(name = "入库流程")
136 136 private String receivingFlow;
137 137  
138 138 /**
... ... @@ -140,7 +140,6 @@ public class Material implements Serializable {
140 140 */
141 141 @TableField(value = "shippingFlow")
142 142 @ApiModelProperty(value="出库流程")
143   - @Excel(name = "出库流程")
144 143 private String shippingFlow;
145 144  
146 145 /**
... ... @@ -148,7 +147,6 @@ public class Material implements Serializable {
148 147 */
149 148 @TableField(value = "attributeTemplateCode")
150 149 @ApiModelProperty(value="属性模版")
151   - @Excel(name = "属性模版")
152 150 private String attributeTemplateCode;
153 151  
154 152 /**
... ... @@ -156,7 +154,6 @@ public class Material implements Serializable {
156 154 */
157 155 @TableField(value = "trackSerialNum")
158 156 @ApiModelProperty(value="记录序列号")
159   - @Excel(name = "记录序列号")
160 157 private Integer trackSerialNum;
161 158  
162 159 /**
... ... @@ -164,7 +161,6 @@ public class Material implements Serializable {
164 161 */
165 162 @TableField(value = "autoGenSerialNum")
166 163 @ApiModelProperty(value="自动生成序列号")
167   - @Excel(name = "自动生成序列号")
168 164 private Integer autoGenSerialNum;
169 165  
170 166 /**
... ... @@ -172,7 +168,6 @@ public class Material implements Serializable {
172 168 */
173 169 @TableField(value = "autoGenSerialNumFormat")
174 170 @ApiModelProperty(value="自动生成序列号表达式")
175   - @Excel(name = "自动生成序列号表达式")
176 171 private String autoGenSerialNumFormat;
177 172  
178 173 /**
... ... @@ -180,7 +175,6 @@ public class Material implements Serializable {
180 175 */
181 176 @TableField(value = "snTemplateCode")
182 177 @ApiModelProperty(value="序列号模版")
183   - @Excel(name = "序列号模版")
184 178 private String snTemplateCode;
185 179  
186 180 /**
... ... @@ -188,7 +182,6 @@ public class Material implements Serializable {
188 182 */
189 183 @TableField(value = "expiringDays")
190 184 @ApiModelProperty(value="临期预警天数")
191   - @Excel(name = "临期预警天数")
192 185 private Integer expiringDays;
193 186  
194 187 /**
... ... @@ -196,7 +189,6 @@ public class Material implements Serializable {
196 189 */
197 190 @TableField(value = "minShelfLifeDays")
198 191 @ApiModelProperty(value="收货预警天数")
199   - @Excel(name = "收货预警天数")
200 192 private Integer minShelfLifeDays;
201 193  
202 194 /**
... ... @@ -240,7 +232,6 @@ public class Material implements Serializable {
240 232 */
241 233 @TableField(value = "version")
242 234 @ApiModelProperty(value="数据版本")
243   - @Excel(name = "数据版本")
244 235 private Integer version;
245 236  
246 237 /**
... ... @@ -248,7 +239,6 @@ public class Material implements Serializable {
248 239 */
249 240 @TableField(value = "userDef1")
250 241 @ApiModelProperty(value="是否AGV区域发货")
251   - @Excel(name = "是否AGV区域发货")
252 242 private String userDef1;
253 243  
254 244 /**
... ...
src/main/java/com/huaheng/pc/config/material/service/MaterialServiceImpl.java
... ... @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
5 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
6 6 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7 +import com.huaheng.common.constant.QuantityConstant;
7 8 import com.huaheng.common.exception.BusinessException;
8 9 import com.huaheng.common.support.Convert;
9 10 import com.huaheng.common.utils.StringUtils;
... ... @@ -102,10 +103,14 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
102 103 lambdaQueryWrapper.eq(Material::getCode, material.getCode());
103 104 // 验证是否存在这个用户
104 105 Material m = this.getOne(lambdaQueryWrapper);
105   - if (StringUtils.isNull(m)) {
  106 + MaterialType one = materialTypeService.getOne(new LambdaQueryWrapper<MaterialType>()
  107 + .eq(MaterialType::getCode, material.getType()));
  108 + if (StringUtils.isNull(m) && StringUtils.isNull(one)) {
106 109 System.out.println(ShiroUtils.getLoginName());
107 110 material.setCreatedBy(ShiroUtils.getUser().getLoginName());
108 111 material.setLastUpdatedBy(ShiroUtils.getLoginName());
  112 + material.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
  113 + material.setCompanyCode(QuantityConstant.DEFAULT_COMPANY);
109 114 this.save(material);
110 115 successNum++;
111 116 successMsg.append("<br/>" + successNum + "、编码 " + material.getCode() + " 导入成功");
... ...
src/main/java/com/huaheng/pc/config/materialType/controller/MaterialTypeController.java
... ... @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
7 7 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
8 8 import com.huaheng.common.support.Convert;
9 9 import com.huaheng.common.utils.StringUtils;
  10 +import com.huaheng.common.utils.poi.ExcelUtil;
10 11 import com.huaheng.common.utils.security.ShiroUtils;
11 12 import com.huaheng.framework.aspectj.lang.annotation.Log;
12 13 import com.huaheng.framework.aspectj.lang.constant.BusinessType;
... ... @@ -28,6 +29,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
28 29 import org.springframework.stereotype.Controller;
29 30 import org.springframework.ui.ModelMap;
30 31 import org.springframework.web.bind.annotation.*;
  32 +import org.springframework.web.multipart.MultipartFile;
31 33  
32 34 import javax.annotation.Resource;
33 35 import java.util.ArrayList;
... ... @@ -99,6 +101,27 @@ public class MaterialTypeController extends BaseController {
99 101 return prefix + "/add";
100 102 }
101 103  
  104 + @PostMapping("/importData")
  105 + @ResponseBody
  106 + public AjaxResult importData (MultipartFile file) throws Exception {
  107 + ExcelUtil<MaterialType> util = new ExcelUtil<>(MaterialType.class);
  108 + List<MaterialType> materialList = util.importExcel(file.getInputStream());
  109 + String operName = ShiroUtils.getLoginName();
  110 + String message = materialTypeService.importMaterial(materialList, false, operName);
  111 + return AjaxResult.success(message);
  112 + }
  113 + /**
  114 + * 导出模板
  115 + *
  116 + * @return
  117 + * @throws Exception
  118 + */
  119 + @GetMapping("/importTemplate")
  120 + @ResponseBody
  121 + public AjaxResult importTemplate () {
  122 + ExcelUtil<MaterialType> util = new ExcelUtil<>(MaterialType.class);
  123 + return util.importTemplateExcel("物料类别");
  124 + }
102 125 /**
103 126 * 新增保存物料类别
104 127 */
... ...
src/main/java/com/huaheng/pc/config/materialType/domain/MaterialType.java
... ... @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
4 4 import com.baomidou.mybatisplus.annotation.TableField;
5 5 import com.baomidou.mybatisplus.annotation.TableId;
6 6 import com.baomidou.mybatisplus.annotation.TableName;
  7 +import com.huaheng.framework.aspectj.lang.annotation.Excel;
7 8 import io.swagger.annotations.ApiModel;
8 9 import io.swagger.annotations.ApiModelProperty;
9 10 import java.io.Serializable;
... ... @@ -26,6 +27,7 @@ public class MaterialType implements Serializable {
26 27 */
27 28 @TableField(value = "code")
28 29 @ApiModelProperty(value="编码")
  30 + @Excel(name = "物料类别编码")
29 31 private String code;
30 32  
31 33 /**
... ... @@ -33,6 +35,7 @@ public class MaterialType implements Serializable {
33 35 */
34 36 @TableField(value = "name")
35 37 @ApiModelProperty(value="名称")
  38 + @Excel(name = "物料类别名称")
36 39 private String name;
37 40  
38 41 /**
... ...
src/main/java/com/huaheng/pc/config/materialType/service/MaterialTypeService.java
... ... @@ -4,7 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
5 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
6 6 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7 +import com.huaheng.common.constant.QuantityConstant;
  8 +import com.huaheng.common.exception.BusinessException;
7 9 import com.huaheng.common.utils.security.ShiroUtils;
  10 +import com.huaheng.pc.config.material.domain.Material;
8 11 import com.huaheng.pc.config.materialType.domain.MaterialType;
9 12 import com.huaheng.pc.config.materialType.mapper.MaterialTypeMapper;
10 13 import org.springframework.stereotype.Service;
... ... @@ -27,4 +30,46 @@ public class MaterialTypeService extends ServiceImpl&lt;MaterialTypeMapper, Materia
27 30 lambda.eq(MaterialType::getWarehouseCode, ShiroUtils.getWarehouseCode());
28 31 return this.listMaps(lambda);
29 32 }
  33 +
  34 + public String importMaterial(List<MaterialType> materialTypeList, Boolean isUpdateSupport, String operName) {
  35 + if (com.huaheng.common.utils.StringUtils.isNull(materialTypeList) || materialTypeList.size() == 0) {
  36 + throw new BusinessException("导入数据不能为空!");
  37 + }
  38 + int successNum = 0;
  39 + int failureNum = 0;
  40 + StringBuilder successMsg = new StringBuilder();
  41 + StringBuilder failureMsg = new StringBuilder();
  42 + for (MaterialType materialType : materialTypeList) {
  43 + try {
  44 + LambdaQueryWrapper<MaterialType> lambdaQueryWrapper = Wrappers.lambdaQuery();
  45 + lambdaQueryWrapper.eq(MaterialType::getCode, materialType.getCode());
  46 + // 验证是否存在这个用户
  47 + MaterialType m = this.getOne(lambdaQueryWrapper);
  48 + if (com.huaheng.common.utils.StringUtils.isNull(m)) {
  49 + System.out.println(ShiroUtils.getLoginName());
  50 + materialType.setCreatedBy(ShiroUtils.getUser().getLoginName());
  51 + materialType.setLastUpdatedBy(ShiroUtils.getLoginName());
  52 + materialType.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
  53 + materialType.setCompanyCode(QuantityConstant.DEFAULT_COMPANY);
  54 + materialType.setLastUpdatedBy(ShiroUtils.getLoginName());
  55 + this.save(materialType);
  56 + successNum++;
  57 + successMsg.append("<br/>" + successNum + "、编码 " + materialType.getCode() + " 导入成功");
  58 + }
  59 + } catch (Exception e) {
  60 + failureNum++;
  61 + String msg = "<br/>" + failureNum + "、编码" + materialType.getCode() + " 导入失败:";
  62 + failureMsg.append(msg + e.getMessage());
  63 + log.error(msg, e);
  64 + }
  65 + }
  66 + if (failureNum > 0) {
  67 + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
  68 + throw new BusinessException(failureMsg.toString());
  69 + } else {
  70 + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
  71 + }
  72 + return successMsg.toString();
  73 + }
  74 +
30 75 }
... ...
src/main/resources/static/huaheng/js/huahengUI.js
... ... @@ -344,7 +344,8 @@ var table = {
344 344 },
345 345 // 下载模板
346 346 importTemplate: function () {
347   - $.get($.table._option.importTemplateUrl, function (result) {
  347 + debugger;
  348 + $.get(table.options.importTemplateUrl, function (result) {
348 349 if (result.code == web_status.SUCCESS) {
349 350 window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
350 351 } else if (result.code == web_status.WARNING) {
... ... @@ -381,7 +382,7 @@ var table = {
381 382 formData.append("file", $('#file')[0].files[0]);
382 383 formData.append("updateSupport", $("input[name='updateSupport']").is(':checked'));
383 384 $.ajax({
384   - url: $.table._option.importUrl,
  385 + url: table.options.importUrl,
385 386 data: formData,
386 387 cache: false,
387 388 contentType: false,
... ... @@ -389,7 +390,7 @@ var table = {
389 390 type: 'POST',
390 391 success: function (result) {
391 392 if (result.code == web_status.SUCCESS) {
392   - $.modal.closeAll();
  393 + layer.closeAll();
393 394 $.modal.alertSuccess(result.msg);
394 395 $.table.refresh();
395 396 } else if (result.code == web_status.WARNING) {
... ...
src/main/resources/templates/config/materialType/materialType.html
... ... @@ -41,6 +41,9 @@
41 41 <a class="btn btn-outline btn-success btn-rounded" onclick="batEdit()" shiro:hasPermission="config:materialType:add">
42 42 <i class="fa fa-edit"></i> 批量编辑
43 43 </a>
  44 + <a class="btn btn-outline btn-info btn-rounded" onclick="$.table.importExcel()">
  45 + <i class="fa fa-upload"></i> 导入
  46 + </a>
44 47 </div>
45 48  
46 49 <div class="col-sm-12 select-info">
... ... @@ -61,6 +64,8 @@
61 64 createUrl: prefix + "/add",
62 65 updateUrl: prefix + "/edit/{id}",
63 66 removeUrl: prefix + "/remove",
  67 + importTemplateUrl: prefix + "/importTemplate",
  68 + importUrl: prefix+"/importData",
64 69 modalName: "物料类别",
65 70 search: false,
66 71 columns: [{
... ... @@ -247,6 +252,20 @@
247 252 }
248 253 }
249 254 </script>
  255 + <!-- 导入区域 -->
  256 + <script id="importTpl" type="text/template">
  257 + <form enctype="multipart/form-data" class="mt20 mb10">
  258 + <div class="col-xs-offset-1">
  259 + <input type="file" id="file" name="file"/>
  260 + <div class="mt10 pt5">
  261 + <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
  262 + </div>
  263 + <font color="red" class="pull-left mt10">
  264 + 提示:仅允许导入“xls”或“xlsx”格式文件!
  265 + </font>
  266 + </div>
  267 + </form>
  268 + </script>
250 269 </body>
251 270  
252 271 </html>
253 272 \ No newline at end of file
... ...