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
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
716 additions
and
424 deletions
+716
-424
BatchAddMaterialDTO.java
...va/com/gic/haoban/manage/api/dto/BatchAddMaterialDTO.java
+147
-0
MaterialApiService.java
...com/gic/haoban/manage/api/service/MaterialApiService.java
+35
-26
TabHaobanMaterialMapper.java
...an/manage/service/dao/mapper/TabHaobanMaterialMapper.java
+7
-6
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
+302
-257
TabHaobanMaterialMapper.xml
...ice/src/main/resources/mapper/TabHaobanMaterialMapper.xml
+51
-0
MaterialController.java
.../gic/haoban/manage/web/controller/MaterialController.java
+160
-125
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
);
void
insertCategory
(
MaterialCategoryDTO
materialCategoryDTO
);
List
<
MaterialCategoryDTO
>
listCategory
(
String
wxEnterpriseId
);
List
<
MaterialCategoryDTO
>
listCategory
(
String
wxEnterpriseId
);
MaterialCategoryDTO
selectMaterialCategoryById
(
String
categoryId
);
MaterialCategoryDTO
selectMaterialCategoryById
(
String
categoryId
);
void
editCategory
(
MaterialCategoryDTO
materialCategoryDTO
);
void
editCategory
(
MaterialCategoryDTO
materialCategoryDTO
);
List
<
MaterialDTO
>
listMaterialByCategoryId
(
String
categoryId
);
List
<
MaterialDTO
>
listMaterialByCategoryId
(
String
categoryId
);
void
insertMaterial
(
MaterialDTO
materialDTO
);
void
insertMaterial
(
MaterialDTO
materialDTO
);
MaterialDTO
selectMaterialById
(
String
materialId
);
MaterialDTO
selectMaterialById
(
String
materialId
);
List
<
MaterialDTO
>
listMaterialByIds
(
List
<
String
>
materialIds
);
void
editMaterial
(
MaterialDTO
materialDTO
);
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
);
String
reUpdalodMetail
(
String
materialId
);
List
<
MaterialCategoryDTO
>
listByParentCategory
(
String
categoryId
);
List
<
MaterialCategoryDTO
>
listByParentCategory
(
String
categoryId
);
/**
* 分析素材
...
...
@@ -45,19 +46,19 @@ public interface MaterialApiService {
*/
ServiceResponse
<
Void
>
shareMaterial
(
String
wxEnterpriseId
,
String
toWxEnterpriseId
,
String
materialId
);
/**
* 素材关联的已分配企业
*
* @param materialId
*/
List
<
MaterialDTO
>
listByFromMaterialId
(
String
materialId
);
/**
* 素材关联的已分配企业
*
* @param materialId
*/
List
<
MaterialDTO
>
listByFromMaterialId
(
String
materialId
);
/**
* 删除
*
* @param ids
*/
void
delMaterial
(
List
<
String
>
ids
);
/**
* 删除
*
* @param ids
*/
void
delMaterial
(
List
<
String
>
ids
);
/**
* 自动刷新madiaid的 获取素材
...
...
@@ -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
);
...
...
@@ -22,9 +23,9 @@ public interface TabHaobanMaterialMapper {
int
updateByPrimaryKey
(
TabHaobanMaterial
record
);
List
<
TabHaobanMaterial
>
listMaterialByCategoryId
(
String
categoryId
);
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
{
@Autowired
private
MaterialCategoryService
materialCategoryService
;
@Autowired
private
MaterialService
materialService
;
@Autowired
private
QywxSuiteApiService
qywxSuiteApiService
;
@Autowired
private
WxEnterpriseService
wxEnterpriseService
;
@Autowired
private
Config
config
;
@Autowired
private
MaterialCategoryService
materialCategoryService
;
@Autowired
private
MaterialService
materialService
;
@Autowired
private
QywxSuiteApiService
qywxSuiteApiService
;
@Autowired
private
WxEnterpriseService
wxEnterpriseService
;
@Autowired
private
Config
config
;
@Autowired
private
MiniprogramSettingService
miniprogramSettingService
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
MaterialApiServiceImpl
.
class
);
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
)){
return
false
;
}
else
{
return
true
;
}
}
return
false
;
}
@Override
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
{
return
true
;
}
}
return
false
;
@Override
public
void
insertCategory
(
MaterialCategoryDTO
materialCategoryDTO
)
{
materialCategoryService
.
insert
(
materialCategoryDTO
);
}
}
@Override
public
List
<
MaterialCategoryDTO
>
listCategory
(
String
wxEnterpriseId
)
{
return
materialCategoryService
.
listCategory
(
wxEnterpriseId
);
}
@Override
public
void
insertCategory
(
MaterialCategoryDTO
materialCategoryDTO
)
{
materialCategoryService
.
insert
(
materialCategoryDTO
);
@Override
public
MaterialCategoryDTO
selectMaterialCategoryById
(
String
categoryId
)
{
return
materialCategoryService
.
selectMaterialCategoryById
(
categoryId
);
}
}
@Override
public
void
editCategory
(
MaterialCategoryDTO
materialCategoryDTO
)
{
materialCategoryService
.
editCategory
(
materialCategoryDTO
);
@Override
public
List
<
MaterialCategoryDTO
>
listCategory
(
String
wxEnterpriseId
)
{
return
materialCategoryService
.
listCategory
(
wxEnterpriseId
);
}
}
@Override
public
MaterialCategoryDTO
selectMaterialCategoryById
(
String
categoryId
)
{
return
materialCategoryService
.
selectMaterialCategoryById
(
categoryId
);
}
@Override
public
List
<
MaterialDTO
>
listMaterialByCategoryId
(
String
categoryId
)
{
return
materialService
.
listMaterialByCategoryId
(
categoryId
);
}
@Override
public
void
editCategory
(
MaterialCategoryDTO
materialCategoryDTO
)
{
materialCategoryService
.
editCategory
(
materialCategoryDTO
);
@Override
public
void
insertMaterial
(
MaterialDTO
materialDTO
)
{
Integer
type
=
materialDTO
.
getMaterialType
();
String
wxEnterpriseId
=
materialDTO
.
getWxEnterpriseId
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
if
(
type
==
null
){
return
;
}
if
(
enterprise
==
null
){
return
;
}
QywxMediaTypeEnum
fileType
=
null
;
String
url
=
""
;
if
(
type
==
2
){
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
materialDTO
.
getImgUrl
();
}
if
(
type
==
4
){
fileType
=
QywxMediaTypeEnum
.
VIDEO
;
url
=
materialDTO
.
getLink
();
}
if
(
type
==
5
){
fileType
=
QywxMediaTypeEnum
.
FILE
;
url
=
materialDTO
.
getLink
();
}
}
@Override
public
List
<
MaterialDTO
>
listMaterialByCategoryId
(
String
categoryId
)
{
return
materialService
.
listMaterialByCategoryId
(
categoryId
);
}
@Override
public
void
insertMaterial
(
MaterialDTO
materialDTO
)
{
Integer
type
=
materialDTO
.
getMaterialType
();
String
wxEnterpriseId
=
materialDTO
.
getWxEnterpriseId
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
if
(
type
==
null
)
{
return
;
}
if
(
enterprise
==
null
)
{
return
;
}
QywxMediaTypeEnum
fileType
=
null
;
String
url
=
""
;
if
(
type
==
2
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
materialDTO
.
getImgUrl
();
}
if
(
type
==
4
)
{
fileType
=
QywxMediaTypeEnum
.
VIDEO
;
url
=
materialDTO
.
getLink
();
}
if
(
type
==
5
)
{
fileType
=
QywxMediaTypeEnum
.
FILE
;
url
=
materialDTO
.
getLink
();
}
if
(
type
==
6
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
materialDTO
.
getImgUrl
();
}
if
(
type
==
3
)
{
String
imgUrl
=
materialDTO
.
getImgUrl
();
logger
.
info
(
"【上传图片】imgUrl={}"
,
imgUrl
);
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
imgUrl
));
logger
.
info
(
"【上传图片返回】response={}"
,
JSON
.
toJSONString
(
response
));
String
wxImgUrl
=
response
.
getResult
()
==
null
?
""
:
response
.
getResult
().
toString
();
materialDTO
.
setWxImgUrl
(
wxImgUrl
);
}
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
)
{
materialDTO
.
setWxLastUploadTime
(
new
Date
());
materialDTO
.
setMediaId
(
jp
.
getResult
().
toString
());
materialService
.
insertMaterial
(
materialDTO
);
}
}
else
{
materialService
.
insertMaterial
(
materialDTO
);
}
}
if
(
type
==
3
)
{
String
imgUrl
=
materialDTO
.
getImgUrl
();
logger
.
info
(
"【上传图片】imgUrl={}"
,
imgUrl
);
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
imgUrl
));
logger
.
info
(
"【上传图片返回】response={}"
,
JSON
.
toJSONString
(
response
));
String
wxImgUrl
=
response
.
getResult
()
==
null
?
""
:
response
.
getResult
().
toString
();
materialDTO
.
setWxImgUrl
(
wxImgUrl
);
}
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
)
{
materialDTO
.
setWxLastUploadTime
(
new
Date
());
materialDTO
.
setMediaId
(
jp
.
getResult
().
toString
());
materialService
.
insertMaterial
(
materialDTO
);
}
}
else
{
materialService
.
insertMaterial
(
materialDTO
);
}
}
@Override
public
MaterialDTO
selectMaterialById
(
String
materialId
)
{
return
materialService
.
selectMaterialById
(
materialId
);
}
@Override
public
MaterialDTO
selectMaterialById
(
String
materialId
)
{
return
materialService
.
selectMaterialById
(
materialId
);
}
@Override
@Override
public
List
<
MaterialDTO
>
listMaterialByIds
(
List
<
String
>
materialIds
)
{
return
materialService
.
listMaterialByIds
(
materialIds
);
}
...
...
@@ -174,118 +169,118 @@ 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
)
{
MaterialDTO
old
=
materialService
.
selectMaterialById
(
materialId
);
Integer
type
=
old
.
getMaterialType
();
if
(
type
==
null
)
{
return
""
;
}
String
wxEnterpriseId
=
old
.
getWxEnterpriseId
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
if
(
enterprise
==
null
)
{
return
""
;
}
String
url
=
""
;
String
oldUrl
=
""
;
QywxMediaTypeEnum
fileType
=
null
;
if
(
type
==
2
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
old
.
getImgUrl
();
}
if
(
type
==
4
)
{
fileType
=
QywxMediaTypeEnum
.
VIDEO
;
url
=
old
.
getLink
();
}
if
(
type
==
5
)
{
fileType
=
QywxMediaTypeEnum
.
FILE
;
url
=
old
.
getLink
();
@Override
public
String
reUpdalodMetail
(
String
materialId
)
{
MaterialDTO
old
=
materialService
.
selectMaterialById
(
materialId
);
Integer
type
=
old
.
getMaterialType
();
if
(
type
==
null
)
{
return
""
;
}
String
wxEnterpriseId
=
old
.
getWxEnterpriseId
();
WxEnterpriseDTO
enterprise
=
wxEnterpriseService
.
selectById
(
wxEnterpriseId
);
if
(
enterprise
==
null
)
{
return
""
;
}
String
url
=
""
;
String
oldUrl
=
""
;
QywxMediaTypeEnum
fileType
=
null
;
if
(
type
==
2
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
old
.
getImgUrl
();
}
if
(
type
==
4
)
{
fileType
=
QywxMediaTypeEnum
.
VIDEO
;
url
=
old
.
getLink
();
}
if
(
type
==
5
)
{
fileType
=
QywxMediaTypeEnum
.
FILE
;
url
=
old
.
getLink
();
}
else
if
(
type
==
6
)
{
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
url
=
old
.
getImgUrl
();
}
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
)
{
old
.
setWxLastUploadTime
(
new
Date
());
old
.
setMediaId
(
jp
.
getResult
().
toString
());
materialService
.
edit
(
old
);
}
return
old
.
getMediaId
();
}
int
count
=
arr
.
length
;
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
);
}
return
old
.
getMediaId
();
}
private
List
<
String
>
listSubCategoryIdsByParentId
(
String
categoryId
)
{
List
<
String
>
categoryIds
=
new
ArrayList
<>();
categoryIds
.
add
(
categoryId
);
if
(
StringUtils
.
isBlank
(
categoryId
))
{
return
categoryIds
;
}
List
<
MaterialCategoryDTO
>
categoryDTOList
=
materialCategoryService
.
listByParentCategory
(
categoryId
);
if
(
CollectionUtils
.
isEmpty
(
categoryDTOList
))
{
return
categoryIds
;
}
for
(
MaterialCategoryDTO
categoryDTO
:
categoryDTOList
)
{
categoryIds
.
addAll
(
this
.
listSubCategoryIdsByParentId
(
categoryDTO
.
getCategoryId
()));
}
return
categoryIds
;
}
private
List
<
String
>
listSubCategoryIdsByParentId
(
String
categoryId
)
{
List
<
String
>
categoryIds
=
new
ArrayList
<>();
categoryIds
.
add
(
categoryId
);
if
(
StringUtils
.
isBlank
(
categoryId
))
{
return
categoryIds
;
}
List
<
MaterialCategoryDTO
>
categoryDTOList
=
materialCategoryService
.
listByParentCategory
(
categoryId
);
if
(
CollectionUtils
.
isEmpty
(
categoryDTOList
))
{
return
categoryIds
;
}
for
(
MaterialCategoryDTO
categoryDTO
:
categoryDTOList
)
{
categoryIds
.
addAll
(
this
.
listSubCategoryIdsByParentId
(
categoryDTO
.
getCategoryId
()));
}
return
categoryIds
;
}
@Override
public
Page
<
MaterialDTO
>
listMaterial
(
String
wxEnterpriseId
,
String
keyword
,
String
categoryId
,
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
);
List
<
TabHaobanMaterial
>
result
=
page
.
getResult
();
@Override
public
Page
<
MaterialDTO
>
listMaterial
(
String
wxEnterpriseId
,
String
keyword
,
String
categoryId
,
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
);
List
<
TabHaobanMaterial
>
result
=
page
.
getResult
();
List
<
TabMiniprogramSetting
>
settings
=
miniprogramSettingService
.
listMiniprogram
(
wxEnterpriseId
);
if
(
CollectionUtils
.
isNotEmpty
(
result
)
&&
CollectionUtils
.
isNotEmpty
(
settings
))
{
Map
<
String
,
TabMiniprogramSetting
>
settingMap
=
settings
.
stream
().
collect
(
Collectors
.
toMap
(
dto
->
dto
.
getAppId
(),
dto
->
dto
));
...
...
@@ -294,73 +289,73 @@ public class MaterialApiServiceImpl implements MaterialApiService {
dto
.
setMaterialDesc
(
miniprogramSetting
==
null
?
"--"
:
miniprogramSetting
.
getMiniprogramName
());
});
}
return
PageUtil
.
changePageHelperToCurrentPage
(
page
,
MaterialDTO
.
class
);
}
public
static
void
main
(
String
[]
args
)
{
String
str
=
"https://other-1251519181.cos.ap-shanghai.myqcloud.com/haoban/20200518101933/【④好办-数据】(1)(1).xlsx"
;
int
count
=
str
.
split
(
"/"
).
length
;
System
.
err
.
println
(
str
.
split
(
"/"
)[
count
-
1
]);
}
private
static
byte
[]
getFileByte
(
String
url
)
{
try
{
InputStream
in
=
new
URL
(
url
).
openStream
();
byte
[]
data
=
IOUtils
.
toByteArray
(
in
);
return
data
;
}
catch
(
Exception
e
){
logger
.
info
(
"【异常】"
+
e
.
getMessage
(),
e
);
}
return
null
;
}
return
PageUtil
.
changePageHelperToCurrentPage
(
page
,
MaterialDTO
.
class
);
}
@Override
public
List
<
MaterialCategoryDTO
>
listByParentCategory
(
String
categoryId
)
{
return
materialCategoryService
.
listByParentCategory
(
categoryId
);
}
public
static
void
main
(
String
[]
args
)
{
String
str
=
"https://other-1251519181.cos.ap-shanghai.myqcloud.com/haoban/20200518101933/【④好办-数据】(1)(1).xlsx"
;
int
count
=
str
.
split
(
"/"
).
length
;
System
.
err
.
println
(
str
.
split
(
"/"
)[
count
-
1
]);
}
@Override
public
ServiceResponse
<
Void
>
shareMaterial
(
String
wxEnterpriseId
,
String
toWxEnterpriseId
,
String
materialId
)
{
ServiceResponse
<
Void
>
res
=
new
ServiceResponse
<>();
MaterialDTO
materialDTO
=
materialService
.
selectMaterialById
(
materialId
);
if
(
null
==
materialDTO
)
{
logger
.
info
(
"不存在该素材"
);
res
.
setCode
(
2
);
res
.
setMessage
(
"不存在该素材"
);
return
res
;
}
if
(!
materialDTO
.
getFromMaterialId
().
equals
(
"-1"
))
{
logger
.
info
(
"该素材不允许分享"
);
res
.
setCode
(
3
);
res
.
setMessage
(
"该素材不允许分享"
);
return
res
;
}
MaterialDTO
fromMaterialDTO
=
materialService
.
getMaterialByFromMaterialId
(
materialId
,
toWxEnterpriseId
);
if
(
fromMaterialDTO
!=
null
)
{
logger
.
info
(
"已经存在素材,不能重复分享"
);
res
.
setCode
(
4
);
res
.
setMessage
(
"已经存在素材,不能重复分享"
);
return
res
;
}
materialDTO
.
setWxEnterpriseId
(
toWxEnterpriseId
);
materialDTO
.
setFromMaterialId
(
materialId
);
materialDTO
.
setMediaId
(
null
);
materialDTO
.
setWxLastUploadTime
(
null
);
materialService
.
insertMaterial
(
materialDTO
);
return
res
;
}
private
static
byte
[]
getFileByte
(
String
url
)
{
@Override
public
List
<
MaterialDTO
>
listByFromMaterialId
(
String
materialId
)
{
List
<
MaterialDTO
>
materialDTOS
=
materialService
.
listMaterialByFromMateralId
(
materialId
);
return
materialDTOS
;
}
try
{
InputStream
in
=
new
URL
(
url
).
openStream
();
byte
[]
data
=
IOUtils
.
toByteArray
(
in
);
return
data
;
}
catch
(
Exception
e
)
{
logger
.
info
(
"【异常】"
+
e
.
getMessage
(),
e
);
}
return
null
;
}
@Override
public
void
delMaterial
(
List
<
String
>
ids
)
{
materialService
.
delmaterialByIds
(
ids
);
}
@Override
public
List
<
MaterialCategoryDTO
>
listByParentCategory
(
String
categoryId
)
{
return
materialCategoryService
.
listByParentCategory
(
categoryId
);
}
@Override
public
ServiceResponse
<
Void
>
shareMaterial
(
String
wxEnterpriseId
,
String
toWxEnterpriseId
,
String
materialId
)
{
ServiceResponse
<
Void
>
res
=
new
ServiceResponse
<>();
MaterialDTO
materialDTO
=
materialService
.
selectMaterialById
(
materialId
);
if
(
null
==
materialDTO
)
{
logger
.
info
(
"不存在该素材"
);
res
.
setCode
(
2
);
res
.
setMessage
(
"不存在该素材"
);
return
res
;
}
if
(!
materialDTO
.
getFromMaterialId
().
equals
(
"-1"
))
{
logger
.
info
(
"该素材不允许分享"
);
res
.
setCode
(
3
);
res
.
setMessage
(
"该素材不允许分享"
);
return
res
;
}
MaterialDTO
fromMaterialDTO
=
materialService
.
getMaterialByFromMaterialId
(
materialId
,
toWxEnterpriseId
);
if
(
fromMaterialDTO
!=
null
)
{
logger
.
info
(
"已经存在素材,不能重复分享"
);
res
.
setCode
(
4
);
res
.
setMessage
(
"已经存在素材,不能重复分享"
);
return
res
;
}
materialDTO
.
setWxEnterpriseId
(
toWxEnterpriseId
);
materialDTO
.
setFromMaterialId
(
materialId
);
materialDTO
.
setMediaId
(
null
);
materialDTO
.
setWxLastUploadTime
(
null
);
materialService
.
insertMaterial
(
materialDTO
);
return
res
;
}
@Override
public
List
<
MaterialDTO
>
listByFromMaterialId
(
String
materialId
)
{
List
<
MaterialDTO
>
materialDTOS
=
materialService
.
listMaterialByFromMateralId
(
materialId
);
return
materialDTOS
;
}
@Override
public
void
delMaterial
(
List
<
String
>
ids
)
{
materialService
.
delmaterialByIds
(
ids
);
}
@Override
public
MaterialDTO
getHasChangeMadieMaterialById
(
String
materialId
)
{
...
...
@@ -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,146 +5,177 @@ 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
{
@Autowired
private
MaterialApiService
materialApiService
;
/**
public
class
MaterialController
extends
WebBaseController
{
@Autowired
private
MaterialApiService
materialApiService
;
/**
* 素材分组新增
*
* @return
*/
@RequestMapping
(
"/mateial-add-category"
)
public
HaobanResponse
materialAddCategory
(
MaterialCategoryDTO
materialCategoryDTO
)
{
LoginDTO
login
=
(
LoginDTO
)
AuthRequestUtil
.
getLoginUser
();
String
wxEnterpriseId
=
login
.
getWxEnterpriseId
();
materialCategoryDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
String
categoryName
=
materialCategoryDTO
.
getCategoryName
();
String
categoryParentId
=
materialCategoryDTO
.
getCategoryParentId
();
if
(
StringUtils
.
isAnyBlank
(
categoryParentId
,
categoryName
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
null
);
if
(
flag
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10015
);
}
materialApiService
.
insertCategory
(
materialCategoryDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
materialCategoryDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
String
categoryName
=
materialCategoryDTO
.
getCategoryName
();
String
categoryParentId
=
materialCategoryDTO
.
getCategoryParentId
();
if
(
StringUtils
.
isAnyBlank
(
categoryParentId
,
categoryName
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
null
);
if
(
flag
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10015
);
}
materialApiService
.
insertCategory
(
materialCategoryDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
/**
* 素材分组查询
*
* @return
*/
@RequestMapping
(
"/category-list"
)
public
HaobanResponse
categoryList
(
String
wxEnterpriseId
)
{
List
<
MaterialCategoryDTO
>
list
=
materialApiService
.
listCategory
(
wxEnterpriseId
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
list
);
List
<
MaterialCategoryDTO
>
list
=
materialApiService
.
listCategory
(
wxEnterpriseId
);
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
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
MaterialCategoryDTO
dto
=
materialApiService
.
selectMaterialCategoryById
(
categoryId
);
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10016
);
}
String
categoryParentId
=
dto
.
getCategoryParentId
();
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
materialCategoryDTO
.
getCategoryId
());
if
(
flag
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10015
);
}
materialApiService
.
editCategory
(
materialCategoryDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
String
categoryName
=
materialCategoryDTO
.
getCategoryName
();
String
categoryId
=
materialCategoryDTO
.
getCategoryId
();
if
(
StringUtils
.
isAnyBlank
(
categoryName
,
categoryId
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
MaterialCategoryDTO
dto
=
materialApiService
.
selectMaterialCategoryById
(
categoryId
);
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10016
);
}
String
categoryParentId
=
dto
.
getCategoryParentId
();
boolean
flag
=
materialApiService
.
hasCategoryNameExsit
(
categoryName
,
categoryParentId
,
materialCategoryDTO
.
getCategoryId
());
if
(
flag
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10015
);
}
materialApiService
.
editCategory
(
materialCategoryDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
* 素材分组删除
*
* @return
*/
@RequestMapping
(
"/category-del"
)
public
HaobanResponse
categoryDel
(
String
categoryId
)
{
MaterialCategoryDTO
dto
=
materialApiService
.
selectMaterialCategoryById
(
categoryId
);
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10016
);
}
List
<
MaterialCategoryDTO
>
categoryList
=
materialApiService
.
listByParentCategory
(
categoryId
);
if
(
categoryList
!=
null
&&
!
categoryList
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10017
);
}
List
<
MaterialDTO
>
list
=
materialApiService
.
listMaterialByCategoryId
(
categoryId
);
if
(
list
!=
null
&&
!
list
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10017
);
}
dto
.
setStatusFlag
(
0
);
materialApiService
.
editCategory
(
dto
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
MaterialCategoryDTO
dto
=
materialApiService
.
selectMaterialCategoryById
(
categoryId
);
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10016
);
}
List
<
MaterialCategoryDTO
>
categoryList
=
materialApiService
.
listByParentCategory
(
categoryId
);
if
(
categoryList
!=
null
&&
!
categoryList
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10017
);
}
List
<
MaterialDTO
>
list
=
materialApiService
.
listMaterialByCategoryId
(
categoryId
);
if
(
list
!=
null
&&
!
list
.
isEmpty
())
{
return
resultResponse
(
HaoBanErrCode
.
ERR_10017
);
}
dto
.
setStatusFlag
(
0
);
materialApiService
.
editCategory
(
dto
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
* 素材新增
*
* @return
*/
@RequestMapping
(
"/material-add"
)
public
HaobanResponse
materialAdd
(
MaterialDTO
materialDTO
)
{
LoginDTO
login
=
(
LoginDTO
)
AuthRequestUtil
.
getLoginUser
();
String
wxEnterpriseId
=
login
.
getWxEnterpriseId
();
materialDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
StaffDTO
staff
=
login
.
getStaffDTO
();
materialDTO
.
setStaffId
(
staff
.
getStaffId
());
materialDTO
.
setStaffName
(
staff
.
getStaffName
());
String
materialTitle
=
materialDTO
.
getMaterialTitle
();
String
categoryId
=
materialDTO
.
getCategoryId
();
Integer
categoryType
=
materialDTO
.
getMaterialType
();
if
(
StringUtils
.
isAnyBlank
(
categoryId
,
materialTitle
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
if
(
categoryType
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
materialApiService
.
insertMaterial
(
materialDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
materialDTO
.
setWxEnterpriseId
(
wxEnterpriseId
);
StaffDTO
staff
=
login
.
getStaffDTO
();
materialDTO
.
setStaffId
(
staff
.
getStaffId
());
materialDTO
.
setStaffName
(
staff
.
getStaffName
());
String
materialTitle
=
materialDTO
.
getMaterialTitle
();
String
categoryId
=
materialDTO
.
getCategoryId
();
Integer
categoryType
=
materialDTO
.
getMaterialType
();
if
(
StringUtils
.
isAnyBlank
(
categoryId
,
materialTitle
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
if
(
categoryType
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
materialApiService
.
insertMaterial
(
materialDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
* 批量新增素材
*
* @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
);
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
dto
);
}
/**
* 素材修改
*
* @return
*/
@RequestMapping
(
"/material-edit"
)
...
...
@@ -152,67 +183,71 @@ public class MaterialController extends WebBaseController{
LoginDTO
login
=
(
LoginDTO
)
AuthRequestUtil
.
getLoginUser
();
StaffDTO
staff
=
login
.
getStaffDTO
();
materialDTO
.
setStaffId
(
staff
.
getStaffId
());
materialDTO
.
setStaffName
(
staff
.
getStaffName
());
String
materialId
=
materialDTO
.
getMaterialId
();
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
materialApiService
.
editMaterial
(
materialDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
materialDTO
.
setStaffId
(
staff
.
getStaffId
());
materialDTO
.
setStaffName
(
staff
.
getStaffName
());
String
materialId
=
materialDTO
.
getMaterialId
();
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
if
(
dto
==
null
)
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
materialApiService
.
editMaterial
(
materialDTO
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
* 素材删除
*
* @return
*/
@RequestMapping
(
"/material-del"
)
public
HaobanResponse
materialEdit
(
String
materialIds
)
{
if
(
StringUtils
.
isBlank
(
materialIds
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
String
[]
stringArr
=
materialIds
.
split
(
","
);
List
<
String
>
list
=
Arrays
.
asList
(
stringArr
);
materialApiService
.
delMaterial
(
list
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
if
(
StringUtils
.
isBlank
(
materialIds
))
{
return
resultResponse
(
HaoBanErrCode
.
ERR_2
);
}
String
[]
stringArr
=
materialIds
.
split
(
","
);
List
<
String
>
list
=
Arrays
.
asList
(
stringArr
);
materialApiService
.
delMaterial
(
list
);
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
* 素材查询
*
* @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
)
{
String
[]
stringArr
=
materialIds
.
split
(
","
);
for
(
String
materialId
:
stringArr
)
{
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
if
(
dto
==
null
){
continue
;
}
dto
.
setCategoryId
(
categoryId
);;
materialApiService
.
editMaterial
(
dto
);
}
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
public
HaobanResponse
materialBatch
(
String
materialIds
,
String
categoryId
)
{
String
[]
stringArr
=
materialIds
.
split
(
","
);
for
(
String
materialId
:
stringArr
)
{
MaterialDTO
dto
=
materialApiService
.
selectMaterialById
(
materialId
);
if
(
dto
==
null
)
{
continue
;
}
dto
.
setCategoryId
(
categoryId
);
;
materialApiService
.
editMaterial
(
dto
);
}
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
/**
* 分析素材
*
* @return
*/
@RequestMapping
(
"/material-share"
)
/**
* 分析素材
*
* @return
*/
@RequestMapping
(
"/material-share"
)
public
HaobanResponse
materialShare
(
String
materialIds
,
String
toWxEnterpriseIds
)
{
LoginDTO
login
=
(
LoginDTO
)
AuthRequestUtil
.
getLoginUser
();
String
[]
wxEids
=
toWxEnterpriseIds
.
split
(
","
);
...
...
@@ -227,7 +262,7 @@ public class MaterialController extends WebBaseController{
return
resultResponse
(
HaoBanErrCode
.
ERR_DEFINE
);
}
}
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
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