TBGoodsInfoServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package cn.com.lzt.goodsinfo.service.impl;
  2. import cn.com.lzt.goodsinfo.dao.TBGoodsDao;
  3. import cn.com.lzt.goodsinfo.entity.TBGoodsInfoEntity;
  4. import cn.com.lzt.goodsinfo.entity.TBGoodsRelatedUnitPriceEntity;
  5. import cn.com.lzt.goodsinfo.service.TBGoodsInfoServiceI;
  6. import cn.com.lzt.priceinfo.entity.TBPriceInfoEntity;
  7. import cn.com.lzt.stockinfo.entity.TBStockInfoEntity;
  8. import org.jeecgframework.core.common.exception.BusinessException;
  9. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  10. import org.jeecgframework.core.constant.Globals;
  11. import org.jeecgframework.core.util.MyBeanUtils;
  12. import org.jeecgframework.core.util.oConvertUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.UUID;
  20. @Service("tBGoodsInfoService")
  21. @Transactional
  22. public class TBGoodsInfoServiceImpl extends CommonServiceImpl implements TBGoodsInfoServiceI {
  23. @Autowired
  24. private TBGoodsDao TBGoodsDao;
  25. public <T> void delete(T entity) {
  26. super.delete(entity);
  27. //执行删除操作配置的sql增强
  28. this.doDelSql((TBGoodsInfoEntity)entity);
  29. }
  30. public void addMain(TBGoodsInfoEntity tBGoodsInfo,
  31. List<TBStockInfoEntity> tBStockInfoList,List<TBPriceInfoEntity> tBPriceInfoList,List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoList){
  32. //保存主信息
  33. this.save(tBGoodsInfo);
  34. /**保存-库存信息*/
  35. for(TBStockInfoEntity tBStockInfo:tBStockInfoList){
  36. //外键设置
  37. tBStockInfo.setGoodsId(tBGoodsInfo.getId());
  38. this.save(tBStockInfo);
  39. }
  40. /**保存-价格信息*/
  41. for(TBPriceInfoEntity tBPriceInfo:tBPriceInfoList){
  42. //外键设置
  43. tBPriceInfo.setGoodsId(tBGoodsInfo.getId());
  44. this.save(tBPriceInfo);
  45. }
  46. /**保存-供应商信息*/
  47. for(TBGoodsRelatedUnitPriceEntity tBPriceInfo:tBRelatedUnitPriceInfoList){
  48. //外键设置
  49. tBPriceInfo.setGoodsId(tBGoodsInfo.getId());
  50. this.save(tBPriceInfo);
  51. }
  52. //执行新增操作配置的sql增强
  53. this.doAddSql(tBGoodsInfo);
  54. }
  55. public void updateMain(TBGoodsInfoEntity tBGoodsInfo,
  56. List<TBStockInfoEntity> tBStockInfoList,List<TBPriceInfoEntity> tBPriceInfoList,List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoList) {
  57. //保存主表信息
  58. this.saveOrUpdate(tBGoodsInfo);
  59. //===================================================================================
  60. //获取参数
  61. Object id0 = tBGoodsInfo.getId();
  62. Object id1 = tBGoodsInfo.getId();
  63. //===================================================================================
  64. //1.查询出数据库的明细数据-库存信息
  65. String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? ";
  66. List<TBStockInfoEntity> tBStockInfoOldList = this.findHql(hql0,id0);
  67. //2.筛选更新明细数据-库存信息
  68. if(tBStockInfoList!=null&&tBStockInfoList.size()>0){
  69. for(TBStockInfoEntity oldE:tBStockInfoOldList){
  70. boolean isUpdate = false;
  71. for(TBStockInfoEntity sendE:tBStockInfoList){
  72. //需要更新的明细数据-库存信息
  73. if(oldE.getId().equals(sendE.getId())){
  74. try {
  75. MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE);
  76. this.saveOrUpdate(oldE);
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. throw new BusinessException(e.getMessage());
  80. }
  81. isUpdate= true;
  82. break;
  83. }
  84. }
  85. if(!isUpdate){
  86. //如果数据库存在的明细,前台没有传递过来则是删除-库存信息
  87. super.delete(oldE);
  88. }
  89. }
  90. //3.持久化新增的数据-库存信息
  91. for(TBStockInfoEntity tBStockInfo:tBStockInfoList){
  92. if(oConvertUtils.isEmpty(tBStockInfo.getId())){
  93. //外键设置
  94. tBStockInfo.setGoodsId(tBGoodsInfo.getId());
  95. this.save(tBStockInfo);
  96. }
  97. }
  98. }
  99. //===================================================================================
  100. //1.查询出数据库的明细数据-价格信息
  101. String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? ";
  102. List<TBPriceInfoEntity> tBPriceInfoOldList = this.findHql(hql1,id1);
  103. //2.筛选更新明细数据-价格信息
  104. if(tBPriceInfoList!=null&&tBPriceInfoList.size()>0){
  105. for(TBPriceInfoEntity oldE:tBPriceInfoOldList){
  106. boolean isUpdate = false;
  107. for(TBPriceInfoEntity sendE:tBPriceInfoList){
  108. //需要更新的明细数据-价格信息
  109. if(oldE.getId().equals(sendE.getId())){
  110. try {
  111. MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE);
  112. this.saveOrUpdate(oldE);
  113. } catch (Exception e) {
  114. e.printStackTrace();
  115. throw new BusinessException(e.getMessage());
  116. }
  117. isUpdate= true;
  118. break;
  119. }
  120. }
  121. if(!isUpdate){
  122. //如果数据库存在的明细,前台没有传递过来则是删除-价格信息
  123. super.delete(oldE);
  124. }
  125. }
  126. //3.持久化新增的数据-价格信息
  127. for(TBPriceInfoEntity tBPriceInfo:tBPriceInfoList){
  128. if(oConvertUtils.isEmpty(tBPriceInfo.getId())){
  129. //外键设置
  130. tBPriceInfo.setGoodsId(tBGoodsInfo.getId());
  131. this.save(tBPriceInfo);
  132. }
  133. }
  134. }
  135. //1.查询出数据库的明细数据-价格信息
  136. String hql2 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? ";
  137. List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoOldList = this.findHql(hql2,id1);
  138. //2.筛选更新明细数据-价格信息
  139. if(tBRelatedUnitPriceInfoList!=null&&tBRelatedUnitPriceInfoList.size()>0){
  140. for(TBGoodsRelatedUnitPriceEntity oldE:tBRelatedUnitPriceInfoOldList){
  141. boolean isUpdate = false;
  142. for(TBGoodsRelatedUnitPriceEntity sendE:tBRelatedUnitPriceInfoList){
  143. //需要更新的明细数据-价格信息
  144. if(oldE.getId().equals(sendE.getId())){
  145. try {
  146. MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE);
  147. this.saveOrUpdate(oldE);
  148. } catch (Exception e) {
  149. e.printStackTrace();
  150. throw new BusinessException(e.getMessage());
  151. }
  152. isUpdate= true;
  153. break;
  154. }
  155. }
  156. if(!isUpdate){
  157. //如果数据库存在的明细,前台没有传递过来则是删除-价格信息
  158. super.delete(oldE);
  159. }
  160. }
  161. //3.持久化新增的数据-价格信息
  162. for(TBGoodsRelatedUnitPriceEntity tBRelatedUnitPriceInfo:tBRelatedUnitPriceInfoList){
  163. if(oConvertUtils.isEmpty(tBRelatedUnitPriceInfo.getId())){
  164. //外键设置
  165. tBRelatedUnitPriceInfo.setGoodsId(tBGoodsInfo.getId());
  166. this.save(tBRelatedUnitPriceInfo);
  167. }
  168. }
  169. }
  170. //执行更新操作配置的sql增强
  171. this.doUpdateSql(tBGoodsInfo);
  172. }
  173. public void delMain(TBGoodsInfoEntity tBGoodsInfo) {
  174. //删除主表信息
  175. this.delete(tBGoodsInfo);
  176. //===================================================================================
  177. //获取参数
  178. Object id0 = tBGoodsInfo.getId();
  179. Object id1 = tBGoodsInfo.getId();
  180. //===================================================================================
  181. //删除-库存信息
  182. String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? ";
  183. List<TBStockInfoEntity> tBStockInfoOldList = this.findHql(hql0,id0);
  184. this.deleteAllEntitie(tBStockInfoOldList);
  185. //===================================================================================
  186. //删除-价格信息
  187. String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? ";
  188. List<TBPriceInfoEntity> tBPriceInfoOldList = this.findHql(hql1,id1);
  189. this.deleteAllEntitie(tBPriceInfoOldList);
  190. //删除-供应商信息
  191. String hql2 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? ";
  192. List<TBGoodsRelatedUnitPriceEntity> tBRelatedUnitPriceInfoOldList = this.findHql(hql2,id1);
  193. this.deleteAllEntitie(tBRelatedUnitPriceInfoOldList);
  194. }
  195. // 逻辑删除
  196. public void logicDelMain(TBGoodsInfoEntity tBGoodsInfo) {
  197. //逻辑删除主表信息
  198. this.updateEntitie(tBGoodsInfo);
  199. //===================================================================================
  200. //获取参数
  201. Object id0 = tBGoodsInfo.getId();
  202. Object id1 = tBGoodsInfo.getId();
  203. //===================================================================================
  204. //删除-库存信息
  205. String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? ";
  206. List<TBStockInfoEntity> tBStockInfoOldList = this.findHql(hql0,id0);
  207. if(tBStockInfoOldList!=null && tBStockInfoOldList.size()>0){
  208. for(TBStockInfoEntity stockInfo : tBStockInfoOldList){
  209. stockInfo.setDeleteFlag(Globals.Delete_Forbidden.toString());
  210. this.updateEntitie(stockInfo);
  211. }
  212. }
  213. //===================================================================================
  214. //删除-价格信息
  215. String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? ";
  216. List<TBPriceInfoEntity> tBPriceInfoOldList = this.findHql(hql1,id1);
  217. if(tBPriceInfoOldList!=null && tBPriceInfoOldList.size()>0){
  218. for(TBPriceInfoEntity priceInfo : tBPriceInfoOldList){
  219. priceInfo.setDeleteFlag(Globals.Delete_Forbidden.toString());
  220. this.updateEntitie(priceInfo);
  221. }
  222. }
  223. }
  224. /**
  225. * 默认按钮-sql增强-新增操作
  226. * @param t
  227. * @return
  228. */
  229. public boolean doAddSql(TBGoodsInfoEntity t){
  230. return true;
  231. }
  232. /**
  233. * 默认按钮-sql增强-更新操作
  234. * @param t
  235. * @return
  236. */
  237. public boolean doUpdateSql(TBGoodsInfoEntity t){
  238. return true;
  239. }
  240. /**
  241. * 默认按钮-sql增强-删除操作
  242. * @param t
  243. * @return
  244. */
  245. public boolean doDelSql(TBGoodsInfoEntity t){
  246. return true;
  247. }
  248. @Override
  249. public Map<String, Integer> commoditySpecificationsNum() {
  250. List<Map<String, String>> list = TBGoodsDao.commoditySpecificationsNum();
  251. Map<String, Integer> map1 = new HashMap<>();
  252. for (Map<String, String> map : list) {
  253. map1.put(String.valueOf(map.get("id")), Integer.parseInt(String.valueOf(map.get("commoditySpecificationsNum"))));
  254. }
  255. return map1;
  256. }
  257. /**
  258. * 替换sql中的变量
  259. * @param sql
  260. * @return
  261. */
  262. public String replaceVal(String sql,TBGoodsInfoEntity t){
  263. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  264. sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
  265. sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
  266. sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
  267. sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
  268. sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
  269. sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
  270. sql = sql.replace("#{goods_code}",String.valueOf(t.getGoodsCode()));
  271. sql = sql.replace("#{goods_name}",String.valueOf(t.getGoodsName()));
  272. sql = sql.replace("#{specification}",String.valueOf(t.getSpecification()));
  273. sql = sql.replace("#{belong_category}",String.valueOf(t.getBelongCategory()));
  274. sql = sql.replace("#{brand}",String.valueOf(t.getBrand()));
  275. sql = sql.replace("#{pricing_method}",String.valueOf(t.getPricingMethod()));
  276. sql = sql.replace("#{base_unit}",String.valueOf(t.getBaseUnit()));
  277. sql = sql.replace("#{purchase_unit}",String.valueOf(t.getPurchaseUnit()));
  278. sql = sql.replace("#{sales_unit}",String.valueOf(t.getSalesUnit()));
  279. sql = sql.replace("#{goods_desc}",String.valueOf(t.getGoodsDesc()));
  280. sql = sql.replace("#{status}",String.valueOf(t.getStatus()));
  281. sql = sql.replace("#{delete_flag}",String.valueOf(t.getDeleteFlag()));
  282. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  283. return sql;
  284. }
  285. }