Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8131f888
authored
May 17, 2023
by
丁伟峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
容量按天查询
1 parent
6a176e90
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
482 additions
and
182 deletions
project-order/src/main/java/com/alibaba/cloud/integration/order/controller/OrderController.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dao/CapacityTeamStatDao.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/CalendarDTO.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/LegendDTO.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/LocationDTO.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/OrderCreateReqDTO.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/TimeDTO.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/TimeRangeReqDTO.java
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/TimeRangeRespDTO.java
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/CapacityTeamStatEntity.java
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/LayerInfoEntity.java
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/Order.java
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/OrderRequestEntity.java
project-order/src/main/java/com/alibaba/cloud/integration/order/mapper/OrderMapper.java
project-order/src/main/java/com/alibaba/cloud/integration/order/service/OrderService.java
project-order/src/main/java/com/alibaba/cloud/integration/order/service/TimeRangeService.java
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/OrderServiceImpl.java
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/ProductServiceImpl.java
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/TimeRangeServiceImpl.java
project-order/src/main/java/com/alibaba/cloud/integration/order/controller/OrderController.java
View file @
8131f88
...
...
@@ -18,10 +18,14 @@ package com.alibaba.cloud.integration.order.controller;
import
com.alibaba.cloud.integration.common.BusinessException
;
import
com.alibaba.cloud.integration.common.Result
;
import
com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO
;
import
com.alibaba.cloud.integration.order.dto.TimeRangeReqDTO
;
import
com.alibaba.cloud.integration.order.service.OrderService
;
import
com.alibaba.cloud.integration.order.service.ProductService
;
import
com.alibaba.cloud.integration.order.service.TimeRangeService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
/**
...
...
@@ -31,35 +35,45 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping
(
"/order"
)
public
class
OrderController
{
@Autowired
private
OrderService
orderService
;
@Autowired
private
OrderService
orderService
;
@Autowired
private
ProductService
productService
;
@Autowired
private
ProductService
productService
;
@PostMapping
(
"/create"
)
public
Result
<?>
createOrder
(
@RequestParam
(
"userId"
)
String
userId
,
@RequestParam
(
"commodityCode"
)
String
commodityCode
,
@RequestParam
(
"count"
)
Integer
count
)
{
Result
<?>
res
=
null
;
try
{
res
=
orderService
.
createOrder
(
userId
,
commodityCode
,
count
);
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
return
res
;
}
@Autowired
private
TimeRangeService
timeRangeService
;
@GetMapping
(
"/service/parameter"
)
public
Result
<?>
getParameter
(){
Result
<?>
res
=
null
;
try
{
res
=
productService
.
getProductCategoryList
();
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
return
res
;
}
@PostMapping
(
"/service/create"
)
public
Result
<?>
createOrder
(
@Validated
@RequestBody
OrderCreateReqDTO
orderCreateReqDTO
)
{
Result
<?>
res
=
null
;
try
{
res
=
orderService
.
createOrder
(
orderCreateReqDTO
);
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
return
res
;
}
@GetMapping
(
"/service/parameter"
)
public
Result
<?>
getParameter
()
{
Result
<?>
res
=
null
;
try
{
res
=
productService
.
getProductCategoryList
();
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
return
res
;
}
@PostMapping
(
"/service/timerange"
)
public
Result
<?>
getTimerange
(
@Validated
@RequestBody
TimeRangeReqDTO
timeRangeReqDTO
)
{
Result
<?>
res
=
null
;
try
{
res
=
timeRangeService
.
getTimeRangeData
(
timeRangeReqDTO
);
}
catch
(
BusinessException
e
)
{
return
Result
.
failed
(
e
.
getMessage
());
}
return
res
;
}
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dao/CapacityTeamStatDao.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dao
;
import
com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
java.util.List
;
public
interface
CapacityTeamStatDao
extends
JpaRepository
<
CapacityTeamStatEntity
,
Long
>
{
List
<
CapacityTeamStatEntity
>
findAllByTeamIdAndSkillTagAndWorkdayBetween
(
String
teamId
,
String
skill
,
String
beginDate
,
String
endDate
);
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/CalendarDTO.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dto
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.util.List
;
@Data
@Accessors
(
chain
=
true
)
public
class
CalendarDTO
{
private
String
week
;
private
String
date
;
private
List
<
TimeDTO
>
times
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/LegendDTO.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dto
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
@Data
@Accessors
(
chain
=
true
)
public
class
LegendDTO
{
private
int
type
;
private
String
memo
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/LocationDTO.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dto
;
import
lombok.Data
;
@Data
public
class
LocationDTO
{
private
String
address
;
private
String
country
;
private
String
province
;
private
String
citycode
;
private
String
city
;
private
String
district
;
private
String
adcode
;
private
String
street
;
private
String
number
;
private
String
location
;
private
String
level
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/OrderCreateReqDTO.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dto
;
import
lombok.Data
;
@Data
public
class
OrderCreateReqDTO
{
private
String
name
;
private
String
phone
;
private
String
address
;
private
LocationDTO
location
;
private
String
brand
;
private
String
catalogId
;
private
String
faultDescribe
;
private
String
expectBegin
;
private
String
expectEnd
;
private
String
priority
;
private
String
orderTags
;
private
String
memo
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/TimeDTO.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dto
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
@Data
@Accessors
(
chain
=
true
)
public
class
TimeDTO
{
private
String
text
;
private
String
begin
;
private
String
end
;
private
int
type
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/TimeRangeReqDTO.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dto
;
import
lombok.Data
;
@Data
public
class
TimeRangeReqDTO
{
private
String
location
;
private
String
categoryId
;
private
String
beginDate
;
private
String
endDate
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/dto/TimeRangeRespDTO.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
dto
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.util.List
;
@Data
@Accessors
(
chain
=
true
)
public
class
TimeRangeRespDTO
{
private
String
beginDate
;
private
String
endDate
;
private
List
<
LegendDTO
>
legend
;
private
List
<
CalendarDTO
>
calendar
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/CapacityTeamStatEntity.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
entity
;
import
lombok.Data
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @description 容量-工作队时间段容量
* @author zhengkai.blog.csdn.net
* @date 2023-05-15
*/
@Entity
@Data
public
class
CapacityTeamStatEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Integer
id
;
private
String
workday
;
private
String
timeSpan
;
private
String
timeSpanDetail
;
private
String
teamId
;
private
String
skillTag
;
private
Integer
engineerCount
;
private
Integer
capTotal
;
private
Integer
capAdd
;
private
Integer
capUsed
;
private
Integer
capUsedTravel
;
private
Integer
capLeft
;
private
Integer
orderCount
;
private
String
memo
;
private
Date
createTime
;
private
Date
updateTime
;
}
\ No newline at end of file
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/LayerInfoEntity.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
entity
;
import
lombok.Data
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
java.io.Serializable
;
import
java.util.Date
;
@Data
@Entity
public
class
LayerInfoEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Integer
id
;
private
String
layerId
;
private
String
layerName
;
private
String
subsectionId
;
private
String
groupId
;
private
String
cityCode
;
private
String
areaDta
;
private
Integer
kind
;
private
String
teamId
;
private
String
tags
;
private
Integer
status
;
private
String
memo
;
private
Date
createTime
;
private
Date
updateTime
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/Order.java
deleted
100644 → 0
View file @
6a176e9
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
alibaba
.
cloud
.
integration
.
order
.
entity
;
import
java.sql.Timestamp
;
/**
* @author TrevorLink
*/
public
class
Order
{
private
Integer
id
;
private
String
userId
;
private
String
commodityCode
;
private
Integer
count
;
private
Integer
money
;
private
Timestamp
createTime
;
private
Timestamp
updateTime
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
String
getCommodityCode
()
{
return
commodityCode
;
}
public
void
setCommodityCode
(
String
commodityCode
)
{
this
.
commodityCode
=
commodityCode
;
}
public
Integer
getCount
()
{
return
count
;
}
public
void
setCount
(
Integer
count
)
{
this
.
count
=
count
;
}
public
Integer
getMoney
()
{
return
money
;
}
public
void
setMoney
(
Integer
money
)
{
this
.
money
=
money
;
}
public
Timestamp
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Timestamp
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Timestamp
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Timestamp
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
@Override
public
String
toString
()
{
return
"Order{"
+
"id="
+
id
+
", userId='"
+
userId
+
'\''
+
", commodityCode='"
+
commodityCode
+
'\''
+
", count="
+
count
+
", money="
+
money
+
", createTime="
+
createTime
+
", updateTime="
+
updateTime
+
'}'
;
}
}
project-order/src/main/java/com/alibaba/cloud/integration/order/entity/OrderRequestEntity.java
0 → 100644
View file @
8131f88
/*
* Copyright 2013-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
alibaba
.
cloud
.
integration
.
order
.
entity
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
java.io.Serializable
;
@Entity
public
class
OrderRequestEntity
implements
Serializable
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Integer
id
;
private
String
orderId
;
private
String
name
;
private
String
phone
;
private
String
address
;
private
String
x
;
private
String
y
;
private
String
province
;
private
String
city
;
private
String
county
;
private
String
categoryId
;
private
String
brand
;
private
String
type
;
private
String
skill
;
private
String
applyNote
;
private
String
faultDescribe
;
private
String
expectTimeBegin
;
private
String
expectTimeEnd
;
private
String
expectTimeDesc
;
private
String
source
;
private
String
priority
;
private
String
areaId
;
private
String
orderTags
;
private
String
tags
;
private
String
status
;
private
String
appointmentStatus
;
private
String
appointmentMethod
;
private
String
orgClusterId
;
private
String
orgClusterName
;
private
String
orgBranchId
;
private
String
orgBranchName
;
private
String
orgGroupId
;
private
String
orgGroupName
;
private
String
orgTeamId
;
private
String
orgTeamName
;
private
String
description
;
private
String
createTime
;
private
String
updateTime
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/mapper/OrderMapper.java
View file @
8131f88
...
...
@@ -16,7 +16,7 @@
package
com
.
alibaba
.
cloud
.
integration
.
order
.
mapper
;
import
com.alibaba.cloud.integration.order.entity.Order
;
import
com.alibaba.cloud.integration.order.entity.Order
RequestEntity
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Options
;
...
...
@@ -32,6 +32,6 @@ public interface OrderMapper {
@Insert
(
"INSERT INTO `order` (user_id, commodity_code,money,create_time,update_time) VALUES (#{userId}, #{commodityCode},#{money},#{createTime},#{updateTime})"
)
@Options
(
useGeneratedKeys
=
true
,
keyColumn
=
"id"
,
keyProperty
=
"id"
)
int
saveOrder
(
Order
order
);
int
saveOrder
(
Order
RequestEntity
orderRequestEntity
);
}
project-order/src/main/java/com/alibaba/cloud/integration/order/service/OrderService.java
View file @
8131f88
...
...
@@ -18,13 +18,14 @@ package com.alibaba.cloud.integration.order.service;
import
com.alibaba.cloud.integration.common.BusinessException
;
import
com.alibaba.cloud.integration.common.Result
;
import
com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO
;
/**
* @author TrevorLink
*/
public
interface
OrderService
{
Result
<?>
createOrder
(
String
userId
,
String
commodityCode
,
Integer
count
)
Result
<?>
createOrder
(
OrderCreateReqDTO
orderCreateReqDTO
)
throws
BusinessException
;
}
project-order/src/main/java/com/alibaba/cloud/integration/order/service/TimeRangeService.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
service
;
import
com.alibaba.cloud.integration.common.Result
;
import
com.alibaba.cloud.integration.order.dto.TimeRangeReqDTO
;
public
interface
TimeRangeService
{
Result
<?>
getTimeRangeData
(
TimeRangeReqDTO
timeRangeReqDTO
);
}
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/OrderServiceImpl.java
View file @
8131f88
...
...
@@ -16,35 +16,23 @@
package
com
.
alibaba
.
cloud
.
integration
.
order
.
service
.
impl
;
import
java.sql.Timestamp
;
import
com.alibaba.cloud.integration.common.BusinessException
;
import
com.alibaba.cloud.integration.common.Result
;
import
com.alibaba.cloud.integration.order.
entity.Order
;
import
com.alibaba.cloud.integration.order.
dto.OrderCreateReqDTO
;
import
com.alibaba.cloud.integration.order.feign.AccountServiceFeignClient
;
import
com.alibaba.cloud.integration.order.feign.StorageServiceFeignClient
;
import
com.alibaba.cloud.integration.order.feign.dto.AccountDTO
;
import
com.alibaba.cloud.integration.order.feign.dto.StorageDTO
;
import
com.alibaba.cloud.integration.order.mapper.OrderMapper
;
import
com.alibaba.cloud.integration.order.service.OrderService
;
import
io.seata.core.context.RootContext
;
import
io.seata.spring.annotation.GlobalTransactional
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
static
com
.
alibaba
.
cloud
.
integration
.
common
.
ResultEnum
.
COMMON_FAILED
;
/**
* @author TrevorLink
*/
@Slf4j
@Service
public
class
OrderServiceImpl
implements
OrderService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Autowired
private
OrderMapper
orderMapper
;
...
...
@@ -56,41 +44,11 @@ public class OrderServiceImpl implements OrderService {
@Override
@GlobalTransactional
public
Result
<?>
createOrder
(
String
userId
,
String
commodityCode
,
Integer
count
)
{
logger
.
info
(
"[createOrder] current XID: {}"
,
RootContext
.
getXID
());
// deduct storage
StorageDTO
storageDTO
=
new
StorageDTO
();
storageDTO
.
setCommodityCode
(
commodityCode
);
storageDTO
.
setCount
(
count
);
Integer
storageCode
=
storageService
.
reduceStock
(
storageDTO
).
getCode
();
if
(
storageCode
.
equals
(
COMMON_FAILED
.
getCode
()))
{
throw
new
BusinessException
(
"stock not enough"
);
}
// deduct balance
int
price
=
count
*
2
;
AccountDTO
accountDTO
=
new
AccountDTO
();
accountDTO
.
setUserId
(
userId
);
accountDTO
.
setPrice
(
price
);
Integer
accountCode
=
accountService
.
reduceBalance
(
accountDTO
).
getCode
();
if
(
accountCode
.
equals
(
COMMON_FAILED
.
getCode
()))
{
throw
new
BusinessException
(
"balance not enough"
);
}
public
Result
<?>
createOrder
(
OrderCreateReqDTO
orderCreateReqDTO
)
{
// save order
Order
order
=
new
Order
();
order
.
setUserId
(
userId
);
order
.
setCommodityCode
(
commodityCode
);
order
.
setCount
(
count
);
order
.
setMoney
(
price
);
order
.
setCreateTime
(
new
Timestamp
(
System
.
currentTimeMillis
()));
order
.
setUpdateTime
(
new
Timestamp
(
System
.
currentTimeMillis
()));
orderMapper
.
saveOrder
(
order
);
logger
.
info
(
"[createOrder] orderId: {}"
,
order
.
getId
());
log
.
info
(
"[createOrder] current XID: {}"
,
RootContext
.
getXID
());
return
Result
.
success
(
order
)
;
return
null
;
}
}
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/ProductServiceImpl.java
View file @
8131f88
...
...
@@ -7,6 +7,7 @@ import com.alibaba.cloud.integration.order.dto.KeyValueDTO;
import
com.alibaba.cloud.integration.order.dto.ParameterRespDTO
;
import
com.alibaba.cloud.integration.order.entity.ProductCategoryEntity
;
import
com.alibaba.cloud.integration.order.service.ProductService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -16,6 +17,7 @@ import java.util.List;
import
java.util.Map
;
@Service
@Slf4j
public
class
ProductServiceImpl
implements
ProductService
{
@Autowired
...
...
project-order/src/main/java/com/alibaba/cloud/integration/order/service/impl/TimeRangeServiceImpl.java
0 → 100644
View file @
8131f88
package
com
.
alibaba
.
cloud
.
integration
.
order
.
service
.
impl
;
import
com.alibaba.cloud.integration.common.Result
;
import
com.alibaba.cloud.integration.order.dao.CapacityTeamStatDao
;
import
com.alibaba.cloud.integration.order.dto.CalendarDTO
;
import
com.alibaba.cloud.integration.order.dto.TimeDTO
;
import
com.alibaba.cloud.integration.order.dto.TimeRangeReqDTO
;
import
com.alibaba.cloud.integration.order.dto.TimeRangeRespDTO
;
import
com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity
;
import
com.alibaba.cloud.integration.order.service.TimeRangeService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.time.DayOfWeek
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.TextStyle
;
import
java.util.*
;
@Service
@Slf4j
public
class
TimeRangeServiceImpl
implements
TimeRangeService
{
private
final
String
[]
fullDay
=
{
"08:00"
,
"18:00"
};
@Autowired
private
CapacityTeamStatDao
capacityTeamStatDao
;
@Override
public
Result
<?>
getTimeRangeData
(
TimeRangeReqDTO
reqDTO
)
{
/*
location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat]
*/
String
teamId
=
getTeamByLayer
(
reqDTO
.
getLocation
());
TimeRangeRespDTO
timeRangeRespDTO
=
new
TimeRangeRespDTO
();
timeRangeRespDTO
.
setBeginDate
(
timeRangeRespDTO
.
getBeginDate
()).
setEndDate
(
reqDTO
.
getEndDate
());
timeRangeRespDTO
.
setCalendar
(
getTimeRangeByTeamSkill
(
teamId
,
reqDTO
.
getCategoryId
(),
reqDTO
.
getBeginDate
(),
reqDTO
.
getEndDate
()));
return
Result
.
success
(
timeRangeRespDTO
);
}
/**
* 根据提供的地址信息,获取对应的片区图层定义的工作队;如果没有找到,返回为空
* 目前layer_info表中,area_data是保存位置围栏的json数据,后面可能会是对于其他图层的引用;
*
* @param location
* @return
*/
private
String
getTeamByLayer
(
String
location
)
{
// todo
return
null
;
}
private
int
getSpanType
(
int
capLeft
,
int
capTotal
)
{
float
ratio
=
(
float
)
capLeft
/
capTotal
;
if
(
ratio
<
0.3
)
{
return
3
;
}
else
if
(
0.6
>=
ratio
&&
ratio
>=
0.3
)
{
return
2
;
}
else
{
return
1
;
}
}
private
Object
[]
getTimeSpanInfo
(
String
date
,
String
timeSpan
,
String
timeSpanDetail
)
{
// 如果是"全天",直接返回标题和2个时间点;否则,解析timeSpanDetail中的数据返回
Object
[]
result
=
new
Object
[
3
];
if
(
"全天"
.
equals
(
timeSpan
))
{
result
[
0
]
=
"全天都可以"
;
result
[
1
]
=
String
.
format
(
"%s %s:00"
,
date
,
fullDay
[
0
]);
result
[
2
]
=
String
.
format
(
"%s %s:00"
,
date
,
fullDay
[
1
]);
return
result
;
}
String
[]
times
=
timeSpanDetail
.
split
(
"~"
);
result
[
0
]
=
String
.
format
(
"%s:00-%s:00"
,
times
[
0
],
times
[
1
]);
result
[
1
]
=
String
.
format
(
"%s %s:00"
,
date
,
times
[
0
]);
result
[
2
]
=
String
.
format
(
"%s %s:00"
,
date
,
times
[
1
]);
return
result
;
}
/**
* 根据工作队、技能,返回对应时间段内的容量
*
* @param teamId
* @param skill
* @param beginDate
* @param endDate
* @return
*/
private
List
<
CalendarDTO
>
getTimeRangeByTeamSkill
(
String
teamId
,
String
skill
,
String
beginDate
,
String
endDate
)
{
Map
<
String
,
CalendarDTO
>
dayMaps
=
new
HashMap
<>();
List
<
CapacityTeamStatEntity
>
capacityTeamStatEntityList
=
capacityTeamStatDao
.
findAllByTeamIdAndSkillTagAndWorkdayBetween
(
teamId
,
skill
,
beginDate
,
endDate
);
for
(
CapacityTeamStatEntity
e
:
capacityTeamStatEntityList
)
{
TimeDTO
timeDTO
=
new
TimeDTO
();
timeDTO
.
setType
(
getSpanType
(
e
.
getCapLeft
(),
e
.
getCapTotal
()));
Object
[]
timeSpans
=
getTimeSpanInfo
(
e
.
getWorkday
(),
e
.
getTimeSpan
(),
e
.
getTimeSpanDetail
());
timeDTO
.
setText
((
String
)
timeSpans
[
0
]);
timeDTO
.
setBegin
((
String
)
timeSpans
[
1
]);
timeDTO
.
setEnd
((
String
)
timeSpans
[
2
]);
if
(!
dayMaps
.
containsKey
(
e
.
getWorkday
()))
{
CalendarDTO
calendarDTO
=
new
CalendarDTO
();
calendarDTO
.
setDate
(
e
.
getWorkday
());
calendarDTO
.
setWeek
(
getWeekday
(
e
.
getWorkday
()));
dayMaps
.
put
(
e
.
getWorkday
(),
calendarDTO
);
}
dayMaps
.
get
(
e
.
getWorkday
()).
getTimes
().
add
(
timeDTO
);
}
return
new
ArrayList
<>(
dayMaps
.
values
());
}
private
String
getWeekday
(
String
day
)
{
DateTimeFormatter
dateFormatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
LocalDate
date
=
LocalDate
.
parse
(
day
,
dateFormatter
);
DayOfWeek
weekday
=
date
.
getDayOfWeek
();
return
String
.
format
(
"周%s"
,
weekday
.
getDisplayName
(
TextStyle
.
SHORT
,
Locale
.
CHINA
));
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment