常规
@ApiOperation ( value = "发送短信" )
@PostMapping ( "/test/sendSms" )
@ActionLog ( action = "发送短信" , remark = "发送短信" )
public R sendSms ( @Valid @RequestBody SendSmsREQ req , @RequestHeader ( "Tenant-Id" ) String tenantId) {
R r = shopRegisterService. sendSms ( req, tenantId) ;
return r;
}
import io. swagger. annotations. ApiModel ;
import io. swagger. annotations. ApiModelProperty ;
import lombok. Data ;
import javax. validation. constraints. NotBlank ;
import java. io. Serializable ;
@Data
@ApiModel ( value = "短信发送对象" )
public class SendSmsREQ implements Serializable {
private static final long serialVersionUID = 1L ;
@ApiModelProperty ( value = "手机号" )
@NotBlank ( message = "手机号不能为空" )
private String phonenum;
@NotBlank ( message = "发送短信场景枚举值不能为空" )
private String scene;
}
@Data
@EqualsAndHashCode ( callSuper = true )
@TableName ( "sys_sms_code" )
@ApiModel ( value= "SysSmsCode对象" , description= "短信验证码表" )
public class SysSmsCode {
private static final long serialVersionUID = 1L ;
@ApiModelProperty ( value = "手机号码" )
@TableField ( "phonenum" )
private String phonenum;
@ApiModelProperty ( value = "验证码内容" )
@TableField ( "code" )
private String code;
@ApiModelProperty ( value = "最后修改时间" )
@TableField ( "update_time" )
private Date updateTime;
@ApiModelProperty ( value = "创建人id" )
@TableField ( "creator_id" )
private Long creatorId;
@ApiModelProperty ( value = "更新人id" )
@TableField ( "update_id" )
private Long updateId;
@ApiModelProperty ( value = "发送短信场景" )
@TableField ( "scene" )
private String scene;
}
@Override
public Integer queryCountByPhoneNum ( Map < String , Object > paramMap) {
Date oneHourBefore = DateUtils . addHours ( new Date ( ) , - 1 ) ;
paramMap. put ( "oneHourBefore" , oneHourBefore) ;
int count = shopRegisterMapper. queryCountByPhoneNum ( paramMap) ;
return count;
}
public interface RegisterMapper extends BaseMapper < SysSmsCode > {
Integer queryCountByPhoneNum ( Map < String , Object > paramMap) ;
Integer queryUserByAccount ( @Param ( "account" ) String account) ;
}
< select id= "queryCountByPhoneNum" parameterType= "java.util.Map" resultType= "java.lang.Integer" >
select count ( * ) from
sys_sms_code
where phonenum = #{ phoneNum}
and create_time between #{ oneHourBefore} and now ( )
and scene = #{ scene}
< / select>
< select id= "queryUserByAccount" parameterType= "java.lang.String" resultType= "java.lang.Integer" >
select count ( * ) from user where account= #{ account} and is_deleted= 0
< / select>
Mapper.java
User queryUserByPhone ( Map < String , Object > paramMap) ;
IPage < ShopUserVO > getShopUserList ( @Param ( "req" ) UserQueryREQ req, @Param ( "page" ) Page page) ;
< select id= "queryUserByPhone" parameterType= "java.util.Map" resultType= "org.test.entity.User" >
select u. id, u. account, u. phonenum
from user u join tenant_user_rel tur on u. id = tur. user_id
where
u. is_deleted = '0' and
u. phonenum = #{ phoneNum}
< if test= "boundRealPhone != null and boundRealPhone != '' " >
AND tur. bound_real_phone = #{ boundRealPhone}
< / if >
< / select>
< select id= "getShopUserList" resultType= "org.test.vo.ShopUserVO" >
SELECT
t1. id,
t1. account,
t1. phonenum,
t1. supplier_id,
t1. status,
t1. update_time,
t1. create_time,
t2. supplier_name
FROM
`user` t1
INNER JOIN `shop_supplier` t2 ON t1. `supplier_id` = t2. `id`
< where>
t1. is_deleted = '0' AND t1. supplier_id < ! [ CDATA [ < > ] ] > 0
< if test= "req.search != null and req.search!='' " >
AND t1. phonenum LIKE concat ( '%' , #{ req. search} , '%' )
< / if >
< if test= "req.status != null and req.status!= '' " >
AND t1. status = #{ req. status}
< / if >
< if test= "req.supplierName != null and req.supplierName!= '' " >
AND t2. supplier_name = #{ req. supplierName}
< / if >
< if test= "req.startTime != null and req.startTime!=''" >
AND t1. update_time < ! [ CDATA [ >= ] ] > #{ req. startTime}
< / if >
< if test= "req.endTime != null and req.endTime!='' " >
AND t1. update_time < ! [ CDATA [ <= ] ] > #{ req. endTime}
< / if >
< / where>
order by t1. id desc
< / select>
< insert id= "saveTenantUserRelInfo" parameterType= "org.test.user.entity.TenantUserRel" >
INSERT INTO tenant_user_rel
( id, user_id, bound_real_phone, register_type)
values (
#{ id} ,
#{ userId} ,
#{ boundRealPhone} ,
#{ registerType} )
< / insert>
< update id= "updateTenantUserRelInfo" parameterType= "java.util.Map" >
update tenant_user_rel set bound_real_phone = #{ boundRealPhone}
where user_id = #{ userId}
< / update>
mybatis-plus 的stream写法
TutorStudent one = this . lambdaQuery ( ) . eq ( TutorStudent :: getId , req. getId ( ) ) . one ( ) ;
@Override
public List < ShopOrder > getOrderPayList ( String param) {
return this . lambdaQuery ( )
. eq ( ShopOrder :: getOrderStatus , CommonConstant . ORDER_STATUS )
. eq ( ShopOrder :: getIsDeleted , CommonConstant . NO )
. list ( ) ;
}
@Override
public Boolean deleteOrderPayInfo ( Long orderId) {
boolean flag = this . lambdaUpdate ( )
. eq ( ShopOrder :: getId , orderId)
. set ( ShopOrder :: getIsDeleted , CommonConstant . YES )
. update ( ) ;
return flag;
}
boolean result = this . lambdaUpdate ( )
. set ( CourseApplication :: getApproveStatus , status)
. eq ( CourseApplication :: getId , id)
. update ( ) ;
@Override
public Boolean addBatchTypeAbilityBusiness ( List < CommonAttachmentAddREQ > entitys) {
if ( Func . isEmpty ( entitys) ) {
return false ;
}
Set < String > ablrIds = entitys. stream ( ) . map ( CommonAttachmentAddREQ :: getBizId ) . collect ( Collectors . toSet ( ) ) ;
this . lambdaUpdate ( ) . in ( CommonAttachment :: getBizId , ablrIds)
. eq ( CommonAttachment :: getCreatorId , AuthUtil . getUserId ( ) )
. eq ( CommonAttachment :: getType , "ability" )
. remove ( ) ;
return this . addBatchTypeAbility ( entitys) ;
}
List < String > userIds = this . lambdaQuery ( ) . select ( LiveSignUp :: getUserId ) . in ( LiveSignUp :: getId , signUpIds) . list ( )
. stream ( ) . map ( e -> Func . toStr ( e. getUserId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < Long > userLongs = userIds. stream ( ) . map ( Func :: toLong ) . collect ( Collectors . toList ( ) ) ;
@Override
public R < Boolean > updateUserInfoById ( String userId) {
ShopUser user = shopUserService. lambdaQuery ( ) . eq ( ShopUser :: getId , userId) . eq ( ShopUser :: getStatus , CommonConstant . YES ) . one ( ) ;
if ( Func . isEmpty ( user) ) {
return R . status ( false ) ;
}
boolean flag = this . lambdaUpdate ( ) . eq ( ShopSupplier :: getId , user. getSupplierId ( ) ) . set ( ShopSupplier :: getIsCommissionid , CommonConstant . YES ) . set ( ShopSupplier :: getUpdateTime , new Date ( ) ) . update ( ) ;
if ( flag) {
return R . status ( true ) ;
}
return R . status ( false ) ;
}
导出
controller
@GetMapping ( "/v1/export" )
@ApiOperation ( value = "导出线上必修总览统计" , notes = "导出线上必修总览统计" )
public void complusoryOverviewExport ( @NotBlank String startTime, @NotBlank String endTime, @NotBlank String exportSignature) throws Exception {
countCompulsoryService. compulsoryOverviewExport ( startTime, endTime, exportSignature) ;
}
public interface ICountCompulsoryService {
void compulsoryOverviewExport ( String startTime, String endTime, String exportSignature) throws IOException ;
}
impl
@Override
public void compulsoryOverviewExport ( String startTime, String endTime, String exportSignature) throws IOException {
CountCompulsoryREQ req = new CountCompulsoryREQ ( ) ;
req. setStartTime ( startTime) ;
req. setEndTime ( endTime) ;
List < CountCompulsoryOverviewVO > compulsoryOverviewList = countCompulsoryMapper. queryCompulsoryOverviewList ( req) ;
AsyncExportStudyPlanOverviewImpl impl = SpringUtil . getBean ( AsyncExportStudyPlanOverviewImpl . class ) ;
impl. exportToRedisRela ( startTime, endTime, exportSignature, CountCompulsoryOverviewVO . class , AuthUtil . getTenantId ( ) , compulsoryOverviewList. size ( ) , DataScopeUtil . getParam ( DataScopeUtil . getMgmtDeptAncestors ( AuthUtil . getUser ( ) ) ) ) ;
}
@Async ( CommonConstant . ASYNC_EXECUTOR )
public < T > CompletableFuture < String > exportToRedis ( String startTime, String endTime, String key, Class < T > clz, String tenantId, int count, String mgmtOrgIds) {
try {
key = key + ":" + tenantId;
redisUtils. setExpireTime ( key, 60L , TimeUnit . MINUTES ) ;
if ( count < 1 ) {
redisUtils. set ( key, EXPORT_NO_RESULT ) ;
return CompletableFuture . completedFuture ( "" ) ;
} else {
String fileName = startTime + "-" + endTime + ".xlsx" ;
int totalSheet = ( int ) Math . ceil ( ( double ) count / HALF_MILLION ) ;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ;
try ( ExcelWriter excelWriter = EasyExcel . write ( byteArrayOutputStream, clz) . build ( ) ) {
for ( int i = 0 ; i < totalSheet; i++ ) {
WriteSheet writeSheet = EasyExcel . writerSheet ( i, "sheet" + i) . build ( ) ;
int sheetStart = i * HALF_MILLION ;
List data = exportRealData ( startTime, endTime, sheetStart, HALF_MILLION , mgmtOrgIds) ;
excelWriter. write ( data, writeSheet) ;
}
}
ByteArrayInputStream inputStream = new ByteArrayInputStream ( byteArrayOutputStream. toByteArray ( ) ) ;
MultipartFile file = generateMultipartFile ( inputStream, fileName) ;
R response = client. putFile ( file, tenantId) ;
String fileUrl = null ;
if ( response. isSuccess ( ) ) {
fileUrl = ( String ) response. getResponse ( ) ;
redisUtils. set ( key, fileUrl) ;
return CompletableFuture . completedFuture ( "" ) ;
}
redisUtils. set ( key, EXPORT_FAIL ) ;
}
} catch ( Exception e) {
redisUtils. set ( key, EXPORT_FAIL ) ;
e. printStackTrace ( ) ;
}
return CompletableFuture . completedFuture ( "" ) ;
}
private MultipartFile generateMultipartFile ( ByteArrayInputStream inputStream, String fileName) {
FileItemFactory factory = new DiskFileItemFactory ( ) ;
DiskFileItem item = ( DiskFileItem ) factory. createItem ( "file" , MediaType . APPLICATION_OCTET_STREAM_VALUE , true , fileName) ;
try ( OutputStream out = item. getOutputStream ( ) ) {
IOUtils . copy ( inputStream, out) ;
return new CommonsMultipartFile ( item) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
return null ;
}
}
@Override
public R putFile ( MultipartFile file, String tenantId) throws IOException {
BladeFile bladeFile = ossBuilder. template ( ) . putFile ( file. getOriginalFilename ( ) , file. getInputStream ( ) ) ;
return R . data ( bladeFile. getLink ( ) ) ;
}