| | |
| | | package com.fzzy.igds.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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.DepotConf; |
| | | import com.fzzy.igds.repository.DepotConfRepository; |
| | | import com.fzzy.igds.mapper.DepotConfMapper; |
| | | import com.fzzy.igds.utils.ContextUtil; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | public class DepotConfService { |
| | | |
| | | @Resource |
| | | private DepotConfRepository depotConfRepository; |
| | | private DepotConfMapper depotConfMapper; |
| | | @Resource |
| | | private DepotService depotService; |
| | | @Resource |
| | | private RedisCache redisCache; |
| | | |
| | | /** |
| | | * jpa查询配置信息 |
| | | * 查询配置信息 |
| | | * |
| | | * @param companyId |
| | | * @param deptId |
| | |
| | | if (StringUtils.isEmpty(companyId)) { |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | if (StringUtils.isEmpty(deptId)) { |
| | | deptId = ContextUtil.subDeptId(null); |
| | | QueryWrapper<DepotConf> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("company_id", companyId); |
| | | |
| | | if(StringUtils.isNotBlank(deptId)){ |
| | | queryWrapper.eq("dept_id", deptId); |
| | | } |
| | | return depotConfRepository.getDepotConf(companyId, deptId); |
| | | return depotConfMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | /** |
| | | * jpa更新保存配置信息 |
| | | * 更新保存配置信息 |
| | | * |
| | | * @param conf |
| | | */ |
| | |
| | | } |
| | | if (StringUtils.isEmpty(conf.getDeptId())) { |
| | | conf.setDeptId(ContextUtil.subDeptId(null)); |
| | | } |
| | | |
| | | if (null == conf.getUpdateBy()) { |
| | | conf.setCreateBy(ContextUtil.getLoginUserName()); |
| | | conf.setCreateTime(new Date()); |
| | | |
| | | conf.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | conf.setUpdateTime(new Date()); |
| | | depotConfMapper.insert(conf); |
| | | }else { |
| | | conf.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | conf.setUpdateTime(new Date()); |
| | | depotConfMapper.updateById(conf); |
| | | } |
| | | conf.setUpdateBy(ContextUtil.getLoginUserName()); |
| | | conf.setUpdateTime(new Date()); |
| | | depotConfRepository.save(conf); |
| | | flushConfCache(conf.getCompanyId()); |
| | | } |
| | | |
| | | /** |
| | | * jpa删除配置信息 |
| | | * 删除配置信息 |
| | | * |
| | | * @param conf |
| | | * @return |
| | | */ |
| | | public void deleteDepotConf(DepotConf conf) { |
| | | depotConfRepository.delete(conf); |
| | | depotConfMapper.deleteById( conf); |
| | | |
| | | //删除配置缓存 |
| | | this.delCacheDepotConf(conf, conf.getCompanyId()); |
| | |
| | | */ |
| | | public void setCacheDepotConf(List<DepotConf> list, String companyId) { |
| | | if (null != list) { |
| | | Depot depot; |
| | | String key; |
| | | for (DepotConf depotConf : list) { |
| | | depot = depotService.getCacheDepot(companyId, depotConf.getDepotId()); |
| | | if (null != depot) { |
| | | depotConf.setDepotName(depot.getName()); |
| | | depotConf.setDepotType(depot.getDepotType()); |
| | | } |
| | | key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF, depotConf.getDepotId()); |
| | | redisCache.setCacheObject(key, depotConf); |
| | | } |
| | |
| | | String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF, depotId); |
| | | DepotConf depotConf = redisCache.getCacheObject(key); |
| | | if (null == depotConf) { |
| | | depotConf = depotConfRepository.getDepotConfByDepotId(companyId, depotId); |
| | | depotConf = depotConfMapper.selectById(depotId); |
| | | redisCache.setCacheObject(key, depotConf); |
| | | } |
| | | |
| | | return depotConf; |
| | | } |
| | | |
| | | /** |
| | | * 根据仓库列表,自动生成仓库配置信息 |
| | | * @param companyId |
| | | */ |
| | | private void addConfByDepot(String companyId) { |
| | | List<Depot> list = depotService.getCacheDepotList(companyId); |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | } |
| | | DepotConf conf; |
| | | for (Depot depot : list) { |
| | | conf = new DepotConf(); |
| | | conf.setDepotId(depot.getId()); |
| | | conf.setCompanyId(depot.getCompanyId()); |
| | | conf.setDeptId(depot.getDeptId()); |
| | | this.saveConf(conf); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | companyId = ContextUtil.getCompanyId(); |
| | | } |
| | | |
| | | List<DepotConf> list = depotConfRepository.getDepotConfByCompanyId(companyId); |
| | | List<DepotConf> list = this.getConfList(companyId, null); |
| | | |
| | | this.setCacheDepotConf(list, companyId); |
| | | } |
| | |
| | | * @param freq |
| | | */ |
| | | public void updateFreq(String freq) { |
| | | depotConfRepository.updateGrainFreq(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), freq); |
| | | UpdateWrapper<DepotConf> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("dept_id", ContextUtil.subDeptId(null)).set("pos_x", freq); |
| | | depotConfMapper.update(null, updateWrapper); |
| | | } |
| | | } |