| | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.fzzy.igds.constant.RedisConst; |
| | | import com.fzzy.igds.domain.Depot; |
| | | import com.fzzy.igds.domain.DepotStore; |
| | | import com.fzzy.igds.mapper.DepotMapper; |
| | | import com.fzzy.igds.utils.ContextUtil; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * @Description |
| | |
| | | private DepotMapper depotMapper; |
| | | @Resource |
| | | private RedisCache redisCache; |
| | | @Resource |
| | | private DepotStoreService depotStoreService; |
| | | |
| | | /** |
| | | * 查询库区下仓库列表 |
| | | * |
| | | * @param companyId |
| | | * @param deptId |
| | | * @param idDesc 是否ID倒序排列 |
| | | * @param idDesc 是否ID倒序排列 |
| | | * @return |
| | | */ |
| | | public List<Depot> getData(String companyId, String deptId, boolean idDesc) { |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | |
| | | |
| | | QueryWrapper<Depot> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("company_id", companyId); |
| | | if(StringUtils.isNotBlank(deptId)){ |
| | | if (StringUtils.isNotBlank(deptId)) { |
| | | queryWrapper.likeRight("dept_id", deptId); |
| | | } |
| | | |
| | | if(idDesc){ |
| | | |
| | | if (idDesc) { |
| | | //ID倒序 |
| | | queryWrapper.orderByDesc("id"); |
| | | }else { |
| | | } else { |
| | | //序号正序 |
| | | queryWrapper.orderByAsc("order_num"); |
| | | } |
| | | |
| | | return depotMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 根据库存表信息,更新仓库库存 |
| | | * |
| | | * @param data |
| | | */ |
| | | public void updateByDepotStore(DepotStore data) { |
| | | UpdateWrapper<Depot> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", data.getDepotId()).set("storage_real", data.getStorageReal()); |
| | | |
| | | depotMapper.update(null, updateWrapper); |
| | | } |
| | | |
| | | /** |
| | |
| | | depot.setCreateBy(ContextUtil.getLoginUserName()); |
| | | depot.setCreateTime(new Date()); |
| | | depotMapper.insert(depot); |
| | | }else { |
| | | } else { |
| | | depot.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | depot.setUpdateTime(new Date()); |
| | | depotMapper.updateById(depot); |
| | | } |
| | | flushCache(depot.getCompanyId()); |
| | | } |
| | | |
| | | /** |
| | | * 更新库存信息 |
| | | * |
| | | * @param depot |
| | | */ |
| | | public void updateStorageReal(Depot depot) { |
| | | |
| | | Depot cacheDepot = this.getCacheDepot(depot.getCompanyId(), depot.getId()); |
| | | |
| | | depot.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | depot.setUpdateTime(new Date()); |
| | | depot.setRemark("【" + ContextUtil.getLoginUserName() + "】于[" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") + "]修改库存:" + cacheDepot.getStorageReal() + "-->" + depot.getStorageReal()); |
| | | depotMapper.updateById(depot); |
| | | |
| | | DepotStore lastData = new DepotStore(); |
| | | |
| | | //主键ID规则:yyyyMMddHHmm_仓库编码 |
| | | lastData.setId(DateFormatUtils.format(new Date(), "yyyyMMddHHmm") + "_" + depot.getId() + "_HAND"); |
| | | lastData.setCompanyId(depot.getCompanyId()); |
| | | lastData.setDeptId(depot.getDeptId()); |
| | | lastData.setDepotId(depot.getId()); |
| | | lastData.setStorageReal(0.0); |
| | | lastData.setUpdateTime(new Date()); |
| | | lastData.setUpdateBy("系统定时统计"); |
| | | |
| | | |
| | | lastData.setDepotStatus(depot.getDepotStatus()); |
| | | lastData.setFoodVariety(depot.getFoodVariety()); |
| | | lastData.setFoodLevel(depot.getFoodLevel()); |
| | | lastData.setFoodLocation(depot.getFoodLocation()); |
| | | lastData.setFoodLocationId(depot.getFoodLocationId()); |
| | | lastData.setFoodType(depot.getFoodType()); |
| | | lastData.setFoodYear(depot.getFoodYear()); |
| | | |
| | | |
| | | lastData.setStorageReal(depot.getStorageReal()); |
| | | lastData.setCreateTime(new Date()); //设置为最新时间,其他系统可以通过此时间查询数据是否有更新修改,同步到省平台接口。 |
| | | lastData.setCreateBy(ContextUtil.getLoginUserName()); |
| | | lastData.setRemark("【" + ContextUtil.getLoginUserName() + "】于[" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") + "]修改库存为:" + depot.getStorageReal()); |
| | | |
| | | depotStoreService.updateAndSave(lastData); |
| | | flushCache(depot.getCompanyId()); |
| | | } |
| | | |
| | |
| | | if (StringUtils.isEmpty(depotId)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | UpdateWrapper<Depot> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", depotId).set("depot_status", status); |
| | | depotMapper.update(null, updateWrapper); |
| | |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | |
| | | List<Depot> list = this.getData(companyId,null, false); |
| | | List<Depot> list = this.getData(companyId, null, false); |
| | | |
| | | this.setCacheDepotList(list, companyId); |
| | | } |
| | |
| | | String key; |
| | | for (Depot depot : list) { |
| | | key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT, depot.getId()); |
| | | redisCache.setCacheObject(key, depot); |
| | | redisCache.setCacheObject(key, depot, 24, TimeUnit.HOURS); |
| | | } |
| | | } |
| | | |
| | |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT) + "*"; |
| | | |
| | | Collection<String> keys = redisCache.keys(patten); |
| | | if (null == keys) { |
| | | return null; |
| | | } |
| | | |
| | | List<Depot> list = new ArrayList<>(); |
| | | for (String key : keys) { |
| | | list.add((Depot) redisCache.getCacheObject(key)); |
| | | |
| | | String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT) + "*"; |
| | | Collection<String> keys = redisCache.keys(patten); |
| | | if (null != keys) { |
| | | for (String key : keys) { |
| | | if(null == redisCache.getCacheObject(key)){ |
| | | list = new ArrayList<>(); |
| | | break; |
| | | } |
| | | list.add((Depot) redisCache.getCacheObject(key)); |
| | | } |
| | | } |
| | | |
| | | //缓存获取为空,则查询数据库 |
| | | if (list.size() < 1) { |
| | | list = this.getData(companyId,null, false); |
| | | if (list.isEmpty()) { |
| | | list = this.getData(companyId, null, false); |
| | | setCacheDepotList(list, companyId); |
| | | } |
| | | |
| | | //重新排序 |
| | | Collections.sort(list, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum()); |
| | | if (!list.isEmpty()) { |
| | | // 检查是否有仓库的排序号为空 |
| | | for (Depot depot : list) { |
| | | if (null == depot.getOrderNum()) { |
| | | //排序号为空,则默认给1 |
| | | depot.setOrderNum(1); |
| | | } |
| | | } |
| | | Collections.sort(list, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum()); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | |
| | | result.add(depot); |
| | | } |
| | | } |
| | | //重新排序 |
| | | Collections.sort(result, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum()); |
| | | if (!result.isEmpty()) { |
| | | //重新排序 |
| | | Collections.sort(list, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | |
| | | String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT, depotId); |
| | | Depot depot = redisCache.getCacheObject(key); |
| | | if (null == depot) { |
| | | depot = depotMapper.selectById(depotId); |
| | | depot = depotMapper.selectById(depotId); |
| | | redisCache.setCacheObject(key, depot); |
| | | } |
| | | return depot; |
| | | } |
| | | |
| | | /** |
| | | * 获取仓库信息-根据仓库名称获取仓库ID |
| | | * |
| | | * @param deptId |
| | | * @return |
| | | */ |
| | | public String getDepotId(String deptId, String depotName) { |
| | | if (StringUtils.isEmpty(deptId)) { |
| | | return null; |
| | | } |
| | | if (StringUtils.isEmpty(depotName)) { |
| | | return null; |
| | | } |
| | | |
| | | List<Depot> depotList = getCacheDepotList(ContextUtil.getCompanyId(), deptId); |
| | | if (null == depotList || depotList.isEmpty()) { |
| | | return null; |
| | | } |
| | | for (Depot depot : depotList) { |
| | | if (depotName.equals(depot.getName())) { |
| | | return depot.getId(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |