Commit 5db7b7cd LN

资源查询bug修改。导入csv资源时需要更新数据。下载资源,下载工单模板改为csv.

1 个父辈 60b82503
......@@ -21,6 +21,7 @@ import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.core.language.util.MessageUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.slf4j.Logger;
......@@ -31,6 +32,7 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
......@@ -233,6 +235,81 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
IoUtil.close(out);
}
/**
* CSV文件列分隔符
*/
private static final String CSV_COLUMN_SEPARATOR = ",";
/**
* CSV文件行分隔符
*/
private static final String CSV_ROW_SEPARATOR = System.lineSeparator();
/**
* 导出CSV文件
* @param dataList 数据集合
* @param titles 表头列表
* @param response
* @throws Exception
*/
public static void downloadCSV(List<Map<String, Object>> dataList, List<String> titles, HttpServletResponse response ) throws Exception {
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".csv";
// 文件导出
OutputStream os = response.getOutputStream();
responseSetProperties(tempPath, response);
// 保证线程安全
StringBuffer buf = new StringBuffer();
// String[] titleArr = null;
// String[] keyArr = null;
// titleArr = titles.split(",");
// keyArr = keys.split(",");
// 组装表头
for (String title : titles) {
buf.append(title).append(CSV_COLUMN_SEPARATOR);
}
buf.append(CSV_ROW_SEPARATOR);
// 组装数据
if (CollectionUtils.isNotEmpty(dataList)) {
for (Map<String, Object> data : dataList) {
for (String key : titles) {
buf.append(data.get(key)).append(CSV_COLUMN_SEPARATOR);
}
buf.append(CSV_ROW_SEPARATOR);
}
}
// 写出响应
os.write(buf.toString().getBytes("UTF-8"));
os.flush();
os.close();
}
/**
* 设置Header
*
* @param fileName
* @param response
* @throws UnsupportedEncodingException
*/
private static void responseSetProperties(String fileName, HttpServletResponse response) throws UnsupportedEncodingException {
// 设置文件后缀
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String fn = fileName + sdf.format(new Date()) + ".csv";
// 读取字符编码
String utf = "UTF-8";
// 设置响应
response.setContentType("application/ms-txt.numberformat:@");
response.setCharacterEncoding(utf);
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=30");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fn, utf));
}
public static String getFileType(String type) {
String documents = "txt doc pdf ppt pps xlsx xls docx";
String music = "mp3 wav wma mpa ram ra aac aif m4a";
......
......@@ -232,12 +232,12 @@ public class BaseDeviceHandler implements IDeviceHandler {
//从API验证
barcodeSave = verifyPutInFromApi(barcodeSave);
if(barcodeSave==null){
barcodeSave= codeResolve.resolveOneValideBarcode(codeStr);
if (barcodeSave == null) {
barcodeSave = codeResolve.resolveOneValideBarcode(codeStr);
}
//查找库位,生成入库任务
DataLog putInTask = generatePutInTask(statusBean,barcodeSave, storage);
DataLog putInTask = generatePutInTask(statusBean, barcodeSave, storage);
String posId = putInTask.getPosName();
int plateW = barcodeSave.getPlateSize();
......
......@@ -305,7 +305,7 @@ public class SensorShelfHandler extends BaseDeviceHandler {
}else{
StoragePos pos = storagePosManager.getByPosName(hasReelPosList[0]);
if(pos == null){
String msg = "未找到库位:"+ hasReelPosList;
String msg = "未找到库位:"+String.join(",",hasReelPosList) ;
log.error(msg);
WebSocketServer.sendGroupMsg(groupId,new SocketMsg(msg, MsgType.ERROR));
}else{
......
......@@ -119,7 +119,9 @@ public class SpBoxHandler extends BaseDeviceHandler {
//从API验证
barcodeSave = verifyPutInFromApi(barcodeSave);
if (barcodeSave == null) {
barcodeSave = codeResolve.resolveOneValideBarcode(codeStr);
}
StoragePos storagePos;
DataLog executingTask = null;
......
......@@ -89,7 +89,7 @@ public class LanguageMsgController {
}
if(csvType.equals(fileType)){
List<LanguageMsg> list=messageService.readCsvFile(file.getAbsolutePath(),dataCache.getLanguageList());
messageService.msgListUpload(file.getName(), list);
messageService.msgListUpload(file.getName(), list,true);
}
return ResultBean.newOkResult(resultMsg);
}
......
......@@ -10,7 +10,7 @@ import java.util.Date;
@Data
public class LanguageMsgCriteria {
@QueryCondition(blurry = "code,type,msg")
@QueryCondition(blurry = "code,type,msg,contentList.msg")
private String blurry;
@QueryCondition(type = QueryCondition.Type.BETWEEN, propName = "updateDate")
......
......@@ -67,24 +67,54 @@ public class LanguageMsgManagerImpl implements ILanguageMsgManager {
@Override
public void download(List<LanguageMsg> msgList, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
// List<Map<String, Object>> list = new ArrayList<>();
// for (LanguageMsg msg : msgList) {
// Map<String, Object> map = new LinkedHashMap<>();
// map.put("编号", msg.getCode());
// map.put("类型", msg.getType());
// map.put("内容", msg.getMsg());
// List<LanguageInfo> lanList=dataCache.getLanguageList();
// for (LanguageInfo languageInfo :
// lanList) {
// String title=languageInfo.getLanCode() ;
// if(ObjectUtil.isNotEmpty(languageInfo.getLanName())){
// title=languageInfo.getLanName();
// }
// map.put(title,msg.getContent(languageInfo.getLanCode()));
// }
// list.add(map);
// }
// FileUtil.downloadExcel(list, response);
try {
List<Map<String, Object>> maps = new ArrayList<>();
List<String> titles = new ArrayList<>();
for (LanguageMsg msg : msgList) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("编号", msg.getCode());
map.put("类型", msg.getType());
map.put("内容", msg.getMsg());
List<LanguageInfo> lanList=dataCache.getLanguageList();
List<LanguageInfo> lanList = dataCache.getLanguageList();
for (LanguageInfo languageInfo :
lanList) {
String title=languageInfo.getLanCode() ;
if(ObjectUtil.isNotEmpty(languageInfo.getLanName())){
title=languageInfo.getLanName();
String title = languageInfo.getLanCode();
if (ObjectUtil.isNotEmpty(languageInfo.getLanName())) {
title = languageInfo.getLanName();
}
map.put(title, msg.getContent(languageInfo.getLanCode()));
}
map.put(title,msg.getContent(languageInfo.getLanCode()));
if (titles.size() <= 0) {
titles = new ArrayList<>(map.keySet());
}
list.add(map);
maps.add(map);
}
FileUtil.downloadCSV(maps, titles, response);
} catch (Exception e) {
log.error("导出失败" + e.getMessage(), e);
}
FileUtil.downloadExcel(list, response);
}
@Override
......
......@@ -50,9 +50,16 @@ public class MessageService {
return resourceMap;
}
public String getResourcesPath() {
String filePath = System.getProperty("user.dir");
log.info("user.dir=" + filePath);
// "\\WEB-INF\\classes\\META-INF\\resources";
return filePath + "\\src\\main\\resources";
}
public void autoImportCsvFile(){
String fielPath = "D:\\resources\\";
File file = new File(fielPath); //需要获取的文件的路径
String filePath = getResourcesPath();
File file = new File(filePath ); //需要获取的文件的路径
List<LanguageInfo> languageInfoList=dataCache.getLanguageList();
if (file.exists() && file.isDirectory()) {
String[] fileNameLists = file.list(); //存储文件名的String数组
......@@ -67,8 +74,7 @@ public class MessageService {
try {
List<LanguageMsg> msgList=readCsvFile(filePathLists[i].getAbsolutePath(),languageInfoList);
if(msgList.size()>0){
msgListUpload(fileName, msgList);
msgListUpload(fileName, msgList,false);
}
}catch (Exception ex){
log.info("autoImportCsvFile 读取文件"+fileName+"错误:"+ex.toString());
......@@ -80,6 +86,8 @@ public class MessageService {
}
public void autoImportProperties() {
// String fielPath = getResourcesPath();
String fielPath = "D:\\resources";
File file = new File(fielPath); //需要获取的文件的路径
......@@ -100,13 +108,13 @@ public class MessageService {
String lanType = fileName.replace("messages", "").replace(".properties", "");
if (ObjectUtil.isEmpty(lanType)) {
defaultLanMap = readPropertiesFile(filePathLists[i]);
log.info("MessageCache 从文件[" + fileName + "]中导入[" + defaultLanMap.size() + "]条默认资源");
log.info("MessageCache 从文件[" + fileName + "]中读取到" + defaultLanMap.size() + "]条默认资源");
} else {
String lan = lanType.substring(1);
lan = lan.replace('_', '-');
Map<String, String> map = readPropertiesFile(filePathLists[i]);
lanMsgMap.put(lan, map);
log.info("MessageCache 从文件[" + fileName + "]中导入[" + defaultLanMap.size() + "]条[" + lan + "]资源");
log.info("MessageCache 从文件[" + fileName + "]中读取到[" + defaultLanMap.size() + "]条[" + lan + "]资源");
}
}
......@@ -127,7 +135,9 @@ public class MessageService {
}
languageMsgs.add(msg);
}
languageMsgManager.insertAll(languageMsgs);
//只能修改不能新增
msgListUpload(".properties", languageMsgs,false);
// languageMsgManager.insertAll(languageMsgs);
}
}
......@@ -192,7 +202,7 @@ public class MessageService {
return "ok";
}
public void msgListUpload(String fileName, List<LanguageMsg> msgList) {
public void msgListUpload(String fileName, List<LanguageMsg> msgList,boolean isNeedUpdate) {
List<LanguageMsg> newLanguageList = new ArrayList<>();
List<LanguageMsg> updateLanguageList = new ArrayList<>();
......@@ -232,13 +242,13 @@ public class MessageService {
List<String> allLanList=getAllLanList();
for (String lanType :
allLanList) {
String oldValue= oldMsg.getContent(lanType);
if(ObjectUtil.isEmpty(oldValue)){
oldMsg.setContent(lanType,msg.getContent(lanType));
isUpdate=true;
String oldValue = oldMsg.getContent(lanType);
if (isNeedUpdate || ObjectUtil.isEmpty(oldValue)) {
oldMsg.setContent(lanType, msg.getContent(lanType));
isUpdate = true;
//内容默认更改为中文
if(lanType.equals(MessageUtils.ZH_CN)){
if(!oldMsg.getMsg().equals(oldValue)){
if (lanType.equals(MessageUtils.ZH_CN)) {
if (!oldMsg.getMsg().equals(oldValue)) {
oldMsg.setMsg(oldValue);
}
}
......@@ -277,7 +287,6 @@ public class MessageService {
) {
String line;
//网友推荐更加简洁的写法
while ((line = br.readLine()) != null) {
// 一次读入一行数据
// System.out.println(line);
......
......@@ -89,14 +89,15 @@ public class MessageUtils {
private void initLanguageMsgList() {
msgMap =messageService.loadMsgMap();
if (msgMap.size() > 0) {
return;
}
msgMap = messageService.loadMsgMap();
//自动导入CSV内容
messageService.autoImportCsvFile();
if (msgMap.size() > 0) {
return;
}
messageService.autoImportProperties();
msgMap = messageService.loadMsgMap();
}
......
package com.neotel.smfcore.core.system.bean;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class OrderSetting implements Serializable {
/**
* 工单监控文件夹
*/
@ApiModelProperty("监控文件夹")
public String orderDir="";
public String pn="PN";
public String feeder="FEEDER";
public String qty="QTY";
public String ri="RI";
public String so="SO";
/**
* 是否显示料架亮灯方式
*/
@ApiModelProperty("是否显示料架亮灯方式 ture=显示")
public boolean showLightType=false;
/**
* 料架亮灯方式,0=全部亮灯,1=亮灯指引,默认0
*/
@ApiModelProperty("料架亮灯方式,0=全部亮灯,1=亮灯指引,默认0")
public Integer shelfLightType=0;
}
package com.neotel.smfcore.core.system.rest;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.common.utils.FileUtil;
import com.neotel.smfcore.common.utils.QueryHelp;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.language.service.bean.LanguageInfo;
import com.neotel.smfcore.core.language.service.po.LanguageMsg;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.system.bean.OrderSetting;
import com.neotel.smfcore.core.system.rest.bean.dto.SettingsDto;
......@@ -11,23 +17,28 @@ import com.neotel.smfcore.core.system.rest.bean.dto.SysSettingsDto;
import com.neotel.smfcore.core.system.rest.bean.mapstruct.SettingsMapper;
import com.neotel.smfcore.core.system.service.po.Settings;
import com.neotel.smfcore.security.rest.bean.dto.MenuDto;
import com.neotel.smfcore.security.rest.bean.query.UserQueryCriteria;
import com.neotel.smfcore.security.service.po.Menu;
import com.neotel.smfcore.security.service.po.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.BooleanOperators;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
@Slf4j
@Api(tags = "系统:设置")
......@@ -197,4 +208,50 @@ public class SettingsController {
return ResultBean.newOkResult("保存成功");
}
@ApiOperation("下载工单模板")
@GetMapping(value = "/downloadOrderModel")
@PreAuthorize("@el.check('user:list')")
public void download(HttpServletResponse response) throws IOException {
downloadOrderModel(response);
}
public void downloadOrderModel( HttpServletResponse response) throws IOException {
try {
List<Map<String, Object>> maps = new ArrayList<>();
List<String> titles = new ArrayList<>();
OrderSetting orderSetting = dataCache.getCache(Constants.CACHE_OrderSetting);
if (orderSetting == null) {
orderSetting = new OrderSetting();
}
titles.add(orderSetting.getPn() );
titles.add(orderSetting.getFeeder());
titles.add((orderSetting.getQty()));
titles.add(orderSetting.getRi());
titles.add(orderSetting.getSo());
for(int i=1;i<=10;i++) {
Map<String, Object> map = new LinkedHashMap<>();
if(i<=4){
map.put(orderSetting.getPn(),"物料编号"+i);
map.put(orderSetting.getFeeder(),"站位号"+i);
map.put(orderSetting.getQty(),"100"+i);
map.put(orderSetting.getRi(),"");
map.put(orderSetting.getSo(),"需求单1001" );
}
else{
map.put(orderSetting.getPn(),"物料编号2"+i);
map.put(orderSetting.getFeeder(),"站位号2"+i);
map.put(orderSetting.getQty(),"200"+i);
map.put(orderSetting.getRi(),"");
map.put(orderSetting.getSo(),"需求单1002" );
}
maps.add(map);
}
FileUtil.downloadCSV(maps, titles, response);
} catch (Exception e) {
log.error("导出失败" + e.getMessage(), e);
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!