Commit 124ae36c by xmh

1. 添加人员池重构接口

2. 修改日志下载查询语句
3. 添加reid获取人员列表和上一个下一个人时根据数量进行筛选
4. 图片信息和图片数据分开进行缓存
1 parent 51ced3cc
...@@ -17,11 +17,16 @@ public class Constants { ...@@ -17,11 +17,16 @@ public class Constants {
public static final Integer USER_TYPE_OUT_INSPECTOR = 4; public static final Integer USER_TYPE_OUT_INSPECTOR = 4;
public static final Integer USER_TYPE_IN_INSPECTOR = 3; public static final Integer USER_TYPE_IN_INSPECTOR = 3;
private static final String REDIS_KEY_PIC_PREFIX = "pic"; private static final String REDIS_KEY_PIC_PREFIX = "pic";
private static final String REDIS_KEY_PIC_IMAGE_PREFIX = "picImage";
public static String getRedisKeyPic(Long picId) { public static String getRedisKeyPic(Long picId) {
return REDIS_KEY_PIC_PREFIX + ":" + picId; return REDIS_KEY_PIC_PREFIX + ":" + picId;
} }
public static String getRedisKeyPicImage(Long picId) {
return REDIS_KEY_PIC_IMAGE_PREFIX + ":" + picId;
}
public static String getReidPoolName(Long packId) { public static String getReidPoolName(Long packId) {
return "reid_pool_" + packId; return "reid_pool_" + packId;
} }
......
...@@ -54,7 +54,7 @@ public class PicController extends PicBaseController { ...@@ -54,7 +54,7 @@ public class PicController extends PicBaseController {
@GetMapping("/image/{picId}") @GetMapping("/image/{picId}")
@ResponseBody @ResponseBody
public void getImage(@PathVariable("picId") Long picId, HttpServletResponse response) throws Exception { public void getImage(@PathVariable("picId") Long picId, HttpServletResponse response) throws Exception {
PicVo pic = storageUtils.getPic(picId); PicVo pic = storageUtils.getPicWithImg(picId);
if (pic == null) { if (pic == null) {
return; return;
} }
......
...@@ -51,10 +51,11 @@ public class ReidController { ...@@ -51,10 +51,11 @@ public class ReidController {
*/ */
@GetMapping("/getPeople") @GetMapping("/getPeople")
public Object getPeople(@RequestParam Long packId, @RequestParam(required = false) Integer status public Object getPeople(@RequestParam Long packId, @RequestParam(required = false) Integer status
, @RequestParam(required = false) Long page, @RequestParam(required = false) Long size) { , @RequestParam(required = false) Long page, @RequestParam(required = false) Long size
, @RequestParam(defaultValue = "1") Integer countGTE, @RequestParam(defaultValue = "10000") Integer countLTE) {
SubTaskMapper mapper = (SubTaskMapper) subTaskService.getMapper(); SubTaskMapper mapper = (SubTaskMapper) subTaskService.getMapper();
List<SubTask> people = mapper.getPeople(packId, status, page == null ? null : (page - 1) * size, size); List<SubTask> people = mapper.getPeople(packId, status, page == null ? null : (page - 1) * size, size, countGTE, countLTE);
LinkedHashMap<String, List<SubTask>> temp = new LinkedHashMap<>(); LinkedHashMap<String, List<SubTask>> temp = new LinkedHashMap<>();
for (SubTask item : people) { for (SubTask item : people) {
...@@ -64,7 +65,7 @@ public class ReidController { ...@@ -64,7 +65,7 @@ public class ReidController {
if (page != null) { if (page != null) {
PageInfo<Object> pageInfo = new PageInfo<>(new ArrayList<>(temp.entrySet()), page.intValue()); PageInfo<Object> pageInfo = new PageInfo<>(new ArrayList<>(temp.entrySet()), page.intValue());
pageInfo.setTotal(mapper.countPeople(packId, status)); pageInfo.setTotal(mapper.countPeople(packId, status, countGTE, countLTE));
return JsonMessageUtil.getSuccessJsonMsg(pageInfo); return JsonMessageUtil.getSuccessJsonMsg(pageInfo);
} else { } else {
return JsonMessageUtil.getSuccessJsonMsg(temp); return JsonMessageUtil.getSuccessJsonMsg(temp);
...@@ -72,9 +73,11 @@ public class ReidController { ...@@ -72,9 +73,11 @@ public class ReidController {
} }
@GetMapping("/getOtherPeople") @GetMapping("/getOtherPeople")
public Object getNextPeoPle(@RequestParam String personUnid, @RequestParam Long packId, @RequestParam(required = false) Integer status, @RequestParam Integer type) { public Object getNextPeoPle(@RequestParam String personUnid, @RequestParam Long packId
, @RequestParam(required = false) Integer status, @RequestParam Integer type
, @RequestParam(defaultValue = "1") Integer countGTE, @RequestParam(defaultValue = "10000") Integer countLTE) {
SubTaskMapper mapper = (SubTaskMapper) subTaskService.getMapper(); SubTaskMapper mapper = (SubTaskMapper) subTaskService.getMapper();
List<SubTask> pics = mapper.getOtherPeople(packId, status, personUnid, type == 0 ? ">" : "<", type == 0 ? "" : "desc"); List<SubTask> pics = mapper.getOtherPeople(packId, status, personUnid, type == 0 ? ">" : "<", type == 0 ? "" : "desc", countGTE, countLTE);
if (pics.size() == 0) { if (pics.size() == 0) {
return JsonMessageUtil.getSuccessJsonMsg("没有数据了"); return JsonMessageUtil.getSuccessJsonMsg("没有数据了");
} }
...@@ -200,8 +203,8 @@ public class ReidController { ...@@ -200,8 +203,8 @@ public class ReidController {
} }
@GetMapping("recovery") @GetMapping("recovery")
public Object recovery(@RequestParam(required = false) String personUnid,@RequestParam(required = false) Long[] subTaskIdArr, @RequestParam Long packId) throws Exception { public Object recovery(@RequestParam(required = false) String personUnid, @RequestParam(required = false) Long[] subTaskIdArr, @RequestParam Long packId) throws Exception {
reidService.recovery(personUnid,subTaskIdArr, packId); reidService.recovery(personUnid, subTaskIdArr, packId);
return JsonMessageUtil.getSuccessJsonMsg("success"); return JsonMessageUtil.getSuccessJsonMsg("success");
} }
...@@ -233,7 +236,11 @@ public class ReidController { ...@@ -233,7 +236,11 @@ public class ReidController {
response.setHeader("Content-Disposition", response.setHeader("Content-Disposition",
"attachment;filename=" + packId + "-" + DateUtil.format("yyyyMMdd", start) + "-" + DateUtil.format("yyyyMMdd", end) + ".xlsx"); "attachment;filename=" + packId + "-" + DateUtil.format("yyyyMMdd", start) + "-" + DateUtil.format("yyyyMMdd", end) + ".xlsx");
EasyExcel.write(response.getOutputStream(), LogVo.class).includeColumnFiledNames(includeColumn).sheet().doWrite(logs); EasyExcel.write(response.getOutputStream(), LogVo.class).includeColumnFiledNames(includeColumn).sheet().doWrite(logs);
}
@GetMapping("reconstruction")
public Object featurePoolReconstruction(@RequestParam Long packId) {
reidService.reConstruction(packId);
return JsonMessageUtil.getSuccessJsonMsg("success");
} }
} }
...@@ -33,8 +33,6 @@ public interface LogMapper extends BaseMapper { ...@@ -33,8 +33,6 @@ public interface LogMapper extends BaseMapper {
int updateByPrimaryKey(Log record); int updateByPrimaryKey(Log record);
@Select("select operate as personUnid,count as picNum,u.name as username,log.create_time as finishTime from " + @Select("select \"max\"(s_user.name) as username ,\"max\"(annotate_time) as finishTime ,person_unid as personUnid,count(*) as picNum from d_sub_task left join s_user on d_sub_task.annotator_id=s_user.id where pack_id=#{packId} and status=3 and annotate_time BETWEEN #{start} and #{end} group by person_unid ")
"(select person_unid,count(*) from d_pic where pack_id=#{packId} and status=3 group by person_unid) as pic left join " +
"(select * from (select *,row_number() over (partition by operate order by create_time desc) row_id from s_log where operate_type=5 and operate_date between #{start} and #{end} ) t where t.row_id=1 ) as log on pic.person_unid=log.operate left join s_user u on log.operate_user=u.id where operate_user is not null")
List<LogVo> exportLogByDateAndPack(Long packId, Date start, Date end); List<LogVo> exportLogByDateAndPack(Long packId, Date start, Date end);
} }
\ No newline at end of file \ No newline at end of file
...@@ -59,12 +59,12 @@ public interface SubTaskMapper extends BaseMapper { ...@@ -59,12 +59,12 @@ public interface SubTaskMapper extends BaseMapper {
" <if test = 'status != null'> and status=#{status}</if> " + " <if test = 'status != null'> and status=#{status}</if> " +
" <if test = 'status == null'> and status != -1</if> " + " <if test = 'status == null'> and status != -1</if> " +
"group by person_unid " + "group by person_unid " +
// " having count(*) > 1 " + " having count(*) between #{countGTE} and #{countLTE} " +
" order by person_unid " + " order by person_unid " +
"<if test='offset != null'> offset #{offset} limit #{limit}</if>) " + "<if test='offset != null'> offset #{offset} limit #{limit}</if>) " +
" order by person_unid " + " order by person_unid " +
"</script>") "</script>")
List<SubTask> getPeople(Long packId, Integer status, Long offset, Long limit); List<SubTask> getPeople(Long packId, Integer status, Long offset, Long limit, Integer countGTE, Integer countLTE);
@Select("<script>" + @Select("<script>" +
"select count(*) from " + "select count(*) from " +
...@@ -72,10 +72,10 @@ public interface SubTaskMapper extends BaseMapper { ...@@ -72,10 +72,10 @@ public interface SubTaskMapper extends BaseMapper {
" <if test = 'status != null'> and status=#{status}</if> " + " <if test = 'status != null'> and status=#{status}</if> " +
" <if test = 'status == null'> and status != -1</if> " + " <if test = 'status == null'> and status != -1</if> " +
" group by person_unid " + " group by person_unid " +
// " having count(*) > 1 " + " having count(*) between #{countGTE} and #{countLTE} " +
") as t " + ") as t " +
"</script>") "</script>")
int countPeople(Long packId, Integer status); int countPeople(Long packId, Integer status, Integer countGTE, Integer countLTE);
@Select("<script>" + @Select("<script>" +
"select id,unid,create_time as createTime,pack_id as packId,pic_id as picId,task_id as taskId,person_unid as personUnid,status from d_sub_task where pack_id=#{packId} and person_unid=" + "select id,unid,create_time as createTime,pack_id as packId,pic_id as picId,task_id as taskId,person_unid as personUnid,status from d_sub_task where pack_id=#{packId} and person_unid=" +
...@@ -83,8 +83,8 @@ public interface SubTaskMapper extends BaseMapper { ...@@ -83,8 +83,8 @@ public interface SubTaskMapper extends BaseMapper {
"<if test = 'status != null'> and status=#{status}</if>" + "<if test = 'status != null'> and status=#{status}</if>" +
" <if test = 'status == null'> and status != -1</if> " + " <if test = 'status == null'> and status != -1</if> " +
" and person_unid ${type} #{personUnid} group by person_unid " + " and person_unid ${type} #{personUnid} group by person_unid " +
// " having count(*) > 1 " + " having count(*) between #{countGTE} and #{countLTE} " +
" order by person_unid ${sort} limit 1) order by id" + " order by person_unid ${sort} limit 1) order by id" +
"</script>") "</script>")
List<SubTask> getOtherPeople(Long packId, Integer status, String personUnid, String type, String sort); List<SubTask> getOtherPeople(Long packId, Integer status, String personUnid, String type, String sort, Integer countGTE, Integer countLTE);
} }
\ No newline at end of file \ No newline at end of file
...@@ -102,6 +102,7 @@ public class ReidService { ...@@ -102,6 +102,7 @@ public class ReidService {
subTask.setPackId(packId); subTask.setPackId(packId);
subTask.setCreateTime(data.getCountTime()); subTask.setCreateTime(data.getCountTime());
subTask.setTaskId(data.getTaskId()); subTask.setTaskId(data.getTaskId());
subTask.setStatus(SubTaskStatus.TO_BE_LABELED.val);
subTaskService.insertSelective(subTask); subTaskService.insertSelective(subTask);
...@@ -331,6 +332,8 @@ public class ReidService { ...@@ -331,6 +332,8 @@ public class ReidService {
subTaskService.updateByExampleSelective(subTask, subTaskExample); subTaskService.updateByExampleSelective(subTask, subTaskExample);
return; return;
} }
} else if (status.contains(SubTaskStatus.recycled.val)) {
return;
} }
subTask.setAnnotatorId(StpUtil.getLoginIdAsLong()); subTask.setAnnotatorId(StpUtil.getLoginIdAsLong());
...@@ -477,8 +480,11 @@ public class ReidService { ...@@ -477,8 +480,11 @@ public class ReidService {
List<SubTask> subTasks = subTaskService.selectByExample(subTaskExample); List<SubTask> subTasks = subTaskService.selectByExample(subTaskExample);
if (subTasks.size() > 0 && subTasks.get(0).getStatus().equals(SubTaskStatus.FINISH_LABELING.val)) { if (subTasks.size() > 0) {
return true; Integer status = subTasks.get(0).getStatus();
if (status.equals(SubTaskStatus.FINISH_LABELING.val) || status.equals(SubTaskStatus.recycled.val)) {
return true;
}
} }
if (subTasks.size() == 0) { if (subTasks.size() == 0) {
return true; return true;
...@@ -539,23 +545,22 @@ public class ReidService { ...@@ -539,23 +545,22 @@ public class ReidService {
public void exitLabeling(String personUnid, Long packId) { public void exitLabeling(String personUnid, Long packId) {
// 数据库更新状态 // 数据库更新状态
SubTask subTask = new SubTask();
subTask.setStatus(SubTaskStatus.TO_BE_LABELED.val);
SubTaskExample subTaskExample = new SubTaskExample(); SubTaskExample subTaskExample = new SubTaskExample();
subTaskExample.createCriteria().andPersonUnidEqualTo(personUnid).andPackIdEqualTo(packId); subTaskExample.createCriteria().andPersonUnidEqualTo(personUnid).andPackIdEqualTo(packId);
// redis 删除缓存
RMap<String, User> labelingSet = redissonClient.getMap("labeling:" + packId);
labelingSet.remove(personUnid);
List<SubTask> subTasks = subTaskService.selectByExample(subTaskExample); List<SubTask> subTasks = subTaskService.selectByExample(subTaskExample);
if (subTasks.size() > 0 && subTasks.get(0).getStatus() != SubTaskStatus.LABELING.val) { if (subTasks.size() > 0 && subTasks.get(0).getStatus() != SubTaskStatus.LABELING.val) {
return; return;
} }
SubTask subTask = new SubTask();
subTask.setStatus(SubTaskStatus.TO_BE_LABELED.val);
subTaskService.updateByExampleSelective(subTask, subTaskExample); subTaskService.updateByExampleSelective(subTask, subTaskExample);
// redis 删除缓存
RMap<String, User> labelingSet = redissonClient.getMap("labeling:" + packId);
labelingSet.remove(personUnid);
//websocket //websocket
ReidWebsocket.sendInfo(packId, new ReidWebsocket.Message().setCommand("exitLabeling").setData(personUnid)); ReidWebsocket.sendInfo(packId, new ReidWebsocket.Message().setCommand("exitLabeling").setData(personUnid));
} }
...@@ -667,13 +672,12 @@ public class ReidService { ...@@ -667,13 +672,12 @@ public class ReidService {
List<SubTask> allSubTask = subTaskService.selectByExample(subTaskExample); List<SubTask> allSubTask = subTaskService.selectByExample(subTaskExample);
Map<String, List<SubTask>> collect = allSubTask.stream().collect(Collectors.groupingBy(SubTask::getPersonUnid, Collectors.toList())); Map<String, List<SubTask>> collect = allSubTask.stream().collect(Collectors.groupingBy(SubTask::getPersonUnid, Collectors.toList()));
byte[] bytes;
for (Map.Entry<String, List<SubTask>> entry : collect.entrySet()) { for (Map.Entry<String, List<SubTask>> entry : collect.entrySet()) {
String personUnid = entry.getKey(); String personUnid = entry.getKey();
List<SubTask> subtasks = entry.getValue(); List<SubTask> subtasks = entry.getValue();
for (SubTask subTask : subtasks) { for (SubTask subTask : subtasks) {
PicVo pic = storageUtils.getPic(subTask.getPicId()); PicVo pic = storageUtils.getPicWithImg(subTask.getPicId());
if (pic == null) { if (pic == null) {
continue; continue;
} }
...@@ -689,6 +693,47 @@ public class ReidService { ...@@ -689,6 +693,47 @@ public class ReidService {
return tempFile; return tempFile;
} }
public void reConstruction(Long packId) {
SubTaskExample subTaskExample = new SubTaskExample();
subTaskExample.createCriteria().andPackIdEqualTo(packId);
String poolName = Constants.getReidPoolName(packId);
try {
CompletableFuture<AlgResult> algResultCompletableFuture = matchClient.EASY_POOL_API.deletePool(poolName);
AlgResult algResult = algResultCompletableFuture.get();
} catch (Exception ignore) {
}
List<SubTask> subTasks = subTaskService.selectByExample(subTaskExample);
if (subTasks.size() == 0) {
return;
}
Map<String, List<SubTask>> collect = subTasks.stream().collect(Collectors.groupingBy(SubTask::getPersonUnid, Collectors.toList()));
for (Map.Entry<String, List<SubTask>> entry : collect.entrySet()) {
String personUnid = entry.getKey();
List<SubTask> value = entry.getValue();
ArrayList<Person> people = new ArrayList<>();
for (SubTask item : value) {
Feature featureByPic = storageUtils.getFeatureByPic(item.getPicId());
if (featureByPic == null) {
continue;
}
Person person = new Person().setPersonId(personUnid).setCounttime(item.getCreateTime()).setBodyFeatures(getBodyFeatures(featureByPic));
people.add(person);
}
try {
if (people.size() > 0) {
CompletableFuture<AlgResult> future = matchClient.EASY_PERSON_API.addPerson(poolName, people);
AlgResult result1 = future.get(20, TimeUnit.SECONDS);
log.info(result1.toString());
}
} catch (Exception e) {
log.error("添加特征失败", e);
}
}
}
public LogService getLogService() { public LogService getLogService() {
return logService; return logService;
} }
......
...@@ -51,26 +51,44 @@ public class StorageUtils { ...@@ -51,26 +51,44 @@ public class StorageUtils {
public PicVo getPic(Long picId) { public PicVo getPic(Long picId) {
String redisKey = Constants.getRedisKeyPic(picId); String redisKey = Constants.getRedisKeyPic(picId);
PicVo picVo = redissonClient.<PicVo>getBucket(redisKey).get(); RBucket<PicVo> picInfoBucket = redissonClient.getBucket(redisKey);
PicVo picVo = picInfoBucket.get();
if (picVo == null) { if (picVo == null) {
// 获取并缓存 picInfo
Pic pic = picService.selectByPrimaryKey(picId); Pic pic = picService.selectByPrimaryKey(picId);
if (pic == null) { if (pic == null) {
return null; return null;
} }
picVo = new PicVo(pic); picVo = new PicVo(pic);
Long packId = pic.getPackId(); picInfoBucket.set(picVo);
byte[] bytes; }
picInfoBucket.expire(12, TimeUnit.HOURS);
return picVo;
}
public PicVo getPicWithImg(Long picId) {
PicVo picVo = getPic(picId);
if (picVo == null) {
return null;
}
// 获取并缓存 image
Long packId = picVo.getPackId();
String picImageKey = Constants.getRedisKeyPicImage(picId);
RBucket<byte[]> picImageBucket = redissonClient.<byte[]>getBucket(picImageKey);
byte[] bytes = picImageBucket.get();
if (bytes == null) {
try { try {
bytes = getFile(packId, pic.getName()); bytes = getFile(packId, picVo.getName());
} catch (Exception e) { } catch (Exception e) {
log.info("", e); log.info("", e);
return null; return null;
} }
picVo.setImage(bytes); picImageBucket.set(bytes);
RBucket<PicVo> bucket = redissonClient.getBucket(redisKey);
bucket.set(picVo);
bucket.expire(12, TimeUnit.HOURS);
} }
picImageBucket.expire(12, TimeUnit.HOURS);
picVo.setImage(bytes);
return picVo; return picVo;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!