Commit d6289d6a authored by licc's avatar licc

修改事务注解

parent 78c99d4b
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</resultMap> </resultMap>
<sql id="table"> <sql id="table">
user_limit user_limit_record
</sql> </sql>
<sql id="cols_all"> <sql id="cols_all">
......
...@@ -19,15 +19,15 @@ public class PayRecord implements Serializable { ...@@ -19,15 +19,15 @@ public class PayRecord implements Serializable {
private static final long serialVersionUID = -7865361068703566832L; private static final long serialVersionUID = -7865361068703566832L;
/** /**
* 充值记录 * 充值记录id
*/ */
@ApiModelProperty(value = "",name = "") @ApiModelProperty(value = "充值记录id",name = "id")
private Integer id; private Integer id;
/** /**
* 充值类型 1:支付宝 2:微信 3:充值卡 * 充值类型 1:支付宝 2:微信 3:充值卡
*/ */
@ApiModelProperty(value = "",name = "") @ApiModelProperty(value = "充值类型 1:支付宝 2:微信 3:充值卡",name = "type")
private Integer type; private Integer type;
/** /**
......
...@@ -7,6 +7,9 @@ import lombok.Data; ...@@ -7,6 +7,9 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
/**
* @author 86187
*/
@Data @Data
@ApiModel(value = "UserLimit") @ApiModel(value = "UserLimit")
public class UserLimit implements Serializable { public class UserLimit implements Serializable {
......
...@@ -39,6 +39,4 @@ public interface VolunteerService extends IService<Volunteer> { ...@@ -39,6 +39,4 @@ public interface VolunteerService extends IService<Volunteer> {
* @throws IOException 异常 * @throws IOException 异常
*/ */
void ceshi(MultipartFile file, HttpServletResponse response) throws IOException; void ceshi(MultipartFile file, HttpServletResponse response) throws IOException;
R<SchemeInfo> add(SchemeInfo schemeInfo);
} }
...@@ -21,6 +21,7 @@ import java.util.Map; ...@@ -21,6 +21,7 @@ import java.util.Map;
* @ Description: 充值记录实现 * @ Description: 充值记录实现
* @ Author : 86187 * @ Author : 86187
* @ Date : 2021/1/13 17:18 * @ Date : 2021/1/13 17:18
* @author 86187
*/ */
@Service @Service
@Slf4j @Slf4j
......
...@@ -16,6 +16,7 @@ import java.util.List; ...@@ -16,6 +16,7 @@ import java.util.List;
* @ Description: 专业接口实现 * @ Description: 专业接口实现
* @ Author : 86187 * @ Author : 86187
* @ Date : 2021/1/13 10:52 * @ Date : 2021/1/13 10:52
* @author 86187
*/ */
@Service @Service
@Slf4j @Slf4j
......
...@@ -29,6 +29,7 @@ import java.util.stream.Collectors; ...@@ -29,6 +29,7 @@ import java.util.stream.Collectors;
* @ Description: 方案查询记录接口实现 * @ Description: 方案查询记录接口实现
* @ Author : 86187 * @ Author : 86187
* @ Date : 2021/1/8 11:41 * @ Date : 2021/1/8 11:41
* @author 86187
*/ */
@Slf4j @Slf4j
@Service @Service
......
...@@ -11,6 +11,7 @@ import cn.wisenergy.model.enums.StudentType; ...@@ -11,6 +11,7 @@ import cn.wisenergy.model.enums.StudentType;
import cn.wisenergy.model.vo.*; import cn.wisenergy.model.vo.*;
import cn.wisenergy.service.app.SchemeService; import cn.wisenergy.service.app.SchemeService;
import cn.wisenergy.service.app.UserVolunteerService; import cn.wisenergy.service.app.UserVolunteerService;
import cn.wisenergy.service.common.VolunteerManager;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -63,6 +64,9 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -63,6 +64,9 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
@Autowired @Autowired
private UserVolunteerService userVolunteerService; private UserVolunteerService userVolunteerService;
@Autowired
private VolunteerManager volunteerManager;
@Override @Override
public R<VolunteerVo> getList(SchemeVo queryVo) { public R<VolunteerVo> getList(SchemeVo queryVo) {
log.info("volunteer-service[]SchemeServiceImpl[]getList[]input.param.queryVo:" + queryVo); log.info("volunteer-service[]SchemeServiceImpl[]getList[]input.param.queryVo:" + queryVo);
...@@ -235,7 +239,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -235,7 +239,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
} }
//6保存用户方案记录、志愿之间的关联关系 //6保存用户方案记录、志愿之间的关联关系
boolean bool = saveUserVolunteer(user, list, scoreInfo, queryVo.getBigMajorNames()); boolean bool = volunteerManager.saveUserVolunteer(user, list, scoreInfo, queryVo.getBigMajorNames());
if (!bool) { if (!bool) {
return R.error("保存方案查询记录失败!"); return R.error("保存方案查询记录失败!");
} }
...@@ -306,46 +310,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp ...@@ -306,46 +310,7 @@ public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, SchemeInfo> imp
} }
/**
* 保存方案查询记录和关联关系
*
* @param user 用户信息
* @param list 志愿信息
* @return true 成功 false 失败
*/
@Transactional(rollbackFor = Exception.class)
public boolean saveUserVolunteer(User user, List<Volunteer> list, ScoreInfo scoreInfo, String name) {
//1、保存方案查询记录
SchemeQueryRecord schemeQueryRecord = new SchemeQueryRecord();
schemeQueryRecord.setMajorName(name);
schemeQueryRecord.setStudentType(user.getExamType());
schemeQueryRecord.setUserId(user.getId());
schemeQueryRecord.setIsDelete(0);
double score = scoreInfo.getCultureGrade() + scoreInfo.getMajorGrade();
schemeQueryRecord.setScore(String.valueOf(score));
List<Integer> ids = list.stream().map(Volunteer::getId).collect(Collectors.toList());
//保存方案查询记录
int count = schemeRecordMapper.add(schemeQueryRecord);
if (count == 0) {
return false;
}
List<UserVolunteer> volunteerList = new ArrayList<>();
for (Integer id : ids) {
UserVolunteer userVolunteer = new UserVolunteer();
userVolunteer.setSchemeRecordId(schemeQueryRecord.getId());
userVolunteer.setUserId(user.getId());
userVolunteer.setVolunteerId(id);
volunteerList.add(userVolunteer);
}
boolean bool = userVolunteerService.saveBatch(volunteerList);
if (!bool) {
return false;
}
return true;
}
/** /**
* 获取文化生志愿列表 * 获取文化生志愿列表
......
...@@ -3,17 +3,16 @@ package cn.wisenergy.service.app.impl; ...@@ -3,17 +3,16 @@ package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.*; import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.*; import cn.wisenergy.model.app.*;
import cn.wisenergy.model.enums.CardStatus;
import cn.wisenergy.model.enums.PayType; import cn.wisenergy.model.enums.PayType;
import cn.wisenergy.model.vo.AddLimitVo; import cn.wisenergy.model.vo.AddLimitVo;
import cn.wisenergy.service.app.UserLimitService; import cn.wisenergy.service.app.UserLimitService;
import cn.wisenergy.service.common.VolunteerManager;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/** /**
* @author 86187 * @author 86187
...@@ -37,6 +36,9 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit ...@@ -37,6 +36,9 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit
@Autowired @Autowired
private UserLimitRecordMapper userLimitRecordMapper; private UserLimitRecordMapper userLimitRecordMapper;
@Autowired
private VolunteerManager volunteerManager;
@Override @Override
public R<UserLimit> getByUserId(Integer userId) { public R<UserLimit> getByUserId(Integer userId) {
log.info("volunteer-service[]UserLimitServiceImpl[]getByUserId[]input.param.userId:" + userId); log.info("volunteer-service[]UserLimitServiceImpl[]getByUserId[]input.param.userId:" + userId);
...@@ -84,7 +86,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit ...@@ -84,7 +86,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit
userLimit.setTotalLimit(total); userLimit.setTotalLimit(total);
//更新充值卡状态和用户查询次数及增加充值记录 //更新充值卡状态和用户查询次数及增加充值记录
boolean bool = updateLimitAndRecord(new Price(), cardInfo, userLimit, addLimitVo); boolean bool = volunteerManager.updateLimitAndRecord(new Price(), cardInfo, userLimit, addLimitVo);
return R.ok(bool); return R.ok(bool);
} else { } else {
...@@ -108,7 +110,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit ...@@ -108,7 +110,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit
userLimit.setTotalLimit(total); userLimit.setTotalLimit(total);
//更新充值卡状态和用户查询次数及增加充值记录 //更新充值卡状态和用户查询次数及增加充值记录
boolean bool = updateLimitAndRecord(price, new CardInfo(), userLimit, addLimitVo); boolean bool = volunteerManager.updateLimitAndRecord(price, new CardInfo(), userLimit, addLimitVo);
return R.ok(bool); return R.ok(bool);
} }
} }
...@@ -127,7 +129,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit ...@@ -127,7 +129,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit
} }
if (userLimit.getUsableLimit() == 0) { if (userLimit.getUsableLimit() == 0) {
return R.error(1,"您的查询次数已使用完了,请充值!", false); return R.error(1, "您的查询次数已使用完了,请充值!", false);
} }
//扣减用户可用查询次数 //扣减用户可用查询次数
...@@ -139,94 +141,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit ...@@ -139,94 +141,7 @@ public class UserLimitServiceImpl extends ServiceImpl<UserLimitMapper, UserLimit
userLimit.setUseLimit(useLimit); userLimit.setUseLimit(useLimit);
//更新用户查询信息并保存扣减记录 //更新用户查询信息并保存扣减记录
boolean bool = updateLimitSaveRecord(userLimit); boolean bool = volunteerManager.updateLimitSaveRecord(userLimit);
return R.ok(bool); return R.ok(bool);
} }
/**
* 更新充值卡状态和用户查询次数及增加充值记录
*
* @param cardInfo 充值卡信息
* @param userLimit 用户查询次数信息
* @param addLimitVo 接口入参
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateLimitAndRecord(Price price, CardInfo cardInfo, UserLimit userLimit, AddLimitVo addLimitVo) {
//是充值卡
if (PayType.REFILL_CARD.getCode().equals(addLimitVo.getPayType())) {
//1、更新充值卡状态
cardInfo.setStatus(CardStatus.ALREADY_USED.getCode());
int count = cardMapper.updateById(cardInfo);
if (count == 0) {
return false;
}
//2、更新用户查询次数信息
int limit = userLimitMapper.edit(userLimit);
if (limit == 0) {
return false;
}
//3、保存充值记录
PayRecord payRecord = new PayRecord();
payRecord.setCardId(cardInfo.getId());
payRecord.setMoney(Integer.valueOf(cardInfo.getMoney()));
payRecord.setPayLimit(cardInfo.getLimit());
payRecord.setResult(0);
payRecord.setType(addLimitVo.getPayType());
payRecord.setUserId(addLimitVo.getUserId());
int pay = payRecordMapper.add(payRecord);
if (pay == 0) {
return false;
}
} else {
//1、更新用户查询次数信息
int limit = userLimitMapper.edit(userLimit);
if (limit == 0) {
return false;
}
//2、保存充值记录
PayRecord payRecord = new PayRecord();
payRecord.setCardId(null);
payRecord.setMoney(addLimitVo.getPayMoney());
payRecord.setPayLimit(price.getUseLimit());
payRecord.setResult(0);
payRecord.setType(addLimitVo.getPayType());
payRecord.setUserId(addLimitVo.getUserId());
int pay = payRecordMapper.add(payRecord);
if (pay == 0) {
return false;
}
}
return true;
}
/**
* 更新用户查询信息并保存扣减记录
*
* @param userLimit 查询信息
* @return true or false
*/
public boolean updateLimitSaveRecord(UserLimit userLimit) {
//1、更新查询信息
int count = userLimitMapper.edit(userLimit);
if (count == 0) {
return false;
}
//2、保存扣减记录
UserLimitRecord userLimitRecord = new UserLimitRecord();
userLimitRecord.setMinusLimit(1);
userLimitRecord.setUserId(userLimit.getUserId());
int record = userLimitRecordMapper.add(userLimitRecord);
if (record == 0) {
return false;
}
return true;
}
} }
...@@ -300,6 +300,4 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, User> impleme ...@@ -300,6 +300,4 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, User> impleme
return true; return true;
} }
} }
...@@ -11,6 +11,7 @@ import cn.wisenergy.model.vo.UserInfoVo; ...@@ -11,6 +11,7 @@ import cn.wisenergy.model.vo.UserInfoVo;
import cn.wisenergy.model.vo.UserQueryVo; import cn.wisenergy.model.vo.UserQueryVo;
import cn.wisenergy.model.vo.UserShowVo; import cn.wisenergy.model.vo.UserShowVo;
import cn.wisenergy.service.app.UserService; import cn.wisenergy.service.app.UserService;
import cn.wisenergy.service.common.VolunteerManager;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -49,6 +50,9 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -49,6 +50,9 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
@Autowired @Autowired
private PayRecordMapper payRecordMapper; private PayRecordMapper payRecordMapper;
@Autowired
protected VolunteerManager volunteerManager;
@Override @Override
public R<PageInfo<UserInfoDto>> getUserList(UserQueryVo queryVo) { public R<PageInfo<UserInfoDto>> getUserList(UserQueryVo queryVo) {
log.info("volunteer_service[]UserServiceImpl[]getUserList[]input.param.queryVo:" + queryVo); log.info("volunteer_service[]UserServiceImpl[]getUserList[]input.param.queryVo:" + queryVo);
...@@ -129,7 +133,7 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -129,7 +133,7 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
ScoreInfo scoreInfo = userInfo.getScoreInfo(); ScoreInfo scoreInfo = userInfo.getScoreInfo();
//4、更新用户信息和保存用户成绩 //4、更新用户信息和保存用户成绩
boolean bool = updateAndSaveUserInfo(user, scoreInfo); boolean bool = volunteerManager.updateAndSaveUserInfo(user, scoreInfo);
if (!bool) { if (!bool) {
return R.error("添加用户信息失败!"); return R.error("添加用户信息失败!");
} }
...@@ -180,7 +184,7 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -180,7 +184,7 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
scoreInfo.setPoliticsGrade(userDto.getScoreInfo().getPoliticsGrade()); scoreInfo.setPoliticsGrade(userDto.getScoreInfo().getPoliticsGrade());
//4、更新用户信息和保存用户成绩 //4、更新用户信息和保存用户成绩
boolean bool = updateAndUserInfo(user, scoreInfo); boolean bool = volunteerManager.updateAndUserInfo(user, scoreInfo);
return R.ok(bool); return R.ok(bool);
} }
...@@ -251,50 +255,4 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U ...@@ -251,50 +255,4 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
orderQueryVo.setPageNo(pageNum); orderQueryVo.setPageNo(pageNum);
orderQueryVo.setPageSize(pageSize); orderQueryVo.setPageSize(pageSize);
} }
/**
* 保存个人信息
* @param user 用户信息
* @param scoreInfo 成绩信息
* @return true or false
*/
@Transactional
public Boolean updateAndSaveUserInfo(User user, ScoreInfo scoreInfo) {
//1、更新用户信息
int count = usersMapper.edit(user);
if (count == 0) {
return false;
}
//2、保存用户成绩信息
int save = scoreInfoMapper.add(scoreInfo);
if (save == 0) {
return false;
}
return true;
}
/**
* 编辑个人信息
* @param user 用户信息
* @param scoreInfo 成绩信息
* @return true or false
*/
@Transactional()
public Boolean updateAndUserInfo(User user, ScoreInfo scoreInfo) {
//1、更新用户信息
int count = usersMapper.edit(user);
if (count == 0) {
return false;
}
//2、保存用户成绩信息
int save = scoreInfoMapper.edit(scoreInfo);
if (save == 0) {
return false;
}
return true;
}
} }
...@@ -8,6 +8,7 @@ import cn.wisenergy.model.app.SchemeInfo; ...@@ -8,6 +8,7 @@ import cn.wisenergy.model.app.SchemeInfo;
import cn.wisenergy.model.app.Volunteer; import cn.wisenergy.model.app.Volunteer;
import cn.wisenergy.service.app.VolunteerService; import cn.wisenergy.service.app.VolunteerService;
import cn.wisenergy.service.common.VolunteerListener; import cn.wisenergy.service.common.VolunteerListener;
import cn.wisenergy.service.common.VolunteerManager;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -26,6 +27,7 @@ import java.util.List; ...@@ -26,6 +27,7 @@ import java.util.List;
* @ Description: 志愿接口实现 * @ Description: 志愿接口实现
* @ Author : 86187 * @ Author : 86187
* @ Date : 2021/1/8 9:44 * @ Date : 2021/1/8 9:44
* @author 86187
*/ */
@Service @Service
@Slf4j @Slf4j
...@@ -39,6 +41,9 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -39,6 +41,9 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
@Autowired @Autowired
private VolunteerService volunteerService; private VolunteerService volunteerService;
@Autowired
private VolunteerManager volunteerManager;
@Override @Override
public R<Boolean> batchAdd(List<Volunteer> list) { public R<Boolean> batchAdd(List<Volunteer> list) {
return null; return null;
...@@ -68,7 +73,7 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -68,7 +73,7 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
schemeInfo.setUploadTime(new Date()); schemeInfo.setUploadTime(new Date());
schemeInfo.setIsDelete(0); schemeInfo.setIsDelete(0);
saveSchemeAndVolunteer(schemeInfo, list); volunteerManager.saveSchemeAndVolunteer(schemeInfo, list);
} }
@Override @Override
...@@ -95,45 +100,10 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -95,45 +100,10 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
schemeInfo.setUploadTime(new Date()); schemeInfo.setUploadTime(new Date());
schemeInfo.setIsDelete(0); schemeInfo.setIsDelete(0);
saveSchemeAndVolunteer(schemeInfo, list); volunteerManager.saveSchemeAndVolunteer(schemeInfo, list);
log.info("导入方案数据成功!"); log.info("导入方案数据成功!");
} }
@Override
public R<SchemeInfo> add(SchemeInfo schemeInfo) {
int count = schemeMapper.add(schemeInfo);
log.info("返回对象:" + schemeInfo);
int id = schemeInfo.getId();
log.info("主键id:" + id);
return R.ok(schemeInfo);
}
/**
* 保存方案和志愿信息
*
* @param schemeInfo 方案信息
* @param list 志愿信息
*/
@Transactional(rollbackFor = Exception.class)
public void saveSchemeAndVolunteer(SchemeInfo schemeInfo, List<Volunteer> list) {
//1、保存方案信息
int count = schemeMapper.add(schemeInfo);
if (count == 0) {
throw new RuntimeException("保存方案信息失败!");
}
//保存志愿信息
for (Volunteer volunteer : list) {
volunteer.setSchemeId(schemeInfo.getId());
volunteer.setType(schemeInfo.getType());
}
boolean bool = volunteerService.saveBatch(list);
if (!bool) {
throw new RuntimeException("保存志愿信息失败!");
}
}
/** /**
* 判断文件类型 * 判断文件类型
* *
...@@ -145,7 +115,7 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -145,7 +115,7 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
return false; return false;
} }
String substring = fileName.substring(fileName.lastIndexOf(".") + 1); String substring = fileName.substring(fileName.lastIndexOf(".") + 1);
if (substring.equals("xlsx") || substring.equals("xls")) { if ("xlsx".equals(substring) || "xls".equals(substring)) {
return true; return true;
} }
return false; return false;
......
package cn.wisenergy.service.common;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.*;
import cn.wisenergy.model.enums.CardStatus;
import cn.wisenergy.model.enums.PayType;
import cn.wisenergy.model.vo.AddLimitVo;
import cn.wisenergy.service.app.UserVolunteerService;
import cn.wisenergy.service.app.VolunteerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author 86187
* @ Description: 事务方法公共类
* @ Author : 86187
* @ Date : 2021/1/28 15:59
*/
@Component
@Slf4j
public class VolunteerManager {
@Autowired
private UserLimitMapper userLimitMapper;
@Autowired
private UserLimitRecordMapper userLimitRecordMapper;
@Autowired
private CardMapper cardMapper;
@Autowired
private PayRecordMapper payRecordMapper;
@Autowired
private SchemeRecordMapper schemeRecordMapper;
@Autowired
private UserVolunteerService userVolunteerService;
@Autowired
private UsersMapper usersMapper;
@Autowired
private ScoreInfoMapper scoreInfoMapper;
@Autowired
private SchemeMapper schemeMapper;
@Autowired
private VolunteerService volunteerService;
/**
* 更新用户查询信息并保存扣减记录
*
* @param userLimit 查询信息
* @return true or false
*/
@Transactional(rollbackFor = Exception.class)
public boolean updateLimitSaveRecord(UserLimit userLimit) {
//1、更新查询信息
int count = userLimitMapper.edit(userLimit);
if (count == 0) {
return false;
}
//2、保存扣减记录
UserLimitRecord userLimitRecord = new UserLimitRecord();
userLimitRecord.setMinusLimit(1);
userLimitRecord.setUserId(userLimit.getUserId());
int record = userLimitRecordMapper.add(userLimitRecord);
if (record == 0) {
return false;
}
return true;
}
/**
* 更新充值卡状态和用户查询次数及增加充值记录
*
* @param cardInfo 充值卡信息
* @param userLimit 用户查询次数信息
* @param addLimitVo 接口入参
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateLimitAndRecord(Price price, CardInfo cardInfo, UserLimit userLimit, AddLimitVo addLimitVo) {
//是充值卡
if (PayType.REFILL_CARD.getCode().equals(addLimitVo.getPayType())) {
//1、更新充值卡状态
cardInfo.setStatus(CardStatus.ALREADY_USED.getCode());
int count = cardMapper.updateById(cardInfo);
if (count == 0) {
return false;
}
//2、更新用户查询次数信息
int limit = userLimitMapper.edit(userLimit);
if (limit == 0) {
return false;
}
//3、保存充值记录
PayRecord payRecord = new PayRecord();
payRecord.setCardId(cardInfo.getId());
payRecord.setMoney(Integer.valueOf(cardInfo.getMoney()));
payRecord.setPayLimit(cardInfo.getLimit());
payRecord.setResult(0);
payRecord.setType(addLimitVo.getPayType());
payRecord.setUserId(addLimitVo.getUserId());
int pay = payRecordMapper.add(payRecord);
if (pay == 0) {
return false;
}
} else {
//1、更新用户查询次数信息
int limit = userLimitMapper.edit(userLimit);
if (limit == 0) {
return false;
}
//2、保存充值记录
PayRecord payRecord = new PayRecord();
payRecord.setCardId(null);
payRecord.setMoney(addLimitVo.getPayMoney());
payRecord.setPayLimit(price.getUseLimit());
payRecord.setResult(0);
payRecord.setType(addLimitVo.getPayType());
payRecord.setUserId(addLimitVo.getUserId());
int pay = payRecordMapper.add(payRecord);
if (pay == 0) {
return false;
}
}
return true;
}
/**
* 保存方案查询记录和关联关系
*
* @param user 用户信息
* @param list 志愿信息
* @return true 成功 false 失败
*/
@Transactional(rollbackFor = Exception.class)
public boolean saveUserVolunteer(User user, List<Volunteer> list, ScoreInfo scoreInfo, String name) {
//1、保存方案查询记录
SchemeQueryRecord schemeQueryRecord = new SchemeQueryRecord();
schemeQueryRecord.setMajorName(name);
schemeQueryRecord.setStudentType(user.getExamType());
schemeQueryRecord.setUserId(user.getId());
schemeQueryRecord.setIsDelete(0);
double score = scoreInfo.getCultureGrade() + scoreInfo.getMajorGrade();
schemeQueryRecord.setScore(String.valueOf(score));
List<Integer> ids = list.stream().map(Volunteer::getId).collect(Collectors.toList());
//保存方案查询记录
int count = schemeRecordMapper.add(schemeQueryRecord);
if (count == 0) {
return false;
}
List<UserVolunteer> volunteerList = new ArrayList<>();
for (Integer id : ids) {
UserVolunteer userVolunteer = new UserVolunteer();
userVolunteer.setSchemeRecordId(schemeQueryRecord.getId());
userVolunteer.setUserId(user.getId());
userVolunteer.setVolunteerId(id);
volunteerList.add(userVolunteer);
}
boolean bool = userVolunteerService.saveBatch(volunteerList);
if (!bool) {
return false;
}
return true;
}
/**
* 保存个人信息
* @param user 用户信息
* @param scoreInfo 成绩信息
* @return true or false
*/
@Transactional(rollbackFor = Exception.class)
public boolean updateAndSaveUserInfo(User user, ScoreInfo scoreInfo) {
//1、更新用户信息
int count = usersMapper.edit(user);
if (count == 0) {
return false;
}
//2、保存用户成绩信息
int save = scoreInfoMapper.add(scoreInfo);
if (save == 0) {
return false;
}
return true;
}
/**
* 编辑个人信息
* @param user 用户信息
* @param scoreInfo 成绩信息
* @return true or false
*/
@Transactional()
public boolean updateAndUserInfo(User user, ScoreInfo scoreInfo) {
//1、更新用户信息
int count = usersMapper.edit(user);
if (count == 0) {
return false;
}
//2、保存用户成绩信息
int save = scoreInfoMapper.edit(scoreInfo);
if (save == 0) {
return false;
}
return true;
}
/**
* 保存方案和志愿信息
*
* @param schemeInfo 方案信息
* @param list 志愿信息
*/
@Transactional(rollbackFor = Exception.class)
public void saveSchemeAndVolunteer(SchemeInfo schemeInfo, List<Volunteer> list) {
//1、保存方案信息
int count = schemeMapper.add(schemeInfo);
if (count == 0) {
throw new RuntimeException("保存方案信息失败!");
}
//保存志愿信息
for (Volunteer volunteer : list) {
volunteer.setSchemeId(schemeInfo.getId());
volunteer.setType(schemeInfo.getType());
}
boolean bool = volunteerService.saveBatch(list);
if (!bool) {
throw new RuntimeException("保存志愿信息失败!");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment