商品模块代码提交
This commit is contained in:
parent
2c324221a9
commit
1642726452
|
|
@ -0,0 +1,118 @@
|
||||||
|
package com.czg.controller.admin;
|
||||||
|
|
||||||
|
import com.czg.log.annotation.OperationLog;
|
||||||
|
import com.czg.product.dto.ConsGroupDTO;
|
||||||
|
import com.czg.product.service.ConsGroupService;
|
||||||
|
import com.czg.resp.CzgResult;
|
||||||
|
import com.czg.utils.AssertUtil;
|
||||||
|
import com.czg.validator.group.DefaultGroup;
|
||||||
|
import com.czg.validator.group.InsertGroup;
|
||||||
|
import com.czg.validator.group.UpdateGroup;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/product/cons-group")
|
||||||
|
public class ConsGroupController {
|
||||||
|
private final ConsGroupService consGroupService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页
|
||||||
|
*/
|
||||||
|
@GetMapping("page")
|
||||||
|
@OperationLog("耗材分组-分页")
|
||||||
|
//@SaAdminCheckPermission("consGroup:page")
|
||||||
|
public CzgResult<Page<ConsGroupDTO>> getConsGroupPage(ConsGroupDTO param) {
|
||||||
|
Page<ConsGroupDTO> data = consGroupService.getConsGroupPage(param);
|
||||||
|
return CzgResult.success(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表
|
||||||
|
*/
|
||||||
|
@GetMapping("list")
|
||||||
|
@OperationLog("耗材分组-列表")
|
||||||
|
//@SaAdminCheckPermission("consGroup:list")
|
||||||
|
public CzgResult<List<ConsGroupDTO>> getConsGroupList(ConsGroupDTO param) {
|
||||||
|
List<ConsGroupDTO> data = consGroupService.getConsGroupList(param);
|
||||||
|
return CzgResult.success(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 详情
|
||||||
|
*
|
||||||
|
* @param id 分组id
|
||||||
|
*/
|
||||||
|
@GetMapping("{id}")
|
||||||
|
@OperationLog("耗材分组-详情")
|
||||||
|
//@SaAdminCheckPermission("consGroup:info")
|
||||||
|
public CzgResult<ConsGroupDTO> getConsGroupById(@PathVariable("id") Long id) {
|
||||||
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
|
ConsGroupDTO data = consGroupService.getConsGroupById(id);
|
||||||
|
return CzgResult.success(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@OperationLog("耗材分组-新增")
|
||||||
|
//@SaAdminCheckPermission("consGroup:add")
|
||||||
|
public CzgResult<Void> addConsGroup(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ConsGroupDTO dto) {
|
||||||
|
consGroupService.addConsGroup(dto);
|
||||||
|
return CzgResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
@OperationLog("耗材分组-修改")
|
||||||
|
//@SaAdminCheckPermission("consGroup:update")
|
||||||
|
public CzgResult<Void> updateConsGroup(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ConsGroupDTO dto) {
|
||||||
|
consGroupService.updateConsGroup(dto);
|
||||||
|
return CzgResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 禁用
|
||||||
|
*
|
||||||
|
* @param id 分组id
|
||||||
|
*/
|
||||||
|
@PostMapping("disable/{id}")
|
||||||
|
@OperationLog("耗材分组-禁用")
|
||||||
|
//@SaAdminCheckPermission("consGroup:able")
|
||||||
|
public CzgResult<Void> disableConsGroup(@PathVariable("id") Long id) {
|
||||||
|
//效验数据
|
||||||
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
|
consGroupService.disableConsGroup(id);
|
||||||
|
return CzgResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用
|
||||||
|
*
|
||||||
|
* @param id 分组id
|
||||||
|
*/
|
||||||
|
@PostMapping("enable/{id}")
|
||||||
|
@OperationLog("耗材分组-启用")
|
||||||
|
//@SaAdminCheckPermission("consGroup:able")
|
||||||
|
public CzgResult<Void> enableConsGroup(@PathVariable("id") Long id) {
|
||||||
|
//效验数据
|
||||||
|
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||||
|
consGroupService.enableConsGroup(id);
|
||||||
|
return CzgResult.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -87,7 +87,6 @@ public class ShopVendorController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
|
||||||
* @param id 供应商id
|
* @param id 供应商id
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("{id}")
|
@DeleteMapping("{id}")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.czg.product.dto;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import com.czg.validator.group.DefaultGroup;
|
||||||
|
import com.czg.validator.group.InsertGroup;
|
||||||
|
import com.czg.validator.group.UpdateGroup;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ConsGroupDTO implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@Null(message = "ID必须为空", groups = InsertGroup.class)
|
||||||
|
@NotNull(message = "ID不能为空", groups = UpdateGroup.class)
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 店铺id
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
/**
|
||||||
|
* 分组名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "分组名称不能为空", groups = DefaultGroup.class)
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 状态 1 正常 0 禁用
|
||||||
|
*/
|
||||||
|
@NotNull(message = "状态不能为空", groups = DefaultGroup.class)
|
||||||
|
@Min(value = 0, message = "状态值必须是0或1", groups = DefaultGroup.class)
|
||||||
|
@Max(value = 1, message = "状态值必须是0或1", groups = DefaultGroup.class)
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材id集合
|
||||||
|
*/
|
||||||
|
private List<Long> consIds;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.czg.product.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组关联关系
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ConsGroupRelationDTO implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组 id
|
||||||
|
*/
|
||||||
|
private Long groupId;
|
||||||
|
/**
|
||||||
|
* 耗材 Id
|
||||||
|
*/
|
||||||
|
private Long consId;
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.czg.product.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Column;
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table("tb_cons_group")
|
||||||
|
public class ConsGroup implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 店铺id
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
/**
|
||||||
|
* 分组名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 状态 1 正常 0 禁用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.czg.product.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组关联关系
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table("tb_cons_group_relation")
|
||||||
|
public class ConsGroupRelation implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组 id
|
||||||
|
*/
|
||||||
|
@Id(keyType = KeyType.None)
|
||||||
|
private Long groupId;
|
||||||
|
/**
|
||||||
|
* 耗材 Id
|
||||||
|
*/
|
||||||
|
@Id(keyType = KeyType.None)
|
||||||
|
private Long consId;
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.czg.product.service;
|
||||||
|
|
||||||
|
import com.czg.product.entity.ConsGroupRelation;
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组关联关系
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
public interface ConsGroupRelationService extends IService<ConsGroupRelation> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.czg.product.service;
|
||||||
|
|
||||||
|
import com.czg.product.dto.ConsGroupDTO;
|
||||||
|
import com.czg.product.entity.ConsGroup;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
public interface ConsGroupService extends IService<ConsGroup> {
|
||||||
|
Page<ConsGroupDTO> getConsGroupPage(ConsGroupDTO param);
|
||||||
|
|
||||||
|
List<ConsGroupDTO> getConsGroupList(ConsGroupDTO param);
|
||||||
|
|
||||||
|
ConsGroupDTO getConsGroupById(Long id);
|
||||||
|
|
||||||
|
boolean addConsGroup(ConsGroupDTO dto);
|
||||||
|
|
||||||
|
boolean updateConsGroup(ConsGroupDTO dto);
|
||||||
|
|
||||||
|
boolean deleteConsGroup(Long id);
|
||||||
|
|
||||||
|
boolean disableConsGroup(Long id);
|
||||||
|
|
||||||
|
boolean enableConsGroup(Long id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.czg.service.product.mapper;
|
||||||
|
|
||||||
|
import com.czg.product.entity.ConsGroup;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ConsGroupMapper extends BaseMapper<ConsGroup> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.czg.service.product.mapper;
|
||||||
|
|
||||||
|
import com.czg.product.entity.ConsGroupRelation;
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组关联关系
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ConsGroupRelationMapper extends BaseMapper<ConsGroupRelation> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.czg.service.product.service.impl;
|
||||||
|
|
||||||
|
import com.czg.product.entity.ConsGroupRelation;
|
||||||
|
import com.czg.product.service.ConsGroupRelationService;
|
||||||
|
import com.czg.service.product.mapper.ConsGroupRelationMapper;
|
||||||
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组关联关系
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ConsGroupRelationServiceImpl extends ServiceImpl<ConsGroupRelationMapper, ConsGroupRelation> implements ConsGroupRelationService {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,152 @@
|
||||||
|
package com.czg.service.product.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.czg.enums.StatusEnum;
|
||||||
|
import com.czg.exception.CzgException;
|
||||||
|
import com.czg.product.dto.ConsGroupDTO;
|
||||||
|
import com.czg.product.entity.ConsGroup;
|
||||||
|
import com.czg.product.entity.ConsGroupRelation;
|
||||||
|
import com.czg.product.service.ConsGroupService;
|
||||||
|
import com.czg.sa.StpKit;
|
||||||
|
import com.czg.service.product.mapper.ConsGroupMapper;
|
||||||
|
import com.czg.service.product.mapper.ConsGroupRelationMapper;
|
||||||
|
import com.czg.utils.PageUtil;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.core.update.UpdateChain;
|
||||||
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 耗材分组
|
||||||
|
*
|
||||||
|
* @author Tankaikai tankaikai@aliyun.com
|
||||||
|
* @since 1.0 2025-02-20
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class ConsGroupServiceImpl extends ServiceImpl<ConsGroupMapper, ConsGroup> implements ConsGroupService {
|
||||||
|
|
||||||
|
private final ConsGroupRelationMapper consGroupRelationMapper;
|
||||||
|
|
||||||
|
private QueryWrapper buildQueryWrapper(ConsGroupDTO param) {
|
||||||
|
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||||
|
if (StrUtil.isNotEmpty(param.getName())) {
|
||||||
|
queryWrapper.like(ConsGroup::getName, param.getName());
|
||||||
|
}
|
||||||
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
queryWrapper.eq(ConsGroup::getShopId, shopId);
|
||||||
|
queryWrapper.orderBy(ConsGroup::getId, false);
|
||||||
|
return queryWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<ConsGroupDTO> getConsGroupPage(ConsGroupDTO param) {
|
||||||
|
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||||
|
return super.pageAs(PageUtil.buildPage(), queryWrapper, ConsGroupDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ConsGroupDTO> getConsGroupList(ConsGroupDTO param) {
|
||||||
|
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||||
|
queryWrapper.eq(ConsGroup::getStatus, StatusEnum.ENABLED.value());
|
||||||
|
return super.listAs(queryWrapper, ConsGroupDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsGroupDTO getConsGroupById(Long id) {
|
||||||
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
ConsGroupDTO dto = super.getOneAs(query().eq(ConsGroup::getId, id).eq(ConsGroup::getShopId, shopId), ConsGroupDTO.class);
|
||||||
|
List<Long> consIds = consGroupRelationMapper.selectListByQueryAs(query().select(ConsGroupRelation::getConsId).eq(ConsGroupRelation::getGroupId, dto.getId()), Long.class);
|
||||||
|
dto.setConsIds(consIds);
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean addConsGroup(ConsGroupDTO dto) {
|
||||||
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
boolean exists = super.exists(query().eq(ConsGroup::getName, dto.getName()).eq(ConsGroup::getShopId, shopId));
|
||||||
|
if (exists) {
|
||||||
|
throw new CzgException("耗材分组已存在");
|
||||||
|
}
|
||||||
|
ConsGroup entity = BeanUtil.copyProperties(dto, ConsGroup.class);
|
||||||
|
entity.setStatus(StatusEnum.ENABLED.value());
|
||||||
|
entity.setShopId(shopId);
|
||||||
|
super.save(entity);
|
||||||
|
List<Long> consIds = dto.getConsIds();
|
||||||
|
if (CollUtil.isEmpty(consIds)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int index = 0;
|
||||||
|
for (Long consId : consIds) {
|
||||||
|
index++;
|
||||||
|
ConsGroupRelation relation = new ConsGroupRelation();
|
||||||
|
relation.setConsId(consId);
|
||||||
|
relation.setGroupId(entity.getId());
|
||||||
|
relation.setSort(index);
|
||||||
|
consGroupRelationMapper.insert(relation);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateConsGroup(ConsGroupDTO dto) {
|
||||||
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
dto.setShopId(shopId);
|
||||||
|
boolean exists = super.exists(query().eq(ConsGroup::getName, dto.getName()).eq(ConsGroup::getShopId, shopId).ne(ConsGroup::getId, dto.getId()));
|
||||||
|
if (exists) {
|
||||||
|
throw new CzgException("耗材分组已存在");
|
||||||
|
}
|
||||||
|
ConsGroup entity = BeanUtil.copyProperties(dto, ConsGroup.class);
|
||||||
|
super.updateById(entity);
|
||||||
|
List<Long> consIds = dto.getConsIds();
|
||||||
|
if (CollUtil.isEmpty(consIds)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
consGroupRelationMapper.deleteByQuery(query().eq(ConsGroupRelation::getGroupId, entity.getId()));
|
||||||
|
int index = 0;
|
||||||
|
for (Long consId : consIds) {
|
||||||
|
index++;
|
||||||
|
ConsGroupRelation relation = new ConsGroupRelation();
|
||||||
|
relation.setConsId(consId);
|
||||||
|
relation.setGroupId(entity.getId());
|
||||||
|
relation.setSort(index);
|
||||||
|
consGroupRelationMapper.insert(relation);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteConsGroup(Long id) {
|
||||||
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
return super.remove(query().eq(ConsGroup::getId, id).eq(ConsGroup::getShopId, shopId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disableConsGroup(Long id) {
|
||||||
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
return UpdateChain.of(ConsGroup.class)
|
||||||
|
.set(ConsGroup::getStatus, StatusEnum.DISABLE.value())
|
||||||
|
.eq(ConsGroup::getId, id)
|
||||||
|
.eq(ConsGroup::getShopId, shopId)
|
||||||
|
.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enableConsGroup(Long id) {
|
||||||
|
Long shopId = StpKit.USER.getLoginIdAsLong();
|
||||||
|
return UpdateChain.of(ConsGroup.class)
|
||||||
|
.set(ConsGroup::getStatus, StatusEnum.ENABLED.value())
|
||||||
|
.eq(ConsGroup::getId, id)
|
||||||
|
.eq(ConsGroup::getShopId, shopId)
|
||||||
|
.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
|
<mapper namespace="com.czg.service.product.mapper.ConsGroupMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
|
<mapper namespace="com.czg.service.product.mapper.ConsGroupRelationMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue