团队代码

2021年6月11日:

服务层代码:

package com.atguigu.crud.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atguigu.crud.bean.Clubapply;
import com.atguigu.crud.dao.ClubapplyMapper;

@Service
public class Applyserviceimpl implements Clubapplyservice {
@Autowired
ClubapplyMapper apply;

public void add(Clubapply club) {
apply.insert(club);
}

public List<Clubapply> list(String name) {

List<Clubapply> a = apply.list(name);

return a;
}

public Clubapply update1(String photo) {

return apply.selectphoto(photo);
}

public void xiugaiyes(String photo) {

apply.xiugaiyes(photo);
}

public void xiugaino(String photo,String refuse) {

apply.xiugaino(photo,refuse);
}

}

 

 

 

package com.atguigu.crud.service;

import com.atguigu.crud.bean.Club;
import com.atguigu.crud.bean.Empty;
import com.atguigu.crud.dao.ClubMapper;
import com.atguigu.crud.dao.EmptyMapper;
import com.atguigu.crud.utils.PageData;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;

@Service
public class ClubServiceImpl implements ClubService {

@Autowired
ClubMapper clubDao;
@Autowired
EmptyMapper emptydao;

@Override
public void createNewClub(Club club) throws Exception {
club.setCreate_time(new Date());
clubDao.insert(club);
}

public void addempty(Empty empty) {
emptydao.insert(empty);
}

public List<Club> list(Long long1) {
return clubDao.select(long1);
}

public PageData<Club> listClubs(Club condition, String sortName, String sortOrder, Integer pagenum,
Integer pagesize) {
List<Club> list = clubDao.listClubs(condition, sortName, sortOrder, pagenum, pagesize);
int count = clubDao.count(condition, sortName, sortOrder);
PageData<Club> page = new PageData<>();
page.setRows(list);
page.setTotal(count);
return page;
}

public Club get(String name) {
return clubDao.selectbyname(name);
}

public void uploadHead(Long id, String imgdata, String path) {
File a = new File(path);
if (!a.exists()) {
a.mkdir();
}
try {
byte[] decode3 = Base64.decodeBase64(imgdata);
FileOutputStream out = new FileOutputStream(path + "/" + id + ".jpg");
out.write(decode3);
out.close();
Club club = new Club();
club.setId(id);
club.setLogo(id + ".jpg");
clubDao.update(club);
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
}

public String photo(String imgBase64, String path, String name, String clubname) {
File a = new File(path);
if (!a.exists()) {
a.mkdir();
}
try {
byte[] decode3 = Base64.decodeBase64(imgBase64);
FileOutputStream out = new FileOutputStream(path + "/" + clubname + "_" + name + ".jpg");
out.write(decode3);
out.close();
String imgPath = clubname + "_" + name + ".jpg";
return imgPath;
} catch (FileNotFoundException e) {
return null;
} catch (IOException e) {
return null;
}
}
public void updatecount(String clubname) {
clubDao.updatecount(clubname);
}

public List<Club> selectpage(Long id, Integer page) {
return clubDao.selectpage(id,page);
}


public List<Club> list2(String name) {
return clubDao.list2(name);
}

public int renshu(String club) {
return clubDao.renshu(club);
}
}

 

 

 

 

package com.atguigu.crud.service;

import com.atguigu.crud.bean.Clubtype;
import com.atguigu.crud.dao.ClubtypeMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClubTypeServiceImpl implements ClubTypeService {

@Autowired
ClubtypeMapper clubTypeDao;

@Override
public List<Clubtype> listTypes() {
return clubTypeDao.listTypes();
}

@Override
public Clubtype list(Byte id) {
return clubTypeDao.selectByPrimaryKey(id);
}
}

 

 

package com.atguigu.crud.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atguigu.crud.bean.Clubuser;
import com.atguigu.crud.dao.ClubuserMapper;
@Service
public class ClubuserServiceimpl implements ClubuserService{
@Autowired
ClubuserMapper clubuser;
public void add(Clubuser clubuser1) {
clubuser.insert(clubuser1);
}

public List<Clubuser> seacher(Long id) {
return clubuser.seacher(id);
}
}

 

 

package com.atguigu.crud.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atguigu.crud.bean.Empty;
import com.atguigu.crud.dao.EmptyMapper;

@Service
public class Emptyserviceimpl implements Emptyservice {
@Autowired
EmptyMapper empty;

public List<Empty> list(String name) {
return empty.list(name);
}

public void update(String club, String emptys, String username) {
empty.update(club, emptys, username);
}

public void update2(String clubname, String emptyname) {
empty.update2(clubname, emptyname);
}

public Empty bumen(String name, String club) {

return empty.bumen(name, club);
}

public List<Empty> bumens(String club) {
return empty.bumens(club);
}

public void xiugaihuodong(Map<String, String> map,String name,String club) {
empty.xiugaihuodong(map,name,club);
}
}

 

 

package com.atguigu.crud.service;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.atguigu.crud.bean.Huodong;
import com.atguigu.crud.bean.Huodongqueren;
import com.atguigu.crud.dao.HuodongMapper;
import com.atguigu.crud.dao.QuerenMapper;
@Service
public class Huodongservice {
@Autowired
HuodongMapper huo;
@Autowired
QuerenMapper queren;
public void add(Huodong huodong) {
huo.add(huodong);
}
public List<Huodong> look(String name) {
return huo.look(name);
}
public void insert(Huodongqueren h) {
queren.add(h);
}
public List<Huodongqueren> select(Integer p,String club,String huo){
return queren.select(club,huo,p);
}
public List<Huodongqueren> select1(String club, String huo1) {
return queren.select1(club, huo1);
}
public Huodong kan(String club, String huodong) {
return huo.kan(club,huodong);
}
public void update(String club, String huo1) {
huo.update(club,huo1);
}
public List<Huodong> join(String name) {
return huo.join(name);
}
}

 

 

package com.atguigu.crud.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atguigu.crud.bean.Message;
import com.atguigu.crud.dao.MessageMapper;

@Service
public class Message1 {
@Autowired
MessageMapper dao;

public void m(Message record) {
dao.insert(record);
}

public List<Message> update(String receiveuser) {
return dao.seacher(receiveuser);
}

public void xiugai(String photo) {
dao.xiugai(photo);
}
public void xiugai1(Integer id) {
dao.xiugai1(id);
}
}

 

 

package com.atguigu.crud.service;

 

import com.atguigu.crud.bean.User;

import com.atguigu.crud.bean.validatecode;
import com.atguigu.crud.dao.UserMapper;
import com.atguigu.crud.dao.validatecodeMapper;
import com.atguigu.crud.utils.QQMailTool;
import com.atguigu.crud.utils.ValidateCodeExpiredException;
import com.atguigu.crud.utils.ValidateCodeTool;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;

import javax.mail.MessagingException;

@Service
public class UserServiceImpl implements UserService {
@Autowired
UserMapper userDao;
@Autowired
validatecodeMapper v;

@Transactional
public boolean register(User user) throws MessagingException {
String md5Pwd = DigestUtils.md5Hex(user.getPwd());
user.setPwd(md5Pwd);
userDao.insert(user);
// 2.生成验证码
String code = ValidateCodeTool.generateCode();
// 3.往验证码表里插入一条
validatecode validateCode = new validatecode();
validateCode.setUser_id(user.getId());
validateCode.setCode(code);
v.insert(validateCode);
// 4.发邮件
QQMailTool.sendMail(user.getLogin_mail(), "欢迎注册优优社团", "您的验证码是" + code + ",请在5分钟内激活");
return true;
}

@Transactional
public User login(String login_mail, String pwd) {
User user = new User();
user.setLogin_mail(login_mail);
user.setPwd(DigestUtils.md5Hex(pwd));
// 查询
User userResult = userDao.get(user);
if (userResult != null && userResult.getStatus() > 0) {

userResult.setLast_time(new Date());

userDao.update(userResult);
}
return userResult;
}

@Transactional
public boolean active(Long userId, String code) throws ValidateCodeExpiredException {
validatecode validateCode = v.get(code);
User user = userDao.selectByPrimaryKey(userId);
if (validateCode != null) {
Date expiredTime = validateCode.getExpired_time();
Date now = new Date();
if (expiredTime.getTime() < now.getTime()) {
String newCode = ValidateCodeTool.generateCode();
validateCode.setCode(newCode);
v.update(validateCode);
try {
QQMailTool.sendMail(user.getLogin_mail(), "你好!", "您的验证码是" + newCode + ",请在5分钟内激活。");
} catch (MessagingException e) {
e.printStackTrace();
}
throw new ValidateCodeExpiredException("验证码失效,已重新发送验证邮件,请重新登录邮箱查看。");
} else {
user.setStatus(1);
userDao.update(user);
return true;
}
} else {
return false;
}
}

@Transactional
public void modify(User user) {
user.setUpdate_time(new Date());
user.setStatus(1);
userDao.update(user);
}

@Transactional
public String uploadHead(Long id, String name,int count, int status, String imgBase64, String path) {
File a = new File(path);
if (!a.exists()) {
a.mkdir();
}
try {
byte[] decode3 = Base64.decodeBase64(imgBase64);
FileOutputStream out = new FileOutputStream(path + "/" + name + ".jpg");
out.write(decode3);
out.close();
User user = new User();
user.setId(id);
user.setTrue_name(name);
user.setClub_count(count);
user.setStatus(status);
String imgPath = name + ".jpg";
user.setHead_img(imgPath);
userDao.update(user);
return imgPath;
} catch (UnsupportedEncodingException e) {
return null;
} catch (IOException e) {
return null;
}
}

public User get(String name) {
return userDao.getname(name);
}

public void update(String name) {
userDao.xiugai(name);
}

public List<User> seacher(Long id) {
return userDao.seacher(id);
}

public List<User> selectpage(Long id, Integer page) {
return userDao.selectpage(id, page);
}
public List<User> cha(Long id) {
return userDao.cha(id);
}
}

 

posted @ 2021-06-11 20:54  一条快乐的小鲸鱼  阅读(9)  评论(0编辑  收藏  举报