|
@@ -6,23 +6,19 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.PageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.web.work.api.util.AppUtil;
|
|
|
-import com.ruoyi.web.work.domain.Column;
|
|
|
-import com.ruoyi.web.work.domain.Enterprise;
|
|
|
-import com.ruoyi.web.work.domain.Position;
|
|
|
-import com.ruoyi.web.work.domain.User;
|
|
|
+import com.ruoyi.web.work.domain.*;
|
|
|
import com.ruoyi.web.work.domain.dto.PositionDto;
|
|
|
import com.ruoyi.web.work.domain.dto.PositionQueryDto;
|
|
|
import com.ruoyi.web.work.domain.dto.PositionStateDto;
|
|
|
import com.ruoyi.web.work.domain.vo.PositionListVo;
|
|
|
import com.ruoyi.web.work.mapper.PositionMapper;
|
|
|
-import com.ruoyi.web.work.service.IColumnService;
|
|
|
-import com.ruoyi.web.work.service.IEnterpriseService;
|
|
|
-import com.ruoyi.web.work.service.IPositionService;
|
|
|
-import com.ruoyi.web.work.service.IUserService;
|
|
|
+import com.ruoyi.web.work.service.*;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -43,6 +39,9 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
@Autowired
|
|
|
private IUserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IPayService payService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<Position> selectList(Position position) {
|
|
|
return positionMapper.selectList(position);
|
|
@@ -88,14 +87,15 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
return AjaxResult.success(result);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public AjaxResult manageAdd(PositionDto dto) {
|
|
|
if (AppUtil.getUser().getIsAuthentication() != 1) {
|
|
|
return AjaxResult.error(7878, "发布全职或兼职需要实名认证");
|
|
|
}
|
|
|
- //如果发布全职需要审核企业信息通过才允许发布
|
|
|
+ User user = userService.getById(AppUtil.getUser().getId());
|
|
|
+ //全职
|
|
|
if (dto.getType() == 0) {
|
|
|
- User user=userService.getById(AppUtil.getUser().getId());
|
|
|
if (user.getType() != 1) {
|
|
|
return AjaxResult.error("只有企业用户才能发布全职");
|
|
|
}
|
|
@@ -103,11 +103,12 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
return AjaxResult.error(7979, "请先完成企业认证");
|
|
|
}
|
|
|
}
|
|
|
+ //兼职
|
|
|
if (dto.getType() == 1) {
|
|
|
- User user=userService.getById(AppUtil.getUser().getId());
|
|
|
- if(user.getMoney())
|
|
|
+ if (new BigDecimal(dto.getSalary()).compareTo(user.getMoney()) > 0) {
|
|
|
+ return AjaxResult.error(8080, "余额不足请先充值");
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
Position position = new Position();
|
|
|
BeanUtils.copyProperties(dto, position);
|
|
|
Column region = columnService.selectRegion(new Column().setTitle(position.getRegionName()).setLevel(3));
|
|
@@ -125,7 +126,28 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
position.setAudit(1);
|
|
|
position.setRecommend(0);
|
|
|
if (!save(position)) {
|
|
|
- throw new ServiceException("发布职位失败");
|
|
|
+ throw new ServiceException("发布职位失败,请联系平台");
|
|
|
+ }
|
|
|
+ //发布兼职更新账户和保存支出记录
|
|
|
+ if (dto.getType() == 1) {
|
|
|
+ //更新用户账户余额
|
|
|
+ user.setMoney(user.getMoney().subtract(new BigDecimal(dto.getSalary())));
|
|
|
+ if (!userService.updateById(user)) {
|
|
|
+ throw new ServiceException("更新账户余额失败,请联系平台");
|
|
|
+ }
|
|
|
+ //添加支出记录
|
|
|
+ Pay pay = new Pay();
|
|
|
+ pay.setUserId(user.getId());
|
|
|
+ pay.setMoney(new BigDecimal(dto.getSalary()));
|
|
|
+ pay.setState(1);
|
|
|
+ pay.setType(1);
|
|
|
+ pay.setTitle(position.getTitle());
|
|
|
+ pay.setVersion(System.currentTimeMillis());
|
|
|
+ pay.setPositionId(position.getId());
|
|
|
+ pay.setNums(StringUtils.generateNumber());
|
|
|
+ if (!payService.save(pay)) {
|
|
|
+ throw new ServiceException("保存支出记录失败,请联系平台");
|
|
|
+ }
|
|
|
}
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
@@ -166,6 +188,7 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
return AjaxResult.success(position);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public AjaxResult manageRemove(Long id) {
|
|
|
Position position = getById(id);
|
|
@@ -175,6 +198,27 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
if (!removeById(id)) {
|
|
|
throw new ServiceException("删除职位失败,请联系平台");
|
|
|
}
|
|
|
+ //删除兼职退回余额
|
|
|
+ if (position.getType() == 1) {
|
|
|
+ User user = userService.getById(position.getUserId());
|
|
|
+ user.setMoney(user.getMoney().add(new BigDecimal(position.getSalary())));
|
|
|
+ if (!userService.updateById(user)) {
|
|
|
+ throw new ServiceException("更新账户余额失败,请联系平台");
|
|
|
+ }
|
|
|
+ //添加退回记录
|
|
|
+ Pay pay = new Pay();
|
|
|
+ pay.setUserId(user.getId());
|
|
|
+ pay.setMoney(new BigDecimal(position.getSalary()));
|
|
|
+ pay.setState(1);
|
|
|
+ pay.setType(4);
|
|
|
+ pay.setTitle(position.getTitle());
|
|
|
+ pay.setVersion(System.currentTimeMillis());
|
|
|
+ pay.setPositionId(position.getId());
|
|
|
+ pay.setNums(StringUtils.generateNumber());
|
|
|
+ if (!payService.save(pay)) {
|
|
|
+ throw new ServiceException("保存退回记录失败,请联系平台");
|
|
|
+ }
|
|
|
+ }
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
@@ -184,6 +228,9 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
if (position == null || !position.getUserId().equals(AppUtil.getUser().getId())) {
|
|
|
return AjaxResult.error("职位不存在或非法操作");
|
|
|
}
|
|
|
+ if (dto.getType() == 1) {
|
|
|
+ return AjaxResult.error("兼职不允许关闭");
|
|
|
+ }
|
|
|
position.setState(dto.getState());
|
|
|
if (!updateById(position)) {
|
|
|
throw new ServiceException("启用或关闭职位失败,请联系平台");
|