|
|
@@ -29,10 +29,10 @@ public class TakeStockService extends GenericProvider {
|
|
|
|
|
|
public List<Map<String,Object>> takeStock(String[] ckIds, String date,String type) throws Exception {
|
|
|
logger.warn("com.lc.ibps.components.reagent.service.TakeStockService.takeStock()--->ckId={},date={},type={}", ckIds, date, type);
|
|
|
- String sql = "SELECT *from v_reagentinventory WHERE withhold=0 ORDER BY ming_cheng_";
|
|
|
+ String sql = "SELECT * from v_reagentinventory WHERE withhold=0 ORDER BY ming_cheng_";
|
|
|
if(BeanUtils.isNotEmpty(ckIds)){
|
|
|
String positions = String.join("','", ckIds);
|
|
|
- sql = "SELECT *from v_reagentinventory where withhold=0 and position in('%s') ORDER BY ming_cheng_";
|
|
|
+ sql = "SELECT * from v_reagentinventory where withhold=0 and position in('%s') ORDER BY ming_cheng_";
|
|
|
sql = String.format(sql, positions);
|
|
|
}
|
|
|
List<Map<String,Object>> list = commonDao.query(sql);
|
|
|
@@ -44,76 +44,90 @@ public class TakeStockService extends GenericProvider {
|
|
|
if (BeanUtils.isEmpty(date)){
|
|
|
date = currDate;
|
|
|
}
|
|
|
- String mainId = UniqueIdUtil.getId();
|
|
|
- Map<String,Object> main = new HashMap<>();
|
|
|
-
|
|
|
- for(Map<String,Object> map : list){
|
|
|
- String transSql = "SELECT sum(quantity) as quantity,type_ from t_reagent_trans WHERE DATE_FORMAT(create_time_,'%%Y-%%m')='%s' and inventory_id='%s' GROUP BY type_";
|
|
|
- String id = StrUtil.str(map.get("id_"));
|
|
|
- long lastMonth = 0L;
|
|
|
- long currIn = 0L;
|
|
|
- long currOut = 0L;
|
|
|
- long currBalance = StrUtil.parseLongSafe(map.get("quantity"));
|
|
|
- List<Map<String,Object>> trans = commonDao.query(String.format(transSql, date, id));
|
|
|
- if(Collections.isNotEmpty(trans)){
|
|
|
- lastMonth = currBalance;
|
|
|
- for (Map<String,Object> tran : trans){
|
|
|
- String lei = StrUtil.str(tran.get("type_"));
|
|
|
- if ("-1".equals(lei)){
|
|
|
- currOut = StrUtil.parseLongSafe(tran.get("quantity"));
|
|
|
- lastMonth = lastMonth + currOut;
|
|
|
- }else {
|
|
|
- currIn = StrUtil.parseLongSafe(tran.get("quantity"));
|
|
|
- lastMonth = lastMonth - currIn;
|
|
|
+
|
|
|
+ // 按仓库(position)分组
|
|
|
+ Map<String, List<Map<String, Object>>> groupByPosition = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(map -> StrUtil.str(map.get("position"))));
|
|
|
+
|
|
|
+ if ("job".equals(type)){
|
|
|
+ // 处理每个仓库组
|
|
|
+ for (Map.Entry<String, List<Map<String, Object>>> entry : groupByPosition.entrySet()) {
|
|
|
+ String position = entry.getKey();
|
|
|
+ List<Map<String, Object>> groupList = entry.getValue();
|
|
|
+
|
|
|
+ // 生成该仓库组的主表ID
|
|
|
+ String mainId = UniqueIdUtil.getId();
|
|
|
+ // 获取该仓库组的地点(取第一个试剂的di_dian_)
|
|
|
+ String diDian = StrUtil.str(groupList.get(0).get("di_dian_"));
|
|
|
+
|
|
|
+ // 处理该仓库组内的所有试剂
|
|
|
+ for (Map<String, Object> map : groupList) {
|
|
|
+ String transSql = "SELECT sum(quantity) as quantity,type_ from t_reagent_trans WHERE DATE_FORMAT(create_time_,'%%Y-%%m')='%s' and inventory_id='%s' GROUP BY type_";
|
|
|
+ String id = StrUtil.str(map.get("id_"));
|
|
|
+ long lastMonth = 0L;
|
|
|
+ long currIn = 0L;
|
|
|
+ long currOut = 0L;
|
|
|
+ long currBalance = StrUtil.parseLongSafe(map.get("quantity"));
|
|
|
+ List<Map<String,Object>> trans = commonDao.query(String.format(transSql, date, id));
|
|
|
+ if(Collections.isNotEmpty(trans)){
|
|
|
+ lastMonth = currBalance;
|
|
|
+ for (Map<String,Object> tran : trans){
|
|
|
+ String lei = StrUtil.str(tran.get("type_"));
|
|
|
+ if ("-1".equals(lei)){
|
|
|
+ currOut = StrUtil.parseLongSafe(tran.get("quantity"));
|
|
|
+ lastMonth = lastMonth + currOut;
|
|
|
+ }else {
|
|
|
+ currIn = StrUtil.parseLongSafe(tran.get("quantity"));
|
|
|
+ lastMonth = lastMonth - currIn;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ lastMonth = Math.max(lastMonth, 0);
|
|
|
+ map.put("lastMonth" , lastMonth);
|
|
|
+ map.put("currIn" , currIn);
|
|
|
+ map.put("currOut" , currOut);
|
|
|
+ map.put("currBalance" , currBalance);
|
|
|
+
|
|
|
+ // 生成子表记录(关联到当前仓库组的主表ID)
|
|
|
+ Map<String,Object> sub = new HashMap<>();
|
|
|
+ sub.put("id_" , UniqueIdUtil.getId());
|
|
|
+ sub.put("parent_id_", mainId);
|
|
|
+ sub.put("create_by_","1");
|
|
|
+ sub.put("create_time_", DateUtil.now());
|
|
|
+ sub.put("shi_fou_guo_shen_","待处理");
|
|
|
+ sub.put("di_dian_","");
|
|
|
+ sub.put("shi_ji_ming_cheng",StrUtil.str(map.get("ming_cheng_")));
|
|
|
+ sub.put("bian_ma_",StrUtil.str(map.get("bian_ma")));
|
|
|
+ sub.put("pi_hao_",StrUtil.str(map.get("batch_num")));
|
|
|
+ sub.put("lei_bie_",StrUtil.str(map.get("lei_bie_")));
|
|
|
+ sub.put("gui_ge_",StrUtil.str(map.get("gui_ge_")));
|
|
|
+ sub.put("dan_wei_",StrUtil.str(map.get("dan_wei_")));
|
|
|
+ sub.put("you_xiao_qi_",StrUtil.str(map.get("exp_date")));
|
|
|
+ sub.put("sheng_chan_shang_",StrUtil.str(map.get("chang_jia_")));
|
|
|
+ sub.put("ku_cun_liang_", StrUtil.parseLongSafe(map.get("quantity")));
|
|
|
+ sub.put("cun_chu_wei_zhi_",StrUtil.str(map.get("position")));
|
|
|
+ sub.put("shang_yue_jie_cun",lastMonth);
|
|
|
+ sub.put("ben_yue_ru_ku_",currIn);
|
|
|
+ sub.put("ben_yue_chu_ku_",currOut);
|
|
|
+ sub.put("ben_yue_jie_cun_",currBalance);
|
|
|
+ sub.put("ku_cun_id_",id);
|
|
|
+ sub.put("pan_cun_shu_liang",StrUtil.parseLongSafe(map.get("quantity")));
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(sub,"t_sjhcpdzb"));
|
|
|
}
|
|
|
+
|
|
|
+ // 创建该仓库组的主表记录
|
|
|
+ Map<String,Object> main = new HashMap<>();
|
|
|
+ main.put("id_" , mainId);
|
|
|
+ main.put("create_by_","1");
|
|
|
+ main.put("create_time_", DateUtil.now());
|
|
|
+ main.put("shi_fou_guo_shen_","待处理");
|
|
|
+ main.put("yue_fen_",date);
|
|
|
+ main.put("di_dian_", diDian); // 设置地点(从该仓库组第一个试剂获取)
|
|
|
+ main.put("cang_ku_",StrUtil.str(groupList.get(0).get("position")));
|
|
|
+ commonDao.execute(SqlUtil.buildInsertSql(main,"t_sjhcpdb"));
|
|
|
}
|
|
|
- lastMonth = Math.max(lastMonth, 0);
|
|
|
- map.put("lastMonth" , lastMonth);
|
|
|
- map.put("currIn" , currIn);
|
|
|
- map.put("currOut" , currOut);
|
|
|
- map.put("currBalance" , currBalance);
|
|
|
- if ("job".equals(type)){
|
|
|
- // 定时任务执行 需要在每月最后一天 自动推送盘点记录流程 添加盘点主子表数据
|
|
|
- // 主表 t_sjhcpdb 子表 t_sjhcpdzb
|
|
|
- main.put("di_dian_",map.get("di_dian_"));
|
|
|
- Map<String,Object> sub = new HashMap<>();
|
|
|
- sub.put("id_" , UniqueIdUtil.getId());
|
|
|
- sub.put("parent_id_",mainId);
|
|
|
- sub.put("create_by_","1");
|
|
|
- sub.put("create_time_", DateUtil.now());
|
|
|
- sub.put("shi_fou_guo_shen_","待处理");
|
|
|
- sub.put("di_dian_","");
|
|
|
- sub.put("shi_ji_ming_cheng",StrUtil.str(map.get("ming_cheng_")));
|
|
|
- sub.put("bian_ma_",StrUtil.str(map.get("bian_ma")));
|
|
|
- sub.put("pi_hao_",StrUtil.str(map.get("batch_num")));
|
|
|
- sub.put("lei_bie_",StrUtil.str(map.get("lei_bie_")));
|
|
|
- sub.put("gui_ge_",StrUtil.str(map.get("gui_ge_")));
|
|
|
- sub.put("dan_wei_",StrUtil.str(map.get("dan_wei_")));
|
|
|
- //sub.put("sheng_chan_ri_qi_","");
|
|
|
- sub.put("you_xiao_qi_",StrUtil.str(map.get("exp_date")));
|
|
|
- sub.put("sheng_chan_shang_",StrUtil.str(map.get("chang_jia_")));
|
|
|
- sub.put("ku_cun_liang_", StrUtil.parseLongSafe(map.get("quantity")));
|
|
|
- sub.put("cun_chu_wei_zhi_",StrUtil.str(map.get("position")));
|
|
|
- sub.put("shang_yue_jie_cun",lastMonth);
|
|
|
- sub.put("ben_yue_ru_ku_",currIn);
|
|
|
- sub.put("ben_yue_chu_ku_",currOut);
|
|
|
- sub.put("ben_yue_jie_cun_",currBalance);
|
|
|
- sub.put("ku_cun_id_",id);
|
|
|
- commonDao.execute(SqlUtil.buildInsertSql(sub,"t_sjhcpdzb"));
|
|
|
- }
|
|
|
- }
|
|
|
- if ("job".equals(type)){
|
|
|
- // 定时任务执行 需要在每月最后一天 自动推送盘点记录流程 添加盘点主子表数据
|
|
|
- // 主表 t_sjhcpdb
|
|
|
- main.put("id_" , mainId);
|
|
|
- main.put("create_by_","1");
|
|
|
- main.put("create_time_", DateUtil.now());
|
|
|
- main.put("shi_fou_guo_shen_","待处理");
|
|
|
- main.put("yue_fen_",date);
|
|
|
- commonDao.execute(SqlUtil.buildInsertSql(main,"t_sjhcpdb"));
|
|
|
-
|
|
|
- // 更新库存为 是否可用为 否 即冻结库存
|
|
|
+
|
|
|
+ // 更新库存(冻结所有试剂,与原逻辑一致)
|
|
|
List<String> ids = list.stream().map(record -> record.get("id_").toString()).collect(Collectors.toList());
|
|
|
String updSql = "update t_reagent_inventory set enable_='否' where id_ in (%s)";
|
|
|
commonDao.execute(String.format(updSql,String.join(",",ids)));
|