You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.0 KiB

5 months ago
  1. package com.lh.service;
  2. import com.lh.bean.CrowdfundingInfo;
  3. import com.lh.bean.Participant;
  4. import com.lh.exception.MyException;
  5. import com.lh.mapper.CrowdfundingMapper;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import java.util.List;
  10. @Service
  11. public class CrowdfundingServiceImpl implements CrowdfundingService {
  12. @Autowired
  13. private CrowdfundingMapper crowdfundingMapper;
  14. @Override
  15. public CrowdfundingInfo loadPage() {
  16. CrowdfundingInfo crowdfundingInfoList = crowdfundingMapper.loadPage();
  17. List<Participant> participants = crowdfundingMapper.queryCrowdUser(null);
  18. crowdfundingInfoList.setParticipantList(participants);
  19. return crowdfundingInfoList;
  20. }
  21. @Override
  22. public void updateTitle(String title) throws MyException {
  23. if (title.length() == 0) {
  24. throw new MyException("标题不能为空");
  25. }
  26. crowdfundingMapper.updateTitle(title);
  27. }
  28. @Override
  29. public void updateTarget(Integer target) throws MyException {
  30. //target不能为空
  31. if (target == null) {
  32. throw new MyException("目标不能为空");
  33. }
  34. //target只能输入数字且必须大于0
  35. if (target <= 0) {
  36. throw new MyException("目标必须大于0");
  37. }
  38. if (target.toString().matches("[0-9]+") == false) {
  39. throw new MyException("目标只能输入数字");
  40. }
  41. crowdfundingMapper.updateTarget(target);
  42. }
  43. @Override
  44. @Transactional(rollbackFor = Exception.class)
  45. public void addCrowdUser(Participant participant) throws MyException {
  46. //精网号重复
  47. if (crowdfundingMapper.queryCrowdUser(new Participant(null,participant.getJwcode(),null,null)) != null) {
  48. throw new MyException("精网号重复");
  49. }
  50. //精网号不能为空
  51. if (participant.getJwcode() == null) {
  52. throw new MyException("精网号不能为空");
  53. }
  54. //精网号不能为空
  55. if (participant.getIdentity() == null) {
  56. throw new MyException("身份不能为空");
  57. }
  58. crowdfundingMapper.updateNowNumber();
  59. crowdfundingMapper.addCrowdUser(participant);
  60. }
  61. @Override
  62. public void deleteCrowdUser(String jwcode) throws MyException {
  63. if (crowdfundingMapper.queryCrowdUser(new Participant(null,jwcode,null,null)) == null) {
  64. throw new MyException("删除失败,用户不存在");
  65. }
  66. List<Participant> participants = crowdfundingMapper.queryCrowdUser(new Participant(null, jwcode, null, null));
  67. Participant participant = participants.get(0);
  68. crowdfundingMapper.saveDeleteCrowdUser(participant);
  69. crowdfundingMapper.deleteCrowdUser(jwcode);
  70. }
  71. @Override
  72. public List<Participant> queryCrowdUser(Participant participant) {
  73. return crowdfundingMapper.queryCrowdUser(participant);
  74. }
  75. }