ShShopMatService.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package com.bofeng.service;
  2. import com.baomidou.mybatisplus.toolkit.IdWorker;
  3. import com.bofeng.dao.ShShopMapper;
  4. import com.bofeng.dao.ShShopMatMapper;
  5. import com.bofeng.entity.ShShopMat;
  6. import lombok.var;
  7. import org.joda.time.DateTime;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Propagation;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import java.util.List;
  13. @Service
  14. @Transactional(readOnly = true)
  15. public class ShShopMatService {
  16. @Autowired
  17. private ShShopMapper shShopMapper;
  18. @Autowired
  19. private ShShopMatMapper shShopMatMapper;
  20. // public List<QzTask> selectAll () {
  21. // return qzTaskDao.selectAll();
  22. // }
  23. //
  24. // public List<QzTask> queryByHouseNumber (String houseNumber, Integer status) {
  25. // return qzTaskDao.queryByHouseNumber(houseNumber, status);
  26. // }
  27. //
  28. // public QzTask queryByTaskId (Long taskId) {
  29. // return qzTaskDao.queryByTaskId(taskId);
  30. // }
  31. //商品的新增
  32. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  33. public int addShShopMat(Long userId, String matName, Integer matNum) throws Exception {
  34. DateTime dateTime = new DateTime();
  35. var shShopDb = shShopMapper.selectById(userId);
  36. if (null == shShopDb) {
  37. throw new Exception("发布失败");
  38. }
  39. var mat = new ShShopMat();
  40. mat.setMatId(IdWorker.getId());
  41. mat.setShopId(shShopDb.getShopId());
  42. mat.setMatName(matName);
  43. mat.setMatNum(matNum);
  44. mat.setStatus(1);
  45. /*long userId = Long.parseLong(JwtHelper.getUserId());
  46. qzTak.setUserId(userId);
  47. qzTak.setUserCreate(userId);*/
  48. mat.setTimeCreate(dateTime);
  49. /* qzTak.setUserUpdate(userId);*/
  50. mat.setTimeUpdate(dateTime);
  51. return shShopMatMapper.insert(mat);
  52. }
  53. //商品的修改
  54. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  55. public int editShShopMat(Long matId, String matName, Integer matNum) throws Exception {
  56. DateTime dateTime = new DateTime();
  57. // var shShopDb = shShopMapper.selectById(userId);
  58. // if (null == shShopDb) {
  59. // throw new Exception("发布失败");
  60. // }
  61. var shShopMatDb = shShopMatMapper.selectById(matId);
  62. if (null == shShopMatDb) {
  63. throw new Exception("修改失败");
  64. }
  65. shShopMatDb.setMatName(matName);
  66. shShopMatDb.setMatNum(matNum);
  67. shShopMatDb.setStatus(1);
  68. /*long userId = Long.parseLong(JwtHelper.getUserId());
  69. qzTak.setUserId(userId);
  70. qzTak.setUserCreate(userId);*/
  71. // mat.setTimeCreate(dateTime);
  72. /* qzTak.setUserUpdate(userId);*/
  73. shShopMatDb.setTimeUpdate(dateTime);
  74. return shShopMatMapper.updateById(shShopMatDb);
  75. }
  76. //商品的置顶2、下架0修改
  77. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  78. public int editShShopMatStatus(Long matId, Integer status) throws Exception {
  79. DateTime dateTime = new DateTime();
  80. // var shShopDb = shShopMapper.selectById(userId);
  81. // if (null == shShopDb) {
  82. // throw new Exception("发布失败");
  83. // }
  84. var shShopMatDb = shShopMatMapper.selectById(matId);
  85. if (null == shShopMatDb) {
  86. throw new Exception("修改失败");
  87. }
  88. shShopMatDb.setStatus(status);
  89. /*long userId = Long.parseLong(JwtHelper.getUserId());
  90. qzTak.setUserId(userId);
  91. qzTak.setUserCreate(userId);*/
  92. // mat.setTimeCreate(dateTime);
  93. /* qzTak.setUserUpdate(userId);*/
  94. shShopMatDb.setTimeUpdate(dateTime);
  95. return shShopMatMapper.updateById(shShopMatDb);
  96. }
  97. public List<ShShopMat> queryMyShShopMat(Long userId) throws Exception {
  98. var shShopDb = shShopMapper.selectById(userId);
  99. if (null == shShopDb) {
  100. throw new Exception("获取失败");
  101. }
  102. return shShopMatMapper.queryMyShShopMat(shShopDb.getShopId());
  103. }
  104. public List<ShShopMat> queryAllShShopMat() throws Exception {
  105. return shShopMatMapper.queryAllShShopMat();
  106. }
  107. }