TGoodsServiceImpl.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package com.ruoyi.basicData.service.impl;
  2. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  3. import com.ruoyi.basicData.domain.TGoods;
  4. import com.ruoyi.basicData.domain.TGoodsImport;
  5. import com.ruoyi.basicData.mapper.TGoodsMapper;
  6. import com.ruoyi.basicData.service.ITGoodsService;
  7. import com.ruoyi.common.constant.UserConstants;
  8. import com.ruoyi.common.core.domain.AjaxResult;
  9. import com.ruoyi.common.core.domain.entity.SysUser;
  10. import com.ruoyi.common.core.domain.model.LoginUser;
  11. import com.ruoyi.common.utils.DateUtils;
  12. import com.ruoyi.common.utils.SecurityUtils;
  13. import com.ruoyi.common.utils.StringUtils;
  14. import com.ruoyi.common.utils.poi.ExcelUtil;
  15. import com.ruoyi.reportManagement.domain.TWhgenleg;
  16. import com.ruoyi.reportManagement.mapper.TWhgenlegMapper;
  17. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsitems;
  18. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsitemsMapper;
  19. import org.springframework.beans.BeanUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import java.math.BigDecimal;
  26. import java.util.Date;
  27. import java.util.List;
  28. import java.util.Map;
  29. /**
  30. * 商品详情Service业务层处理
  31. *
  32. * @author ruoyi
  33. * @date 2020-12-11
  34. */
  35. @Service
  36. public class TGoodsServiceImpl implements ITGoodsService {
  37. @Autowired
  38. private TGoodsMapper tGoodsMapper;
  39. @Autowired
  40. private TWarehousebillsitemsMapper tWarehousebillsitemsMapper;
  41. @Autowired
  42. private TWhgenlegMapper tWhgenlegMapper;
  43. /**
  44. * 查询商品详情
  45. *
  46. * @param fId 商品详情ID
  47. * @return 商品详情
  48. */
  49. @Override
  50. public TGoods selectTGoodsById(Long fId) {
  51. return tGoodsMapper.selectTGoodsById(fId);
  52. }
  53. /**
  54. * 查询商品详情列表
  55. *
  56. * @param tGoods 商品详情
  57. * @return 商品详情
  58. */
  59. @Override
  60. public List<TGoods> selectTGoodsList(TGoods tGoods) {
  61. return tGoodsMapper.selectTGoodsList(tGoods);
  62. }
  63. /**
  64. * 新增商品详情
  65. *
  66. * @param tGoods 商品详情
  67. * @return 结果
  68. */
  69. @Override
  70. public int insertTGoods(TGoods tGoods) {
  71. tGoods.setCreateTime(DateUtils.getNowDate());
  72. tGoods.setCreateBy(SecurityUtils.getUsername());
  73. if (ObjectUtils.isNull(tGoods.getStockWarning())) {
  74. tGoods.setStockWarning(new BigDecimal(0));
  75. }
  76. return tGoodsMapper.insertTGoods(tGoods);
  77. }
  78. /**
  79. * 修改商品详情
  80. *
  81. * @param tGoods 商品详情
  82. * @return 结果
  83. */
  84. @Override
  85. public AjaxResult updateTGoods(TGoods tGoods) {
  86. if (tGoods.getfStatus() != null && tGoods.getfStatus().equals("1")) {
  87. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  88. tWarehousebillsitems.setfGoodsid(tGoods.getfId());
  89. List<TWarehousebillsitems> warehousebillsitemsList1 = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
  90. if (warehousebillsitemsList1 != null && !warehousebillsitemsList1.isEmpty()) {
  91. return AjaxResult.error("商品在库存总账有记录不可变更状态");
  92. }
  93. }
  94. /* TWhgenleg tWhgenleg = new TWhgenleg();
  95. tWhgenleg.setfGoodsid(tGoods.getfId());
  96. List<TWhgenleg> selectTWhgenlegList = tWhgenlegMapper.selectTWhgenlegV2(tWhgenleg);
  97. for (TWhgenleg selectTWhgenleg : selectTWhgenlegList) {
  98. if (ObjectUtils.isNotNull(selectTWhgenleg) && selectTWhgenleg.getfQtyblc().compareTo(new BigDecimal("0")) != 0) {
  99. return AjaxResult.error("该商品存在未出库库存,禁止修改");
  100. }
  101. }*/
  102. if (ObjectUtils.isNull(tGoods.getStockWarning())) {
  103. tGoods.setStockWarning(new BigDecimal(0));
  104. }
  105. tGoods.setUpdateTime(DateUtils.getNowDate());
  106. tGoods.setUpdateBy(SecurityUtils.getUsername());
  107. tGoodsMapper.updateTGoods(tGoods);
  108. return AjaxResult.success();
  109. }
  110. /**
  111. * 批量删除商品详情
  112. *
  113. * @param fIds 需要删除的商品详情ID
  114. * @return 结果
  115. */
  116. @Override
  117. @Transactional
  118. public AjaxResult deleteTGoodsByIds(Long[] fIds) {
  119. // return tGoodsMapper.deleteTGoodsByIds(fIds);
  120. int i = 1;
  121. for (Long id : fIds) {
  122. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  123. tWarehousebillsitems.setfGoodsid(id);
  124. List<TWarehousebillsitems> warehousebillsitemsList1 = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
  125. if (warehousebillsitemsList1 != null && !warehousebillsitemsList1.isEmpty()) {
  126. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  127. return AjaxResult.error("商品第" + i + "行 仓库有货物不可删除");
  128. }
  129. tGoodsMapper.deleteTGoodsById(id);
  130. i++;
  131. }
  132. return AjaxResult.success();
  133. }
  134. /**
  135. * 删除商品详情信息
  136. *
  137. * @param fId 商品详情ID
  138. * @return 结果
  139. */
  140. @Override
  141. public int deleteTGoodsById(Long fId) {
  142. return tGoodsMapper.deleteTGoodsById(fId);
  143. }
  144. @Override
  145. public String checkUFNoUnique(TGoods tGoods) {
  146. TGoods tGoods1 = tGoodsMapper.checkFNoUnique(tGoods.getfNo());
  147. if (StringUtils.isNotNull(tGoods1) && !tGoods1.getfId().equals(tGoods.getfId())) {
  148. return UserConstants.NOT_UNIQUE;
  149. }
  150. return UserConstants.UNIQUE;
  151. }
  152. @Override
  153. public String checkUFNnameUnique(TGoods tGoods) {
  154. TGoods tGoods1 = tGoodsMapper.checkUFNnameUnique(tGoods.getfName());
  155. if (StringUtils.isNotNull(tGoods1) && !tGoods1.getfId().equals(tGoods.getfId())) {
  156. return UserConstants.NOT_UNIQUE;
  157. }
  158. return UserConstants.UNIQUE;
  159. }
  160. @Override
  161. public List<Map<String, Object>> getGoodName() {
  162. return tGoodsMapper.getGoodName();
  163. }
  164. @Override
  165. public AjaxResult importGoods(MultipartFile file) {
  166. ExcelUtil<TGoodsImport> util = new ExcelUtil<>(TGoodsImport.class);
  167. try {
  168. LoginUser loginUser = SecurityUtils.getLoginUser();
  169. List<TGoodsImport> tCorpsImportList = util.importExcel(file.getInputStream());
  170. if (tCorpsImportList.isEmpty()) {
  171. throw new RuntimeException("导入数据为空");
  172. }
  173. for (TGoodsImport item : tCorpsImportList) {
  174. TGoods goods = new TGoods();
  175. BeanUtils.copyProperties(item, goods);
  176. if (UserConstants.NOT_UNIQUE.equals(this.checkUFNoUnique(goods))) {
  177. return AjaxResult.error("新增商品'" + goods.getfNo() + "'失败,编号已存在");
  178. } else if (UserConstants.NOT_UNIQUE.equals(this.checkUFNnameUnique(goods))) {
  179. return AjaxResult.error("新增商品'" + goods.getfName() + "'失败,名称已存在");
  180. }
  181. SysUser user = loginUser.getUser();
  182. TGoods tGoods1 = tGoodsMapper.checkFNoUnique(goods.getfNo());
  183. if (tGoods1 == null) {
  184. goods.setCreateTime(DateUtils.getNowDate());
  185. goods.setCreateBy(SecurityUtils.getUsername());
  186. if (ObjectUtils.isNull(goods.getStockWarning())) {
  187. goods.setStockWarning(new BigDecimal(0));
  188. }
  189. tGoodsMapper.insertTGoods(goods);
  190. } else {
  191. goods.setfId(tGoods1.getfId());
  192. goods.setUpdateBy(user.getUserName());
  193. goods.setUpdateTime(new Date());
  194. tGoodsMapper.updateTGoods(goods);
  195. }
  196. }
  197. } catch (Exception e) {
  198. e.printStackTrace();
  199. }
  200. return AjaxResult.success();
  201. }
  202. }