Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 52d2ed89
authored
Mar 19, 2021
by
wnb0128
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'dev' of 192.168.3.233:open-source/chejia-smart-service into dev
2 parents
840a3851
a68c0e66
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
255 additions
and
768 deletions
src/main/java/com/glsx/smart/controller/ProductController.java
src/main/java/com/glsx/smart/controller/ProductTypeController.java
src/main/java/com/glsx/smart/dao/entity/SmartProduct.java
src/main/java/com/glsx/smart/dao/entity/SmartProductType.java
src/main/java/com/glsx/smart/dao/mapper/SmartProductMapper.java
src/main/java/com/glsx/smart/dao/mapper/SmartProductTypeMapper.java
src/main/java/com/glsx/smart/exception/GlobalExceptionHandler.java
src/main/java/com/glsx/smart/exception/ResultEnum.java
src/main/java/com/glsx/smart/filter/CorsFilter.java
src/main/java/com/glsx/smart/service/SmartProductService.java
src/main/java/com/glsx/smart/service/SmartProductTypeService.java
src/main/java/com/glsx/smart/service/impl/SmartProductServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartProductTypeServiceImpl.java
src/main/resources/mapper/SmartProductMapper.xml
src/main/resources/mapper/SmartProductTypeMapper.xml
src/main/java/com/glsx/smart/controller/ProductController.java
View file @
52d2ed8
package
com
.
glsx
.
smart
.
controller
;
package
com
.
glsx
.
smart
.
controller
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.
plat.common.utils.StringUtils
;
import
com.glsx.
smart.dao.entity.SmartDeviceOrder
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.service.SmartProductService
;
import
com.glsx.smart.service.SmartProductService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
@@ -49,6 +47,7 @@ public class ProductController {
...
@@ -49,6 +47,7 @@ public class ProductController {
*/
*/
@RequestMapping
(
value
=
"/getById"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/getById"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
SmartProduct
getById
(
Long
id
)
{
public
SmartProduct
getById
(
Long
id
)
{
log
.
info
(
"$$$$ /product/getById param: {}"
,
id
);
return
productService
.
getById
(
id
);
return
productService
.
getById
(
id
);
}
}
...
@@ -56,11 +55,12 @@ public class ProductController {
...
@@ -56,11 +55,12 @@ public class ProductController {
* 保存产品。无则插入,有则更新。
* 保存产品。无则插入,有则更新。
*
*
* @param product 产品
* @param product 产品
* @return 是否成功
*/
*/
@RequestMapping
(
value
=
"/save"
,
method
=
{
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/save"
,
method
=
{
RequestMethod
.
POST
})
public
void
save
(
@RequestBody
@Validated
SmartProduct
product
)
{
public
Boolean
save
(
@RequestBody
SmartProduct
product
)
{
log
.
info
(
"$$$$ /product/save param: {}"
,
JSON
.
toJSONString
(
product
));
log
.
info
(
"$$$$ /product/save param: {}"
,
JSON
.
toJSONString
(
product
));
productService
.
save
(
product
);
return
productService
.
save
(
product
);
}
}
/**
/**
...
@@ -69,25 +69,20 @@ public class ProductController {
...
@@ -69,25 +69,20 @@ public class ProductController {
* @param id 产品 id
* @param id 产品 id
*/
*/
@RequestMapping
(
value
=
"/getCommandSetById"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/getCommandSetById"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
void
getCommandSetById
(
Long
id
)
{
public
List
<
SmartDeviceOrder
>
getCommandSetById
(
Long
id
)
{
log
.
info
(
"$$$$ /product/getCommandSetById param: {}"
,
id
);
log
.
info
(
"$$$$ /product/getCommandSetById param: {}"
,
id
);
if
(
id
==
null
)
{
return
productService
.
getCommandSetById
(
id
);
throw
new
BusinessException
(
ResultEnum
.
PARAM_ERROR
);
}
productService
.
getCommandSetById
(
id
);
}
}
/**
/**
* 校验商城商品 id。
* 校验商城商品 id。
*
*
* @param shopProductId 商品 id
* @param shopProductId 商品 id
* @return 商品 id 是否合法
*/
*/
@RequestMapping
(
value
=
"/checkShopProductId"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/checkShopProductId"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
b
oolean
checkShopProductId
(
String
shopProductId
)
{
public
B
oolean
checkShopProductId
(
String
shopProductId
)
{
log
.
info
(
"$$$$ /product/checkShopProductId param: {}"
,
shopProductId
);
log
.
info
(
"$$$$ /product/checkShopProductId param: {}"
,
shopProductId
);
if
(
StringUtils
.
isBlank
(
shopProductId
))
{
throw
new
BusinessException
(
ResultEnum
.
PARAM_ERROR
);
}
return
productService
.
checkShopProductId
(
shopProductId
);
return
productService
.
checkShopProductId
(
shopProductId
);
}
}
...
@@ -95,13 +90,11 @@ public class ProductController {
...
@@ -95,13 +90,11 @@ public class ProductController {
* 上下架产品。
* 上下架产品。
*
*
* @param id 产品 id
* @param id 产品 id
* @return 是否成功
*/
*/
@RequestMapping
(
value
=
"/putOnOff"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/putOnOff"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
void
putOnOff
(
Long
id
)
{
public
Boolean
putOnOff
(
Long
id
)
{
log
.
info
(
"$$$$ /product/putOnOff param: {}"
,
id
);
log
.
info
(
"$$$$ /product/putOnOff param: {}"
,
id
);
if
(
id
==
null
)
{
return
productService
.
putOnOff
(
id
);
throw
new
BusinessException
(
ResultEnum
.
PARAM_ERROR
);
}
productService
.
putOnOff
(
id
);
}
}
}
}
src/main/java/com/glsx/smart/controller/ProductTypeController.java
View file @
52d2ed8
...
@@ -2,12 +2,12 @@ package com.glsx.smart.controller;
...
@@ -2,12 +2,12 @@ package com.glsx.smart.controller;
import
java.util.List
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.smart.dao.entity.SmartProductType
;
import
com.glsx.smart.dao.entity.SmartProductType
;
import
com.glsx.smart.service.SmartProductTypeService
;
import
com.glsx.smart.service.SmartProductTypeService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
@@ -39,24 +39,42 @@ public class ProductTypeController {
...
@@ -39,24 +39,42 @@ public class ProductTypeController {
return
productTypeService
.
getList
(
req
);
return
productTypeService
.
getList
(
req
);
}
}
/**
* 根据 id 获取产品类型。
*
* @param id 产品类型 id
* @return 结果
*/
@RequestMapping
(
value
=
"/getById"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/getById"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
SmartProductType
getById
(
Long
id
)
{
public
SmartProductType
getById
(
Long
id
)
{
return
productTypeService
.
getById
(
id
);
return
productTypeService
.
getById
(
id
);
}
}
/**
/**
* 获取结构化的产品类型。
*
* @return 结果
*/
@RequestMapping
(
value
=
"/getTypeAndCategory"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
JSONObject
getProductTypeTree
()
{
log
.
info
(
"$$$$ /productType/getTypeAndCategory..."
);
return
productTypeService
.
getTypeAndCategory
();
}
/**
* 保存产品类型。
* 保存产品类型。
*
*
* @param productType 产品类型
* @param productType 产品类型
* @return 是否成功
*/
*/
@RequestMapping
(
value
=
"/save"
,
method
=
{
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/save"
,
method
=
{
RequestMethod
.
POST
})
public
void
save
(
@RequestBody
@Validated
SmartProductType
productType
)
{
public
Boolean
save
(
@RequestBody
SmartProductType
productType
)
{
log
.
info
(
"$$$$ /productType/save param: {}"
,
JSON
.
toJSONString
(
productType
));
log
.
info
(
"$$$$ /productType/save param: {}"
,
JSON
.
toJSONString
(
productType
));
productTypeService
.
save
(
productType
);
return
productTypeService
.
save
(
productType
);
}
}
/**
/**
* 获取商城标签
* 获取商城标签
。
*
*
* @return 结果
* @return 结果
*/
*/
...
...
src/main/java/com/glsx/smart/dao/entity/SmartProduct.java
View file @
52d2ed8
...
@@ -5,7 +5,6 @@ import javax.persistence.GenerationType;
...
@@ -5,7 +5,6 @@ import javax.persistence.GenerationType;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
import
javax.persistence.Transient
;
import
javax.validation.constraints.NotBlank
;
import
java.util.Date
;
import
java.util.Date
;
import
com.glsx.smart.pojo.BaseDTO
;
import
com.glsx.smart.pojo.BaseDTO
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -48,7 +47,6 @@ public class SmartProduct extends BaseDTO {
...
@@ -48,7 +47,6 @@ public class SmartProduct extends BaseDTO {
/**
/**
* 产品名称
* 产品名称
*/
*/
@NotBlank
private
String
productName
;
private
String
productName
;
/**
/**
...
...
src/main/java/com/glsx/smart/dao/entity/SmartProductType.java
View file @
52d2ed8
...
@@ -4,7 +4,6 @@ import javax.persistence.GeneratedValue;
...
@@ -4,7 +4,6 @@ import javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
javax.persistence.Table
;
import
javax.validation.constraints.NotBlank
;
import
java.util.Date
;
import
java.util.Date
;
import
com.glsx.smart.pojo.BaseDTO
;
import
com.glsx.smart.pojo.BaseDTO
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -34,7 +33,6 @@ public class SmartProductType extends BaseDTO {
...
@@ -34,7 +33,6 @@ public class SmartProductType extends BaseDTO {
/**
/**
* 类型名称
* 类型名称
*/
*/
@NotBlank
private
String
typeName
;
private
String
typeName
;
/**
/**
...
...
src/main/java/com/glsx/smart/dao/mapper/SmartProductMapper.java
View file @
52d2ed8
package
com
.
glsx
.
smart
.
dao
.
mapper
;
package
com
.
glsx
.
smart
.
dao
.
mapper
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
/**
* <p>Description:
* <p>Description:
...
@@ -16,18 +14,9 @@ import java.util.List;
...
@@ -16,18 +14,9 @@ import java.util.List;
@Mapper
@Mapper
public
interface
SmartProductMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartProduct
>
{
public
interface
SmartProductMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartProduct
>
{
List
<
SmartProduct
>
getList
(
SmartProduct
product
);
List
<
SmartProduct
>
getList
(
SmartProduct
req
);
SmartProduct
getById
(
Long
id
);
int
countByProductName
(
String
productName
);
int
countByProductName
(
String
productName
);
int
insertOrUpdate
(
SmartProduct
record
);
int
insertOrUpdateSelective
(
SmartProduct
record
);
int
updateBatch
(
List
<
SmartProduct
>
list
);
int
updateBatchSelective
(
List
<
SmartProduct
>
list
);
int
batchInsert
(
@Param
(
"list"
)
List
<
SmartProduct
>
list
);
}
}
src/main/java/com/glsx/smart/dao/mapper/SmartProductTypeMapper.java
View file @
52d2ed8
...
@@ -3,7 +3,6 @@ package com.glsx.smart.dao.mapper;
...
@@ -3,7 +3,6 @@ package com.glsx.smart.dao.mapper;
import
java.util.List
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartProductType
;
import
com.glsx.smart.dao.entity.SmartProductType
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
/**
/**
* <p>Description:
* <p>Description:
...
@@ -15,16 +14,11 @@ import org.apache.ibatis.annotations.Param;
...
@@ -15,16 +14,11 @@ import org.apache.ibatis.annotations.Param;
@Mapper
@Mapper
public
interface
SmartProductTypeMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartProductType
>
{
public
interface
SmartProductTypeMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartProductType
>
{
List
<
SmartProductType
>
getList
(
SmartProductType
req
);
List
<
SmartProductType
>
getList
(
SmartProductType
productType
);
SmartProductType
getById
(
Long
id
);
int
insertOrUpdate
(
SmartProductType
record
);
int
countByProductTypeName
(
String
typeName
);
int
insertOrUpdateSelective
(
SmartProductType
record
);
List
<
SmartProductType
>
getAllList
();
int
updateBatch
(
List
<
SmartProductType
>
list
);
int
updateBatchSelective
(
List
<
SmartProductType
>
list
);
int
batchInsert
(
@Param
(
"list"
)
List
<
SmartProductType
>
list
);
}
}
src/main/java/com/glsx/smart/exception/GlobalExceptionHandler.java
View file @
52d2ed8
...
@@ -6,7 +6,6 @@ import org.springframework.validation.BindException;
...
@@ -6,7 +6,6 @@ import org.springframework.validation.BindException;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.ServletRequestBindingException
;
import
org.springframework.web.bind.ServletRequestBindingException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
/**
/**
* <p>Description:
* <p>Description:
...
@@ -14,27 +13,28 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
...
@@ -14,27 +13,28 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
*
*
* @author wbh
* @author wbh
* @date 2021-03-16
* @date 2021-03-16
* @deprecated 抛出异常,让上游服务捕获信息
*/
*/
@Slf4j
@Slf4j
@RestControllerAdvice
//@RestControllerAdvice
@Deprecated
public
class
GlobalExceptionHandler
{
public
class
GlobalExceptionHandler
{
@ExceptionHandler
({
BusinessException
.
class
})
@ExceptionHandler
({
BusinessException
.
class
})
public
R
handleBusinessException
(
BusinessException
e
)
{
public
R
handleBusinessException
(
BusinessException
e
)
{
log
.
error
(
"业务异常
:{}
"
,
e
);
log
.
error
(
"业务异常"
,
e
);
return
R
.
error
(
e
.
getMessage
());
return
R
.
error
(
e
.
getMessage
());
}
}
@ExceptionHandler
({
ServletRequestBindingException
.
class
,
MethodArgumentNotValidException
.
class
,
@ExceptionHandler
({
ServletRequestBindingException
.
class
,
MethodArgumentNotValidException
.
class
,
BindException
.
class
})
BindException
.
class
})
public
R
handleBindException
(
Exception
e
)
{
public
R
handleBindException
(
Exception
e
)
{
log
.
error
(
"参数错误
:{}
"
,
e
);
log
.
error
(
"参数错误"
,
e
);
return
R
.
error
(
ResultEnum
.
PARAM_ERROR
.
getCode
(),
ResultEnum
.
PARAM_ERROR
.
getMessage
());
return
R
.
error
(
ResultEnum
.
PARAM_ERROR
.
getCode
(),
ResultEnum
.
PARAM_ERROR
.
getMessage
());
}
}
@ExceptionHandler
(
Exception
.
class
)
@ExceptionHandler
(
Exception
.
class
)
public
R
handleException
(
Exception
e
)
{
public
R
handleException
(
Exception
e
)
{
log
.
error
(
"未知异常
:{}
"
,
e
);
log
.
error
(
"未知异常"
,
e
);
return
R
.
error
(
e
.
getMessage
());
return
R
.
error
(
e
.
getMessage
());
}
}
}
}
src/main/java/com/glsx/smart/exception/ResultEnum.java
View file @
52d2ed8
...
@@ -13,10 +13,12 @@ public enum ResultEnum {
...
@@ -13,10 +13,12 @@ public enum ResultEnum {
PARAM_ERROR
(
1001
,
"参数错误"
),
PARAM_ERROR
(
1001
,
"参数错误"
),
ID_NOT_FOUND
(
1002
,
"ID不存在"
),
ID_NOT_FOUND
(
1002
,
"ID不存在"
),
PRODUCT_NOT_FOUND
(
2001
,
"产品ID未找到"
),
PRODUCT_NOT_FOUND
(
2001
,
"产品ID未找到"
),
PRODUCT_NAME_DUPLICATE
(
2002
,
"产品名称重复"
),
PRODUCT_NAME_DUPLICATE
(
2002
,
"产品名称重复"
),
PRODUCT_TYPE_NOT_FOUND
(
3001
,
"产品类型ID未找到"
),
PRODUCT_TYPE_NOT_FOUND
(
3001
,
"产品类型ID未找到"
),
PRODUCT_TYPE_NAME_DUPLICATE
(
3002
,
"产品类型名称重复"
),
;
;
private
final
Integer
code
;
private
final
Integer
code
;
...
...
src/main/java/com/glsx/smart/filter/CorsFilter.java
0 → 100644
View file @
52d2ed8
package
com
.
glsx
.
smart
.
filter
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.Enumeration
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.stereotype.Component
;
/**
* <p>Description: 跨域配置
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-03-18
*/
@Component
public
class
CorsFilter
implements
Filter
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
HttpServletRequest
httpRequest
=
(
HttpServletRequest
)
request
;
HttpServletResponse
httpResponse
=
(
HttpServletResponse
)
response
;
StringBuffer
headersSb
=
new
StringBuffer
();
Enumeration
<
String
>
headerNames
=
httpRequest
.
getHeaderNames
();
while
(
headerNames
.
hasMoreElements
())
{
headersSb
.
append
(
headerNames
.
nextElement
()).
append
(
", "
);
}
if
(!
headersSb
.
toString
().
toLowerCase
().
contains
(
"authorization"
))
{
headersSb
.
append
(
"authorization"
);
}
httpResponse
.
addHeader
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_HEADERS
,
headersSb
.
toString
().
replaceAll
(
", +$"
,
""
));
httpResponse
.
addHeader
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_CREDENTIALS
,
"true"
);
httpResponse
.
addHeader
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_ORIGIN
,
httpRequest
.
getHeader
(
HttpHeaders
.
ORIGIN
));
httpResponse
.
addHeader
(
HttpHeaders
.
ACCESS_CONTROL_ALLOW_METHODS
,
httpRequest
.
getMethod
());
httpResponse
.
addHeader
(
HttpHeaders
.
ACCESS_CONTROL_EXPOSE_HEADERS
,
"*"
);
httpResponse
.
addHeader
(
HttpHeaders
.
ACCESS_CONTROL_MAX_AGE
,
"18000L"
);
chain
.
doFilter
(
request
,
response
);
}
}
src/main/java/com/glsx/smart/service/SmartProductService.java
View file @
52d2ed8
package
com
.
glsx
.
smart
.
service
;
package
com
.
glsx
.
smart
.
service
;
import
java.util.List
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.smart.dao.entity.SmartDeviceOrder
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartProduct
;
/**
/**
...
@@ -12,15 +14,15 @@ import com.glsx.smart.dao.entity.SmartProduct;
...
@@ -12,15 +14,15 @@ import com.glsx.smart.dao.entity.SmartProduct;
*/
*/
public
interface
SmartProductService
{
public
interface
SmartProductService
{
PageInfo
<
SmartProduct
>
getList
(
SmartProduct
req
);
PageInfo
<
SmartProduct
>
getList
(
SmartProduct
product
);
SmartProduct
getById
(
Long
id
);
SmartProduct
getById
(
Long
id
);
void
save
(
SmartProduct
product
);
Boolean
save
(
SmartProduct
product
);
void
getCommandSetById
(
Long
id
);
List
<
SmartDeviceOrder
>
getCommandSetById
(
Long
id
);
b
oolean
checkShopProductId
(
String
shopProductId
);
B
oolean
checkShopProductId
(
String
shopProductId
);
void
putOnOff
(
Long
id
);
Boolean
putOnOff
(
Long
id
);
}
}
src/main/java/com/glsx/smart/service/SmartProductTypeService.java
View file @
52d2ed8
package
com
.
glsx
.
smart
.
service
;
package
com
.
glsx
.
smart
.
service
;
import
java.util.List
;
import
java.util.List
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.smart.dao.entity.SmartProductType
;
import
com.glsx.smart.dao.entity.SmartProductType
;
...
@@ -13,11 +14,13 @@ import com.glsx.smart.dao.entity.SmartProductType;
...
@@ -13,11 +14,13 @@ import com.glsx.smart.dao.entity.SmartProductType;
*/
*/
public
interface
SmartProductTypeService
{
public
interface
SmartProductTypeService
{
PageInfo
<
SmartProductType
>
getList
(
SmartProductType
req
);
PageInfo
<
SmartProductType
>
getList
(
SmartProductType
productType
);
SmartProductType
getById
(
Long
id
);
SmartProductType
getById
(
Long
id
);
void
save
(
SmartProductType
productType
);
JSONObject
getTypeAndCategory
();
Boolean
save
(
SmartProductType
productType
);
List
<
String
>
getShopTagList
();
List
<
String
>
getShopTagList
();
}
}
src/main/java/com/glsx/smart/service/impl/SmartProductServiceImpl.java
View file @
52d2ed8
...
@@ -5,13 +5,16 @@ import java.util.Date;
...
@@ -5,13 +5,16 @@ import java.util.Date;
import
java.util.List
;
import
java.util.List
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.smart.dao.entity.SmartDeviceOrder
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.mapper.SmartDeviceOrderMapper
;
import
com.glsx.smart.dao.mapper.SmartProductMapper
;
import
com.glsx.smart.dao.mapper.SmartProductMapper
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.SmartProductService
;
import
com.glsx.smart.service.SmartProductService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -28,16 +31,19 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
...
@@ -28,16 +31,19 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
@Resource
@Resource
private
SmartProductMapper
productMapper
;
private
SmartProductMapper
productMapper
;
@Autowired
private
SmartDeviceOrderMapper
deviceOrderMapper
;
/**
/**
* 获取产品列表。
* 获取产品列表。
*
*
* @param
req
请求体
* @param
product
请求体
* @return 结果
* @return 结果
*/
*/
@Override
@Override
public
PageInfo
<
SmartProduct
>
getList
(
SmartProduct
req
)
{
public
PageInfo
<
SmartProduct
>
getList
(
SmartProduct
product
)
{
super
.
startPagination
(
req
);
super
.
startPagination
(
product
);
List
<
SmartProduct
>
productList
=
productMapper
.
getList
(
req
);
List
<
SmartProduct
>
productList
=
productMapper
.
getList
(
product
);
PageInfo
<
SmartProduct
>
pageInfo
=
PageInfo
.
of
(
productList
);
PageInfo
<
SmartProduct
>
pageInfo
=
PageInfo
.
of
(
productList
);
return
pageInfo
;
return
pageInfo
;
}
}
...
@@ -50,7 +56,10 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
...
@@ -50,7 +56,10 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
*/
*/
@Override
@Override
public
SmartProduct
getById
(
Long
id
)
{
public
SmartProduct
getById
(
Long
id
)
{
SmartProduct
product
=
productMapper
.
selectByPrimaryKey
(
id
);
SmartProduct
product
=
productMapper
.
getById
(
id
);
if
(
product
==
null
)
{
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_NOT_FOUND
);
}
return
product
;
return
product
;
}
}
...
@@ -58,39 +67,47 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
...
@@ -58,39 +67,47 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* 保存产品。无则插入,有则更新。
* 保存产品。无则插入,有则更新。
*
*
* @param product 产品
* @param product 产品
* @return 是否成功
*/
*/
@Override
@Override
@Transactional
@Transactional
public
void
save
(
SmartProduct
product
)
{
public
Boolean
save
(
SmartProduct
product
)
{
boolean
success
;
Date
now
=
new
Date
();
Date
now
=
new
Date
();
product
.
setUpdateTime
(
now
);
product
.
setUpdateTime
(
now
);
product
.
setUpdateBy
(
0L
);
if
(
product
.
getId
()
==
null
)
{
int
nameCount
=
productMapper
.
countByProductName
(
product
.
getProductName
());
int
nameCount
=
productMapper
.
countByProductName
(
product
.
getProductName
());
if
(
nameCount
>
0
)
{
if
(
nameCount
>
0
)
{
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_NAME_DUPLICATE
);
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_NAME_DUPLICATE
);
}
}
if
(
product
.
getId
()
==
null
)
{
product
.
setCreateTime
(
now
);
product
.
setCreateTime
(
now
);
productMapper
.
insertSelective
(
product
);
product
.
setCreateBy
(
0L
);
success
=
productMapper
.
insertSelective
(
product
)
>
0
;
}
else
{
}
else
{
SmartProduct
record
=
productMapper
.
selectByPrimaryKey
(
product
.
getId
());
SmartProduct
record
=
productMapper
.
selectByPrimaryKey
(
product
.
getId
());
if
(
record
!=
null
)
{
if
(
record
!=
null
)
{
productMapper
.
updateByPrimaryKeySelective
(
product
)
;
success
=
productMapper
.
updateByPrimaryKeySelective
(
product
)
>
0
;
}
else
{
}
else
{
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_NOT_FOUND
);
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_NOT_FOUND
);
}
}
}
}
return
success
;
}
}
/**
/**
* 根据产品 id 获取指令集。
* 根据产品 id 获取指令集。
*
*
* @param id 产品 id
* @param id 产品 id
* @return 结果
*/
*/
@Override
@Override
public
void
getCommandSetById
(
Long
id
)
{
public
List
<
SmartDeviceOrder
>
getCommandSetById
(
Long
id
)
{
SmartDeviceOrder
example
=
new
SmartDeviceOrder
();
example
.
setProductId
(
String
.
valueOf
(
id
));
return
deviceOrderMapper
.
select
(
example
);
}
}
/**
/**
...
@@ -100,7 +117,7 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
...
@@ -100,7 +117,7 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* @return 商品 id 是否合法
* @return 商品 id 是否合法
*/
*/
@Override
@Override
public
b
oolean
checkShopProductId
(
String
shopProductId
)
{
public
B
oolean
checkShopProductId
(
String
shopProductId
)
{
return
RandomUtil
.
randomBoolean
();
return
RandomUtil
.
randomBoolean
();
}
}
...
@@ -108,14 +125,18 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
...
@@ -108,14 +125,18 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* 上下架产品。
* 上下架产品。
*
*
* @param id 产品 id
* @param id 产品 id
* @return 是否成功
*/
*/
@Override
@Override
public
void
putOnOff
(
Long
id
)
{
@Transactional
public
Boolean
putOnOff
(
Long
id
)
{
boolean
success
;
SmartProduct
product
=
productMapper
.
selectByPrimaryKey
(
id
);
SmartProduct
product
=
productMapper
.
selectByPrimaryKey
(
id
);
if
(
product
==
null
)
{
if
(
product
==
null
)
{
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_NOT_FOUND
);
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_NOT_FOUND
);
}
}
product
.
setStatus
((
byte
)
(
product
.
getStatus
()
^
0b00000001
));
product
.
setStatus
((
byte
)
(
product
.
getStatus
()
^
0b00000001
));
productMapper
.
updateByPrimaryKeySelective
(
product
);
success
=
productMapper
.
updateByPrimaryKeySelective
(
product
)
>
0
;
return
success
;
}
}
}
}
src/main/java/com/glsx/smart/service/impl/SmartProductTypeServiceImpl.java
View file @
52d2ed8
...
@@ -3,7 +3,12 @@ package com.glsx.smart.service.impl;
...
@@ -3,7 +3,12 @@ package com.glsx.smart.service.impl;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.smart.dao.entity.SmartProductType
;
import
com.glsx.smart.dao.entity.SmartProductType
;
import
com.glsx.smart.dao.mapper.SmartProductTypeMapper
;
import
com.glsx.smart.dao.mapper.SmartProductTypeMapper
;
...
@@ -31,48 +36,109 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
...
@@ -31,48 +36,109 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
/**
/**
* 获取产品类型列表。
* 获取产品类型列表。
*
*
* @param
req
请求
* @param
productType
请求
* @return 结果
* @return 结果
*/
*/
@Override
@Override
public
PageInfo
<
SmartProductType
>
getList
(
SmartProductType
req
)
{
public
PageInfo
<
SmartProductType
>
getList
(
SmartProductType
productType
)
{
super
.
startPagination
(
req
);
super
.
startPagination
(
productType
);
List
<
SmartProductType
>
productTypeList
=
productTypeMapper
.
getList
(
req
);
List
<
SmartProductType
>
productTypeList
=
productTypeMapper
.
getList
(
productType
);
PageInfo
<
SmartProductType
>
pageInfo
=
PageInfo
.
of
(
productTypeList
);
PageInfo
<
SmartProductType
>
pageInfo
=
PageInfo
.
of
(
productTypeList
);
return
pageInfo
;
return
pageInfo
;
}
}
/**
* 根据 id 获取产品类型。
*
* @param id 产品类型 id
* @return 结果
*/
@Override
@Override
public
SmartProductType
getById
(
Long
id
)
{
public
SmartProductType
getById
(
Long
id
)
{
return
productTypeMapper
.
selectByPrimaryKey
(
id
);
SmartProductType
productType
=
productTypeMapper
.
getById
(
id
);
if
(
productType
==
null
)
{
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_TYPE_NOT_FOUND
);
}
return
productType
;
}
/**
* 获取结构化的产品类型。
* 数据格式为:
* {
* "车智能": ["产品类型1-1", "产品类型1-2"],
* "产品类型1-1": ["产品名称1", "产品名称2"],
*
* "家智能": ["产品类型2-1"],
* "产品类型2-1": ["产品名称3", "产品名称4", "产品名称5"]
* }
*
* @return 结果
*/
@Override
public
JSONObject
getTypeAndCategory
()
{
JSONObject
result
=
new
JSONObject
();
List
<
SmartProductType
>
productTypeList
=
productTypeMapper
.
getAllList
();
for
(
SmartProductType
productType
:
productTypeList
)
{
// 一级分类放在备注字段中
String
parentCategoryKey
=
productType
.
getRemark
();
// 二级分类
String
categoryKey
=
productType
.
getCategoryKey
();
// 根据一级分类将二级分类分组
if
(!
result
.
containsKey
(
parentCategoryKey
))
{
result
.
put
(
parentCategoryKey
,
new
HashSet
<>());
}
Set
<
Object
>
set
=
result
.
getObject
(
parentCategoryKey
,
new
TypeReference
<
Set
<
Object
>>()
{});
set
.
add
(
categoryKey
);
result
.
put
(
parentCategoryKey
,
set
);
// 根据二级分类将产品类型分组
if
(!
result
.
containsKey
(
categoryKey
))
{
result
.
put
(
categoryKey
,
new
JSONArray
());
}
result
.
getJSONArray
(
categoryKey
).
add
(
productType
);
}
return
result
;
}
}
/**
/**
* 保存产品类型。
* 保存产品类型。
*
*
* @param productType 产品类型
* @param productType 产品类型
* @return 是否成功
*/
*/
@Override
@Override
@Transactional
@Transactional
public
void
save
(
SmartProductType
productType
)
{
public
Boolean
save
(
SmartProductType
productType
)
{
boolean
success
;
Date
now
=
new
Date
();
Date
now
=
new
Date
();
productType
.
setUpdateTime
(
now
);
productType
.
setUpdateTime
(
now
);
productType
.
setUpdateBy
(
0L
);
if
(
productType
.
getId
()
==
null
)
{
if
(
productType
.
getId
()
==
null
)
{
int
nameCount
=
productTypeMapper
.
countByProductTypeName
(
productType
.
getTypeName
());
if
(
nameCount
>
0
)
{
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_TYPE_NAME_DUPLICATE
);
}
productType
.
setCreateTime
(
now
);
productType
.
setCreateTime
(
now
);
productTypeMapper
.
insertSelective
(
productType
);
productType
.
setCreateBy
(
0L
);
success
=
productTypeMapper
.
insertSelective
(
productType
)
>
0
;
}
else
{
}
else
{
SmartProductType
record
=
productTypeMapper
.
selectByPrimaryKey
(
productType
.
getId
());
SmartProductType
record
=
productTypeMapper
.
selectByPrimaryKey
(
productType
.
getId
());
if
(
record
!=
null
)
{
if
(
record
!=
null
)
{
productTypeMapper
.
updateByPrimaryKeySelective
(
productType
)
;
success
=
productTypeMapper
.
updateByPrimaryKeySelective
(
productType
)
>
0
;
}
else
{
}
else
{
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_TYPE_NOT_FOUND
);
throw
new
BusinessException
(
ResultEnum
.
PRODUCT_TYPE_NOT_FOUND
);
}
}
}
}
return
success
;
}
}
/**
/**
* 获取商城标签
* 获取商城标签
。
*
*
* @return 结果
* @return 结果
*/
*/
...
...
src/main/resources/mapper/SmartProductMapper.xml
View file @
52d2ed8
...
@@ -43,414 +43,21 @@
...
@@ -43,414 +43,21 @@
order by sp.create_time desc
order by sp.create_time desc
</select>
</select>
<select
id=
"getById"
resultMap=
"BaseResultMap"
>
select sp.id, sp.product_name, sp.icon, sp.type_id, sp.shop_product_id, sp.platform_key,
sp.platform_product_id, sp.network_key, sp.status, sp.remark, sp.create_time,
sp.create_by, sp.update_time, sp.update_by,
ssf.url iconUrl,
spt.type_name typeName
from smart_product sp
left join smart_sys_file ssf on ssf.id = sp.icon
left join smart_product_type spt on spt.id = sp.type_id
where sp.id = #{id,jdbcType=BIGINT}
</select>
<select
id=
"countByProductName"
resultType=
"integer"
>
<select
id=
"countByProductName"
resultType=
"integer"
>
select count(0)
select count(0)
from smart_product
from smart_product
where product_name = #{productName,jdbcType=VARCHAR}
where product_name = #{productName,jdbcType=VARCHAR}
</select>
</select>
<update
id=
"updateBatch"
parameterType=
"java.util.List"
>
<!--@mbg.generated-->
update smart_product
<trim
prefix=
"set"
suffixOverrides=
","
>
<trim
prefix=
"product_name = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.productName,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"icon = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.icon,jdbcType=BIGINT}
</foreach>
</trim>
<trim
prefix=
"type_id = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.typeId,jdbcType=BIGINT}
</foreach>
</trim>
<trim
prefix=
"shop_product_id = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.shopProductId,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"platform_key = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.platformKey,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"platform_product_id = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.platformProductId,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"network_key = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.networkKey,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"`status` = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.status,jdbcType=TINYINT}
</foreach>
</trim>
<trim
prefix=
"remark = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.remark,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"create_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.createTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim
prefix=
"create_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.createBy,jdbcType=BIGINT}
</foreach>
</trim>
<trim
prefix=
"update_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.updateTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim
prefix=
"update_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.updateBy,jdbcType=BIGINT}
</foreach>
</trim>
</trim>
where id in
<foreach
close=
")"
collection=
"list"
item=
"item"
open=
"("
separator=
", "
>
#{item.id,jdbcType=BIGINT}
</foreach>
</update>
<update
id=
"updateBatchSelective"
parameterType=
"java.util.List"
>
<!--@mbg.generated-->
update smart_product
<trim
prefix=
"set"
suffixOverrides=
","
>
<trim
prefix=
"product_name = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.productName != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.productName,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"icon = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.icon != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.icon,jdbcType=BIGINT}
</if>
</foreach>
</trim>
<trim
prefix=
"type_id = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.typeId != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.typeId,jdbcType=BIGINT}
</if>
</foreach>
</trim>
<trim
prefix=
"shop_product_id = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.shopProductId != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.shopProductId,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"platform_key = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.platformKey != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.platformKey,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"platform_product_id = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.platformProductId != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.platformProductId,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"network_key = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.networkKey != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.networkKey,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"`status` = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.status != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.status,jdbcType=TINYINT}
</if>
</foreach>
</trim>
<trim
prefix=
"remark = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.remark != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.remark,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"create_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.createTime != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.createTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim
prefix=
"create_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.createBy != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.createBy,jdbcType=BIGINT}
</if>
</foreach>
</trim>
<trim
prefix=
"update_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.updateTime != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.updateTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim
prefix=
"update_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.updateBy != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.updateBy,jdbcType=BIGINT}
</if>
</foreach>
</trim>
</trim>
where id in
<foreach
close=
")"
collection=
"list"
item=
"item"
open=
"("
separator=
", "
>
#{item.id,jdbcType=BIGINT}
</foreach>
</update>
<insert
id=
"batchInsert"
keyColumn=
"id"
keyProperty=
"id"
parameterType=
"map"
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into smart_product
(product_name, icon, type_id, shop_product_id, platform_key, platform_product_id,
network_key, `status`, remark, create_time, create_by, update_time, update_by)
values
<foreach
collection=
"list"
item=
"item"
separator=
","
>
(#{item.productName,jdbcType=VARCHAR}, #{item.icon,jdbcType=BIGINT},
#{item.typeId,jdbcType=BIGINT},
#{item.shopProductId,jdbcType=VARCHAR}, #{item.platformKey,jdbcType=VARCHAR},
#{item.platformProductId,jdbcType=VARCHAR},
#{item.networkKey,jdbcType=VARCHAR}, #{item.status,jdbcType=TINYINT},
#{item.remark,jdbcType=VARCHAR},
#{item.createTime,jdbcType=TIMESTAMP}, #{item.createBy,jdbcType=BIGINT},
#{item.updateTime,jdbcType=TIMESTAMP},
#{item.updateBy,jdbcType=BIGINT})
</foreach>
</insert>
<insert
id=
"insertOrUpdate"
keyColumn=
"id"
keyProperty=
"id"
parameterType=
"com.glsx.smart.dao.entity.SmartProduct"
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into smart_product
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
product_name,
icon,
type_id,
shop_product_id,
platform_key,
platform_product_id,
network_key,
`status`,
remark,
create_time,
create_by,
update_time,
update_by,
</trim>
values
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=BIGINT},
</if>
#{productName,jdbcType=VARCHAR},
#{icon,jdbcType=BIGINT},
#{typeId,jdbcType=BIGINT},
#{shopProductId,jdbcType=VARCHAR},
#{platformKey,jdbcType=VARCHAR},
#{platformProductId,jdbcType=VARCHAR},
#{networkKey,jdbcType=VARCHAR},
#{status,jdbcType=TINYINT},
#{remark,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP},
#{createBy,jdbcType=BIGINT},
#{updateTime,jdbcType=TIMESTAMP},
#{updateBy,jdbcType=BIGINT},
</trim>
on duplicate key update
<trim
suffixOverrides=
","
>
<if
test=
"id != null"
>
id = #{id,jdbcType=BIGINT},
</if>
product_name = #{productName,jdbcType=VARCHAR},
icon = #{icon,jdbcType=BIGINT},
type_id = #{typeId,jdbcType=BIGINT},
shop_product_id = #{shopProductId,jdbcType=VARCHAR},
platform_key = #{platformKey,jdbcType=VARCHAR},
platform_product_id = #{platformProductId,jdbcType=VARCHAR},
network_key = #{networkKey,jdbcType=VARCHAR},
`status` = #{status,jdbcType=TINYINT},
remark = #{remark,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
create_by = #{createBy,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=TIMESTAMP},
update_by = #{updateBy,jdbcType=BIGINT},
</trim>
</insert>
<insert
id=
"insertOrUpdateSelective"
keyColumn=
"id"
keyProperty=
"id"
parameterType=
"com.glsx.smart.dao.entity.SmartProduct"
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into smart_product
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"productName != null and productName != ''"
>
product_name,
</if>
<if
test=
"icon != null"
>
icon,
</if>
<if
test=
"typeId != null"
>
type_id,
</if>
<if
test=
"shopProductId != null and shopProductId != ''"
>
shop_product_id,
</if>
<if
test=
"platformKey != null and platformKey != ''"
>
platform_key,
</if>
<if
test=
"platformProductId != null and platformProductId != ''"
>
platform_product_id,
</if>
<if
test=
"networkKey != null and networkKey != ''"
>
network_key,
</if>
<if
test=
"status != null"
>
`status`,
</if>
<if
test=
"remark != null and remark != ''"
>
remark,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
<if
test=
"createBy != null"
>
create_by,
</if>
<if
test=
"updateTime != null"
>
update_time,
</if>
<if
test=
"updateBy != null"
>
update_by,
</if>
</trim>
values
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=BIGINT},
</if>
<if
test=
"productName != null and productName != ''"
>
#{productName,jdbcType=VARCHAR},
</if>
<if
test=
"icon != null"
>
#{icon,jdbcType=BIGINT},
</if>
<if
test=
"typeId != null"
>
#{typeId,jdbcType=BIGINT},
</if>
<if
test=
"shopProductId != null and shopProductId != ''"
>
#{shopProductId,jdbcType=VARCHAR},
</if>
<if
test=
"platformKey != null and platformKey != ''"
>
#{platformKey,jdbcType=VARCHAR},
</if>
<if
test=
"platformProductId != null and platformProductId != ''"
>
#{platformProductId,jdbcType=VARCHAR},
</if>
<if
test=
"networkKey != null and networkKey != ''"
>
#{networkKey,jdbcType=VARCHAR},
</if>
<if
test=
"status != null"
>
#{status,jdbcType=TINYINT},
</if>
<if
test=
"remark != null and remark != ''"
>
#{remark,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
#{createTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"createBy != null"
>
#{createBy,jdbcType=BIGINT},
</if>
<if
test=
"updateTime != null"
>
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"updateBy != null"
>
#{updateBy,jdbcType=BIGINT},
</if>
</trim>
on duplicate key update
<trim
suffixOverrides=
","
>
<if
test=
"id != null"
>
id = #{id,jdbcType=BIGINT},
</if>
<if
test=
"productName != null and productName != ''"
>
product_name = #{productName,jdbcType=VARCHAR},
</if>
<if
test=
"icon != null"
>
icon = #{icon,jdbcType=BIGINT},
</if>
<if
test=
"typeId != null"
>
type_id = #{typeId,jdbcType=BIGINT},
</if>
<if
test=
"shopProductId != null and shopProductId != ''"
>
shop_product_id = #{shopProductId,jdbcType=VARCHAR},
</if>
<if
test=
"platformKey != null and platformKey != ''"
>
platform_key = #{platformKey,jdbcType=VARCHAR},
</if>
<if
test=
"platformProductId != null and platformProductId != ''"
>
platform_product_id = #{platformProductId,jdbcType=VARCHAR},
</if>
<if
test=
"networkKey != null and networkKey != ''"
>
network_key = #{networkKey,jdbcType=VARCHAR},
</if>
<if
test=
"status != null"
>
`status` = #{status,jdbcType=TINYINT},
</if>
<if
test=
"remark != null and remark != ''"
>
remark = #{remark,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"createBy != null"
>
create_by = #{createBy,jdbcType=BIGINT},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"updateBy != null"
>
update_by = #{updateBy,jdbcType=BIGINT},
</if>
</trim>
</insert>
</mapper>
</mapper>
src/main/resources/mapper/SmartProductTypeMapper.xml
View file @
52d2ed8
...
@@ -33,279 +33,24 @@
...
@@ -33,279 +33,24 @@
order by spt.create_time desc
order by spt.create_time desc
</select>
</select>
<select
id=
"getById"
resultMap=
"BaseResultMap"
>
select spt.id, spt.type_name, spt.category_key, spt.shop_tag, spt.remark, spt.create_time,
spt.create_by, spt.update_time, spt.update_by
from smart_product_type spt
where spt.id = #{id,jdbcType=BIGINT}
</select>
<update
id=
"updateBatch"
parameterType=
"java.util.List"
>
<select
id=
"countByProductTypeName"
resultType=
"int"
>
<!--@mbg.generated-->
select count(0)
update smart_product_type
from smart_product_type
<trim
prefix=
"set"
suffixOverrides=
","
>
where type_name = #{typeName,jdbcType=VARCHAR}
<trim
prefix=
"type_name = case"
suffix=
"end,"
>
</select>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.typeName,jdbcType=VARCHAR}
<select
id=
"getAllList"
resultMap=
"BaseResultMap"
>
</foreach>
select spt.id, spt.type_name, spt.category_key, spt.shop_tag,
</trim>
ssc.parent_key remark
<trim
prefix=
"category_key = case"
suffix=
"end,"
>
from smart_product_type spt
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
left join smart_sys_code ssc on ssc.dict_key = spt.category_key
when id = #{item.id,jdbcType=BIGINT} then #{item.categoryKey,jdbcType=VARCHAR}
order by ssc.sort
</foreach>
</select>
</trim>
<trim
prefix=
"shop_tag = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.shopTag,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"remark = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.remark,jdbcType=VARCHAR}
</foreach>
</trim>
<trim
prefix=
"create_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.createTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim
prefix=
"create_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.createBy,jdbcType=BIGINT}
</foreach>
</trim>
<trim
prefix=
"update_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.updateTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim
prefix=
"update_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.updateBy,jdbcType=BIGINT}
</foreach>
</trim>
</trim>
where id in
<foreach
close=
")"
collection=
"list"
item=
"item"
open=
"("
separator=
", "
>
#{item.id,jdbcType=BIGINT}
</foreach>
</update>
<update
id=
"updateBatchSelective"
parameterType=
"java.util.List"
>
<!--@mbg.generated-->
update smart_product_type
<trim
prefix=
"set"
suffixOverrides=
","
>
<trim
prefix=
"type_name = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.typeName != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.typeName,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"category_key = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.categoryKey != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.categoryKey,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"shop_tag = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.shopTag != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.shopTag,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"remark = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.remark != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.remark,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim
prefix=
"create_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.createTime != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.createTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim
prefix=
"create_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.createBy != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.createBy,jdbcType=BIGINT}
</if>
</foreach>
</trim>
<trim
prefix=
"update_time = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.updateTime != null"
>
when id = #{item.id,jdbcType=BIGINT} then
#{item.updateTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim
prefix=
"update_by = case"
suffix=
"end,"
>
<foreach
collection=
"list"
index=
"index"
item=
"item"
>
<if
test=
"item.updateBy != null"
>
when id = #{item.id,jdbcType=BIGINT} then #{item.updateBy,jdbcType=BIGINT}
</if>
</foreach>
</trim>
</trim>
where id in
<foreach
close=
")"
collection=
"list"
item=
"item"
open=
"("
separator=
", "
>
#{item.id,jdbcType=BIGINT}
</foreach>
</update>
<insert
id=
"batchInsert"
keyColumn=
"id"
keyProperty=
"id"
parameterType=
"map"
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into smart_product_type
(type_name, category_key, shop_tag, remark, create_time, create_by, update_time,
update_by)
values
<foreach
collection=
"list"
item=
"item"
separator=
","
>
(#{item.typeName,jdbcType=VARCHAR}, #{item.categoryKey,jdbcType=VARCHAR},
#{item.shopTag,jdbcType=VARCHAR},
#{item.remark,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
#{item.createBy,jdbcType=BIGINT},
#{item.updateTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=BIGINT})
</foreach>
</insert>
<insert
id=
"insertOrUpdate"
keyColumn=
"id"
keyProperty=
"id"
parameterType=
"com.glsx.smart.dao.entity.SmartProductType"
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into smart_product_type
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
type_name,
category_key,
shop_tag,
remark,
create_time,
create_by,
update_time,
update_by,
</trim>
values
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=BIGINT},
</if>
#{typeName,jdbcType=VARCHAR},
#{categoryKey,jdbcType=VARCHAR},
#{shopTag,jdbcType=VARCHAR},
#{remark,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP},
#{createBy,jdbcType=BIGINT},
#{updateTime,jdbcType=TIMESTAMP},
#{updateBy,jdbcType=BIGINT},
</trim>
on duplicate key update
<trim
suffixOverrides=
","
>
<if
test=
"id != null"
>
id = #{id,jdbcType=BIGINT},
</if>
type_name = #{typeName,jdbcType=VARCHAR},
category_key = #{categoryKey,jdbcType=VARCHAR},
shop_tag = #{shopTag,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
create_by = #{createBy,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=TIMESTAMP},
update_by = #{updateBy,jdbcType=BIGINT},
</trim>
</insert>
<insert
id=
"insertOrUpdateSelective"
keyColumn=
"id"
keyProperty=
"id"
parameterType=
"com.glsx.smart.dao.entity.SmartProductType"
useGeneratedKeys=
"true"
>
<!--@mbg.generated-->
insert into smart_product_type
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"typeName != null and typeName != ''"
>
type_name,
</if>
<if
test=
"categoryKey != null and categoryKey != ''"
>
category_key,
</if>
<if
test=
"shopTag != null and shopTag != ''"
>
shop_tag,
</if>
<if
test=
"remark != null and remark != ''"
>
remark,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
<if
test=
"createBy != null"
>
create_by,
</if>
<if
test=
"updateTime != null"
>
update_time,
</if>
<if
test=
"updateBy != null"
>
update_by,
</if>
</trim>
values
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=BIGINT},
</if>
<if
test=
"typeName != null and typeName != ''"
>
#{typeName,jdbcType=VARCHAR},
</if>
<if
test=
"categoryKey != null and categoryKey != ''"
>
#{categoryKey,jdbcType=VARCHAR},
</if>
<if
test=
"shopTag != null and shopTag != ''"
>
#{shopTag,jdbcType=VARCHAR},
</if>
<if
test=
"remark != null and remark != ''"
>
#{remark,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
#{createTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"createBy != null"
>
#{createBy,jdbcType=BIGINT},
</if>
<if
test=
"updateTime != null"
>
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"updateBy != null"
>
#{updateBy,jdbcType=BIGINT},
</if>
</trim>
on duplicate key update
<trim
suffixOverrides=
","
>
<if
test=
"id != null"
>
id = #{id,jdbcType=BIGINT},
</if>
<if
test=
"typeName != null and typeName != ''"
>
type_name = #{typeName,jdbcType=VARCHAR},
</if>
<if
test=
"categoryKey != null and categoryKey != ''"
>
category_key = #{categoryKey,jdbcType=VARCHAR},
</if>
<if
test=
"shopTag != null and shopTag != ''"
>
shop_tag = #{shopTag,jdbcType=VARCHAR},
</if>
<if
test=
"remark != null and remark != ''"
>
remark = #{remark,jdbcType=VARCHAR},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"createBy != null"
>
create_by = #{createBy,jdbcType=BIGINT},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if
test=
"updateBy != null"
>
update_by = #{updateBy,jdbcType=BIGINT},
</if>
</trim>
</insert>
</mapper>
</mapper>
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