| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.utils.MatExcelListener; |
| | | import com.zy.asrs.utils.MatV2ExcelListener; |
| | | import com.zy.common.entity.MatExcel; |
| | | import com.zy.common.entity.MatV2Excel; |
| | | import com.zy.common.web.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | |
| | | } |
| | | return R.ok().add(matV2s); |
| | | } |
| | | |
| | | /** |
| | | * excel导入模板下载 |
| | | */ |
| | | @RequestMapping(value = "/matV2/excel/import/mould") |
| | | public void matV2ExcelImportMould(HttpServletResponse response) throws IOException { |
| | | List<MatV2Excel> excels = new ArrayList<>(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode("组件档案Excel导入模板", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), MatV2Excel.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .sheet("sheet1") |
| | | .doWrite(excels); |
| | | } |
| | | |
| | | // excel导入 |
| | | @PostMapping(value = "/matV2/excel/import/auth") |
| | | @ManagerAuth(memo = "组件档案数据导入") |
| | | @Transactional |
| | | public R matV2ExcelImport(MultipartFile file) throws IOException { |
| | | MatV2ExcelListener listener = new MatV2ExcelListener(getUserId()); |
| | | EasyExcel.read(file.getInputStream(), MatV2Excel.class, listener).sheet().doRead(); |
| | | return R.ok("成功同步"+listener.getTotal()+"条商品数据"); |
| | | } |
| | | } |
| | |
| | | package com.zy.asrs.entity; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableId; |
| | | import com.baomidou.mybatisplus.enums.IdType; |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | |
| | | private String tagId; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @ExcelProperty(value = "商品编码") |
| | | private String matnr; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @ExcelProperty(value = "商品名称") |
| | | private String maktx; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | private String name; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @ExcelProperty(value = "规格") |
| | | private String specs; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @ExcelProperty(value = "型号") |
| | | private String model; |
| | | |
| | | @ApiModelProperty(value= "") |
| | |
| | | private String brand; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @ExcelProperty(value = "单位") |
| | | private String unit; |
| | | |
| | | @ApiModelProperty(value= "") |
| | |
| | | private Double safeQty; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @ExcelProperty(value = "重量") |
| | | private Double weight; |
| | | |
| | | @ApiModelProperty(value= "") |
| | |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @TableField("be_batch") |
| | | private Integer beBatch; |
| | | @ExcelProperty(value = "组成用量") |
| | | private Float beBatch; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @TableField("dead_time") |
| | |
| | | private Date updateTime; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @ExcelProperty(value = "备注") |
| | | private String memo; |
| | | |
| | | public MatV2() {} |
| | | |
| | | public MatV2(String uuid,String tagId,String matnr,String maktx,String name,String specs,String model,String color,String brand,String unit,Double price,String sku,Double units,String barcode,String origin,String manu,String manuDate,String itemNum,Double safeQty,Double weight,Double length,Double volume,String threeCode,String supp,String suppCode,Integer beBatch,String deadTime,Integer deadWarn,Integer source,Integer inspect,Integer danger,Integer status,Long createBy,Date createTime,Long updateBy,Date updateTime,String memo) { |
| | | public MatV2(String uuid,String tagId,String matnr,String maktx,String name,String specs,String model,String color,String brand,String unit,Double price,String sku,Double units,String barcode,String origin,String manu,String manuDate,String itemNum,Double safeQty,Double weight,Double length,Double volume,String threeCode,String supp,String suppCode,Float beBatch,String deadTime,Integer deadWarn,Integer source,Integer inspect,Integer danger,Integer status,Long createBy,Date createTime,Long updateBy,Date updateTime,String memo) { |
| | | this.uuid = uuid; |
| | | this.tagId = tagId; |
| | | this.matnr = matnr; |
| | |
| | | package com.zy.asrs.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.entity.MatV2; |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface MatV2Mapper extends BaseMapper<MatV2> { |
| | | |
| | | List<MatV2> listByPage(Page page, @Param("tagId") String tagId, @Param("matnr") Object matnr, @Param("maktx") Object maktx); |
| | | |
| | | MatV2 selectByMatnr(@Param("matnr")String matnr); |
| | | |
| | | |
| | | } |
| | |
| | | package com.zy.asrs.service; |
| | | |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.entity.MatV2; |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | |
| | | public interface MatV2Service extends IService<MatV2> { |
| | | |
| | | Page<MatV2> getPage(Page page, String tagId, Object matnr, Object maktx); |
| | | |
| | | MatV2 selectByMatnr(String matnr); |
| | | |
| | | } |
| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.mapper.MatV2Mapper; |
| | | import com.zy.asrs.entity.MatV2; |
| | | import com.zy.asrs.service.MatV2Service; |
| | |
| | | @Service("matV2Service") |
| | | public class MatV2ServiceImpl extends ServiceImpl<MatV2Mapper, MatV2> implements MatV2Service { |
| | | |
| | | @Override |
| | | public Page<MatV2> getPage(Page page, String tagId, Object matnr, Object maktx) { |
| | | return page.setRecords(baseMapper.listByPage(page, tagId, matnr, maktx)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MatV2 selectByMatnr(String matnr) { |
| | | return this.baseMapper.selectByMatnr(matnr); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.utils; |
| | | |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.MatV2; |
| | | import com.zy.asrs.service.MatService; |
| | | import com.zy.asrs.service.MatV2Service; |
| | | import com.zy.common.entity.MatExcel; |
| | | import com.zy.common.entity.MatV2Excel; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Created by vincent on 2019-11-25 |
| | | */ |
| | | @Slf4j |
| | | public class MatV2ExcelListener extends AnalysisEventListener<MatV2Excel> { |
| | | |
| | | private int total = 0; |
| | | private Long userId; |
| | | |
| | | public MatV2ExcelListener() { |
| | | } |
| | | |
| | | public MatV2ExcelListener(Long userId) { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | /** |
| | | * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 |
| | | */ |
| | | private static final int BATCH_COUNT = 50; |
| | | |
| | | private final List<MatV2Excel> list = new ArrayList<>(); |
| | | |
| | | /** |
| | | * 这里会一行行的返回头 |
| | | */ |
| | | @Override |
| | | public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { |
| | | } |
| | | |
| | | /** |
| | | * 这个每一条数据解析都会来调用 |
| | | */ |
| | | @Override |
| | | public void invoke(MatV2Excel excel, AnalysisContext ctx) { |
| | | MatV2Service matV2Service = SpringUtils.getBean(MatV2Service.class); |
| | | Date now = new Date(); |
| | | String number = excel.getNumber(); |
| | | String[] split = number.split("\\."); |
| | | String uuid; |
| | | String tagId; |
| | | if (split.length == 1) { |
| | | uuid = "1"; |
| | | tagId = split[0]; |
| | | } else { |
| | | StringBuilder sb = new StringBuilder(); |
| | | StringBuilder sb2 = new StringBuilder(); |
| | | for (int i = 0; i < split.length; i++) { |
| | | if (i == 0) { |
| | | sb.append(split[i]); |
| | | } else { |
| | | sb.append("." + split[i]); |
| | | } |
| | | } |
| | | tagId = sb.toString(); |
| | | for (int i = 0; i < split.length-1; i++) { |
| | | if (i == 0) { |
| | | sb2.append(split[i]); |
| | | } else { |
| | | sb2.append("." + split[i]); |
| | | } |
| | | } |
| | | uuid = sb2.toString(); |
| | | } |
| | | // 商品 |
| | | MatV2 matV2 = matV2Service.selectByMatnr(excel.getMatnr()); |
| | | if (matV2 == null) { |
| | | matV2 = excel; |
| | | matV2.setUuid(uuid); |
| | | matV2.setTagId(tagId); |
| | | if (!matV2Service.insert(matV2)) { |
| | | throw new CoolException("保存商品信息失败,商品编码:" + excel.getMatnr()); |
| | | } |
| | | total++; |
| | | } else { |
| | | matV2 = excel; |
| | | matV2.setUuid(uuid); |
| | | matV2.setTagId(tagId); |
| | | if (!matV2Service.update(matV2,new EntityWrapper<MatV2>().eq("matnr",matV2.getMatnr()))) { |
| | | throw new CoolException("保存商品信息失败,商品编码:" + excel.getMatnr()); |
| | | } |
| | | total++; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 所有数据解析完成了调用 |
| | | * 适合事务 |
| | | */ |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext ctx) { |
| | | log.info("新增{}条物料信息!", total); |
| | | } |
| | | |
| | | public int getTotal() { |
| | | return total; |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.common.entity; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.zy.asrs.entity.MatV2; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 0.A 1.B 2.C 3.D 4.E 5.F 6.G 7.H 8.I |
| | | * 9.J 10.K 11.L 12.M 13.N 14.O 15.P 16.Q 17.R 18.S |
| | | * 19.T 20.U 21.V 22.W 23.X 24.Y 25.Z |
| | | */ |
| | | @Data |
| | | @ExcelIgnoreUnannotated |
| | | public class MatV2Excel extends MatV2 { |
| | | |
| | | @ExcelProperty(index = 0, value = "序号") |
| | | private String number; |
| | | |
| | | } |
| | |
| | | storePass: public_zhongyang_123456789 |
| | | licensePath: license.lic |
| | | publicKeysStorePath: publicCerts.keystore |
| | | |
| | | |
| | | loc-move: |
| | | move-all: true |
| | |
| | | |
| | | </resultMap> |
| | | |
| | | <select id="listByPage" resultMap="BaseResultMap"> |
| | | SELECT |
| | | isnull(mld.amount,0) as stock, |
| | | mm.* |
| | | FROM man_mat_v2 mm |
| | | LEFT JOIN man_tag mt ON mm.tag_id = mt.id |
| | | LEFT JOIN ( |
| | | select |
| | | matnr, |
| | | sum(anfme) as amount |
| | | from man_loc_detl |
| | | group by matnr |
| | | ) as mld on mld.matnr = mm.matnr |
| | | WHERE 1=1 |
| | | and (mm.memo is null or mm.memo != '打包上线') |
| | | AND (CHARINDEX(','+#{tagId}+',', ','+mt.path+',') > 0 OR mt.id = #{tagId}) |
| | | <if test="matnr != null and matnr != ''"> |
| | | and mm.matnr like concat('%',#{matnr},'%') |
| | | </if> |
| | | <if test="maktx != null and maktx != ''"> |
| | | and mm.maktx like concat('%',#{maktx},'%') |
| | | </if> |
| | | ORDER BY mm.create_time DESC |
| | | </select> |
| | | |
| | | <select id="selectByMatnr" resultMap="BaseResultMap"> |
| | | select top 1 * from man_mat_v2 where 1=1 and matnr = #{matnr} |
| | | </select> |
| | | </mapper> |
| | |
| | | var pageCurr; |
| | | var admin; |
| | | layui.config({ |
| | | base: baseUrl + "/static/layui/lay/modules/" |
| | | }).extend({ |
| | |
| | | var layer = layui.layer; |
| | | var layDate = layui.laydate; |
| | | var form = layui.form; |
| | | var admin = layui.admin; |
| | | admin = layui.admin; |
| | | |
| | | // 数据渲染 |
| | | tableIns = table.render({ |
| | |
| | | page: {curr: pageCurr} |
| | | }); |
| | | } |
| | | |
| | | // excel导入模板下载 |
| | | function excelMouldDownload(){ |
| | | layer.load(1, {shade: [0.1,'#fff']}); |
| | | location.href = baseUrl + "/matV2/excel/import/mould"; |
| | | layer.closeAll('loading'); |
| | | } |
| | | |
| | | // excel导入 |
| | | function importExcel() { |
| | | $("#importExcel").trigger("click"); |
| | | } |
| | | function upload(obj){ |
| | | if(!obj.files) { |
| | | return; |
| | | } |
| | | var file = obj.files[0]; |
| | | admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) { |
| | | layer.load(1, {shade: [0.1,'#fff']}); |
| | | var url = baseUrl + "/matV2/excel/import/auth"; |
| | | var form = new FormData(); |
| | | form.append("file", file); |
| | | xhr = new XMLHttpRequest(); |
| | | xhr.open("post", url, true); //post方式,url为服务器请求地址,true 该参数规定请求是否异步处理。 |
| | | xhr.setRequestHeader('token', localStorage.getItem('token')); |
| | | xhr.onload = uploadComplete; //请求完成 |
| | | xhr.onerror = uploadFailed; //请求失败 |
| | | xhr.onloadend = function () { // // 上传完成重置文件流 |
| | | layer.closeAll('loading'); |
| | | $("#importExcel").val(""); |
| | | }; |
| | | // xhr.upload.onprogress = progressFunction;//【上传进度调用方法实现】 |
| | | xhr.upload.onloadstart = function(){//上传开始执行方法 |
| | | ot = new Date().getTime(); //设置上传开始时间 |
| | | oloaded = 0;//设置上传开始时,以上传的文件大小为0 |
| | | }; |
| | | xhr.send(form); |
| | | }, function(index){ |
| | | $("#importExcel").val(""); |
| | | }); |
| | | } |
| | | function uploadComplete(evt) { |
| | | var res = JSON.parse(evt.target.responseText); |
| | | if(res.code === 200) { |
| | | layer.msg(res.msg, {icon: 1}); |
| | | loadTree(""); |
| | | } else { |
| | | layer.msg(res.msg, {icon: 2}); |
| | | } |
| | | } |
| | | function uploadFailed(evt) { |
| | | var res = JSON.parse(evt.target.responseText); |
| | | layer.msg(res.msg, {icon: 2}); |
| | | } |