13 changed files with 522 additions and 84 deletions
@ -0,0 +1,189 @@ |
|||||
|
package com.qs.serve.modules.bms.controller; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.qs.serve.common.model.annotation.SysLog; |
||||
|
import com.qs.serve.common.model.dto.PageVo; |
||||
|
import com.qs.serve.common.model.dto.R; |
||||
|
import com.qs.serve.common.model.enums.BizType; |
||||
|
import com.qs.serve.common.model.enums.SystemModule; |
||||
|
import com.qs.serve.common.util.*; |
||||
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
||||
|
import com.qs.serve.modules.bms.entity.bo.BmsRegionBatchBo; |
||||
|
import com.qs.serve.modules.bms.entity.vo.BmsRegionTreeVo; |
||||
|
import com.qs.serve.modules.bms.service.BmsFactoryService; |
||||
|
import com.qs.serve.modules.bms.service.BmsRegion2Service; |
||||
|
import com.qs.serve.modules.bms.service.BmsRuleRegionService; |
||||
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.validation.Valid; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 基础档案 行政区域 |
||||
|
* @author YenHex |
||||
|
* @since 2022-10-10 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@AllArgsConstructor |
||||
|
@RestController |
||||
|
@RequestMapping("bms/bizRegion") |
||||
|
public class BmsRegion2Controller { |
||||
|
|
||||
|
private BmsRegion2Service BmsRegion2Service; |
||||
|
private BmsSupplierService bmsSupplierService; |
||||
|
private BmsRuleRegionService bmsRuleRegionService; |
||||
|
|
||||
|
/** |
||||
|
* 列表 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/list") |
||||
|
@PreAuthorize("hasRole('bms:region:query')") |
||||
|
public R<List<BmsRegion2>> getList(BmsRegion2 param){ |
||||
|
LambdaQueryWrapper<BmsRegion2> regionWrapper = new LambdaQueryWrapper<>(param); |
||||
|
List<BmsRegion2> list = BmsRegion2Service.list(regionWrapper); |
||||
|
return R.ok(list); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 翻页查询 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/page") |
||||
|
@PreAuthorize("hasRole('bms:region:query')") |
||||
|
public R<PageVo<BmsRegion2>> getPage(BmsRegion2 param){ |
||||
|
PageUtil.startPage(); |
||||
|
LambdaQueryWrapper<BmsRegion2> regionWrapper = new LambdaQueryWrapper<>(param); |
||||
|
List<BmsRegion2> list = BmsRegion2Service.list(regionWrapper); |
||||
|
return R.byPageHelperList(list); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 树查询 |
||||
|
* @param param |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/tree") |
||||
|
@PreAuthorize("hasRole('bms:region:query')") |
||||
|
public R<List<BmsRegionTreeVo>> getTree(BmsRegion2 param){ |
||||
|
return R.ok(BmsRegion2Service.getTree(param)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据ID查询 |
||||
|
* @param id |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/getById/{id}") |
||||
|
@SysLog(module = SystemModule.BASE, title = "区域档案", biz = BizType.QUERY) |
||||
|
@PreAuthorize("hasRole('bms:region:query')") |
||||
|
public R<BmsRegion2> getById(@PathVariable("id") String id){ |
||||
|
BmsRegion2 BmsRegion2 = BmsRegion2Service.getById(id); |
||||
|
return R.ok(BmsRegion2); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新(只允许改名称) |
||||
|
* @param regionBo |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/updateById") |
||||
|
@SysLog(module = SystemModule.BASE, title = "区域档案", biz = BizType.UPDATE) |
||||
|
@PreAuthorize("hasRole('bms:region:update')") |
||||
|
public R<?> updateById(@RequestBody @Valid BmsRegionBatchBo.BmsRegionBo regionBo){ |
||||
|
BmsRegion2 param = new BmsRegion2(); |
||||
|
param.setId(regionBo.getId()); |
||||
|
param.setName(regionBo.getName()); |
||||
|
boolean result = BmsRegion2Service.updateById(param); |
||||
|
return R.isTrue(result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新工厂 |
||||
|
* @param regionBo |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/updateFactory") |
||||
|
@SysLog(module = SystemModule.BASE, title = "区域档案", biz = BizType.UPDATE) |
||||
|
@PreAuthorize("hasRole('bms:region:update')") |
||||
|
public R<?> updateFactory(@RequestBody BmsRegion2 regionBo){ |
||||
|
BmsRegion2 param = new BmsRegion2(); |
||||
|
param.setId(regionBo.getId()); |
||||
|
boolean result = BmsRegion2Service.updateById(param); |
||||
|
return R.isTrue(result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 新增区域档案 |
||||
|
* @param regionBo |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/save") |
||||
|
@SysLog(module = SystemModule.BASE, title = "区域档案", biz = BizType.INSERT) |
||||
|
@PreAuthorize("hasRole('bms:region:insert')") |
||||
|
public R<?> save(@RequestBody @Valid BmsRegionBatchBo.BmsRegionBo regionBo){ |
||||
|
BmsRegion2 param = CopierUtil.copy(regionBo,new BmsRegion2()); |
||||
|
if(param.getId()==null){ |
||||
|
param.setId(IdUtil.getSnowFlakeId()+""); |
||||
|
} |
||||
|
BmsRegion2Service.flushLevel(param); |
||||
|
boolean result = BmsRegion2Service.save(param); |
||||
|
return R.isTrue(result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* (批量)编辑(更新,只允许改名称) |
||||
|
* @param regionBo |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/editBatch") |
||||
|
@SysLog(module = SystemModule.BASE, title = "区域档案", biz = BizType.INSERT) |
||||
|
@PreAuthorize("hasRole('bms:region:insert')") |
||||
|
public R<?> editBatch(@RequestBody @Valid BmsRegionBatchBo regionBo){ |
||||
|
ValidateTools.valid(regionBo.getRegionList()); |
||||
|
for (BmsRegionBatchBo.BmsRegionBo BmsRegion2Bo : regionBo.getRegionList()) { |
||||
|
BmsRegion2 dbRegion = BmsRegion2Service.getByCode(BmsRegion2Bo.getCode()); |
||||
|
if(dbRegion==null){ |
||||
|
BmsRegion2 region = CopierUtil.copy(BmsRegion2Bo,new BmsRegion2()); |
||||
|
BmsRegion2Service.save(region); |
||||
|
}else { |
||||
|
BmsRegion2 param = new BmsRegion2(); |
||||
|
param.setId(BmsRegion2Bo.getId()); |
||||
|
param.setName(BmsRegion2Bo.getName()); |
||||
|
BmsRegion2Service.updateById(param); |
||||
|
} |
||||
|
} |
||||
|
BmsRegion2Service.flushAllLevel(); |
||||
|
return R.ok(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除区域档案 |
||||
|
* @param id |
||||
|
* @return |
||||
|
*/ |
||||
|
@DeleteMapping("/deleteById/{id}") |
||||
|
@SysLog(module = SystemModule.BASE, title = "区域档案", biz = BizType.DELETE) |
||||
|
@PreAuthorize("hasRole('bms:region:delete')") |
||||
|
public R<?> deleteById(@PathVariable("id") String id){ |
||||
|
if(BmsRegion2Service.listChild(id).size()>0){ |
||||
|
return R.error("含有子区域无法删除"); |
||||
|
} |
||||
|
//如果有供应商则不允许删除
|
||||
|
if(bmsSupplierService.listByRegionId(id).size()>0){ |
||||
|
return R.error("地区含有供应商无法删除"); |
||||
|
} |
||||
|
//删除商品限制
|
||||
|
bmsRuleRegionService.removeByRegionId(Long.parseLong(id)); |
||||
|
boolean result = BmsRegion2Service.removeById(id); |
||||
|
return R.isTrue(result); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,78 @@ |
|||||
|
package com.qs.serve.modules.bms.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import com.qs.serve.common.framework.mybatis.handler.meta.SplitStringTypeHandler; |
||||
|
import lombok.Data; |
||||
|
import org.apache.ibatis.type.JdbcType; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 区域档案 实体类 |
||||
|
* @author YenHex |
||||
|
* @since 2022-10-10 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName(value = "bms_region2") |
||||
|
public class BmsRegion2 implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** id */ |
||||
|
@TableId(type = IdType.INPUT) |
||||
|
private String id; |
||||
|
|
||||
|
/** 名称 */ |
||||
|
@Length(max = 20,message = "名称长度不能超过20字") |
||||
|
private String name; |
||||
|
|
||||
|
/** 编码 */ |
||||
|
@Length(max = 20,message = "编码长度不能超过20字") |
||||
|
private String code; |
||||
|
|
||||
|
/** 父级ID */ |
||||
|
@Length(max = 32,message = "父级ID长度不能超过32字") |
||||
|
private String pid; |
||||
|
|
||||
|
/** 层级 */ |
||||
|
private Integer level; |
||||
|
|
||||
|
/** 创建时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private LocalDateTime createTime; |
||||
|
|
||||
|
/** 创建人 */ |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private String createBy; |
||||
|
|
||||
|
/** 更新时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private LocalDateTime updateTime; |
||||
|
|
||||
|
/** 更新人 */ |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private String updateBy; |
||||
|
|
||||
|
/** 租户id */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String tenantId; |
||||
|
|
||||
|
/** 删除标识 */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private Boolean delFlag; |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,14 @@ |
|||||
|
package com.qs.serve.modules.bms.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
||||
|
|
||||
|
/** |
||||
|
* 区域档案 Mapper |
||||
|
* @author YenHex |
||||
|
* @date 2022-10-10 |
||||
|
*/ |
||||
|
public interface BmsRegion2Mapper extends BaseMapper<BmsRegion2> { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,30 @@ |
|||||
|
package com.qs.serve.modules.bms.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
||||
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
||||
|
import com.qs.serve.modules.bms.entity.vo.BmsRegionTreeVo; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 区域档案 服务接口 |
||||
|
* @author YenHex |
||||
|
* @date 2022-10-10 |
||||
|
*/ |
||||
|
public interface BmsRegion2Service extends IService<BmsRegion2> { |
||||
|
|
||||
|
List<BmsRegionTreeVo> getTree(BmsRegion2 param); |
||||
|
|
||||
|
List<BmsRegion2> listChild(String pid); |
||||
|
|
||||
|
BmsRegion2 getByCode(String code); |
||||
|
|
||||
|
void flushLevel(BmsRegion2 param); |
||||
|
|
||||
|
void flushAllLevel(); |
||||
|
|
||||
|
void updateLevel(String id,Integer level); |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,107 @@ |
|||||
|
package com.qs.serve.modules.bms.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.qs.serve.common.model.dto.TreeNode; |
||||
|
import com.qs.serve.common.util.*; |
||||
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
||||
|
import com.qs.serve.modules.bms.entity.vo.BmsRegionTreeVo; |
||||
|
import com.qs.serve.modules.bms.mapper.BmsRegion2Mapper; |
||||
|
import com.qs.serve.modules.bms.service.BmsRegion2Service; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 区域档案 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2022-10-10 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class BmsRegion2ServiceImpl extends ServiceImpl<BmsRegion2Mapper,BmsRegion2> implements BmsRegion2Service { |
||||
|
|
||||
|
@Override |
||||
|
public List<BmsRegionTreeVo> getTree(BmsRegion2 param) { |
||||
|
LambdaQueryWrapper<BmsRegion2> regionWrapper = new LambdaQueryWrapper<>(param); |
||||
|
List<BmsRegion2> list = this.list(regionWrapper); |
||||
|
List<BmsRegionTreeVo> treeVoList = list.stream().map(region->{ |
||||
|
BmsRegionTreeVo treeNode = CopierUtil.copy(region,new BmsRegionTreeVo()); |
||||
|
treeNode.setId(region.getId()); |
||||
|
treeNode.setParentId(region.getPid()); |
||||
|
treeNode.setSort(0); |
||||
|
return treeNode; |
||||
|
}).collect(Collectors.toList()); |
||||
|
return TreeUtil.buildByRecursive(treeVoList,TreeUtil.DEFAULT_PID_STRING); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<BmsRegion2> listChild(String pid) { |
||||
|
LambdaQueryWrapper<BmsRegion2> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(BmsRegion2::getPid,pid); |
||||
|
return this.list(lqw); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public BmsRegion2 getByCode(String code) { |
||||
|
LambdaQueryWrapper<BmsRegion2> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(BmsRegion2::getCode,code); |
||||
|
return this.getOne(lqw,false); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void flushLevel(BmsRegion2 param) { |
||||
|
if(StringUtils.hasText(param.getPid())){ |
||||
|
BmsRegion2 parent = this.getById(param.getPid()); |
||||
|
if(parent!=null){ |
||||
|
if(parent.getLevel()>2){ |
||||
|
Assert.throwEx("最高支持3层级"); |
||||
|
} |
||||
|
param.setLevel(parent.getLevel()+1); |
||||
|
}else { |
||||
|
param.setPid(null); |
||||
|
param.setLevel(1); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void flushAllLevel() { |
||||
|
List<BmsRegionTreeVo> treeVoList = this.getTree(new BmsRegion2()); |
||||
|
for (BmsRegionTreeVo firstTree : treeVoList) { |
||||
|
if(firstTree.getLevel()==null||firstTree.getLevel()!=1){ |
||||
|
this.updateLevel(firstTree.getId(),1); |
||||
|
} |
||||
|
if(CollectionUtil.isNotEmpty(firstTree.getChildren())){ |
||||
|
for (TreeNode secondTreeNode : firstTree.getChildren()) { |
||||
|
BmsRegionTreeVo secondTree = (BmsRegionTreeVo)secondTreeNode; |
||||
|
if(secondTree.getLevel()==null||secondTree.getLevel()!=2){ |
||||
|
this.updateLevel(secondTree.getId(),2); |
||||
|
} |
||||
|
if(CollectionUtil.isNotEmpty(secondTree.getChildren())){ |
||||
|
for (TreeNode thirdTreeNode : secondTree.getChildren()) { |
||||
|
BmsRegionTreeVo thirdTree = (BmsRegionTreeVo)thirdTreeNode; |
||||
|
if(thirdTree.getLevel()==null||thirdTree.getLevel()!=3){ |
||||
|
this.updateLevel(thirdTree.getId(),3); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public void updateLevel(String id, Integer level) { |
||||
|
BmsRegion2 param = new BmsRegion2(); |
||||
|
param.setId(id); |
||||
|
param.setLevel(level); |
||||
|
this.updateById(param); |
||||
|
} |
||||
|
} |
||||
|
|
@ -1,25 +0,0 @@ |
|||||
package com.qs.serve.modules.sys.entity.bo; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
|
|
||||
import javax.validation.constraints.NotNull; |
|
||||
|
|
||||
/** |
|
||||
* @author YenHex |
|
||||
* @since 2022/10/25 |
|
||||
*/ |
|
||||
@Data |
|
||||
public class SysRelateSuppliersParam3 { |
|
||||
|
|
||||
/** |
|
||||
* 删除传入空数组 |
|
||||
*/ |
|
||||
String[] userIds; |
|
||||
|
|
||||
/** |
|
||||
* 供应商id列表 |
|
||||
*/ |
|
||||
@NotNull |
|
||||
Long supplierId; |
|
||||
|
|
||||
} |
|
Loading…
Reference in new issue