| | |
| | | |
| | | // get a list of records based on an array of ids |
| | | getMany: async (resource, params) => { |
| | | // console.log("getMany", resource, params); |
| | | |
| | | if (resource === "user") { |
| | | await new Promise((r) => setTimeout(r, 1000)); |
| | | } |
| | | const res = await request.post(resource + "/many/" + params.ids); |
| | | const { code, msg, data } = res.data; |
| | | if (code === 200) { |
| | |
| | | }, |
| | | })); |
| | | |
| | | const locUseStatusChoices = typeof localStorage !== 'undefined' |
| | | ? (JSON.parse(localStorage.getItem('sys_dicts') || '[]')).filter((d) => d.dictTypeCode === 'sys_loc_use_stas') |
| | | : []; |
| | | |
| | | const filters = [ |
| | | <SearchInput source="condition" alwaysOn />, |
| | | <AutocompleteInput |
| | | source="useStatus" |
| | | label="table.field.loc.useStatus" |
| | | choices={locUseStatusChoices} |
| | | optionText="label" |
| | | optionValue="value" |
| | | resettable |
| | | />, |
| | | <NumberInput source="locId" label="table.field.locItem.locId" />, |
| | | <TextInput source="locCode" label="table.field.locItem.locCode" />, |
| | | <NumberInput source="matnrId" label="table.field.locItem.matnrId" />, |
| | |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | import com.vincent.rsf.server.manager.enums.LocStsType; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<LocItem, BaseParam> pageParam = new PageParam<>(baseParam, LocItem.class); |
| | | |
| | | // 库位状态筛选:关联 man_loc,不能作为 man_loc_item 字段参与 buildWrapper |
| | | Object useStatus = map.get("useStatus"); |
| | | if (pageParam.getWhere() != null && pageParam.getWhere().getMap() != null) { |
| | | pageParam.getWhere().getMap().remove("useStatus"); |
| | | } |
| | | QueryWrapper<LocItem> wrapper = pageParam.buildWrapper(true); |
| | | if (useStatus != null && StringUtils.isNotBlank(useStatus.toString())) { |
| | | String status = useStatus.toString().replace("'", "''"); |
| | | wrapper.apply("EXISTS (SELECT 1 FROM man_loc ml WHERE ml.id = man_loc_item.loc_id AND ml.use_status = '" + status + "')"); |
| | | } |
| | | FieldsUtils.setFieldsFilters(wrapper, pageParam, LocItem.class); |
| | | |
| | | /**拼接扩展字段*/ |
| | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |
| | | @PostMapping({"/user/many/{ids}", "/users/many/{ids}"}) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(userService.listByIds(Arrays.asList(ids))); |
| | | return R.ok().add(userService.listByIdsCached(Arrays.asList(ids))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:user:list')") |
| | |
| | | import com.vincent.rsf.server.common.domain.PageResult; |
| | | import com.vincent.rsf.server.system.entity.User; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | | public interface UserService extends IService<User> { |
| | | |
| | | /** 按 ID 批量查询用户(带短期缓存,减轻列表页 createBy/updateBy 等多次请求压力) */ |
| | | List<User> listByIdsCached(Collection<Long> ids); |
| | | |
| | | PageResult<User> pageRel(PageParam<User, BaseParam> pageParam); |
| | | |
| | | User getByUsername(String username, Long tenantId); |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("userService") |
| | | public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService { |
| | | |
| | | /** 批量查询缓存:key = 排序后的 ids 拼接,value = (过期时间戳, 用户列表),TTL 5 分钟 */ |
| | | private static final long CACHE_TTL_MS = 5 * 60 * 1000L; |
| | | private static final ConcurrentHashMap<String, CacheEntry<List<User>>> USER_MANY_CACHE = new ConcurrentHashMap<>(64); |
| | | |
| | | @Resource |
| | | private UserRoleService userRoleService; |
| | |
| | | return baseMapper.selectByUsernameWithoutTenant(username,tenantId); |
| | | } |
| | | |
| | | @Override |
| | | public List<User> listByIdsCached(Collection<Long> ids) { |
| | | if (ids == null || ids.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | String key = ids.stream().sorted().map(Object::toString).collect(Collectors.joining(",")); |
| | | long now = System.currentTimeMillis(); |
| | | CacheEntry<List<User>> entry = USER_MANY_CACHE.get(key); |
| | | if (entry != null && entry.expireAt > now) { |
| | | return entry.data; |
| | | } |
| | | List<User> list = listByIds(ids); |
| | | USER_MANY_CACHE.put(key, new CacheEntry<>(now + CACHE_TTL_MS, list)); |
| | | return list; |
| | | } |
| | | |
| | | private static class CacheEntry<T> { |
| | | final long expireAt; |
| | | final T data; |
| | | CacheEntry(long expireAt, T data) { |
| | | this.expireAt = expireAt; |
| | | this.data = data; |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | , GROUP_CONCAT(DISTINCT l.use_status ORDER BY l.use_status) AS locStatuses |
| | | </if> |
| | | FROM man_loc_item li |
| | | INNER JOIN man_loc l ON l.id = li.loc_id |
| | | WHERE li.matnr_id IN |
| | | INNER JOIN man_loc l ON l.id = li.loc_id AND (l.deleted = 0 OR l.deleted IS NULL) |
| | | WHERE li.deleted = 0 |
| | | AND li.matnr_id IN |
| | | <foreach collection="matnrIds" item="id" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |