package cn.com.lzt.goodsinfo.service.impl; import cn.com.lzt.goodsinfo.dao.TBGoodsDao; import cn.com.lzt.goodsinfo.entity.TBGoodsInfoEntity; import cn.com.lzt.goodsinfo.entity.TBGoodsRelatedUnitPriceEntity; import cn.com.lzt.goodsinfo.service.TBGoodsInfoServiceI; import cn.com.lzt.priceinfo.entity.TBPriceInfoEntity; import cn.com.lzt.stockinfo.entity.TBStockInfoEntity; import org.jeecgframework.core.common.exception.BusinessException; import org.jeecgframework.core.common.service.impl.CommonServiceImpl; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.core.util.MyBeanUtils; import org.jeecgframework.core.util.oConvertUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @Service("tBGoodsInfoService") @Transactional public class TBGoodsInfoServiceImpl extends CommonServiceImpl implements TBGoodsInfoServiceI { @Autowired private TBGoodsDao TBGoodsDao; public void delete(T entity) { super.delete(entity); //执行删除操作配置的sql增强 this.doDelSql((TBGoodsInfoEntity)entity); } public void addMain(TBGoodsInfoEntity tBGoodsInfo, List tBStockInfoList,List tBPriceInfoList,List tBRelatedUnitPriceInfoList){ //保存主信息 this.save(tBGoodsInfo); /**保存-库存信息*/ for(TBStockInfoEntity tBStockInfo:tBStockInfoList){ //外键设置 tBStockInfo.setGoodsId(tBGoodsInfo.getId()); this.save(tBStockInfo); } /**保存-价格信息*/ for(TBPriceInfoEntity tBPriceInfo:tBPriceInfoList){ //外键设置 tBPriceInfo.setGoodsId(tBGoodsInfo.getId()); this.save(tBPriceInfo); } /**保存-供应商信息*/ for(TBGoodsRelatedUnitPriceEntity tBPriceInfo:tBRelatedUnitPriceInfoList){ //外键设置 tBPriceInfo.setGoodsId(tBGoodsInfo.getId()); this.save(tBPriceInfo); } //执行新增操作配置的sql增强 this.doAddSql(tBGoodsInfo); } public void updateMain(TBGoodsInfoEntity tBGoodsInfo, List tBStockInfoList,List tBPriceInfoList,List tBRelatedUnitPriceInfoList) { //保存主表信息 this.saveOrUpdate(tBGoodsInfo); //=================================================================================== //获取参数 Object id0 = tBGoodsInfo.getId(); Object id1 = tBGoodsInfo.getId(); //=================================================================================== //1.查询出数据库的明细数据-库存信息 String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? "; List tBStockInfoOldList = this.findHql(hql0,id0); //2.筛选更新明细数据-库存信息 if(tBStockInfoList!=null&&tBStockInfoList.size()>0){ for(TBStockInfoEntity oldE:tBStockInfoOldList){ boolean isUpdate = false; for(TBStockInfoEntity sendE:tBStockInfoList){ //需要更新的明细数据-库存信息 if(oldE.getId().equals(sendE.getId())){ try { MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE); this.saveOrUpdate(oldE); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(e.getMessage()); } isUpdate= true; break; } } if(!isUpdate){ //如果数据库存在的明细,前台没有传递过来则是删除-库存信息 super.delete(oldE); } } //3.持久化新增的数据-库存信息 for(TBStockInfoEntity tBStockInfo:tBStockInfoList){ if(oConvertUtils.isEmpty(tBStockInfo.getId())){ //外键设置 tBStockInfo.setGoodsId(tBGoodsInfo.getId()); this.save(tBStockInfo); } } } //=================================================================================== //1.查询出数据库的明细数据-价格信息 String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? "; List tBPriceInfoOldList = this.findHql(hql1,id1); //2.筛选更新明细数据-价格信息 if(tBPriceInfoList!=null&&tBPriceInfoList.size()>0){ for(TBPriceInfoEntity oldE:tBPriceInfoOldList){ boolean isUpdate = false; for(TBPriceInfoEntity sendE:tBPriceInfoList){ //需要更新的明细数据-价格信息 if(oldE.getId().equals(sendE.getId())){ try { MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE); this.saveOrUpdate(oldE); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(e.getMessage()); } isUpdate= true; break; } } if(!isUpdate){ //如果数据库存在的明细,前台没有传递过来则是删除-价格信息 super.delete(oldE); } } //3.持久化新增的数据-价格信息 for(TBPriceInfoEntity tBPriceInfo:tBPriceInfoList){ if(oConvertUtils.isEmpty(tBPriceInfo.getId())){ //外键设置 tBPriceInfo.setGoodsId(tBGoodsInfo.getId()); this.save(tBPriceInfo); } } } //1.查询出数据库的明细数据-价格信息 String hql2 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? "; List tBRelatedUnitPriceInfoOldList = this.findHql(hql2,id1); //2.筛选更新明细数据-价格信息 if(tBRelatedUnitPriceInfoList!=null&&tBRelatedUnitPriceInfoList.size()>0){ for(TBGoodsRelatedUnitPriceEntity oldE:tBRelatedUnitPriceInfoOldList){ boolean isUpdate = false; for(TBGoodsRelatedUnitPriceEntity sendE:tBRelatedUnitPriceInfoList){ //需要更新的明细数据-价格信息 if(oldE.getId().equals(sendE.getId())){ try { MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE); this.saveOrUpdate(oldE); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(e.getMessage()); } isUpdate= true; break; } } if(!isUpdate){ //如果数据库存在的明细,前台没有传递过来则是删除-价格信息 super.delete(oldE); } } //3.持久化新增的数据-价格信息 for(TBGoodsRelatedUnitPriceEntity tBRelatedUnitPriceInfo:tBRelatedUnitPriceInfoList){ if(oConvertUtils.isEmpty(tBRelatedUnitPriceInfo.getId())){ //外键设置 tBRelatedUnitPriceInfo.setGoodsId(tBGoodsInfo.getId()); this.save(tBRelatedUnitPriceInfo); } } } //执行更新操作配置的sql增强 this.doUpdateSql(tBGoodsInfo); } public void delMain(TBGoodsInfoEntity tBGoodsInfo) { //删除主表信息 this.delete(tBGoodsInfo); //=================================================================================== //获取参数 Object id0 = tBGoodsInfo.getId(); Object id1 = tBGoodsInfo.getId(); //=================================================================================== //删除-库存信息 String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? "; List tBStockInfoOldList = this.findHql(hql0,id0); this.deleteAllEntitie(tBStockInfoOldList); //=================================================================================== //删除-价格信息 String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? "; List tBPriceInfoOldList = this.findHql(hql1,id1); this.deleteAllEntitie(tBPriceInfoOldList); //删除-供应商信息 String hql2 = "from TBGoodsRelatedUnitPriceEntity where 1 = 1 AND gOODS_ID =? "; List tBRelatedUnitPriceInfoOldList = this.findHql(hql2,id1); this.deleteAllEntitie(tBRelatedUnitPriceInfoOldList); } // 逻辑删除 public void logicDelMain(TBGoodsInfoEntity tBGoodsInfo) { //逻辑删除主表信息 this.updateEntitie(tBGoodsInfo); //=================================================================================== //获取参数 Object id0 = tBGoodsInfo.getId(); Object id1 = tBGoodsInfo.getId(); //=================================================================================== //删除-库存信息 String hql0 = "from TBStockInfoEntity where 1 = 1 AND gOODS_ID =? "; List tBStockInfoOldList = this.findHql(hql0,id0); if(tBStockInfoOldList!=null && tBStockInfoOldList.size()>0){ for(TBStockInfoEntity stockInfo : tBStockInfoOldList){ stockInfo.setDeleteFlag(Globals.Delete_Forbidden.toString()); this.updateEntitie(stockInfo); } } //=================================================================================== //删除-价格信息 String hql1 = "from TBPriceInfoEntity where 1 = 1 AND gOODS_ID =? "; List tBPriceInfoOldList = this.findHql(hql1,id1); if(tBPriceInfoOldList!=null && tBPriceInfoOldList.size()>0){ for(TBPriceInfoEntity priceInfo : tBPriceInfoOldList){ priceInfo.setDeleteFlag(Globals.Delete_Forbidden.toString()); this.updateEntitie(priceInfo); } } } /** * 默认按钮-sql增强-新增操作 * @param t * @return */ public boolean doAddSql(TBGoodsInfoEntity t){ return true; } /** * 默认按钮-sql增强-更新操作 * @param t * @return */ public boolean doUpdateSql(TBGoodsInfoEntity t){ return true; } /** * 默认按钮-sql增强-删除操作 * @param t * @return */ public boolean doDelSql(TBGoodsInfoEntity t){ return true; } @Override public Map commoditySpecificationsNum() { List> list = TBGoodsDao.commoditySpecificationsNum(); Map map1 = new HashMap<>(); for (Map map : list) { map1.put(String.valueOf(map.get("id")), Integer.parseInt(String.valueOf(map.get("commoditySpecificationsNum")))); } return map1; } /** * 替换sql中的变量 * @param sql * @return */ public String replaceVal(String sql,TBGoodsInfoEntity t){ sql = sql.replace("#{id}",String.valueOf(t.getId())); sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName())); sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy())); sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate())); sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName())); sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy())); sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate())); sql = sql.replace("#{goods_code}",String.valueOf(t.getGoodsCode())); sql = sql.replace("#{goods_name}",String.valueOf(t.getGoodsName())); sql = sql.replace("#{specification}",String.valueOf(t.getSpecification())); sql = sql.replace("#{belong_category}",String.valueOf(t.getBelongCategory())); sql = sql.replace("#{brand}",String.valueOf(t.getBrand())); sql = sql.replace("#{pricing_method}",String.valueOf(t.getPricingMethod())); sql = sql.replace("#{base_unit}",String.valueOf(t.getBaseUnit())); sql = sql.replace("#{purchase_unit}",String.valueOf(t.getPurchaseUnit())); sql = sql.replace("#{sales_unit}",String.valueOf(t.getSalesUnit())); sql = sql.replace("#{goods_desc}",String.valueOf(t.getGoodsDesc())); sql = sql.replace("#{status}",String.valueOf(t.getStatus())); sql = sql.replace("#{delete_flag}",String.valueOf(t.getDeleteFlag())); sql = sql.replace("#{UUID}",UUID.randomUUID().toString()); return sql; } }