Browse Source

为物料导入添加单价修改功能

lwx_dev
erdanergou 2 years ago
parent
commit
fea6f098b3
  1. 23
      src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java
  2. 8
      src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java
  3. 55
      src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml
  4. 62
      src/main/java/com/dreamchaser/depository_manage/security/pool/ExcelFileInfoPool.java
  5. 4
      src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java
  6. 61
      src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java
  7. 33
      src/main/resources/templates/pages/material/material-out.html

23
src/main/java/com/dreamchaser/depository_manage/controller/ExcelController.java

@ -38,6 +38,7 @@ public class ExcelController {
return excelService.importExcelMaterial(excel,userToken); return excelService.importExcelMaterial(excel,userToken);
} }
/** /**
* 用于物料类型的导入 * 用于物料类型的导入
* *
@ -88,6 +89,28 @@ public class ExcelController {
return CrudUtil.insertHandle(1,1); return CrudUtil.insertHandle(1,1);
} }
/**
* 用于覆盖之前导入的物料数据
* @param map 覆盖的数据
* @return
*/
@PostMapping("/overwriteExcelByMaterial")
public RestResponse overwriteExcelByMaterial(@RequestBody Map<String,String> map,HttpServletRequest request){
String s = map.get("result");
String token = request.getHeader("user-token");
if (token == null) {
token = (String) request.getSession().getAttribute("userToken");
}
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
if ("yes".equals(s)) {
excelService.executeOverwriteForMaterial(userToken);
}else{
excelService.clearImportFileData(userToken);
}
return CrudUtil.updateHandle(1,1);
}
/** /**
* 用于实际导入物料类型信息 * 用于实际导入物料类型信息

8
src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java

@ -78,6 +78,14 @@ public interface MaterialMapper {
*/ */
Integer updateMaterial(Map<String, Object> map); Integer updateMaterial(Map<String, Object> map);
/**
* 根据条件更改物料信息用于导入时的重写
*
* @param map 参数列表
* @return 受影响的行数
*/
Integer updateMaterialForImport(Map<String, Object> map);
/** /**
* 更新一条物料信息 * 更新一条物料信息
* @param material 修改的参数 * @param material 修改的参数

55
src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml

@ -1154,6 +1154,61 @@
WHERE id = #{id} WHERE id = #{id}
</update> </update>
<update id="updateMaterialForImport">
UPDATE material
<set>
<if test="uid != '' and uid != null">
uid = #{uid},
</if>
<if test="price != null">
price = #{price},
</if>
<if test="updateTime != '' and updateTime != null">
updateTime = #{updateTime},
</if>
<if test="unit != null and unit != ''">
unit = #{unit},
</if>
<if test="texture != null and texture != ''">
texture = #{texture},
</if>
<if test="shelfLife != null">
shelfLife = #{shelfLife},
</if>
<if test="producedDate != null">
producedDate = #{producedDate},
</if>
<if test="productionPlace != null and productionPlace !=''">
productionPlace = #{productionPlace},
</if>
<if test="brand != '' and brand != null">
brand = #{brand},
</if>
<if test="remark != '' and remark != null">
remark = #{remark}
</if>
</set>
WHERE
1 = 1
<if test="mname != null and mname != ''">
and mname = #{mname}
</if>
<if test="version != null and version != ''">
and version = #{version}
</if>
<if test="version == null or version == ''">
and version is null
</if>
<if test="mcode != null and mcode != ''">
and `code` = #{mcode}
</if>
</update>
<!-- 修改数据 --> <!-- 修改数据 -->
<update id="updateInventory"> <update id="updateInventory">
UPDATE inventory UPDATE inventory

62
src/main/java/com/dreamchaser/depository_manage/security/pool/ExcelFileInfoPool.java

@ -4,6 +4,8 @@ import com.dreamchaser.depository_manage.entity.ExcelInfoByInventory;
import com.dreamchaser.depository_manage.entity.ExcelInfoByMT; import com.dreamchaser.depository_manage.entity.ExcelInfoByMT;
import com.dreamchaser.depository_manage.entity.ExcelInfoForMaterial; import com.dreamchaser.depository_manage.entity.ExcelInfoForMaterial;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -12,12 +14,18 @@ import java.util.concurrent.ConcurrentHashMap;
* 用于设置用户的上传物料信息 * 用于设置用户的上传物料信息
*/ */
public class ExcelFileInfoPool { public class ExcelFileInfoPool {
// 用于存储当前用户导入的库存数据
private static Map<String, List<ExcelInfoByInventory>> excelVosForInventoryPool = new ConcurrentHashMap<>(1000); private static Map<String, List<ExcelInfoByInventory>> excelVosForInventoryPool = new ConcurrentHashMap<>(1000);
// 用于存储当前用户导入的物料类型数据
private static Map<String, List<ExcelInfoByMT>> excelVosForMaterialTypePool = new ConcurrentHashMap<>(1000); private static Map<String, List<ExcelInfoByMT>> excelVosForMaterialTypePool = new ConcurrentHashMap<>(1000);
// 用于存储当前用户导入的物料数据
private static Map<String, List<ExcelInfoForMaterial>> excelVosForMaterialPool = new ConcurrentHashMap<>(1000); private static Map<String, List<ExcelInfoForMaterial>> excelVosForMaterialPool = new ConcurrentHashMap<>(1000);
// 用于存储当前用户导入的物料数据(用于覆盖)
private static Map<String, List<ExcelInfoForMaterial>> excelVosForMaterialPoolByOverwrite = new ConcurrentHashMap<>(1000);
/** /**
* 用于暂存当前用户的上传库存数据 * 用于暂存当前用户的上传库存数据
*
* @param key 用户工号 * @param key 用户工号
*/ */
public static void addUserExcelInventoryInfo(String key, List<ExcelInfoByInventory> excelVosForInventory) { public static void addUserExcelInventoryInfo(String key, List<ExcelInfoByInventory> excelVosForInventory) {
@ -26,6 +34,7 @@ public class ExcelFileInfoPool {
/** /**
* 获取当前用户上传的库存数据 * 获取当前用户上传的库存数据
*
* @param key * @param key
* @return * @return
*/ */
@ -35,6 +44,7 @@ public class ExcelFileInfoPool {
/** /**
* 用于删除当前用户上传的库存数据 * 用于删除当前用户上传的库存数据
*
* @param key * @param key
*/ */
public static void removeUserExcelInventoryInfo(String key) { public static void removeUserExcelInventoryInfo(String key) {
@ -43,6 +53,7 @@ public class ExcelFileInfoPool {
/** /**
* 用于暂存当前用户的上传物料数据 * 用于暂存当前用户的上传物料数据
*
* @param key 用户工号 * @param key 用户工号
*/ */
public static void addUserExcelMaterialInfo(String key, List<ExcelInfoForMaterial> excelVosForMaterial) { public static void addUserExcelMaterialInfo(String key, List<ExcelInfoForMaterial> excelVosForMaterial) {
@ -51,6 +62,7 @@ public class ExcelFileInfoPool {
/** /**
* 获取当前用户上传的物料数据 * 获取当前用户上传的物料数据
*
* @param key * @param key
* @return * @return
*/ */
@ -60,6 +72,7 @@ public class ExcelFileInfoPool {
/** /**
* 用于删除当前用户上传的物料数据 * 用于删除当前用户上传的物料数据
*
* @param key * @param key
*/ */
public static void removeUserExcelMaterialInfo(String key) { public static void removeUserExcelMaterialInfo(String key) {
@ -68,14 +81,17 @@ public class ExcelFileInfoPool {
/** /**
* 用于暂存当前用户的上传物料类型数据 * 用于暂存当前用户的上传物料类型数据
*
* @param key 用户工号 * @param key 用户工号
*/ */
public static void addUserExcelMaterialTypeInfo(String key, List<ExcelInfoByMT> excelVosForMaterialType) { public static void addUserExcelMaterialTypeInfo(String key, List<ExcelInfoByMT> excelVosForMaterialType) {
excelVosForMaterialTypePool.put(key, excelVosForMaterialType); excelVosForMaterialTypePool.put(key, excelVosForMaterialType);
} }
/** /**
* 获取当前用户上传的物料类型数据 * 获取当前用户上传的物料类型数据
*
* @param key * @param key
* @return * @return
*/ */
@ -85,6 +101,7 @@ public class ExcelFileInfoPool {
/** /**
* 用于删除当前用户上传的物料类型数据 * 用于删除当前用户上传的物料类型数据
*
* @param key * @param key
*/ */
public static void removeUserExcelMaterialTypeInfo(String key) { public static void removeUserExcelMaterialTypeInfo(String key) {
@ -92,5 +109,50 @@ public class ExcelFileInfoPool {
} }
/**
* 用于暂存当前用户的上传物料数据(用于覆盖)
*
* @param key 用户工号
*/
public static void addUserExcelMaterialInfoByOverwrite(String key, List<ExcelInfoForMaterial> excelVosForMaterial) {
excelVosForMaterialPoolByOverwrite.put(key, excelVosForMaterial);
}
/**
* 获取当前用户上传的物料数据(用于覆盖)
*
* @param key
* @return
*/
public static List<ExcelInfoForMaterial> getUserExcelMaterialInfoByOverwrite(String key) {
return excelVosForMaterialPoolByOverwrite.get(key);
}
/**
* 用于删除当前用户上传的物料数据(用于覆盖)
*
* @param key
*/
public static void removeUserExcelMaterialInfoByOverwrite(String key) {
excelVosForMaterialPoolByOverwrite.remove(key);
}
/**
* 用于添加一条数据到用于覆盖的数据暂存列表中
*
* @param key 要存储到的列表key
* @param excelInfoForMaterial 要存储的数据
*/
public static void addExcelMaterialInfoByOverwrite(String key, ExcelInfoForMaterial excelInfoForMaterial) {
List<ExcelInfoForMaterial> excelInfoForMaterials = excelVosForMaterialPoolByOverwrite.get(key);
if (excelInfoForMaterials != null) {
excelInfoForMaterials.add(excelInfoForMaterial);
} else {
List<ExcelInfoForMaterial> list = Collections.synchronizedList(new ArrayList<>());
list.add(excelInfoForMaterial);
excelVosForMaterialPoolByOverwrite.put(key, list);
}
}
} }

4
src/main/java/com/dreamchaser/depository_manage/service/ExcelService.java

@ -57,6 +57,10 @@ public interface ExcelService {
*/ */
void executeImportForMaterial(UserByPort userByPort); void executeImportForMaterial(UserByPort userByPort);
/**
* 用于执行物料覆盖方法
*/
void executeOverwriteForMaterial(UserByPort userByPort);
/** /**
* 用于清空导入的数据 * 用于清空导入的数据

61
src/main/java/com/dreamchaser/depository_manage/service/impl/ExcelServiceImpl.java

@ -16,6 +16,7 @@ import com.dreamchaser.depository_manage.mapper.ConstructionUnitMapper;
import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper; import com.dreamchaser.depository_manage.mapper.DepositoryRecordMapper;
import com.dreamchaser.depository_manage.mapper.MaterialMapper; import com.dreamchaser.depository_manage.mapper.MaterialMapper;
import com.dreamchaser.depository_manage.security.pool.ExcelFileInfoPool; import com.dreamchaser.depository_manage.security.pool.ExcelFileInfoPool;
import com.dreamchaser.depository_manage.security.pool.HandlesOtherFunctionalThreadPool;
import com.dreamchaser.depository_manage.service.*; import com.dreamchaser.depository_manage.service.*;
import com.dreamchaser.depository_manage.utils.*; import com.dreamchaser.depository_manage.utils.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -851,6 +852,59 @@ public class ExcelServiceImpl implements ExcelService {
} }
/**
* 用于执行物料覆盖方法
*/
@Override
public void executeOverwriteForMaterial(UserByPort userByPort) {
List<Object> success = new ArrayList<>();
String number = userByPort.getNumber();
List<ExcelInfoForMaterial> excelMaterialInfoByOverwrite = ExcelFileInfoPool.getUserExcelMaterialInfoByOverwrite(number);
List<ExcelInfoForMaterial> userExcelMaterialInfo = ExcelFileInfoPool.getUserExcelMaterialInfo(number);
if(userExcelMaterialInfo != null && userExcelMaterialInfo.size() > 0){
// 如果有需要导入的数据
HandlesOtherFunctionalThreadPool.execute(()->{
// 开启一个线程去执行导入方法
executeImportForMaterial(userByPort);
});
}
int successNum = 0;
for (int i = 0; i < excelMaterialInfoByOverwrite.size(); i++) {
ExcelInfoForMaterial excelVo = excelMaterialInfoByOverwrite.get(i);
Map<String, Object> map = new HashMap<>();
String code = excelVo.getCode();
if (code != null && !"".equals(code)) {
map.put("mcode", code);
} else {
map.put("mname", excelVo.getMname());
map.put("version", excelVo.getVersion());
}
String price = excelVo.getPrice();
if (price != null && !"".equals(price)) {
map.put("price", (int)(ObjectFormatUtil.toDouble(price) * 100));
} else {
map.put("price", 0);
}
map.put("uid", userByPort.getId());
map.put("updateTime", System.currentTimeMillis());
successNum += materialMapper.updateMaterialForImport(map);
success.add(excelVo);
if ((i + 1) % 100 == 0 || excelMaterialInfoByOverwrite.size() - 1 == i) {
// 如果凑够100条或者已经循环完成 发送消息
try {
WebSocketController.sendInfo(JSONObject.toJSONString(success), number);
success = new ArrayList<>();
} catch (IOException e) {
e.printStackTrace();
}
}
ExcelFileInfoPool.removeUserExcelMaterialInfoByOverwrite(number);
log.info("【批量添加】批量修改数据:{}", JSON.toJSONString(excelMaterialInfoByOverwrite) + ";导入人员" + userByPort.getName() + ":" + userByPort.getNumber() + ";导入总数" + successNum + ",导入时间为: " + DateUtil.getNowTime());
}
}
/** /**
* 用于清空导入的数据 * 用于清空导入的数据
*/ */
@ -858,6 +912,7 @@ public class ExcelServiceImpl implements ExcelService {
ExcelFileInfoPool.removeUserExcelInventoryInfo(userByPort.getNumber()); ExcelFileInfoPool.removeUserExcelInventoryInfo(userByPort.getNumber());
ExcelFileInfoPool.removeUserExcelMaterialInfo(userByPort.getNumber()); ExcelFileInfoPool.removeUserExcelMaterialInfo(userByPort.getNumber());
ExcelFileInfoPool.removeUserExcelMaterialTypeInfo(userByPort.getNumber()); ExcelFileInfoPool.removeUserExcelMaterialTypeInfo(userByPort.getNumber());
ExcelFileInfoPool.removeUserExcelMaterialInfoByOverwrite(userByPort.getNumber());
} }
@ -1080,6 +1135,9 @@ public class ExcelServiceImpl implements ExcelService {
String s = dataIndex.get(i); String s = dataIndex.get(i);
String msg = s + "出现异常,名称为:" + mname + ",型号为:" + excelInfoForMaterial.getVersion() + "的物料已存在"; String msg = s + "出现异常,名称为:" + mname + ",型号为:" + excelInfoForMaterial.getVersion() + "的物料已存在";
errMsg.add(msg); errMsg.add(msg);
// 添加一条数据用于覆盖
ExcelFileInfoPool.addExcelMaterialInfoByOverwrite(userByPort.getNumber(), excelInfoForMaterial);
log.info("要覆盖的数据" + JSONObject.toJSONString(excelInfoForMaterial));
continue; continue;
} }
if (excelInfoForMaterial.getCode() != null) { if (excelInfoForMaterial.getCode() != null) {
@ -1087,6 +1145,9 @@ public class ExcelServiceImpl implements ExcelService {
if (materialByCode != null) { if (materialByCode != null) {
String s = dataIndex.get(i); String s = dataIndex.get(i);
String msg = s + "出现异常,编码为:" + excelInfoForMaterial.getCode() + "的物料已存在"; String msg = s + "出现异常,编码为:" + excelInfoForMaterial.getCode() + "的物料已存在";
// 添加一条数据用于覆盖
ExcelFileInfoPool.addExcelMaterialInfoByOverwrite(userByPort.getNumber(), excelInfoForMaterial);
log.info("要覆盖的数据" + JSONObject.toJSONString(excelInfoForMaterial));
errMsg.add(msg); errMsg.add(msg);
continue; continue;
} }

33
src/main/resources/templates/pages/material/material-out.html

@ -352,7 +352,7 @@
, shade: 0.8 , shade: 0.8
, id: 'LAY_layuipro' //设定一个id,防止重复弹出 , id: 'LAY_layuipro' //设定一个id,防止重复弹出
, resize: false , resize: false
, btn: ['导入', '取消'] , btn: ['导入', '取消', '覆盖']
, btnAlign: 'c' , btnAlign: 'c'
, moveType: 1 //拖拽模式,0或者1 , moveType: 1 //拖拽模式,0或者1
, content: re , content: re
@ -414,6 +414,37 @@
} }
}) })
} }
, btn3: function (index, layero) {
// 按钮【按钮三】的回调
$.ajax({
url: "/excel/overwriteExcelByMaterial",
type: "post",
data: JSON.stringify({"result": "yes"}),
dataType: "json",
contentType: "application/json;charset=utf-8",
success: function () {
if (socket !== null) {
socket.close();
} else {
layer.close(index);
}
layer.alert("数据修改完成", {
icon: 0
}, function (indexForMsg, layero) {
layer.close(indexForMsg);
layer.close(loading2);
closeShowDataMessage();
table.reload('currentTableId', {
url: '/material/material',
page: {
curr: 1
},
}, 'data');
})
}
})
return false;
}
}); });

Loading…
Cancel
Save