Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
a0bad81d
Commit
a0bad81d
authored
Dec 10, 2021
by
季圣华
Browse files
完善消息接口
parent
69a77358
Changes
5
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/controller/MsgController.java
View file @
a0bad81d
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 {
...
@@ -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
<
Msg
Ex
>
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 {
...
@@ -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 {
...
@@ -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
;
}
}
}
jshERP-boot/src/main/java/com/jsh/erp/datasource/entities/MsgEx.java
0 → 100644
View file @
a0bad81d
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
;
}
}
\ No newline at end of file
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MsgMapperEx.java
View file @
a0bad81d
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
<
Msg
Ex
>
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
);
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/msg/MsgService.java
View file @
a0bad81d
...
@@ -4,15 +4,18 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -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;
...
@@ -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 {
...
@@ -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
<
Msg
Ex
>
select
(
String
name
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
Msg
>
list
=
null
;
List
<
Msg
Ex
>
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 {
...
@@ -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 {
...
@@ -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
l
ist
;
return
resL
ist
;
}
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
...
@@ -249,4 +279,20 @@ public class MsgService {
...
@@ -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
;
}
}
}
jshERP-boot/src/main/resources/mapper_xml/MsgMapperEx.xml
View file @
a0bad81d
<?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 @@
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment