Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
youjj
cloud-platform
Commits
47b235e5
Commit
47b235e5
authored
May 13, 2019
by
周健威
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
6696dbab
300f55c0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
485 additions
and
0 deletions
+485
-0
CampsiteBiz.java
...va/com/xinxincaravan/caravan/vehicle/biz/CampsiteBiz.java
+183
-0
RedisKey.java
.../com/xinxincaravan/caravan/vehicle/constant/RedisKey.java
+15
-0
Campsite.java
...va/com/xinxincaravan/caravan/vehicle/entity/Campsite.java
+92
-0
CampsiteMapper.java
.../xinxincaravan/caravan/vehicle/mapper/CampsiteMapper.java
+8
-0
CampsiteController.java
...inxincaravan/caravan/vehicle/rest/CampsiteController.java
+86
-0
CampsiteVo.java
...java/com/xinxincaravan/caravan/vehicle/vo/CampsiteVo.java
+81
-0
CampsiteMapper.xml
vehicle/src/main/resources/mapper/CampsiteMapper.xml
+20
-0
No files found.
vehicle/src/main/java/com/xinxincaravan/caravan/vehicle/biz/CampsiteBiz.java
0 → 100644
View file @
47b235e5
package
com
.
xinxincaravan
.
caravan
.
vehicle
.
biz
;
import
com.ace.cache.annotation.Cache
;
import
com.ace.cache.annotation.CacheClear
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.google.common.collect.Lists
;
import
com.xinxincaravan.caravan.vehicle.common.RestResponse
;
import
com.xinxincaravan.caravan.vehicle.constant.RedisKey
;
import
com.xinxincaravan.caravan.vehicle.entity.Campsite
;
import
com.xinxincaravan.caravan.vehicle.feign.dto.UserDTO
;
import
com.xinxincaravan.caravan.vehicle.mapper.CampsiteMapper
;
import
com.xinxincaravan.caravan.vehicle.vo.CampsiteVo
;
import
com.xinxincaravan.caravan.vehicle.vo.PageDataVo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.joda.time.DateTime
;
import
org.joda.time.format.DateTimeFormat
;
import
org.joda.time.format.DateTimeFormatter
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
tk.mybatis.mapper.entity.Example
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
static
com
.
github
.
wxiaoqi
.
security
.
auth
.
common
.
constatns
.
CommonConstants
.
DATA_ALL_FALSE
;
import
static
com
.
xinxincaravan
.
caravan
.
vehicle
.
constant
.
DbColumnConstant
.
COMPANY_ZONE_ID
;
import
static
com
.
xinxincaravan
.
caravan
.
vehicle
.
constant
.
DbColumnConstant
.
ID
;
import
static
com
.
xinxincaravan
.
caravan
.
vehicle
.
constant
.
RedisKey
.
CAMPSITE_CACHE_DATAZONE
;
@Service
@Slf4j
public
class
CampsiteBiz
extends
BaseBiz
<
CampsiteMapper
,
Campsite
>
{
public
static
final
DateTimeFormatter
DEFAULT_DATE_TIME_FORMATTER
=
DateTimeFormat
.
forPattern
(
"yyyy-MM-dd"
);
public
static
final
DateTimeFormatter
YEARMONTH_DATE_TIME_FORMATTER
=
DateTimeFormat
.
forPattern
(
"yyyy-MM"
);
@Autowired
private
RedisTemplate
customRedisTemplate
;
@Value
(
"${campsitePic.baseUploadPath}"
)
private
String
baseUploadPath
;
/**
* 按主键获取公司
* @param id
* @return
*/
public
Campsite
getById
(
Integer
id
){
return
mapper
.
selectByPrimaryKey
(
id
);
}
public
Boolean
exits
(
Integer
id
){
Campsite
param
=
new
Campsite
();
param
.
setId
(
id
);
return
mapper
.
selectCount
(
param
)>
0
;
}
/**
* 转换为vo类
* @param campsites
* @returns
*/
private
List
<
CampsiteVo
>
branchCompany2VO
(
List
<
Campsite
>
campsites
){
List
<
CampsiteVo
>
campsiteVoList
=
Lists
.
newArrayList
();
if
(
CollectionUtils
.
isNotEmpty
(
campsites
)){
for
(
Campsite
campsite:
campsites
){
CampsiteVo
campsiteVo
=
new
CampsiteVo
();
BeanUtils
.
copyProperties
(
campsite
,
campsiteVo
);
campsiteVoList
.
add
(
campsiteVo
);
}
}
return
campsiteVoList
;
}
public
PageDataVo
<
Campsite
>
getAll
(
Integer
page
,
Integer
limit
,
Integer
addrProvince
,
Integer
addrCity
,
Integer
addrTown
,
UserDTO
userDTO
){
Example
example
=
new
Example
(
Campsite
.
class
);
Example
.
Criteria
criteria
=
example
.
createCriteria
();
if
(
addrProvince
!=
null
)
{
criteria
.
andCondition
(
" addr_province = '"
+
addrProvince
+
"'"
);
}
if
(
addrCity
!=
null
)
{
criteria
.
andCondition
(
" addr_city = '"
+
addrCity
+
"'"
);
}
if
(
addrTown
!=
null
)
{
criteria
.
andCondition
(
" addr_town = '"
+
addrTown
+
"'"
);
}
if
(
DATA_ALL_FALSE
.
equals
(
userDTO
.
getDataAll
()))
{
if
(
StringUtils
.
isNotBlank
(
userDTO
.
getDataZone
()))
{
criteria
.
andIn
(
COMPANY_ZONE_ID
,
userDTO
.
dataZone2List
());
}
if
(
StringUtils
.
isNotBlank
(
userDTO
.
getDataCompany
()))
{
criteria
.
andIn
(
ID
,
userDTO
.
dataCompany2List
());
}
}
example
.
setOrderByClause
(
"`id` asc"
);
PageHelper
.
startPage
(
page
,
limit
);
PageInfo
<
Campsite
>
campsitePageInfo
=
new
PageInfo
<>(
mapper
.
selectByExample
(
example
));
return
PageDataVo
.
pageInfo
(
campsitePageInfo
);
}
@Cache
(
key
=
RedisKey
.
CAMPSITE_CACHE_ALL
)
public
List
<
Campsite
>
getAll
(){
return
mapper
.
selectAll
();
}
/**
* 增加公司,返回id
* @param campsiteVo
* @return
*/
@CacheClear
(
key
=
RedisKey
.
CAMPSITE_CACHE
)
public
Integer
add
(
CampsiteVo
campsiteVo
){
Campsite
campsite
=
new
Campsite
();
BeanUtils
.
copyProperties
(
campsiteVo
,
campsite
);
mapper
.
insertSelective
(
campsite
);
return
campsite
.
getId
();
}
@CacheClear
(
key
=
RedisKey
.
CAMPSITE_CACHE
)
public
void
del
(
Integer
id
){
mapper
.
deleteByPrimaryKey
(
id
);
}
/**
* 更新公司信息
* @param campsite
* @return
*/
@CacheClear
(
key
=
RedisKey
.
CAMPSITE_CACHE
)
public
Integer
update
(
Campsite
campsite
){
return
mapper
.
updateByPrimaryKeySelective
(
campsite
);
}
/**
* 写入上传文件,返回相对路径
* @param file
* @return
*/
public
RestResponse
<
String
>
uploadCompanyPic
(
MultipartFile
file
)
throws
Exception
{
//创建本日存放目录
DateTime
now
=
DateTime
.
now
();
String
dirPathToday
=
File
.
separator
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
String
redisNoKey
=
RedisKey
.
UPLOAD_FILE_NO_PREFIX
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
Long
no
=
customRedisTemplate
.
opsForValue
().
increment
(
redisNoKey
);
if
(
no
.
equals
(
1
l
)){
customRedisTemplate
.
expire
(
redisNoKey
,
1
,
TimeUnit
.
DAYS
);
}
String
fileName
=
file
.
getOriginalFilename
();
String
realFileRelPath
=
dirPathToday
+
File
.
separator
+
no
+
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
//文件存放路径
String
filePath
=
baseUploadPath
+
realFileRelPath
;
//将文件写入指定位置
FileUtils
.
copyInputStreamToFile
(
file
.
getInputStream
(),
new
File
(
filePath
));
return
RestResponse
.
suc
(
realFileRelPath
);
}
@Cache
(
key
=
CAMPSITE_CACHE_DATAZONE
)
public
List
<
Campsite
>
dataCompany
(
String
dataZone
)
{
if
(
StringUtils
.
isBlank
(
dataZone
))
{
return
new
ArrayList
<
Campsite
>();
}
List
<
Integer
>
zoneIds
=
Arrays
.
asList
(
dataZone
.
split
(
","
)).
parallelStream
().
map
(
s
->
Integer
.
valueOf
(
s
)).
collect
(
Collectors
.
toList
());
Example
example
=
new
Example
(
Campsite
.
class
);
example
.
createCriteria
().
andIn
(
"zoneId"
,
zoneIds
);
List
<
Campsite
>
zoneCompanys
=
selectByExample
(
example
);
return
zoneCompanys
;
}
}
vehicle/src/main/java/com/xinxincaravan/caravan/vehicle/constant/RedisKey.java
View file @
47b235e5
...
...
@@ -51,6 +51,21 @@ public class RedisKey {
*/
public
static
final
String
BRANCH_COMPANY_CACHE_DATAZONE
=
BRANCH_COMPANY_CACHE
+
":dataZone{1}"
;
/**
* 营地列表缓存key前缀
*/
public
static
final
String
CAMPSITE_CACHE
=
"cache:campsite"
;
/**
* 营地列表缓存key前缀
*/
public
static
final
String
CAMPSITE_CACHE_ALL
=
CAMPSITE_CACHE
+
":all"
;
/**
* 片区对应的营地缓存key前缀
*/
public
static
final
String
CAMPSITE_CACHE_DATAZONE
=
CAMPSITE_CACHE
+
":dataZone{1}"
;
// 随车物品相关key
public
static
final
String
ACCOMPANYING_ITEM_CACHE_ALL
=
"cache:accompanyItem:all"
;
...
...
vehicle/src/main/java/com/xinxincaravan/caravan/vehicle/entity/Campsite.java
0 → 100644
View file @
47b235e5
package
com
.
xinxincaravan
.
caravan
.
vehicle
.
entity
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.math.BigDecimal
;
import
java.util.Date
;
@Table
(
name
=
"campsite"
)
@Data
public
class
Campsite
{
@Id
@GeneratedValue
(
generator
=
"JDBC"
)
private
Integer
id
;
/**
* 分公司名称
*/
private
String
name
;
/**
* 分支机构类型
*/
@Column
(
name
=
"branch_type"
)
private
Integer
branchType
;
/**
* 分支机构所属机构
*/
@Column
(
name
=
"subordinate_branch"
)
private
Integer
subordinateBranch
;
/**
* 地址-省/直辖市(编码)
*/
@Column
(
name
=
"addr_province"
)
private
Integer
addrProvince
;
/**
* 地址-市(编码)
*/
@Column
(
name
=
"addr_city"
)
private
Integer
addrCity
;
/**
* 地址-镇/县(编码)
*/
@Column
(
name
=
"addr_town"
)
private
Integer
addrTown
;
/**
* 详细地址
*/
@Column
(
name
=
"addr_detail"
)
private
String
addrDetail
;
private
Date
createTime
;
private
Date
updateTime
;
/**
* 负责人
*/
private
String
leader
;
/**
* 负责人联系方式
*/
private
String
leaderContactInfo
;
/**
* 分公司状态
*/
private
Integer
status
;
/**
*公司地址-纬度
*/
private
BigDecimal
latitude
;
/**
* 公司地址-经度
*/
private
BigDecimal
longitude
;
private
String
companyPic
;
private
Integer
zoneId
;
}
\ No newline at end of file
vehicle/src/main/java/com/xinxincaravan/caravan/vehicle/mapper/CampsiteMapper.java
0 → 100644
View file @
47b235e5
package
com
.
xinxincaravan
.
caravan
.
vehicle
.
mapper
;
import
com.xinxincaravan.caravan.vehicle.entity.Campsite
;
import
tk.mybatis.mapper.common.Mapper
;
public
interface
CampsiteMapper
extends
Mapper
<
Campsite
>
{
}
\ No newline at end of file
vehicle/src/main/java/com/xinxincaravan/caravan/vehicle/rest/CampsiteController.java
0 → 100644
View file @
47b235e5
package
com
.
xinxincaravan
.
caravan
.
vehicle
.
rest
;
import
com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken
;
import
com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken
;
import
com.github.wxiaoqi.security.auth.client.config.UserAuthConfig
;
import
com.xinxincaravan.caravan.vehicle.biz.CampsiteBiz
;
import
com.xinxincaravan.caravan.vehicle.common.BaseController
;
import
com.xinxincaravan.caravan.vehicle.common.RestResponse
;
import
com.xinxincaravan.caravan.vehicle.constant.ResCode.ResCode
;
import
com.xinxincaravan.caravan.vehicle.entity.Campsite
;
import
com.xinxincaravan.caravan.vehicle.feign.UserFeign
;
import
com.xinxincaravan.caravan.vehicle.feign.dto.UserDTO
;
import
com.xinxincaravan.caravan.vehicle.vo.CampsiteVo
;
import
com.xinxincaravan.caravan.vehicle.vo.PageDataVo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/campsite"
)
@Slf4j
@IgnoreClientToken
public
class
CampsiteController
extends
BaseController
<
CampsiteBiz
>
{
private
static
Integer
MAX_DRIVING_LICENSE_SIZE
=
10
*
1024
*
1024
;
//10M
@Autowired
UserFeign
userFeign
;
@Autowired
private
UserAuthConfig
userAuthConfig
;
@IgnoreUserToken
@RequestMapping
(
value
=
"/page"
,
method
=
RequestMethod
.
GET
)
public
RestResponse
<
PageDataVo
<
Campsite
>>
page
(
@RequestParam
Integer
page
,
@RequestParam
Integer
limit
,
@RequestParam
(
required
=
false
)
Integer
addrProvince
,
@RequestParam
(
required
=
false
)
Integer
addrCity
,
@RequestParam
(
required
=
false
)
Integer
addrTown
)
{
UserDTO
userDTO
=
userFeign
.
userinfoByToken
(
userAuthConfig
.
getToken
(
request
)).
getData
();
return
RestResponse
.
data
(
baseBiz
.
getAll
(
page
,
limit
,
addrProvince
,
addrCity
,
addrTown
,
userDTO
));
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
)
public
RestResponse
<
List
<
Campsite
>>
getAll
()
{
return
RestResponse
.
data
(
baseBiz
.
getAll
());
}
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
public
RestResponse
<
Campsite
>
get
(
@PathVariable
Integer
id
)
{
return
RestResponse
.
data
(
baseBiz
.
getById
(
id
));
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
)
public
RestResponse
<
Integer
>
add
(
@RequestBody
CampsiteVo
campsiteVo
)
{
return
RestResponse
.
data
(
baseBiz
.
add
(
campsiteVo
));
}
@RequestMapping
(
value
=
"/upload/companyPic"
,
method
=
RequestMethod
.
POST
)
public
RestResponse
uploadCompanyPic
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
Exception
{
String
contentType
=
file
.
getContentType
();
//图片文件类型
// String fileName = file.getOriginalFilename(); //图片名字
if
(!
contentType
.
equals
(
"image/jpeg"
)
&&
!
contentType
.
equals
(
"image/gif"
)){
return
RestResponse
.
code
(
ResCode
.
INVALID_REST_REQ_PARAM
.
getCode
());
}
if
(
file
.
getSize
()
>
MAX_DRIVING_LICENSE_SIZE
){
return
RestResponse
.
code
(
ResCode
.
INVALID_REST_REQ_PARAM
.
getCode
());
}
return
baseBiz
.
uploadCompanyPic
(
file
);
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
PUT
)
public
RestResponse
update
(
@RequestBody
Campsite
campsite
)
{
baseBiz
.
update
(
campsite
);
return
RestResponse
.
sucResponse
();
}
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
DELETE
)
public
RestResponse
del
(
@PathVariable
Integer
id
)
{
baseBiz
.
del
(
id
);
return
RestResponse
.
sucResponse
();
}
}
vehicle/src/main/java/com/xinxincaravan/caravan/vehicle/vo/CampsiteVo.java
0 → 100644
View file @
47b235e5
package
com
.
xinxincaravan
.
caravan
.
vehicle
.
vo
;
import
lombok.Data
;
import
java.math.BigDecimal
;
@Data
public
class
CampsiteVo
{
/**
* 分公司名称
*/
private
String
name
;
/**
* 分支机构类型
*/
private
Integer
branchType
;
/**
* 分支机构所属机构
*/
private
Integer
subordinateBranch
;
/**
* 分支机构地址:经纬度
*/
private
String
location
;
/**
* 地址-省/直辖市(编码)
*/
private
Integer
addrProvince
;
/**
* 地址-市(编码)
*/
private
Integer
addrCity
;
/**
* 地址-镇/县(编码)
*/
private
Integer
addrTown
;
/**
* 详细地址
*/
private
String
addrDetail
;
/**
* 负责人
*/
private
String
leader
;
/**
* 负责人联系方式
*/
private
String
leaderContactInfo
;
/**
* 分公司状态
*/
private
Integer
status
;
private
String
companyPic
;
/**
*公司地址-纬度
*/
private
BigDecimal
latitude
;
/**
* 公司地址-经度
*/
private
BigDecimal
longitude
;
/**
* 片区Id
*/
private
Integer
zoneId
;
}
\ No newline at end of file
vehicle/src/main/resources/mapper/CampsiteMapper.xml
0 → 100644
View file @
47b235e5
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"com.xinxincaravan.caravan.vehicle.mapper.CampsiteMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.xinxincaravan.caravan.vehicle.entity.Campsite"
>
<!--
WARNING - @mbg.generated
-->
<id
column=
"id"
property=
"id"
jdbcType=
"INTEGER"
/>
<result
column=
"name"
property=
"name"
jdbcType=
"VARCHAR"
/>
<result
column=
"branch_type"
property=
"branchType"
jdbcType=
"INTEGER"
/>
<result
column=
"subordinate_branch"
property=
"subordinateBranch"
jdbcType=
"INTEGER"
/>
<result
column=
"location"
property=
"location"
jdbcType=
"VARCHAR"
/>
<result
column=
"addr_province"
property=
"addrProvince"
jdbcType=
"INTEGER"
/>
<result
column=
"addr_city"
property=
"addrCity"
jdbcType=
"INTEGER"
/>
<result
column=
"addr_town"
property=
"addrTown"
jdbcType=
"INTEGER"
/>
<result
column=
"addr_detail"
property=
"addrDetail"
jdbcType=
"VARCHAR"
/>
<result
column=
"create_time"
property=
"createTime"
jdbcType=
"TIMESTAMP"
/>
<result
column=
"update_time"
property=
"updateTime"
jdbcType=
"TIMESTAMP"
/>
</resultMap>
</mapper>
\ No newline at end of file
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