diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java index 553f8cf..29bedf0 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/storageLocation/storageLocationController.java @@ -1,6 +1,5 @@ package com.ruoyi.web.controller.storageLocation; -import com.ruoyi.clMaterial.domain.CYlMaterial; import com.ruoyi.common.annotation.DataSource; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.constant.CacheConstants; @@ -11,13 +10,12 @@ import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.DataSourceType; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.storageLocation.domain.StorageLocation; +import com.ruoyi.storageLocation.domain.StorageSelected; import com.ruoyi.storageLocation.service.StorageLocationService; import com.ruoyi.system.service.ISysConfigService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; - -import java.util.List; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -106,6 +104,7 @@ public class storageLocationController extends BaseController return error("已超过有效录入信息时间,当前库位有人正在操作!"); }else{ redisCache.setCacheObject(getLocationZyCacheKey(materialBh),user_name); + redisCache.deleteObject(getLocationLyCacheKey(materialBh)); return toAjax(storageLocationService.addStorageLocation(storageLocation)); } @@ -167,42 +166,26 @@ public class storageLocationController extends BaseController ajaxResult.put("materialDetailB",listB); ajaxResult.put("materialDetailC",listC); - //根据库位状态 同步更新库位占用缓存-刷新页面时用 - for(StorageLocation sl:listA){ - String materialBh = sl.getMaterialBh(); - String materialState = sl.getMaterialState(); - String kw_user_name = redisCache.getCacheObject(getLocationLyCacheKey(materialBh)); - if("1".equals(materialState)){ - if(StringUtils.isNotNull(kw_user_name)&&user_name.equals(kw_user_name)){ - redisCache.deleteObject(getLocationLyCacheKey(materialBh)); - } - } - } - for(StorageLocation sl:listB){ - String materialBh = sl.getMaterialBh(); - String materialState = sl.getMaterialState(); - String kw_user_name = redisCache.getCacheObject(getLocationLyCacheKey(materialBh)); - if("1".equals(materialState)){ - if(StringUtils.isNotNull(kw_user_name)&&user_name.equals(kw_user_name)){ - redisCache.deleteObject(getLocationLyCacheKey(materialBh)); - } - } - } - for(StorageLocation sl:listC){ - String materialBh = sl.getMaterialBh(); - String materialState = sl.getMaterialState(); - String kw_user_name = redisCache.getCacheObject(getLocationLyCacheKey(materialBh)); - if("1".equals(materialState)){ - if(StringUtils.isNotNull(kw_user_name)&&user_name.equals(kw_user_name)){ - redisCache.deleteObject(getLocationLyCacheKey(materialBh)); - } - } + // 读取已选列表 + List selectedListA = storageLocationService.selectStorageSelectedLocationAList(user_name); + List selectedListB = storageLocationService.selectStorageSelectedLocationBList(user_name); + List selectedListC = storageLocationService.selectStorageSelectedLocationCList(user_name); + + ajaxResult.put("selMaterialDetailA",selectedListA); + ajaxResult.put("selMaterialDetailB",selectedListB); + ajaxResult.put("selMaterialDetailC",selectedListC); + + // 读取全部已选列表 + List selectedList = storageLocationService.selectStorageSelectedLocationList(); + + for(StorageSelected sl:selectedList){ + String materialBh = sl.getMaterial_bh(); + String userName = sl.getUser_name(); + redisCache.setCacheObject(getLocationLyCacheKey(materialBh),userName);//缓存keys丢失,重新设置缓存key } return ajaxResult; } - - /** * 校验库位是否被领用 */ @@ -210,16 +193,27 @@ public class storageLocationController extends BaseController @PostMapping("/checklyStorageLocation") public AjaxResult checklyStorageLocation(@RequestBody StorageLocation storageLocation) { - String storageExpire = configService.selectConfigByKey("storage.expire.ly"); String user_name = getLoginUser().getUsername();//当前登陆者 String materialBh = storageLocation.getMaterialBh(); String kw_user_name = redisCache.getCacheObject(getLocationLyCacheKey(materialBh)); if(StringUtils.isNotNull(kw_user_name)&&!user_name.equals(kw_user_name)){ - return error("当前库位有人正在操作,请勿操作!"); + return error("该库位当前有人正在操作,请勿操作!"); }else{ - redisCache.setCacheObject(getLocationLyCacheKey(materialBh),user_name); + // 判断已选库位表是否存在库位信息 + StorageSelected storageSelected = storageLocationService.hasStorageLocation(materialBh); + if(storageSelected!=null){ + if(!user_name.equals(storageSelected.getUser_name())){ + return error("该库位当前有人正在领用操作,请勿操作!"); + }else{ + return error("该库位已被选择领用,请勿重复操作!"); + } + }else{ + // 保存至已选库位表并缓存 + redisCache.setCacheObject(getLocationLyCacheKey(materialBh),user_name); + storageLocationService.saveStorageLocation(user_name,materialBh); + } return success(); } } @@ -238,6 +232,7 @@ public class storageLocationController extends BaseController if(StringUtils.isNotNull(kw_user_name)&&user_name.equals(kw_user_name)){ redisCache.deleteObject(getLocationLyCacheKey(materialBh)); } + storageLocationService.deleteStorageLocation(user_name,materialBh); return success(); } @@ -249,20 +244,15 @@ public class storageLocationController extends BaseController public AjaxResult confirmStorageLocation(@RequestBody String [] materialBhArr) { - System.out.println(materialBhArr); - /* String storageExpire = configService.selectConfigByKey("storage.expire.ly"); - - String user_name = getLoginUser().getUsername();//当前登陆者 - String materialBh = storageLocation.getMaterialBh(); - - String kw_user_name = redisCache.getCacheObject(getLocationLyCacheKey(materialBh)); - if(StringUtils.isNotNull(kw_user_name)&&!user_name.equals(kw_user_name)){ - return error("当前库位有人正在操作,请勿操作!"); - }else{ - redisCache.setCacheObject(getLocationLyCacheKey(materialBh),user_name); - return success(); - }*/ storageLocationService.confirmStorageLocation(materialBhArr); + + List list = new ArrayList(); + for(String materialBh:materialBhArr){ + list.add(getLocationZyCacheKey(materialBh)); + } + Collection> collection = new ArrayList<>(); + collection.add(list); + redisCache.deleteObject(collection);// 清空占用缓存keys return success(); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/domain/StorageLocation.java b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/domain/StorageLocation.java index 59d2804..37a32ab 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/domain/StorageLocation.java +++ b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/domain/StorageLocation.java @@ -12,6 +12,7 @@ public class StorageLocation extends BaseEntity { private static final long serialVersionUID = 1L; + private String userName; private String materialBh; private String materialZlh; private String materialXingh; @@ -20,6 +21,14 @@ public class StorageLocation extends BaseEntity private String materialMs; private String materialState; + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + public String getMaterialBh() { return materialBh; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/domain/StorageSelected.java b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/domain/StorageSelected.java new file mode 100644 index 0000000..3149c16 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/domain/StorageSelected.java @@ -0,0 +1,28 @@ +package com.ruoyi.storageLocation.domain; + +/** + * 已选库位管理对象 StorageLocation + * + * @author ruoyi + * @date 2024-02-28 + */ +public class StorageSelected { + private String user_name; + private String material_bh; + + public String getUser_name() { + return user_name; + } + + public void setUser_name(String user_name) { + this.user_name = user_name; + } + + public String getMaterial_bh() { + return material_bh; + } + + public void setMaterial_bh(String material_bh) { + this.material_bh = material_bh; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/mapper/StorageLocationMapper.java b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/mapper/StorageLocationMapper.java index 00d21e5..57c57e8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/mapper/StorageLocationMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/mapper/StorageLocationMapper.java @@ -1,6 +1,8 @@ package com.ruoyi.storageLocation.mapper; import com.ruoyi.storageLocation.domain.StorageLocation; +import com.ruoyi.storageLocation.domain.StorageSelected; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -34,4 +36,39 @@ public interface StorageLocationMapper * @param materialBhArr */ void confirmStorageLocation(String[] materialBhArr); + + /** + * 判断已选库位表是否存在库位信息 + * @param materialBh + * @return + */ + StorageSelected hasStorageLocation(String materialBh); + + /** + * 保存至已选库位表 + * @param materialBh + */ + void saveStorageLocation(@Param("userName") String userName, @Param("materialBh") String materialBh); + + /** + * 删除已选库位表记录 + * @param userName + * @param materialBh + */ + void deleteStorageLocation(@Param("userName") String userName, @Param("materialBh") String materialBh); + + /** + * 读取已选列表 + * @param userName + * @return + */ + List selectStorageSelectedLocationAList(String userName); + List selectStorageSelectedLocationBList(String userName); + List selectStorageSelectedLocationCList(String userName); + + /** + * 读取全部已选列表 + * @return + */ + List selectStorageSelectedLocationList(); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/StorageLocationService.java b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/StorageLocationService.java index 8496e16..bc19956 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/StorageLocationService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/StorageLocationService.java @@ -2,6 +2,7 @@ package com.ruoyi.storageLocation.service; import com.ruoyi.clMaterial.domain.CYlMaterial; import com.ruoyi.storageLocation.domain.StorageLocation; +import com.ruoyi.storageLocation.domain.StorageSelected; import java.util.List; @@ -35,4 +36,39 @@ public interface StorageLocationService * @param materialBhArr */ void confirmStorageLocation(String[] materialBhArr); + + /** + * 判断已选库位表是否存在库位信息 + * @param materialBh + * @return + */ + StorageSelected hasStorageLocation(String materialBh); + + /** + * 保存至已选库位表 + * @param materialBh + */ + void saveStorageLocation(String userName,String materialBh); + + /** + * 删除已选库位表记录 + * @param userName + * @param materialBh + */ + void deleteStorageLocation(String userName, String materialBh); + + /** + * 读取已选列表 + * @param userName + * @return + */ + List selectStorageSelectedLocationAList(String userName); + List selectStorageSelectedLocationBList(String userName); + List selectStorageSelectedLocationCList(String userName); + + /** + * 读取全部已选列表 + * @return + */ + List selectStorageSelectedLocationList(); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/impl/StorageLocationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/impl/StorageLocationServiceImpl.java index a78f160..8476d87 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/impl/StorageLocationServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/storageLocation/service/impl/StorageLocationServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.storageLocation.service.impl; import com.ruoyi.storageLocation.domain.StorageLocation; +import com.ruoyi.storageLocation.domain.StorageSelected; import com.ruoyi.storageLocation.mapper.StorageLocationMapper; import com.ruoyi.storageLocation.service.StorageLocationService; import org.springframework.beans.factory.annotation.Autowired; @@ -56,4 +57,60 @@ public class StorageLocationServiceImpl implements StorageLocationService public void confirmStorageLocation(String[] materialBhArr) { storageLocationMapper.confirmStorageLocation(materialBhArr); } + + /** + * 判断已选库位表是否存在库位信息 + * @param materialBh + * @return + */ + @Override + public StorageSelected hasStorageLocation(String materialBh) { + return storageLocationMapper.hasStorageLocation(materialBh); + } + + /** + * 保存至已选库位表 + * @param materialBh + */ + @Override + public void saveStorageLocation(String userName,String materialBh) { + storageLocationMapper.saveStorageLocation(userName,materialBh); + } + + /** + * 删除已选库位表记录 + * @param userName + * @param materialBh + */ + @Override + public void deleteStorageLocation(String userName, String materialBh) { + storageLocationMapper.deleteStorageLocation(userName,materialBh); + } + + /** + * 读取已选列表 + * @param userName + * @return + */ + @Override + public List selectStorageSelectedLocationAList(String userName) { + return storageLocationMapper.selectStorageSelectedLocationAList(userName); + } + @Override + public List selectStorageSelectedLocationBList(String userName) { + return storageLocationMapper.selectStorageSelectedLocationBList(userName); + } + @Override + public List selectStorageSelectedLocationCList(String userName) { + return storageLocationMapper.selectStorageSelectedLocationCList(userName); + } + + /** + * 读取全部已选列表 + * @return + */ + @Override + public List selectStorageSelectedLocationList() { + return storageLocationMapper.selectStorageSelectedLocationList(); + } } diff --git a/ruoyi-system/src/main/resources/mapper/storageLocation/StorageLocationMapper.xml b/ruoyi-system/src/main/resources/mapper/storageLocation/StorageLocationMapper.xml index dd5fe0d..e1a0014 100644 --- a/ruoyi-system/src/main/resources/mapper/storageLocation/StorageLocationMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/storageLocation/StorageLocationMapper.xml @@ -5,6 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -50,5 +51,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + insert into storageSelected (user_name,material_bh) values (#{userName},#{materialBh}) + + + + delete from storageSelected where user_name = #{userName} and material_bh = #{materialBh} + + + + + + + diff --git a/ruoyi-ui/src/views/storageLocation/locationConsuming.vue b/ruoyi-ui/src/views/storageLocation/locationConsuming.vue index ae16c8d..5aedb51 100644 --- a/ruoyi-ui/src/views/storageLocation/locationConsuming.vue +++ b/ruoyi-ui/src/views/storageLocation/locationConsuming.vue @@ -519,6 +519,11 @@ this.materialDetailA = response.materialDetailA; this.materialDetailB = response.materialDetailB; this.materialDetailC = response.materialDetailC; + + //已选库位数据 + this.selMaterialDetailA = response.selMaterialDetailA; + this.selMaterialDetailB = response.selMaterialDetailB; + this.selMaterialDetailC = response.selMaterialDetailC; }); }, @@ -675,6 +680,15 @@ this.selMaterialDetailC.forEach(function(item,index,array) { materialBhArr.push(item.materialBh) }) + + if(materialBhArr.length==0){ + this.$message({ + message: '没有选择库位领用,无法继续操作!', + type: 'error' + }); + return; + } + confirmStorageLocation(materialBhArr).then(response => { this.$modal.msgSuccess("领用成功"); this.activeName = 'locationShow';