Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
cd5e0eb7
Commit
cd5e0eb7
authored
Nov 08, 2021
by
xugaojun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【3.0】11-1迭代:素材库支持添加多张图片实现
parent
eeb3a234
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
401 additions
and
109 deletions
+401
-109
BatchAddMaterialDTO.java
...va/com/gic/haoban/manage/api/dto/BatchAddMaterialDTO.java
+147
-0
MaterialApiService.java
...com/gic/haoban/manage/api/service/MaterialApiService.java
+13
-4
TabHaobanMaterialMapper.java
...an/manage/service/dao/mapper/TabHaobanMaterialMapper.java
+6
-5
MaterialService.java
...om/gic/haoban/manage/service/service/MaterialService.java
+4
-2
MaterialServiceImpl.java
...oban/manage/service/service/impl/MaterialServiceImpl.java
+10
-8
MaterialApiServiceImpl.java
...nage/service/service/out/impl/MaterialApiServiceImpl.java
+108
-63
TabHaobanMaterialMapper.xml
...ice/src/main/resources/mapper/TabHaobanMaterialMapper.xml
+51
-0
MaterialController.java
.../gic/haoban/manage/web/controller/MaterialController.java
+62
-27
No files found.
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/dto/BatchAddMaterialDTO.java
0 → 100644
View file @
cd5e0eb7
package
com
.
gic
.
haoban
.
manage
.
api
.
dto
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* desc:批量新增素材请求类
*
* @author: YongEn
* @date: 2021/11/8
**/
public
class
BatchAddMaterialDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
4485943179748351877L
;
/**
* 素材主要信息
*/
private
Material
material
;
/**
* 素材媒体信息列表
*/
private
List
<
MaterialMedia
>
materialMediaList
;
public
Material
getMaterial
()
{
return
material
;
}
public
void
setMaterial
(
Material
material
)
{
this
.
material
=
material
;
}
public
List
<
MaterialMedia
>
getMaterialMediaList
()
{
return
materialMediaList
;
}
public
void
setMaterialMediaList
(
List
<
MaterialMedia
>
materialMediaList
)
{
this
.
materialMediaList
=
materialMediaList
;
}
@Override
public
String
toString
()
{
return
"BatchAddMaterialDTO{"
+
"material="
+
material
+
", materialMediaList="
+
materialMediaList
+
'}'
;
}
/**
* 素材主要信息
*/
public
static
class
Material
implements
Serializable
{
private
static
final
long
serialVersionUID
=
5186039465841424394L
;
/**
* 素材标题
*/
private
String
materialTitle
;
/**
* 素材类型
* 素材类型, 1文本, 2图片, 3网页, 4视频, 5文件,6小程序
*/
private
Integer
materialType
;
/**
* 素材分类id
*/
private
String
categoryId
;
/**
* 企业微信id
*/
private
String
wxEnterpriseId
;
/**
* 员工id
*/
private
String
staffId
;
/**
* 员工姓名
*/
private
String
staffName
;
public
String
getMaterialTitle
()
{
return
materialTitle
;
}
public
void
setMaterialTitle
(
String
materialTitle
)
{
this
.
materialTitle
=
materialTitle
;
}
public
Integer
getMaterialType
()
{
return
materialType
;
}
public
void
setMaterialType
(
Integer
materialType
)
{
this
.
materialType
=
materialType
;
}
public
String
getCategoryId
()
{
return
categoryId
;
}
public
void
setCategoryId
(
String
categoryId
)
{
this
.
categoryId
=
categoryId
;
}
public
String
getWxEnterpriseId
()
{
return
wxEnterpriseId
;
}
public
void
setWxEnterpriseId
(
String
wxEnterpriseId
)
{
this
.
wxEnterpriseId
=
wxEnterpriseId
;
}
public
String
getStaffId
()
{
return
staffId
;
}
public
void
setStaffId
(
String
staffId
)
{
this
.
staffId
=
staffId
;
}
public
String
getStaffName
()
{
return
staffName
;
}
public
void
setStaffName
(
String
staffName
)
{
this
.
staffName
=
staffName
;
}
}
/**
* 素材媒体信息
*/
public
static
class
MaterialMedia
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6540716764890860601L
;
/**
* 素材路径
*/
String
url
;
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
}
}
haoban-manage3-api/src/main/java/com/gic/haoban/manage/api/service/MaterialApiService.java
View file @
cd5e0eb7
package
com
.
gic
.
haoban
.
manage
.
api
.
service
;
import
java.util.List
;
import
com.gic.api.base.commons.Page
;
import
com.gic.haoban.base.api.common.BasePageInfo
;
import
com.gic.haoban.base.api.common.ServiceResponse
;
import
com.gic.haoban.manage.api.dto.BatchAddMaterialDTO
;
import
com.gic.haoban.manage.api.dto.MaterialCategoryDTO
;
import
com.gic.haoban.manage.api.dto.MaterialDTO
;
import
java.util.List
;
public
interface
MaterialApiService
{
boolean
hasCategoryNameExsit
(
String
categoryName
,
String
categoryParentId
,
String
categoryId
);
boolean
hasCategoryNameExsit
(
String
categoryName
,
String
categoryParentId
,
String
categoryId
);
void
insertCategory
(
MaterialCategoryDTO
materialCategoryDTO
);
...
...
@@ -30,7 +31,7 @@ public interface MaterialApiService {
void
editMaterial
(
MaterialDTO
materialDTO
);
Page
<
MaterialDTO
>
listMaterial
(
String
wxEnterpriseId
,
String
keyword
,
String
categoryId
,
Integer
materialType
,
BasePageInfo
pageInfo
);
Page
<
MaterialDTO
>
listMaterial
(
String
wxEnterpriseId
,
String
keyword
,
String
categoryId
,
Integer
materialType
,
BasePageInfo
pageInfo
);
String
reUpdalodMetail
(
String
materialId
);
...
...
@@ -67,4 +68,12 @@ public interface MaterialApiService {
*/
MaterialDTO
getHasChangeMadieMaterialById
(
String
materialId
);
/**
* 批量新增素材
*
* @param dto dto
* @author: YongEn
*/
void
batchInsertMaterial
(
BatchAddMaterialDTO
dto
);
}
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/dao/mapper/TabHaobanMaterialMapper.java
View file @
cd5e0eb7
package
com
.
gic
.
haoban
.
manage
.
service
.
dao
.
mapper
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
import
com.gic.haoban.manage.service.entity.TabHaobanMaterial
;
import
com.github.pagehelper.Page
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
TabHaobanMaterialMapper
{
int
deleteByPrimaryKey
(
String
materialId
);
int
insert
(
TabHaobanMaterial
record
);
int
batchInsert
(
@Param
(
"records"
)
List
<
TabHaobanMaterial
>
records
);
int
insertSelective
(
TabHaobanMaterial
record
);
TabHaobanMaterial
selectByPrimaryKey
(
String
materialId
);
...
...
@@ -24,7 +25,7 @@ public interface TabHaobanMaterialMapper {
List
<
TabHaobanMaterial
>
listMaterialByCategoryId
(
String
categoryId
);
Page
<
TabHaobanMaterial
>
listMaterial
(
@Param
(
"wxEnterpriseId"
)
String
wxEnterpriseId
,
@Param
(
"keyword"
)
String
keyword
,
@Param
(
"categoryId"
)
String
categoryId
,
@Param
(
"materialType"
)
Integer
materialType
);
Page
<
TabHaobanMaterial
>
listMaterial
(
@Param
(
"wxEnterpriseId"
)
String
wxEnterpriseId
,
@Param
(
"keyword"
)
String
keyword
,
@Param
(
"categoryId"
)
String
categoryId
,
@Param
(
"materialType"
)
Integer
materialType
);
List
<
TabHaobanMaterial
>
listMaterialByCategoryIds
(
@Param
(
"wxEnterpriseId"
)
String
wxEnterpriseId
,
@Param
(
"keyword"
)
String
keyword
,
@Param
(
"categoryIds"
)
List
<
String
>
categoryIds
,
@Param
(
"materialType"
)
Integer
materialType
);
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/MaterialService.java
View file @
cd5e0eb7
package
com
.
gic
.
haoban
.
manage
.
service
.
service
;
import
java.util.List
;
import
com.gic.haoban.manage.api.dto.MaterialDTO
;
import
java.util.List
;
public
interface
MaterialService
{
List
<
MaterialDTO
>
listMaterialByCategoryId
(
String
categoryId
);
void
insertMaterial
(
MaterialDTO
materialDTO
);
void
batchInsertMaterial
(
List
<
MaterialDTO
>
materialList
);
MaterialDTO
selectMaterialById
(
String
materialId
);
List
<
MaterialDTO
>
listMaterialByIds
(
List
<
String
>
materialIds
);
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/impl/MaterialServiceImpl.java
View file @
cd5e0eb7
package
com
.
gic
.
haoban
.
manage
.
service
.
service
.
impl
;
import
java.util.Date
;
import
java.util.List
;
import
com.github.pagehelper.PageInfo
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.gic.haoban.common.utils.EntityUtil
;
import
com.gic.haoban.common.utils.StringUtil
;
import
com.gic.haoban.manage.api.dto.MaterialDTO
;
...
...
@@ -15,6 +7,11 @@ import com.gic.haoban.manage.service.dao.mapper.TabHaobanMaterialMapper;
import
com.gic.haoban.manage.service.entity.TabHaobanMaterial
;
import
com.gic.haoban.manage.service.service.MaterialService
;
import
com.github.pagehelper.Page
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
MaterialServiceImpl
implements
MaterialService
{
...
...
@@ -38,6 +35,11 @@ public class MaterialServiceImpl implements MaterialService {
}
@Override
public
void
batchInsertMaterial
(
List
<
MaterialDTO
>
materialList
)
{
mapper
.
batchInsert
(
EntityUtil
.
changeEntityListByOrika
(
TabHaobanMaterial
.
class
,
materialList
));
}
@Override
public
MaterialDTO
selectMaterialById
(
String
materialId
)
{
return
EntityUtil
.
changeEntityByJSON
(
MaterialDTO
.
class
,
mapper
.
selectByPrimaryKey
(
materialId
));
}
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/MaterialApiServiceImpl.java
View file @
cd5e0eb7
package
com
.
gic
.
haoban
.
manage
.
service
.
service
.
out
.
impl
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
com.gic.haoban.base.api.common.ServiceResponse
;
import
com.gic.haoban.manage.service.entity.TabMiniprogramSetting
;
import
com.gic.haoban.manage.service.service.MiniprogramSettingService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.gic.api.base.commons.JSONResponse
;
import
com.gic.api.base.commons.Page
;
import
com.gic.commons.util.GlobalInfo
;
import
com.gic.commons.util.GlobalVar
;
import
com.gic.haoban.base.api.common.BasePageInfo
;
import
com.gic.haoban.base.api.common.ServiceResponse
;
import
com.gic.haoban.common.utils.PageUtil
;
import
com.gic.haoban.manage.api.dto.DepartmentDTO
;
import
com.gic.haoban.common.utils.StringUtil
;
import
com.gic.haoban.manage.api.dto.BatchAddMaterialDTO
;
import
com.gic.haoban.manage.api.dto.MaterialCategoryDTO
;
import
com.gic.haoban.manage.api.dto.MaterialDTO
;
import
com.gic.haoban.manage.api.dto.WxEnterpriseDTO
;
import
com.gic.haoban.manage.api.service.MaterialApiService
;
import
com.gic.haoban.manage.service.config.Config
;
import
com.gic.haoban.manage.service.entity.TabHaobanMaterial
;
import
com.gic.haoban.manage.service.entity.TabMiniprogramSetting
;
import
com.gic.haoban.manage.service.service.MaterialCategoryService
;
import
com.gic.haoban.manage.service.service.MaterialService
;
import
com.gic.haoban.manage.service.service.MiniprogramSettingService
;
import
com.gic.haoban.manage.service.service.WxEnterpriseService
;
import
com.gic.thirdparty.api.dto.PicUploadResDTO
;
import
com.gic.wechat.api.enums.QywxMediaTypeEnum
;
import
com.gic.wechat.api.service.qywx.QywxSuiteApiService
;
import
com.github.pagehelper.PageHelper
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
public
class
MaterialApiServiceImpl
implements
MaterialApiService
{
...
...
@@ -64,13 +60,12 @@ public class MaterialApiServiceImpl implements MaterialApiService {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
MaterialApiServiceImpl
.
class
);
@Override
public
boolean
hasCategoryNameExsit
(
String
categoryName
,
String
categoryParentId
,
String
categoryId
)
{
MaterialCategoryDTO
category
=
materialCategoryService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
);
if
(
category
!=
null
)
{
if
(
category
.
getCategoryId
().
equals
(
categoryId
))
{
public
boolean
hasCategoryNameExsit
(
String
categoryName
,
String
categoryParentId
,
String
categoryId
)
{
MaterialCategoryDTO
category
=
materialCategoryService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
);
if
(
category
!=
null
)
{
if
(
category
.
getCategoryId
().
equals
(
categoryId
))
{
return
false
;
}
else
{
}
else
{
return
true
;
}
}
...
...
@@ -111,23 +106,23 @@ public class MaterialApiServiceImpl implements MaterialApiService {
Integer
type
=
materialDTO
.
getMaterialType
();
String
wxEnterpriseId
=
materialDTO
.
getWxEnterpriseId
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
if
(
type
==
null
)
{
if
(
type
==
null
)
{
return
;
}
if
(
enterprise
==
null
)
{
if
(
enterprise
==
null
)
{
return
;
}
QywxMediaTypeEnum
fileType
=
null
;
String
url
=
""
;
if
(
type
==
2
)
{
if
(
type
==
2
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
materialDTO
.
getImgUrl
();
}
if
(
type
==
4
)
{
if
(
type
==
4
)
{
fileType
=
QywxMediaTypeEnum
.
VIDEO
;
url
=
materialDTO
.
getLink
();
}
if
(
type
==
5
)
{
if
(
type
==
5
)
{
fileType
=
QywxMediaTypeEnum
.
FILE
;
url
=
materialDTO
.
getLink
();
}
...
...
@@ -135,24 +130,24 @@ public class MaterialApiServiceImpl implements MaterialApiService {
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
materialDTO
.
getImgUrl
();
}
if
(
type
==
3
)
{
if
(
type
==
3
)
{
String
imgUrl
=
materialDTO
.
getImgUrl
();
logger
.
info
(
"【上传图片】imgUrl={}"
,
imgUrl
);
logger
.
info
(
"【上传图片】imgUrl={}"
,
imgUrl
);
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
imgUrl
));
logger
.
info
(
"【上传图片返回】response={}"
,
JSON
.
toJSONString
(
response
));
logger
.
info
(
"【上传图片返回】response={}"
,
JSON
.
toJSONString
(
response
));
String
wxImgUrl
=
response
.
getResult
()
==
null
?
""
:
response
.
getResult
().
toString
();
materialDTO
.
setWxImgUrl
(
wxImgUrl
);
}
if
(
fileType
!=
null
)
{
if
(
fileType
!=
null
)
{
String
[]
arr
=
url
.
split
(
"/"
);
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
materialDTO
.
setWxLastUploadTime
(
new
Date
());
materialDTO
.
setMediaId
(
jp
.
getResult
().
toString
());
materialService
.
insertMaterial
(
materialDTO
);
}
}
else
{
}
else
{
materialService
.
insertMaterial
(
materialDTO
);
}
}
...
...
@@ -174,78 +169,78 @@ public class MaterialApiServiceImpl implements MaterialApiService {
MaterialDTO
old
=
materialService
.
selectMaterialById
(
materialId
);
String
wxEnterpriseId
=
old
.
getWxEnterpriseId
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
if
(
type
==
null
)
{
if
(
type
==
null
)
{
return
;
}
if
(
enterprise
==
null
)
{
if
(
enterprise
==
null
)
{
return
;
}
QywxMediaTypeEnum
fileType
=
null
;
String
url
=
""
;
String
oldUrl
=
""
;
if
(
type
==
2
)
{
if
(
type
==
2
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
materialDTO
.
getImgUrl
();
oldUrl
=
old
.
getImgUrl
();
}
if
(
type
==
4
)
{
if
(
type
==
4
)
{
fileType
=
QywxMediaTypeEnum
.
VIDEO
;
url
=
materialDTO
.
getLink
();
oldUrl
=
old
.
getLink
();
}
if
(
type
==
5
)
{
if
(
type
==
5
)
{
fileType
=
QywxMediaTypeEnum
.
FILE
;
url
=
materialDTO
.
getLink
();
oldUrl
=
old
.
getLink
();
}
if
(
type
==
3
)
{
if
(
type
==
3
)
{
String
imgUrl
=
materialDTO
.
getImgUrl
();
String
oldImgUrl
=
materialDTO
.
getImgUrl
();
if
(!
imgUrl
.
equals
(
oldImgUrl
))
{
if
(!
imgUrl
.
equals
(
oldImgUrl
))
{
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
imgUrl
));
String
wxImgUrl
=
response
.
getResult
()
==
null
?
""
:
response
.
getResult
().
toString
();
materialDTO
.
setWxImgUrl
(
wxImgUrl
);
}
}
if
(
fileType
!=
null
&&
!
url
.
equals
(
oldUrl
))
{
if
(
fileType
!=
null
&&
!
url
.
equals
(
oldUrl
))
{
String
[]
arr
=
url
.
split
(
"/"
);
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
materialDTO
.
setWxLastUploadTime
(
new
Date
());
materialDTO
.
setMediaId
(
jp
.
getResult
().
toString
());
materialService
.
edit
(
materialDTO
);
}
}
else
{
}
else
{
materialService
.
edit
(
materialDTO
);
}
}
@Override
public
String
reUpdalodMetail
(
String
materialId
)
{
public
String
reUpdalodMetail
(
String
materialId
)
{
MaterialDTO
old
=
materialService
.
selectMaterialById
(
materialId
);
Integer
type
=
old
.
getMaterialType
();
if
(
type
==
null
)
{
if
(
type
==
null
)
{
return
""
;
}
String
wxEnterpriseId
=
old
.
getWxEnterpriseId
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
if
(
enterprise
==
null
)
{
if
(
enterprise
==
null
)
{
return
""
;
}
String
url
=
""
;
String
oldUrl
=
""
;
QywxMediaTypeEnum
fileType
=
null
;
if
(
type
==
2
)
{
if
(
type
==
2
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
old
.
getImgUrl
();
}
if
(
type
==
4
)
{
if
(
type
==
4
)
{
fileType
=
QywxMediaTypeEnum
.
VIDEO
;
url
=
old
.
getLink
();
}
if
(
type
==
5
)
{
if
(
type
==
5
)
{
fileType
=
QywxMediaTypeEnum
.
FILE
;
url
=
old
.
getLink
();
}
else
if
(
type
==
6
)
{
...
...
@@ -254,8 +249,8 @@ public class MaterialApiServiceImpl implements MaterialApiService {
}
String
[]
arr
=
url
.
split
(
"/"
);
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
old
.
setWxLastUploadTime
(
new
Date
());
old
.
setMediaId
(
jp
.
getResult
().
toString
());
materialService
.
edit
(
old
);
...
...
@@ -281,7 +276,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
@Override
public
Page
<
MaterialDTO
>
listMaterial
(
String
wxEnterpriseId
,
String
keyword
,
String
categoryId
,
Integer
materialType
,
BasePageInfo
pageInfo
)
{
Integer
materialType
,
BasePageInfo
pageInfo
)
{
List
<
String
>
categoryIds
=
this
.
listSubCategoryIdsByParentId
(
categoryId
);
PageHelper
.
startPage
(
pageInfo
.
getPageNum
(),
pageInfo
.
getPageSize
());
com
.
github
.
pagehelper
.
Page
<
TabHaobanMaterial
>
page
=
materialService
.
listMaterial
(
wxEnterpriseId
,
keyword
,
categoryIds
,
materialType
);
...
...
@@ -294,7 +289,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
dto
.
setMaterialDesc
(
miniprogramSetting
==
null
?
"--"
:
miniprogramSetting
.
getMiniprogramName
());
});
}
return
PageUtil
.
changePageHelperToCurrentPage
(
page
,
MaterialDTO
.
class
);
return
PageUtil
.
changePageHelperToCurrentPage
(
page
,
MaterialDTO
.
class
);
}
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -309,8 +304,8 @@ public class MaterialApiServiceImpl implements MaterialApiService {
InputStream
in
=
new
URL
(
url
).
openStream
();
byte
[]
data
=
IOUtils
.
toByteArray
(
in
);
return
data
;
}
catch
(
Exception
e
)
{
logger
.
info
(
"【异常】"
+
e
.
getMessage
(),
e
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"【异常】"
+
e
.
getMessage
(),
e
);
}
return
null
;
}
...
...
@@ -385,4 +380,54 @@ public class MaterialApiServiceImpl implements MaterialApiService {
materialDTO
.
setWxLastUploadTime
(
date
);
return
materialDTO
;
}
@Override
public
void
batchInsertMaterial
(
BatchAddMaterialDTO
dto
)
{
// 构造素材实体类
BatchAddMaterialDTO
.
Material
material
=
dto
.
getMaterial
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
material
.
getWxEnterpriseId
());
if
(
enterprise
==
null
)
{
return
;
}
List
<
BatchAddMaterialDTO
.
MaterialMedia
>
materialMediaList
=
dto
.
getMaterialMediaList
();
if
(
CollectionUtils
.
isEmpty
(
materialMediaList
))
{
return
;
}
List
<
MaterialDTO
>
materialList
=
materialMediaList
.
stream
().
map
(
one
->
{
MaterialDTO
materialDTO
=
new
MaterialDTO
();
// 必填字段
materialDTO
.
setCreateTime
(
new
Date
());
materialDTO
.
setUpdateTime
(
materialDTO
.
getCreateTime
());
materialDTO
.
setStatusFlag
(
1
);
materialDTO
.
setMaterialId
(
StringUtil
.
randomUUID
());
// 传入字段
materialDTO
.
setCategoryId
(
material
.
getCategoryId
());
materialDTO
.
setMaterialTitle
(
material
.
getMaterialTitle
());
materialDTO
.
setMaterialType
(
material
.
getMaterialType
());
materialDTO
.
setWxEnterpriseId
(
material
.
getWxEnterpriseId
());
materialDTO
.
setStaffId
(
material
.
getStaffId
());
materialDTO
.
setStaffName
(
material
.
getStaffName
());
String
mediaId
=
uploadMediaToWx
(
enterprise
.
getCorpid
(),
one
.
getUrl
());
if
(
StringUtils
.
isNotEmpty
(
mediaId
))
{
materialDTO
.
setWxLastUploadTime
(
new
Date
());
materialDTO
.
setMediaId
(
mediaId
);
}
return
materialDTO
;
}).
collect
(
Collectors
.
toList
());
// batch-insert
materialService
.
batchInsertMaterial
(
materialList
);
}
private
String
uploadMediaToWx
(
String
corPid
,
String
url
)
{
String
[]
arr
=
url
.
split
(
"/"
);
// 先写死为图片类型, 以后有别的再扩展
QywxMediaTypeEnum
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
corPid
,
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
return
jp
.
getResult
().
toString
();
}
return
null
;
}
}
haoban-manage3-service/src/main/resources/mapper/TabHaobanMaterialMapper.xml
View file @
cd5e0eb7
...
...
@@ -173,6 +173,57 @@
</if>
</trim>
</insert>
<insert
id=
"batchInsert"
parameterType=
"com.gic.haoban.manage.service.entity.TabHaobanMaterial"
>
insert into tab_haoban_material
(
material_id,
from_material_id,
material_title,
material_type,
category_id,
material_content,
wx_last_upload_time,
media_id,
wx_enterprise_id,
staff_id,
staff_name,
img_url,
wx_img_url,
material_desc,
status_flag,
link,
app_id,
create_time,
update_time
)
VALUES
(
<foreach
collection=
"records"
item=
"one"
separator=
","
>
#{one.materialId,jdbcType=VARCHAR},
#{one.fromMaterialId,jdbcType=VARCHAR},
#{one.materialTitle,jdbcType=VARCHAR},
#{one.materialType,jdbcType=INTEGER},
#{one.categoryId,jdbcType=VARCHAR},
#{one.materialContent,jdbcType=VARCHAR},
#{one.wxLastUploadTime,jdbcType=TIMESTAMP},
#{one.mediaId,jdbcType=VARCHAR},
#{one.wxEnterpriseId,jdbcType=VARCHAR},
#{one.staffId,jdbcType=VARCHAR},
#{one.staffName,jdbcType=VARCHAR},
#{one.imgUrl,jdbcType=VARCHAR},
#{one.wxImgUrl,jdbcType=VARCHAR},
#{one.materialDesc,jdbcType=VARCHAR},
#{one.statusFlag,jdbcType=INTEGER},
#{one.link,jdbcType=VARCHAR},
#{one.appId,jdbcType=VARCHAR},
#{one.createTime,jdbcType=TIMESTAMP},
#{one.updateTime,jdbcType=TIMESTAMP}
</foreach>
)
</insert>
<update
id=
"updateByPrimaryKeySelective"
parameterType=
"com.gic.haoban.manage.service.entity.TabHaobanMaterial"
>
update tab_haoban_material
<set
>
...
...
haoban-manage3-web/src/main/java/com/gic/haoban/manage/web/controller/MaterialController.java
View file @
cd5e0eb7
...
...
@@ -5,29 +5,29 @@ import com.gic.api.base.commons.Page;
import
com.gic.haoban.base.api.common.BasePageInfo
;
import
com.gic.haoban.base.api.common.ServiceResponse
;
import
com.gic.haoban.common.utils.HaobanResponse
;
import
com.gic.haoban.manage.api.dto.LoginDTO
;
import
com.gic.haoban.manage.api.dto.MaterialCategoryDTO
;
import
com.gic.haoban.manage.api.dto.MaterialDTO
;
import
com.gic.haoban.manage.api.dto.StaffDTO
;
import
com.gic.haoban.manage.api.dto.*
;
import
com.gic.haoban.manage.api.service.MaterialApiService
;
import
com.gic.haoban.manage.web.auth.AuthRequestUtil
;
import
com.gic.haoban.manage.web.errCode.HaoBanErrCode
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Objects
;
@RestController
public
class
MaterialController
extends
WebBaseController
{
public
class
MaterialController
extends
WebBaseController
{
@Autowired
private
MaterialApiService
materialApiService
;
/**
* 素材分组新增
*
* @return
*/
@RequestMapping
(
"/mateial-add-category"
)
...
...
@@ -37,11 +37,11 @@ public class MaterialController extends WebBaseController{
materialCategoryDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
String
categoryName
=
materialCategoryDTO
.
getCategoryName
();
String
categoryParentId
=
materialCategoryDTO
.
getCategoryParentId
();
if
(
StringUtils
.
isAnyBlank
(
categoryParentId
,
categoryName
))
{
if
(
StringUtils
.
isAnyBlank
(
categoryParentId
,
categoryName
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
null
);
if
(
flag
)
{
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
null
);
if
(
flag
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10015
);
}
materialApiService
.
insertCategory
(
materialCategoryDTO
);
...
...
@@ -50,32 +50,34 @@ public class MaterialController extends WebBaseController{
/**
* 素材分组查询
*
* @return
*/
@RequestMapping
(
"/category-list"
)
public
HaobanResponse
categoryList
(
String
wxEnterpriseId
)
{
List
<
MaterialCategoryDTO
>
list
=
materialApiService
.
listCategory
(
wxEnterpriseId
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
list
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
list
);
}
/**
* 素材分组修改
*
* @return
*/
@RequestMapping
(
"/category-edit"
)
public
HaobanResponse
categoryEdit
(
MaterialCategoryDTO
materialCategoryDTO
)
{
String
categoryName
=
materialCategoryDTO
.
getCategoryName
();
String
categoryId
=
materialCategoryDTO
.
getCategoryId
();
if
(
StringUtils
.
isAnyBlank
(
categoryName
,
categoryId
))
{
if
(
StringUtils
.
isAnyBlank
(
categoryName
,
categoryId
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
MaterialCategoryDTO
dto
=
materialApiService
.
selectMaterialCategoryById
(
categoryId
);
if
(
dto
==
null
)
{
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10016
);
}
String
categoryParentId
=
dto
.
getCategoryParentId
();
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
materialCategoryDTO
.
getCategoryId
());
if
(
flag
)
{
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
materialCategoryDTO
.
getCategoryId
());
if
(
flag
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10015
);
}
materialApiService
.
editCategory
(
materialCategoryDTO
);
...
...
@@ -85,21 +87,22 @@ public class MaterialController extends WebBaseController{
/**
* 素材分组删除
*
* @return
*/
@RequestMapping
(
"/category-del"
)
public
HaobanResponse
categoryDel
(
String
categoryId
)
{
MaterialCategoryDTO
dto
=
materialApiService
.
selectMaterialCategoryById
(
categoryId
);
if
(
dto
==
null
)
{
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10016
);
}
List
<
MaterialCategoryDTO
>
categoryList
=
materialApiService
.
listByParentCategory
(
categoryId
);
if
(
categoryList
!=
null
&&
!
categoryList
.
isEmpty
())
{
if
(
categoryList
!=
null
&&
!
categoryList
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10017
);
}
List
<
MaterialDTO
>
list
=
materialApiService
.
listMaterialByCategoryId
(
categoryId
);
if
(
list
!=
null
&&
!
list
.
isEmpty
())
{
if
(
list
!=
null
&&
!
list
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10017
);
}
dto
.
setStatusFlag
(
0
);
...
...
@@ -109,6 +112,7 @@ public class MaterialController extends WebBaseController{
/**
* 素材新增
*
* @return
*/
@RequestMapping
(
"/material-add"
)
...
...
@@ -123,10 +127,10 @@ public class MaterialController extends WebBaseController{
String
materialTitle
=
materialDTO
.
getMaterialTitle
();
String
categoryId
=
materialDTO
.
getCategoryId
();
Integer
categoryType
=
materialDTO
.
getMaterialType
();
if
(
StringUtils
.
isAnyBlank
(
categoryId
,
materialTitle
))
{
if
(
StringUtils
.
isAnyBlank
(
categoryId
,
materialTitle
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
if
(
categoryType
==
null
)
{
if
(
categoryType
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
materialApiService
.
insertMaterial
(
materialDTO
);
...
...
@@ -134,17 +138,44 @@ public class MaterialController extends WebBaseController{
}
/**
* 批量新增素材
*
* @param dto dto
* @return res
*/
@RequestMapping
(
"/material-batch-add"
)
public
HaobanResponse
batchAddMaterial
(
@RequestBody
BatchAddMaterialDTO
dto
)
{
if
(
Objects
.
isNull
(
dto
)
||
Objects
.
isNull
(
dto
.
getMaterial
()))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
BatchAddMaterialDTO
.
Material
material
=
dto
.
getMaterial
();
LoginDTO
login
=
(
LoginDTO
)
AuthRequestUtil
.
getLoginUser
();
material
.
setWxEnterpriseId
(
login
.
getWxEnterpriseId
());
StaffDTO
staff
=
login
.
getStaffDTO
();
material
.
setStaffId
(
staff
.
getStaffId
());
material
.
setStaffName
(
staff
.
getStaffName
());
if
(
StringUtils
.
isAnyBlank
(
material
.
getCategoryId
(),
material
.
getMaterialTitle
())
||
Objects
.
isNull
(
material
.
getMaterialType
()))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
materialApiService
.
batchInsertMaterial
(
dto
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
* 素材详情
*
* @return
*/
@RequestMapping
(
"/material-detail"
)
public
HaobanResponse
materialDetail
(
String
materialId
)
{
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
dto
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
dto
);
}
/**
* 素材修改
*
* @return
*/
@RequestMapping
(
"/material-edit"
)
...
...
@@ -156,7 +187,7 @@ public class MaterialController extends WebBaseController{
materialDTO
.
setStaffName
(
staff
.
getStaffName
());
String
materialId
=
materialDTO
.
getMaterialId
();
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
if
(
dto
==
null
)
{
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
materialApiService
.
editMaterial
(
materialDTO
);
...
...
@@ -165,11 +196,12 @@ public class MaterialController extends WebBaseController{
/**
* 素材删除
*
* @return
*/
@RequestMapping
(
"/material-del"
)
public
HaobanResponse
materialEdit
(
String
materialIds
)
{
if
(
StringUtils
.
isBlank
(
materialIds
))
{
if
(
StringUtils
.
isBlank
(
materialIds
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
String
[]
stringArr
=
materialIds
.
split
(
","
);
...
...
@@ -181,27 +213,30 @@ public class MaterialController extends WebBaseController{
/**
* 素材查询
*
* @return
*/
@RequestMapping
(
"/material-list"
)
public
HaobanResponse
materialList
(
String
wxEnterpriseId
,
String
keyword
,
String
categoryId
,
Integer
materialType
,
BasePageInfo
pageInfo
)
{
Page
<
MaterialDTO
>
page
=
materialApiService
.
listMaterial
(
wxEnterpriseId
,
keyword
,
categoryId
,
materialType
,
pageInfo
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
page
);
public
HaobanResponse
materialList
(
String
wxEnterpriseId
,
String
keyword
,
String
categoryId
,
Integer
materialType
,
BasePageInfo
pageInfo
)
{
Page
<
MaterialDTO
>
page
=
materialApiService
.
listMaterial
(
wxEnterpriseId
,
keyword
,
categoryId
,
materialType
,
pageInfo
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
page
);
}
/**
* 素材批量转移
*
* @return
*/
@RequestMapping
(
"/material-batch"
)
public
HaobanResponse
materialBatch
(
String
materialIds
,
String
categoryId
)
{
public
HaobanResponse
materialBatch
(
String
materialIds
,
String
categoryId
)
{
String
[]
stringArr
=
materialIds
.
split
(
","
);
for
(
String
materialId
:
stringArr
)
{
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
if
(
dto
==
null
)
{
if
(
dto
==
null
)
{
continue
;
}
dto
.
setCategoryId
(
categoryId
);;
dto
.
setCategoryId
(
categoryId
);
;
materialApiService
.
editMaterial
(
dto
);
}
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
...
...
Write
Preview
Markdown
is supported
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