yangdamao 2 年之前
父節點
當前提交
76b6eff552

+ 9 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/goods/GoodsController.java

@@ -346,6 +346,15 @@ public class GoodsController extends BaseController {
         return toAjax(iGoodsService.goodsNodeCopyAddTenant(bo) ? 1 : 0);
     }
 
+    /**
+     * 商品讲义复制
+     */
+    @ApiOperation("商品讲义复制")
+    @PostMapping("/handouts/copy/add")
+    public AjaxResult<Void> goodsHandoutsCopyAddTenant(@RequestBody GoodsHandoutsCopyTenantBo bo) {
+        return toAjax(iGoodsService.goodsHandoutsCopyAddTenant(bo) ? 1 : 0);
+    }
+
     /**
      * 商品关系ID处理(全量复制后的处理方法)
      */

+ 13 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/mapper/CourseHandoutsMapper.java

@@ -27,4 +27,17 @@ public interface CourseHandoutsMapper extends BaseMapper<CourseHandouts> {
 
     @InterceptorIgnore(tenantLine = "true")
     CourseHandouts getHandoutsByTenant(@Param("encoder") String encoder,@Param("newTenantId") Long newTenantId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<Long> getGoodsIds(@Param("handoutsId") Long handoutsId,@Param("tenantId") Long tenantId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    void removeHandouts(@Param("handoutsId") Long handoutsId,@Param("tenantId") Long tenantId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    void removeHandoutsBusiness(@Param("handoutsId") Long handoutsId,@Param("tenantId") Long tenantId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    void removeHandoutsFile(@Param("handoutsId") Long handoutsId,@Param("tenantId") Long tenantId);
+
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/ICourseHandoutsService.java

@@ -57,4 +57,7 @@ public interface ICourseHandoutsService extends IService<CourseHandouts> {
 
     CourseHandouts getHandoutsByTenant(String encoder, Long newTenantId);
 
+    List<Long> getGoodsIds(Long handoutsId, Long tenantId);
+
+	void removeHandouts(Long handoutsId, Long tenantId);
 }

+ 12 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseHandoutsServiceImpl.java

@@ -325,5 +325,17 @@ public class CourseHandoutsServiceImpl extends ServiceImpl<CourseHandoutsMapper,
         return baseMapper.getHandoutsByTenant(encoder, newTenantId);
     }
 
+    @Override
+    public List<Long> getGoodsIds(Long handoutsId, Long tenantId) {
+        return baseMapper.getGoodsIds(handoutsId,tenantId);
+    }
+
+    @Override
+    public void removeHandouts(Long handoutsId, Long tenantId) {
+        baseMapper.removeHandouts(handoutsId, tenantId);
+        baseMapper.removeHandoutsBusiness(handoutsId, tenantId);
+        baseMapper.removeHandoutsFile(handoutsId, tenantId);
+    }
+
 
 }

+ 25 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/bo/GoodsHandoutsCopyTenantBo.java

@@ -0,0 +1,25 @@
+package com.zhongzheng.modules.goods.bo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author yangdamao
+ * @date 2022年12月28日 9:28
+ */
+@Data
+public class GoodsHandoutsCopyTenantBo implements Serializable {
+
+    @ApiModelProperty("机构ID")
+    private List<Long> tenantId;
+
+    @ApiModelProperty("讲义ID")
+    private Long handoutsId;
+
+    @ApiModelProperty("商品ID")
+    private Long goodsId;
+
+}

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/mapper/GoodsMapper.java

@@ -75,4 +75,7 @@ public interface GoodsMapper extends BaseMapper<Goods> {
 
     @InterceptorIgnore(tenantLine = "true")
     Goods getGoodsByTenantTwo(@Param("goodsName") String goodsName,@Param("code") String code,@Param("tenantId") Long tenantId);
+
+    @InterceptorIgnore(tenantLine = "true")
+    void updateHandoutsId(@Param("goodsId") Long goodsId,@Param("tenantId") Long tenantId,@Param("handoutsId") Long handoutsId);
 }

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/service/IGoodsService.java

@@ -141,4 +141,5 @@ public interface IGoodsService extends IService<Goods> {
 
 	Goods queryGoodsByIdTenant(Long goodsId, Long tenantId);
 
+    boolean goodsHandoutsCopyAddTenant(GoodsHandoutsCopyTenantBo bo);
 }

+ 66 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/service/impl/GoodsServiceImpl.java

@@ -1789,6 +1789,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
         }
     }
 
+    @Override
     public boolean goodsCopyOne(GoodsBatchCopyTenantBo bo){
 
         log.info("一建商品复制开始:"+ DateUtils.getTime());
@@ -4882,6 +4883,71 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
         return baseMapper.queryGoodsByIdTenant(goodsId,tenantId);
     }
 
+    @Override
+    public boolean goodsHandoutsCopyAddTenant(GoodsHandoutsCopyTenantBo bo) {
+        CourseHandouts handouts = iCourseHandoutsService.getById(bo.getHandoutsId());
+        if (ObjectUtils.isNull(handouts)){
+            throw new CustomException("讲义不存在,请检查!");
+        }
+        List<SysGoodsCopyRecord> array = new ArrayList<>();
+
+        Long oldId = handouts.getHandoutsId();
+        Goods goods = getById(bo.getGoodsId());
+        for (Long tenantId : bo.getTenantId()) {
+            //讲义复制
+            Goods goodsTwo = baseMapper.getGoodsByTenantTwo(goods.getGoodsName(), goods.getCode(), tenantId);
+            if (ObjectUtils.isNull(goodsTwo)){
+                continue;
+            }
+           List<Long> goodsIds = iCourseHandoutsService.getGoodsIds(goodsTwo.getHandoutsId(),tenantId);
+            if (goodsIds.stream().allMatch(x -> x.equals(goodsTwo.getGoodsId()))){
+                //删除讲义
+                iCourseHandoutsService.removeHandouts(goodsTwo.getHandoutsId(),tenantId);
+            }
+
+            //新增
+            handouts.setHandoutsId(null);
+            handouts.setTenantId(tenantId);
+            iCourseHandoutsService.save(handouts);
+            Long newId = handouts.getHandoutsId();
+
+            //业务层次
+            List<CourseHandoutsBusiness> list = iCourseHandoutsBusinessService
+                    .list(new LambdaQueryWrapper<CourseHandoutsBusiness>()
+                    .eq(CourseHandoutsBusiness::getHandoutsId, oldId));
+            if (CollectionUtils.isNotEmpty(list)){
+                List<CourseHandoutsBusiness> collect = list.stream().map(business -> {
+                    business.setId(null);
+                    business.setTenantId(tenantId);
+                    //项目
+                    business.setEducationId(getNewEducationTypeId(business.getEducationId(), tenantId,array));
+                    //业务
+                    business.setBusinessId(getNewBusinessId(business.getBusinessId(), tenantId,array));
+                    //科目
+                    business.setSubjectId(getNewSubjectId(business.getSubjectId(), tenantId,array));
+                    //讲义
+                    business.setHandoutsId(newId);
+                    return business;
+                }).collect(Collectors.toList());
+                iCourseHandoutsBusinessService.saveBatch(collect);
+            }
+
+            //讲义文件
+            List<CourseFile> courseFileList = iCourseFileService.list(new LambdaQueryWrapper<CourseFile>().eq(CourseFile::getHandoutsId, oldId).eq(CourseFile::getStatus, 1));
+            if (CollectionUtils.isNotEmpty(courseFileList)){
+                //重新添加讲义文件
+                handleCourseFile(courseFileList,newId,tenantId);
+            }
+
+            updateHandoutsId(goodsTwo.getGoodsId(),tenantId,newId);
+        }
+        return true;
+    }
+
+    private void updateHandoutsId(Long goodsId, Long tenantId, Long handoutsId) {
+        baseMapper.updateHandoutsId(goodsId,tenantId,handoutsId);
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean updateGoodsRepair(UpdateGoodsRepairBo bo) {

+ 16 - 0
zhongzheng-system/src/main/resources/mapper/modules/course/CourseHandoutsMapper.xml

@@ -127,4 +127,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ORDER BY cf.sort
     </select>
 
+    <select id="getGoodsIds" parameterType="java.lang.Long"  resultType="java.lang.Long">
+        SELECT goods_id FROM goods WHERE handouts_id = #{handoutsId} AND `status` = 1 AND tenant_id = #{tenantId}
+    </select>
+
+    <delete id="removeHandouts" parameterType="java.lang.Long" >
+        DELETE FROM course_handouts WHERE handouts_id = #{handoutsId} AND tenant_id = #{tenantId}
+    </delete>
+
+    <delete id="removeHandoutsBusiness" parameterType="java.lang.Long" >
+        DELETE FROM course_handouts_business WHERE handouts_id = #{handoutsId} AND tenant_id = #{tenantId}
+    </delete>
+
+    <delete id="removeHandoutsFile" parameterType="java.lang.Long" >
+        DELETE FROM course_file WHERE handouts_id = #{handoutsId} AND tenant_id = #{tenantId}
+    </delete>
+
 </mapper>

+ 4 - 0
zhongzheng-system/src/main/resources/mapper/modules/goods/GoodsMapper.xml

@@ -935,4 +935,8 @@
               and g.tenant_id = #{tenantId}
     </select>
 
+    <update id="updateHandoutsId" parameterType="java.lang.Long">
+        UPDATE goods SET handouts_id = #{handoutsId} WHERE goods_id = #{goodsId} and tenant_id = #{tenantId}
+    </update>
+
 </mapper>