|
@@ -1,7 +1,9 @@
|
|
|
package com.jpsoft.picc.modules.auth.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.picc.modules.base.entity.Company;
|
|
|
import com.jpsoft.picc.modules.base.entity.Message;
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
import com.jpsoft.picc.modules.base.service.MessageService;
|
|
|
import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.picc.modules.common.dto.Sort;
|
|
@@ -29,30 +31,47 @@ public class MessageController {
|
|
|
@Autowired
|
|
|
private MessageService messageService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyService companyService;
|
|
|
+
|
|
|
+ private Boolean read(String id,String updateBy){
|
|
|
+ Boolean bl = false;
|
|
|
+ try{
|
|
|
+ Message message = messageService.get(id);
|
|
|
+ message.setStatus(true);
|
|
|
+ message.setUpdateBy(updateBy);
|
|
|
+ message.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = messageService.update(message);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ bl = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return bl;
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation(value="消息列表")
|
|
|
@RequestMapping(value = "list",method = RequestMethod.POST)
|
|
|
@ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "senderId",value = "发件人ID", required = false, paramType = "form",dataType = "String"),
|
|
|
- @ApiImplicitParam(name = "recipientId",value = "收件人ID", required = false, paramType = "form",dataType = "String"),
|
|
|
@ApiImplicitParam(name = "status",value = "状态(未读/已读)", required = false, paramType = "form",dataType = "Boolean")
|
|
|
})
|
|
|
- public MessageResult<Map> list(@RequestParam(value="senderId",defaultValue="") String senderId,
|
|
|
- @RequestParam(value="recipientId",defaultValue="") String recipientId,
|
|
|
- @RequestParam(value="status",defaultValue="") Boolean status){
|
|
|
+ public MessageResult<Map> list(@RequestParam(value="status",defaultValue="") Boolean status,
|
|
|
+ HttpServletRequest request){
|
|
|
+ AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
+ Company company = companyService.findByCreateBy(principal.getName());
|
|
|
MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
|
|
Map<String,Object> searchParams = new HashMap<>();
|
|
|
- searchParams.put("delFlag",false);
|
|
|
+ searchParams.put("recipientId",company.getId());
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
sortList.add(new Sort("create_time","desc"));
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(senderId)) {
|
|
|
- searchParams.put("senderId",senderId);
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(recipientId)) {
|
|
|
- searchParams.put("recipientId",recipientId);
|
|
|
- }
|
|
|
if (status != null) {
|
|
|
searchParams.put("status",status);
|
|
|
}
|
|
@@ -65,32 +84,29 @@ public class MessageController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="消息设为已读")
|
|
|
- @PostMapping("read")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "id",value = "编号", required = true, paramType = "form",dataType = "String")
|
|
|
- })
|
|
|
- public MessageResult<Integer> read(@RequestParam(value="id",defaultValue="") String id,
|
|
|
- HttpServletRequest request){
|
|
|
+ @ApiOperation(value="全部消息设为已读")
|
|
|
+ @PostMapping("allRead")
|
|
|
+ public MessageResult<String> allRead(HttpServletRequest request){
|
|
|
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
-
|
|
|
- MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+ Company company = companyService.findByCreateBy(principal.getName());
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
- Message message = messageService.get(id);
|
|
|
- message.setStatus(true);
|
|
|
- message.setUpdateBy(principal.getName());
|
|
|
- message.setUpdateTime(new Date());
|
|
|
-
|
|
|
- int affectCount = messageService.update(message);
|
|
|
-
|
|
|
- if (affectCount > 0) {
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(affectCount);
|
|
|
- } else {
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage("删除失败");
|
|
|
+ int affectCount = 0;
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ searchParams.put("recipientId",company.getId());
|
|
|
+ searchParams.put("status",false);
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
+ Page<Message> page = messageService.pageSearch(searchParams,1,1000,sortList);
|
|
|
+ for(Message message : page.getResult()){
|
|
|
+ if(read(message.getId(),principal.getName())){
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData("共计"+affectCount+"条消息设为已读。");
|
|
|
}
|
|
|
catch(Exception ex){
|
|
|
logger.error(ex.getMessage(),ex);
|
|
@@ -101,4 +117,32 @@ public class MessageController {
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value="获取消息信息")
|
|
|
+ @RequestMapping(value = "detail",method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "id",value = "编号", required = true, paramType = "form",dataType = "String")
|
|
|
+ })
|
|
|
+ public MessageResult<Message> detail(@RequestParam(value="id",defaultValue="") String id,
|
|
|
+ HttpServletRequest request){
|
|
|
+ MessageResult<Message> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
+ Company company = companyService.findByCreateBy(principal.getName());
|
|
|
+
|
|
|
+ Message message = messageService.get(id);
|
|
|
+
|
|
|
+ if(read(id,principal.getName())) {
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setData(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
}
|