解决通知两个小bug。

This commit is contained in:
little-cat-sweet 2021-08-06 11:07:10 +08:00
parent b295ec8bcf
commit a1828094e5
5 changed files with 56 additions and 34 deletions

View File

@ -91,10 +91,10 @@ public class SysNoticeController extends BaseController
* @return * @return
*/ */
@GetMapping(value = "/show") @GetMapping(value = "/show")
public TableDataInfo show(){ public TableDataInfo show(@RequestParam Long userId){
startPage(); startPage();
return getDataTable(noticeService.show()); return getDataTable(noticeService.show(userId));
} }
/** /**
@ -109,17 +109,6 @@ public class SysNoticeController extends BaseController
} }
/**
* Showing ids which have not been read in small app.
* @param userId
* @return
*/
@GetMapping(value = "/showNotReadIds")
public AjaxResult showNotReadIds(Integer userId){
return AjaxResult.success(noticeService.showNotReadIds(userId));
}
@PostMapping("/add") @PostMapping("/add")
public AjaxResult add(@RequestBody SysXhpcNoticeReadEntity sysXhpcNoticeReadEntity){ public AjaxResult add(@RequestBody SysXhpcNoticeReadEntity sysXhpcNoticeReadEntity){

View File

@ -65,7 +65,7 @@ public interface SysNoticeMapper
* Showing notice items in the small app. * Showing notice items in the small app.
* @return * @return
*/ */
List<Map<String,Object>> selectTypeContentCreateTime(); List<Map<String,Object>> selectTypeContentCreateTimeId();
/** /**
* Show the number of notices which have not been read in small app. * Show the number of notices which have not been read in small app.
@ -75,7 +75,15 @@ public interface SysNoticeMapper
int countNotRead(@Param("userId") Integer userId); int countNotRead(@Param("userId") Integer userId);
List<Map<String,Object>> selectNotReadIds(@Param("userId") Integer userId); /**
* Showing ids which have not been read in small app.
* @param userId
* @return
*/
List<Map<String,Object>> selectNotReadIds(@Param("userId") Long userId);
int insertIntoRead(@Param("noticeId") Integer noticeId,@Param("userId") Long userId); int insertIntoRead(@Param("noticeId") Integer noticeId,@Param("userId") Long userId);

View File

@ -66,7 +66,7 @@ public interface ISysNoticeService
* Showing notice items in small app. * Showing notice items in small app.
* @return * @return
*/ */
List<Map<String,Object>> show(); List<Map<String,Object>> show(Long userId);
/** /**
* Showing the number of notices which have not been read in small app. * Showing the number of notices which have not been read in small app.
@ -75,12 +75,6 @@ public interface ISysNoticeService
*/ */
int showNotRead(Integer userId); int showNotRead(Integer userId);
/**
* Showing ids which have not been read in small app.
* @param userId
* @return
*/
List<Map<String,Object>> showNotReadIds(Integer userId);
AjaxResult addReadItem(Integer noticeId,Long userId); AjaxResult addReadItem(Integer noticeId,Long userId);

View File

@ -95,9 +95,28 @@ public class SysNoticeServiceImpl implements ISysNoticeService
@Override @Override
public List<Map<String, Object>> show() { public List<Map<String, Object>> show(Long userId) {
//If status's value equals zero it means read, if not not read.
List<Map<String,Object>> list=noticeMapper.selectTypeContentCreateTimeId();
List<Map<String,Object>> readId=noticeMapper.selectNotReadIds(userId);
for(Map<String,Object> value1:list){
int temp1= (int) value1.get("noticeId");
boolean flag=false;
for(Map<String,Object> value2:readId){
int temp2=(int)value2.get("noticeId");
if(temp1==temp2){
flag=true;
value1.put("status",1);
break;
}
}
if(!flag){
value1.put("status",0);
}
return noticeMapper.selectTypeContentCreateTime(); }
return list;
} }
@Override @Override
@ -106,19 +125,26 @@ public class SysNoticeServiceImpl implements ISysNoticeService
return noticeMapper.countNotRead(userId); return noticeMapper.countNotRead(userId);
} }
@Override
public List<Map<String, Object>> showNotReadIds(Integer userId) {
return noticeMapper.selectNotReadIds(userId);
}
@Override @Override
public AjaxResult addReadItem(Integer noticeId, Long userId) { public AjaxResult addReadItem(Integer noticeId, Long userId) {
int res=noticeMapper.insertIntoRead(noticeId, userId); List<Map<String,Object>> notReadIds=noticeMapper.selectNotReadIds(userId);
if(res==0){ boolean flag=false;
for(Map<String,Object> value:notReadIds){
int temp1=(int)value.get("noticeId");
if(noticeId==temp1){
flag=true;
break;
}
}
if (flag) {
int res = noticeMapper.insertIntoRead(noticeId, userId);
if (res == 0) {
return AjaxResult.error("插入失败"); return AjaxResult.error("插入失败");
} }
}
return AjaxResult.success(); return AjaxResult.success();
} }
} }

View File

@ -95,9 +95,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</delete> </delete>
<select id="selectTypeContentCreateTime" resultType="map"> <select id="selectTypeContentCreateTimeId" resultType="map">
select notice_type as noticeType, cast(notice_content as char) as noticeContent,create_time as createTime select notice_type as noticeType,
cast(notice_content as char) as noticeContent,
create_time as createTime,
notice_id as noticeId
from sys_notice from sys_notice
</select> </select>
@ -115,6 +118,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where r.user_id=#{userId} where r.user_id=#{userId}
) )
</select> </select>
<select id="selectNotReadIds" resultType="map"> <select id="selectNotReadIds" resultType="map">
select notice_id as noticeId select notice_id as noticeId