完善消息接口
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.jsh.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.utils.BaseResponseInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -40,7 +42,7 @@ public class MsgController {
|
||||
HttpServletRequest request)throws Exception {
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
try {
|
||||
List<Msg> list = msgService.getMsgByStatus(status);
|
||||
List<MsgEx> list = msgService.getMsgByStatus(status);
|
||||
res.code = 200;
|
||||
res.data = list;
|
||||
} catch(Exception e){
|
||||
@@ -53,19 +55,19 @@ public class MsgController {
|
||||
|
||||
/**
|
||||
* 批量更新状态
|
||||
* @param ids
|
||||
* @param status
|
||||
* @param jsonObject
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/batchUpdateStatus")
|
||||
@ApiOperation(value = "批量更新状态")
|
||||
public BaseResponseInfo batchUpdateStatus(@RequestParam("ids") String ids,
|
||||
@RequestParam("status") String status,
|
||||
public BaseResponseInfo batchUpdateStatus(@RequestBody JSONObject jsonObject,
|
||||
HttpServletRequest request)throws Exception {
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
try {
|
||||
String ids = jsonObject.getString("ids");
|
||||
String status = jsonObject.getString("status");
|
||||
msgService.batchUpdateStatus(ids, status);
|
||||
res.code = 200;
|
||||
res.data = "更新成功";
|
||||
@@ -102,4 +104,30 @@ public class MsgController {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.jsh.erp.datasource.mappers;
|
||||
|
||||
import com.jsh.erp.datasource.entities.Msg;
|
||||
import com.jsh.erp.datasource.entities.MsgEx;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MsgMapperEx {
|
||||
|
||||
List<Msg> selectByConditionMsg(
|
||||
List<MsgEx> selectByConditionMsg(
|
||||
@Param("name") String name,
|
||||
@Param("offset") Integer offset,
|
||||
@Param("rows") Integer rows);
|
||||
|
||||
@@ -4,15 +4,18 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.BusinessConstants;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
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.User;
|
||||
import com.jsh.erp.datasource.mappers.MsgMapper;
|
||||
import com.jsh.erp.datasource.mappers.MsgMapperEx;
|
||||
import com.jsh.erp.datasource.vo.DepotHeadVo4List;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.service.depotHead.DepotHeadService;
|
||||
import com.jsh.erp.service.log.LogService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import com.jsh.erp.utils.Tools;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -22,8 +25,12 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.jsh.erp.utils.Tools.getCenternTime;
|
||||
|
||||
@Service
|
||||
public class MsgService {
|
||||
private Logger logger = LoggerFactory.getLogger(MsgService.class);
|
||||
@@ -70,10 +77,17 @@ public class MsgService {
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Msg> select(String name, int offset, int rows)throws Exception {
|
||||
List<Msg> list=null;
|
||||
public List<MsgEx> select(String name, int offset, int rows)throws Exception {
|
||||
List<MsgEx> list=null;
|
||||
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){
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
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);
|
||||
int result=0;
|
||||
try{
|
||||
msg.setCreateTime(new Date());
|
||||
msg.setStatus("1");
|
||||
result=msgMapper.insertSelective(msg);
|
||||
logService.insertLog("消息",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(msg.getMsgTitle()).toString(), request);
|
||||
@@ -204,19 +220,33 @@ public class MsgService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Msg> getMsgByStatus(String status)throws Exception {
|
||||
MsgExample example = new MsgExample();
|
||||
example.createCriteria().andStatusEqualTo(status).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
List<Msg> list=null;
|
||||
public List<MsgEx> getMsgByStatus(String status)throws Exception {
|
||||
List<MsgEx> resList=new ArrayList<>();
|
||||
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){
|
||||
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 list;
|
||||
return resList;
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
@@ -249,4 +279,20 @@ public class MsgService {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<?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">
|
||||
<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 *
|
||||
FROM jsh_msg
|
||||
WHERE 1=1
|
||||
@@ -13,7 +15,7 @@
|
||||
order by create_time desc
|
||||
<if test="offset != null and rows != null">
|
||||
limit #{offset},#{rows}
|
||||
</if>;
|
||||
</if>
|
||||
</select>
|
||||
<select id="countsByMsg" resultType="java.lang.Long">
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user