@@ -2,22 +2,39 @@ package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import com.peanut.modules.common.dao.CourseCatalogueDao ;
import com.peanut.modules.common.dao.MyUserDao ;
import com.peanut.modules.common.dao.ShopProductCourseDao ;
import com.peanut.modules.common.dao.UserCourseBuyDao ;
import com.peanut.modules.common.entity.BuyOrder ;
import com.peanut.modules.common.entity.ShopProductCourseEntity ;
import com.peanut.modules.common.entity.UserCourseBuyEntity ;
import com.peanut.modules.common.entity.* ;
import com.peanut.modules.common.to.AddCourses ;
import com.peanut.modules.common.vo.AddCoursesFrag ;
import com.peanut.modules.master.service.UserCourseBuyService ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.poi.ss.usermodel.* ;
import org.apache.poi.xssf.usermodel.XSSFWorkbook ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import java.io.IOException ;
import java.io.InputStream ;
import java.net.URL ;
import java.net.URLConnection ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.Iterator ;
import java.util.Map ;
@Slf4j
@Service ( " masterUserCourseBuyService " )
public class UserCourseBuyServiceImpl extends ServiceImpl < UserCourseBuyDao , UserCourseBuyEntity > implements UserCourseBuyService {
@Autowired
public ShopProductCourseDao shopProductCourseDao ;
@Autowired
public MyUserDao userDao ;
@Autowired
public CourseCatalogueDao courseCatalogueDao ;
@Override
public void addUserCourseBuyRelearn ( BuyOrder buyOrder , String come ) {
@@ -36,4 +53,118 @@ public class UserCourseBuyServiceImpl extends ServiceImpl<UserCourseBuyDao, User
userCourseBuyEntity . setCome ( " 复读- " + come ) ;
this . baseMapper . insert ( userCourseBuyEntity ) ;
}
@Override
public void addCourseForUser ( String phone ) {
MyUserEntity myUserEntity = userDao . selectOne ( new LambdaQueryWrapper < MyUserEntity > ( ) . eq ( MyUserEntity : : getTel , phone ) ) ;
// if(myUserEntity!=null){
// System.out.println(myUserEntity.getName());
// UserCourseBuyEntity userCourseBuyEntity = new UserCourseBuyEntity();
// userCourseBuyEntity.setUserId(myUserEntity.getId());
// userCourseBuyEntity.setCourseId(222);
// userCourseBuyEntity.setCatalogueId(295);
// userCourseBuyEntity.setDays(183);
// this.baseMapper.insert(userCourseBuyEntity);
//
// UserCourseBuyEntity userCourseBuyEntity1 = new UserCourseBuyEntity();
// userCourseBuyEntity1.setUserId(myUserEntity.getId());
// userCourseBuyEntity1.setCourseId(222);
// userCourseBuyEntity1.setCatalogueId(296);
// userCourseBuyEntity1.setDays(183);
// this.baseMapper.insert(userCourseBuyEntity1);
// }else {
// System.out.println("未找到:"+phone);
// }
}
@Override
public Map < String , ArrayList < AddCoursesFrag > > addCourses ( AddCourses addCourses ) {
HashMap < String , ArrayList < AddCoursesFrag > > frag = new HashMap < > ( ) ;
ArrayList < AddCoursesFrag > falseList = new ArrayList < > ( ) ;
ArrayList < AddCoursesFrag > successList = new ArrayList < > ( ) ;
String [ ] cata = ( addCourses . getCatalogueId ( ) ) . split ( " , " ) ;
CourseCatalogueEntity courseCatalogueEntity = courseCatalogueDao . selectById ( cata [ 0 ] ) ;
for ( MyUserEntity m : addCourses . getList ( ) ) {
for ( String s : cata ) {
int check = this . getBaseMapper ( ) . selectCount ( new LambdaQueryWrapper < UserCourseBuyEntity > ( )
. eq ( UserCourseBuyEntity : : getCatalogueId , s )
. eq ( UserCourseBuyEntity : : getUserId , m . getId ( ) ) ) ;
if ( check > 0 ) {
AddCoursesFrag addCoursesFrag = new AddCoursesFrag ( ) ;
addCoursesFrag . setUserId ( m . getId ( ) ) ;
addCoursesFrag . setCatalogueId ( Integer . valueOf ( s ) ) ;
addCoursesFrag . setName ( m . getName ( ) ) ;
addCoursesFrag . setCourseId ( courseCatalogueEntity . getCourseId ( ) ) ;
addCoursesFrag . setFrag ( false ) ;
addCoursesFrag . setTel ( m . getTel ( ) ) ;
falseList . add ( addCoursesFrag ) ;
} else {
UserCourseBuyEntity userCourseBuyEntity = new UserCourseBuyEntity ( ) ;
userCourseBuyEntity . setCourseId ( courseCatalogueEntity . getCourseId ( ) ) ;
userCourseBuyEntity . setCatalogueId ( Integer . valueOf ( s ) ) ;
userCourseBuyEntity . setDays ( addCourses . getDays ( ) ) ;
userCourseBuyEntity . setUserId ( m . getId ( ) ) ;
this . getBaseMapper ( ) . insert ( userCourseBuyEntity ) ;
AddCoursesFrag addCoursesFrag = new AddCoursesFrag ( ) ;
addCoursesFrag . setUserId ( m . getId ( ) ) ;
addCoursesFrag . setCatalogueId ( Integer . valueOf ( s ) ) ;
addCoursesFrag . setName ( m . getName ( ) ) ;
addCoursesFrag . setCourseId ( courseCatalogueEntity . getCourseId ( ) ) ;
addCoursesFrag . setFrag ( true ) ;
addCoursesFrag . setTel ( m . getTel ( ) ) ;
successList . add ( addCoursesFrag ) ;
}
}
}
frag . put ( " successList " , successList ) ;
frag . put ( " failList " , falseList ) ;
return frag ;
}
@Override
public Map < String , ArrayList > readExcelForAddCourse ( String file ) {
Map < String , ArrayList > stringArrayListMap = new HashMap < > ( ) ;
ArrayList < MyUserEntity > has = new ArrayList < > ( ) ;
ArrayList < Map < String , String > > nohas = new ArrayList < > ( ) ;
try {
URL url = new URL ( file ) ;
URLConnection connection = url . openConnection ( ) ;
InputStream inputStream = connection . getInputStream ( ) ;
// 创建工作簿( Workbook)
Workbook workbook = new XSSFWorkbook ( inputStream ) ;
// 获取工作表( Sheet)
Sheet sheet = workbook . getSheetAt ( 0 ) ; // 获取第一个工作表
// 获取行的迭代器
Iterator < Row > rowIterator = sheet . iterator ( ) ;
while ( rowIterator . hasNext ( ) ) {
Row row = rowIterator . next ( ) ;
Cell cell = row . getCell ( 1 ) ;
CellType cellTypeEnum = cell . getCellTypeEnum ( ) ;
if ( cellTypeEnum = = CellType . NUMERIC ) {
String phone = String . format ( " %.0f " , cell . getNumericCellValue ( ) ) ;
MyUserEntity myUserEntity = userDao . selectOne ( new LambdaQueryWrapper < MyUserEntity > ( ) . eq ( MyUserEntity : : getTel , phone ) ) ;
if ( myUserEntity ! = null ) {
has . add ( myUserEntity ) ;
} else {
HashMap < String , String > stringStringHashMap = new HashMap < > ( ) ;
stringStringHashMap . put ( " name " , row . getCell ( 0 ) . toString ( ) ) ;
stringStringHashMap . put ( " phone " , phone ) ;
nohas . add ( stringStringHashMap ) ;
}
}
}
stringArrayListMap . put ( " has " , has ) ;
stringArrayListMap . put ( " no " , nohas ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
return stringArrayListMap ;
}
}