完善消息接口

This commit is contained in:
季圣华
2021-12-10 00:47:06 +08:00
parent 69a77358e6
commit a0bad81d5c
5 changed files with 108 additions and 17 deletions

View File

@@ -1,6 +1,8 @@
package com.jsh.erp.controller; package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.Msg; import com.jsh.erp.datasource.entities.Msg;
import com.jsh.erp.datasource.entities.MsgEx;
import com.jsh.erp.service.msg.MsgService; import com.jsh.erp.service.msg.MsgService;
import com.jsh.erp.utils.BaseResponseInfo; import com.jsh.erp.utils.BaseResponseInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@@ -40,7 +42,7 @@ public class MsgController {
HttpServletRequest request)throws Exception { HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
try { try {
List<Msg> list = msgService.getMsgByStatus(status); List<MsgEx> list = msgService.getMsgByStatus(status);
res.code = 200; res.code = 200;
res.data = list; res.data = list;
} catch(Exception e){ } catch(Exception e){
@@ -53,19 +55,19 @@ public class MsgController {
/** /**
* 批量更新状态 * 批量更新状态
* @param ids * @param jsonObject
* @param status
* @param request * @param request
* @return * @return
* @throws Exception * @throws Exception
*/ */
@PostMapping("/batchUpdateStatus") @PostMapping("/batchUpdateStatus")
@ApiOperation(value = "批量更新状态") @ApiOperation(value = "批量更新状态")
public BaseResponseInfo batchUpdateStatus(@RequestParam("ids") String ids, public BaseResponseInfo batchUpdateStatus(@RequestBody JSONObject jsonObject,
@RequestParam("status") String status,
HttpServletRequest request)throws Exception { HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
try { try {
String ids = jsonObject.getString("ids");
String status = jsonObject.getString("status");
msgService.batchUpdateStatus(ids, status); msgService.batchUpdateStatus(ids, status);
res.code = 200; res.code = 200;
res.data = "更新成功"; res.data = "更新成功";
@@ -102,4 +104,30 @@ public class MsgController {
} }
return res; return res;
} }
/**
* 根据类型查询数量
* @param type
* @param request
* @return
* @throws Exception
*/
@GetMapping("/getMsgCountByType")
@ApiOperation(value = "根据类型查询数量")
public BaseResponseInfo getMsgCountByType(@RequestParam("type") String type,
HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
try {
Map<String, Integer> map = new HashMap<>();
Integer count = msgService.getMsgCountByType(type);
map.put("count", count);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
} }

View File

@@ -0,0 +1,14 @@
package com.jsh.erp.datasource.entities;
public class MsgEx extends Msg{
private String createTimeStr;
public String getCreateTimeStr() {
return createTimeStr;
}
public void setCreateTimeStr(String createTimeStr) {
this.createTimeStr = createTimeStr;
}
}

View File

@@ -1,13 +1,14 @@
package com.jsh.erp.datasource.mappers; package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.Msg; import com.jsh.erp.datasource.entities.Msg;
import com.jsh.erp.datasource.entities.MsgEx;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
public interface MsgMapperEx { public interface MsgMapperEx {
List<Msg> selectByConditionMsg( List<MsgEx> selectByConditionMsg(
@Param("name") String name, @Param("name") String name,
@Param("offset") Integer offset, @Param("offset") Integer offset,
@Param("rows") Integer rows); @Param("rows") Integer rows);

View File

@@ -4,15 +4,18 @@ import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants; import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants; import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Msg; import com.jsh.erp.datasource.entities.Msg;
import com.jsh.erp.datasource.entities.MsgEx;
import com.jsh.erp.datasource.entities.MsgExample; import com.jsh.erp.datasource.entities.MsgExample;
import com.jsh.erp.datasource.entities.User; import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.MsgMapper; import com.jsh.erp.datasource.mappers.MsgMapper;
import com.jsh.erp.datasource.mappers.MsgMapperEx; import com.jsh.erp.datasource.mappers.MsgMapperEx;
import com.jsh.erp.datasource.vo.DepotHeadVo4List;
import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.depotHead.DepotHeadService; import com.jsh.erp.service.depotHead.DepotHeadService;
import com.jsh.erp.service.log.LogService; import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService; import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil; import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -22,8 +25,12 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import static com.jsh.erp.utils.Tools.getCenternTime;
@Service @Service
public class MsgService { public class MsgService {
private Logger logger = LoggerFactory.getLogger(MsgService.class); private Logger logger = LoggerFactory.getLogger(MsgService.class);
@@ -70,10 +77,17 @@ public class MsgService {
return list; return list;
} }
public List<Msg> select(String name, int offset, int rows)throws Exception { public List<MsgEx> select(String name, int offset, int rows)throws Exception {
List<Msg> list=null; List<MsgEx> list=null;
try{ try{
list=msgMapperEx.selectByConditionMsg(name, offset, rows); list = msgMapperEx.selectByConditionMsg(name, offset, rows);
if (null != list) {
for (MsgEx msgEx : list) {
if(msgEx.getCreateTime() != null) {
msgEx.setCreateTimeStr(getCenternTime(msgEx.getCreateTime()));
}
}
}
}catch(Exception e){ }catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]", logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e); ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
@@ -101,6 +115,8 @@ public class MsgService {
Msg msg = JSONObject.parseObject(obj.toJSONString(), Msg.class); Msg msg = JSONObject.parseObject(obj.toJSONString(), Msg.class);
int result=0; int result=0;
try{ try{
msg.setCreateTime(new Date());
msg.setStatus("1");
result=msgMapper.insertSelective(msg); result=msgMapper.insertSelective(msg);
logService.insertLog("消息", logService.insertLog("消息",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(msg.getMsgTitle()).toString(), request); new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(msg.getMsgTitle()).toString(), request);
@@ -204,19 +220,33 @@ public class MsgService {
return result; return result;
} }
public List<Msg> getMsgByStatus(String status)throws Exception { public List<MsgEx> getMsgByStatus(String status)throws Exception {
MsgExample example = new MsgExample(); List<MsgEx> resList=new ArrayList<>();
example.createCriteria().andStatusEqualTo(status).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Msg> list=null;
try{ try{
list=msgMapper.selectByExample(example); MsgExample example = new MsgExample();
example.createCriteria().andStatusEqualTo(status).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Msg> list = msgMapper.selectByExample(example);
if (null != list) {
for (Msg msg : list) {
if(msg.getCreateTime() != null) {
MsgEx msgEx = new MsgEx();
msgEx.setId(msg.getId());
msgEx.setMsgTitle(msg.getMsgTitle());
msgEx.setMsgContent(msg.getMsgContent());
msgEx.setStatus(msg.getStatus());
msgEx.setType(msg.getType());
msgEx.setCreateTimeStr(Tools.parseDateToStr(msg.getCreateTime()));
resList.add(msgEx);
}
}
}
}catch(Exception e){ }catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]", logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e); ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE, throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG); ExceptionConstants.DATA_READ_FAIL_MSG);
} }
return list; return resList;
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
@@ -249,4 +279,20 @@ public class MsgService {
} }
return result; return result;
} }
public Integer getMsgCountByType(String type)throws Exception {
int msgCount = 0;
try{
MsgExample example = new MsgExample();
example.createCriteria().andTypeEqualTo(type).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Msg> list = msgMapper.selectByExample(example);
msgCount = list.size();
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return msgCount;
}
} }

View File

@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jsh.erp.datasource.mappers.MsgMapperEx"> <mapper namespace="com.jsh.erp.datasource.mappers.MsgMapperEx">
<select id="selectByConditionMsg" resultMap="com.jsh.erp.datasource.mappers.MsgMapper.BaseResultMap"> <resultMap extends="com.jsh.erp.datasource.mappers.MsgMapper.BaseResultMap" id="ResultExMap" type="com.jsh.erp.datasource.entities.MsgEx">
</resultMap>
<select id="selectByConditionMsg" parameterType="com.jsh.erp.datasource.entities.MsgExample" resultMap="ResultExMap">
SELECT * SELECT *
FROM jsh_msg FROM jsh_msg
WHERE 1=1 WHERE 1=1
@@ -13,7 +15,7 @@
order by create_time desc order by create_time desc
<if test="offset != null and rows != null"> <if test="offset != null and rows != null">
limit #{offset},#{rows} limit #{offset},#{rows}
</if>; </if>
</select> </select>
<select id="countsByMsg" resultType="java.lang.Long"> <select id="countsByMsg" resultType="java.lang.Long">
SELECT SELECT