1.在切割完成后自动生成预配盘信息,当存在分段配套表excel时同步修正零件流向和预配盘流向

master
董哲奇 1 month ago
parent 414060455a
commit f66e77bf96

@ -321,9 +321,9 @@ public class DmYdjhLj implements Serializable {
private String lljhrq; // 理料计划日期
private String tz;
private String lx;
private String xj;
private String tz;//特征
private String lx;//流向
private String xj;//下级
//=====预配盘相关==============

@ -1,6 +1,7 @@
package com.dsic.gj_erp.bean.zyjh;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@ -57,6 +58,23 @@ public class DmYppyz extends Model<DmYppyz> {
return StatusEnum.;
}
public static DmYppyz of(String key){
String[] keys=key.split(" ");
if (keys.length>=5){
DmYppyz dmYppyz = new DmYppyz();
dmYppyz.setDcCh(keys[0]);
dmYppyz.setDcPl(keys[1]);
dmYppyz.setDcFd(keys[2]);
dmYppyz.setZl(keys[3]);
if (StrUtil.isNotEmpty(keys[4])&&!"null".equals(keys[4])){
dmYppyz.setLx(keys[4]);
}
return dmYppyz;
}
return null;
}
public static DmYppyz of(DmYdjh ydjh){
DmYppyz dmYppyz = new DmYppyz();

@ -2,6 +2,7 @@ package com.dsic.gj_erp.service.zyjh;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -17,19 +18,21 @@ import com.dsic.gj_erp.bean.zyjh.DmYppyz;
import com.dsic.gj_erp.controller.zyjh.dto.PgWithPcDto;
import com.dsic.gj_erp.controller.zyjh.dto.ShangLiao;
import com.dsic.gj_erp.controller.zyjh.dto.SljhSearch;
import com.dsic.gj_erp.dao.zyjh.PPBGongDto;
import com.dsic.gj_erp.mapper.jhgk.DmYdjhMapper;
import com.dsic.gj_erp.service.jcsj.DmBzryService;
import com.dsic.gj_erp.service.jcsj.DmCbxxpService;
import com.dsic.gj_erp.service.jhgk.DmYdjhLjService;
import com.dsic.gj_erp.util.ExcelUtil;
import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Service
@ -114,13 +117,80 @@ public class ZyjhService extends ServiceImpl<DmYdjhMapper,DmYdjh> {
@Transactional(rollbackFor = Exception.class)
public List<DmYdjhLj> createLj(String dcCh, String dcPl, String tzbh){
List<DmYdjhLj> ljInfo = baseMapper.getLjInfo(dcCh, dcPl, tzbh);
//给零件设置流向
Map<String, List<DmYdjhLj>> _ljMap = ljInfo.stream()
.collect(Collectors
.groupingBy(item ->
item.getCzbh() + "_" + item.getPl() + "_" + item.getFd()
));
_ljMap.forEach((key,values)->{
try {
String[] keys=key.split("_");
String ch=keys[0];
String pl=keys[1];
String fd=keys[2];
File dir = new File("static/upload/" + ch + "/" + pl + "/其他");
String patternStr = pl + "_" + fd + "_分段配套表";
List<File> fileList = FileUtil.loopFiles(dir);
fileList.stream()
.filter(file -> file.getName().contains(patternStr))
.forEach(file -> {
if (file.exists()){
List<String> strings = ExcelUtil.ReadExcelByLine(file);
System.out.println(strings);
for (DmYdjhLj _lj : values){
for (String _str:strings){
if (_str.contains(_lj.getTlth())&&_str.contains(_lj.getLjbh())){
String[] _strArr=_str.split(" ");
if (_strArr.length>8){
_lj.setLx(_strArr[8]);
}
}
}
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
});
ljService.remove(Wrappers.<DmYdjhLj>lambdaQuery()
.eq(DmYdjhLj::getCzbh,dcCh)
.eq(DmYdjhLj::getPl,dcPl)
.eq(DmYdjhLj::getTlth,tzbh)
);
List<DmYdjhLj> ljInfo = baseMapper.getLjInfo(dcCh, dcPl, tzbh);
ljService.saveBatch(ljInfo);
//自动生成无摆放位置的预配盘原则
Map<String, List<DmYdjhLj>> collect = ljInfo.stream()
.collect(Collectors
.groupingBy(item ->
item.getCzbh() + " "
+ item.getPl() + " "
+ item.getFd() + " "
+ item.getZl() + " "
+ (StrUtil.isNotEmpty(item.getLx())?item.getLx():"")
));
collect.keySet().forEach(item -> {
DmYppyz dmYppyz = DmYppyz.of(item);
if (dmYppyz!=null){
int count = yppyzService.count(Wrappers.<DmYppyz>lambdaQuery()
.eq(DmYppyz::getDcCh, dmYppyz.getDcCh())
.eq(DmYppyz::getDcPl, dmYppyz.getDcPl())
.eq(DmYppyz::getDcFd, dmYppyz.getDcFd())
.eq(DmYppyz::getZl, dmYppyz.getZl())
.eq(StrUtil.isNotEmpty(dmYppyz.getLx()),DmYppyz::getLx, dmYppyz.getLx())
);
if (count==0){
yppyzService.save(dmYppyz);
}
}
});
return ljInfo;
}

@ -2,6 +2,7 @@ package com.dsic.gj_erp.util;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -11,13 +12,69 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Slf4j
public class ExcelUtil {
public static List<String> ReadExcelByLine(File file){
try (FileInputStream fis = new FileInputStream(file);
Workbook workbook = new XSSFWorkbook(fis)) { // 对于xls文件使用HSSFWorkbook
return handler(workbook);
} catch (IOException e) {
try (FileInputStream fis = new FileInputStream(file);
Workbook workbook = new HSSFWorkbook(fis)){
return handler(workbook);
}catch (IOException e1){
log.info("{}损坏",file.getName());
}
}
return new ArrayList<>();
}
private static List<String> handler(Workbook workbook){
ArrayList<String> strs = new ArrayList<>();
Sheet sheet = workbook.getSheetAt(1); // 获取第一个工作表
for (Row row : sheet) { // 遍历每一行
StringBuilder stringBuilder= new StringBuilder();
for (Cell cell : row) { // 遍历每一列
String cellData = getCellValueAsString(cell); // 获取单元格数据并转换为字符串
stringBuilder.append(cellData).append(" ");
}
strs.add(stringBuilder.toString());
}
return strs;
}
private static String getCellValueAsString(Cell cell) {
Object result;
switch (cell.getCellType()) {
case STRING:
result = cell.getRichStringCellValue().getString();
break;
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) { // 处理日期类型数字单元格
result = cell.getDateCellValue();
} else { // 处理数字类型单元格
result = cell.getNumericCellValue();
}
break;
case BOOLEAN:
result = cell.getBooleanCellValue();
break;
case FORMULA:
result = cell.getCellFormula(); // 获取公式内容并转换为字符串也可以调用getCellValueAsString来获取计算后的值作为字符串
break;
default: // 处理空单元格等其它情况,这里简单返回空字符串或根据需要处理
result = "";
}
return result.toString(); // 返回单元格内容的字符串表示形式
}
public static Map<String,String> ZRCJHKeyMap=new HashMap<String,String>(){
{
//put("状态","zt");put("周期(天)","b");

@ -28,7 +28,7 @@
dm_yppyz a,
dm_ydjh b left join dm_ydjh_lj c on b.dc_ch=c.czbh and b.dc_pl=c.pl and b.tzbh=c.tlth
where
a.dc_ch=b.dc_ch and a.dc_pl=b.dc_pl and a.dc_fd =c.fd and a.status='已摆放' and b.lx='b' and b.zt>=62
a.dc_ch=b.dc_ch and a.dc_pl=b.dc_pl and a.dc_fd =c.fd and a.status='已摆放' and a.lx=b.lx and b.lx='b' and b.zt>=62
<if test="dcCh!=null and dcCh!=''">
and a.dc_ch=#{dcCh}
</if>
@ -49,7 +49,7 @@
dm_yppyz a,
dm_ydjh b left join dm_ydjh_lj c on b.dc_ch=c.czbh and b.dc_pl=c.pl and b.tzbh=c.tlth
where
a.dc_ch=b.dc_ch and a.dc_pl=b.dc_pl and a.dc_fd =c.fd and b.lx='b'
a.dc_ch=b.dc_ch and a.dc_pl=b.dc_pl and a.dc_fd =c.fd and b.lx='b' and a.lx=c.lx
and a.status='设置垛位' and b.zt>=62
and b.zyq1=#{zyq} and a.dc_ch=#{dcCh}
and isnull(c.qq,'')='' and isnull(c.dw,'')=''

Loading…
Cancel
Save