规格信息有商品不能删除

cloud-server
刘河平 2024-11-16 09:11:55 +08:00
parent cc37d9af04
commit bbf1bd502f
6 changed files with 40 additions and 1 deletions

View File

@ -36,6 +36,7 @@ public class RuleInfoResp extends BaseEntity {
* *
*/ */
private List<RuleAttrAddModel> ruleAttrList; private List<RuleAttrAddModel> ruleAttrList;
private Boolean dis;
public static RuleInfoResp infoBuild (RuleInfo ruleInfo, Function<Long, List<RuleAttrAddModel>> ruleAttrList) { public static RuleInfoResp infoBuild (RuleInfo ruleInfo, Function<Long, List<RuleAttrAddModel>> ruleAttrList) {
return RuleInfoResp.builder() return RuleInfoResp.builder()

View File

@ -130,4 +130,14 @@ public class RuleInfoController extends BaseController {
public Result<String> remove(@PathVariable List<Long> ids) { public Result<String> remove(@PathVariable List<Long> ids) {
return toAjax(ruleInfoService.removeBatchByIds(ids)); return toAjax(ruleInfoService.removeBatchByIds(ids));
} }
/**
*
*/
@GetMapping("have")
@ApiOperation("校验是否存在商品信息")
public Result have(Long id) {
return Result.success(ruleInfoService.have(id));
}
} }

View File

@ -22,4 +22,6 @@ public interface RuleInfoMapper extends BaseMapper<RuleInfo> {
void deleteRule(Long id); void deleteRule(Long id);
void addRuleAttrModel(@Param("id") Long id, @Param("name") String name, @Param("valueData") String substring); void addRuleAttrModel(@Param("id") Long id, @Param("name") String name, @Param("valueData") String substring);
Integer have(Long id);
} }

View File

@ -42,4 +42,6 @@ public interface RuleInfoService extends IService<RuleInfo> {
void edit(Long id, RuleAttrInfoReq ruleInfoEditReq); void edit(Long id, RuleAttrInfoReq ruleInfoEditReq);
Result have(Long id);
} }

View File

@ -2,6 +2,7 @@ package com.muyu.product.service.impl;
import java.util.List; import java.util.List;
import java.util.Objects;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -11,6 +12,7 @@ import com.muyu.common.core.utils.ObjUtils;
import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.AttributeInfo; import com.muyu.product.domain.AttributeInfo;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.RuleAttrInfo; import com.muyu.product.domain.RuleAttrInfo;
import com.muyu.product.domain.model.RuleAttrAddModel; import com.muyu.product.domain.model.RuleAttrAddModel;
import com.muyu.product.domain.model.RuleInfoAddModel; import com.muyu.product.domain.model.RuleInfoAddModel;
@ -20,6 +22,7 @@ import com.muyu.product.domain.req.RuleInfoQueryReq;
import com.muyu.product.domain.req.RuleInfoSaveReq; import com.muyu.product.domain.req.RuleInfoSaveReq;
import com.muyu.product.domain.resp.RuleGroupUpdResp; import com.muyu.product.domain.resp.RuleGroupUpdResp;
import com.muyu.product.domain.resp.RuleInfoResp; import com.muyu.product.domain.resp.RuleInfoResp;
import com.muyu.product.service.ProjectInfoService;
import com.muyu.product.service.RuleAttrInfoService; import com.muyu.product.service.RuleAttrInfoService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -45,6 +48,8 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo> i
private RuleAttrInfoService ruleAttrInfoService; private RuleAttrInfoService ruleAttrInfoService;
@Autowired @Autowired
private RuleInfoMapper ruleAttrInfoMapper; private RuleInfoMapper ruleAttrInfoMapper;
@Autowired
private ProjectInfoService projectInfoService;
/** /**
* *
@ -103,7 +108,14 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo> i
})) }))
.toList(); .toList();
boolean isPage = ruleInfoQueryReq.getParams().get("isPage") == null || Convert.toBool(ruleInfoQueryReq.getParams().get("isPage"), true); boolean isPage = ruleInfoQueryReq.getParams().get("isPage") == null || Convert.toBool(ruleInfoQueryReq.getParams().get("isPage"), true);
List<ProjectInfo> projectInfoList = projectInfoService.list();
for (ProjectInfo projectInfo : projectInfoList) {
for (RuleInfoResp ruleInfoResp : ruleInfoRespList) {
if (Objects.equals(projectInfo.getId(), ruleInfoResp.getId())){
ruleInfoResp.setDis(true);
}
}
}
return TableDataInfo.<RuleInfoResp>builder() return TableDataInfo.<RuleInfoResp>builder()
.rows(ruleInfoRespList) .rows(ruleInfoRespList)
.total(isPage ? new PageInfo<>(list).getTotal() : 0) .total(isPage ? new PageInfo<>(list).getTotal() : 0)
@ -173,4 +185,13 @@ public class RuleInfoServiceImpl extends ServiceImpl<RuleInfoMapper, RuleInfo> i
// } // }
} }
@Override
public Result have(Long id) {
Integer count = ruleAttrInfoMapper.have(id);
if (count>0){
return Result.error(400,"规格下有商品,无法删除");
}
return Result.success(count);
}
} }

View File

@ -53,4 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
INNER JOIN rule_attr_info ON rule_info.id = rule_attr_info.rule_id INNER JOIN rule_attr_info ON rule_info.id = rule_attr_info.rule_id
WHERE rule_info.`id`=#{id} WHERE rule_info.`id`=#{id}
</select> </select>
<select id="have" resultType="java.lang.Integer">
SELECT count(1) FROM project_info WHERE id=#{id}
</select>
</mapper> </mapper>