mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
添加库存商品属性
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package cn.lihongjie.coal.orderNoRule.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.CreateOrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.OrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.UpdateOrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.service.OrderNoRuleService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/orderNoRule")
|
||||
@SysLog(module = "单号生成规则")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class OrderNoRuleController {
|
||||
@Autowired private OrderNoRuleService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public OrderNoRuleDto create(@RequestBody CreateOrderNoRuleDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public OrderNoRuleDto update(@RequestBody UpdateOrderNoRuleDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public OrderNoRuleDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<OrderNoRuleDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/initDefault")
|
||||
public Boolean initDefault() {
|
||||
this.service.initDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.orderNoRule.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateOrderNoRuleDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.orderNoRule.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OrderNoRuleDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.orderNoRule.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateOrderNoRuleDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.lihongjie.coal.orderNoRule.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_orderNoRule_org_id",
|
||||
columnList = "organization_id"))
|
||||
public class OrderNoRuleEntity extends OrgCommonEntity {
|
||||
|
||||
private String ruleTemplate;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.lihongjie.coal.orderNoRule.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.CreateOrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.OrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.UpdateOrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.entity.OrderNoRuleEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface OrderNoRuleMapper
|
||||
extends BaseMapper<
|
||||
OrderNoRuleEntity, OrderNoRuleDto, CreateOrderNoRuleDto, UpdateOrderNoRuleDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.orderNoRule.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.orderNoRule.entity.OrderNoRuleEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface OrderNoRuleRepository extends BaseRepository<OrderNoRuleEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package cn.lihongjie.coal.orderNoRule.service;
|
||||
|
||||
import cn.lihongjie.coal.orderNoRule.entity.OrderNoRuleEntity;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OrderNoGenService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private OrderNoRuleService orderNoRuleService;
|
||||
|
||||
|
||||
public String genOrderNo(String ruleCode, String orgId) {
|
||||
|
||||
log.info("生成订单号, 规则编码: {}, 机构: {}", ruleCode, orgId);
|
||||
|
||||
|
||||
List<OrderNoRuleEntity> all = orderNoRuleService.findAll(new Specification<OrderNoRuleEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<OrderNoRuleEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
||||
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
||||
predicates.add(criteriaBuilder.equal(root.get("code"), ruleCode));
|
||||
predicates.add(criteriaBuilder.equal(root.get("organizationId"), orgId));
|
||||
|
||||
|
||||
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (all.isEmpty()) {
|
||||
log.error("未找到规则: {}", ruleCode);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
OrderNoRuleEntity rule = all.get(0);
|
||||
|
||||
|
||||
|
||||
// RuleTemplateUtils.genNo(rule.getRuleTemplate(),
|
||||
// RuleTemplateUtils.CompositePlaceholderResolver.of(RuleTemplateUtils.DatePlaceholderResolver.INSTANCE,
|
||||
// RuleTemplateUtils.RandomPlaceholderResolver.INSTANCE,
|
||||
//
|
||||
//
|
||||
//
|
||||
// )
|
||||
|
||||
|
||||
// );
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package cn.lihongjie.coal.orderNoRule.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.Ctx;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.CreateOrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.OrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.dto.UpdateOrderNoRuleDto;
|
||||
import cn.lihongjie.coal.orderNoRule.entity.OrderNoRuleEntity;
|
||||
import cn.lihongjie.coal.orderNoRule.mapper.OrderNoRuleMapper;
|
||||
import cn.lihongjie.coal.orderNoRule.repository.OrderNoRuleRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class OrderNoRuleService extends BaseService<OrderNoRuleEntity, OrderNoRuleRepository> {
|
||||
@Autowired private OrderNoRuleRepository repository;
|
||||
|
||||
@Autowired private OrderNoRuleMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public OrderNoRuleDto create(CreateOrderNoRuleDto request) {
|
||||
OrderNoRuleEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public OrderNoRuleDto update(UpdateOrderNoRuleDto request) {
|
||||
OrderNoRuleEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public OrderNoRuleDto getById(String id) {
|
||||
OrderNoRuleEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<OrderNoRuleDto> list(CommonQuery query) {
|
||||
Page<OrderNoRuleEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
|
||||
public void initDefault() {
|
||||
initDefault(Ctx.currentUser().getOrganizationId());
|
||||
}
|
||||
|
||||
public void initDefault(String orgId){
|
||||
|
||||
// 删除原有的规则
|
||||
this.repository.deleteByOrganizationId(orgId);
|
||||
|
||||
|
||||
insertOne(orgId, "MTCG", "煤炭采购订单号规则", "MTCG{yyyyMMdd}{seq:4}");
|
||||
insertOne(orgId, "MTXS", "煤炭销售订单号规则", "MTXS{yyyyMMdd}{seq:4}");
|
||||
|
||||
/**
|
||||
* 库房相关
|
||||
*/
|
||||
insertOne(orgId, "KF_QTRKD", "库房其他入库单", "QTRKD{yyyyMMdd}{seq:4}");
|
||||
insertOne(orgId, "KF_QTCKD", "库房其他出库单", "QTCKD{yyyyMMdd}{seq:4}");
|
||||
insertOne(orgId, "KF_RKD", "库房入库单", "RKD{yyyyMMdd}{seq:4}");
|
||||
insertOne(orgId, "KF_CKD", "库房出库单", "CKD{yyyyMMdd}{seq:4}");
|
||||
insertOne(orgId, "KF_PDD", "库房盘点单", "PDD{yyyyMMdd}{seq:4}");
|
||||
|
||||
}
|
||||
|
||||
private void insertOne(String orgId, String code, String name, String ruleTemplate) {
|
||||
OrderNoRuleEntity rule = new OrderNoRuleEntity();
|
||||
rule.setOrganizationId(orgId);
|
||||
rule.setRuleTemplate(ruleTemplate);
|
||||
rule.setName(name);
|
||||
rule.setCode(code);
|
||||
rule.setStatus(1);
|
||||
this.save(rule);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package cn.lihongjie.coal.orderNoRule.service;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
@UtilityClass
|
||||
public class RuleTemplateUtils {
|
||||
|
||||
public static String genNo(String template, PlaceholderResolver resolver, ResolveContext context) {
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
int length = template.length();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
char c = template.charAt(i);
|
||||
|
||||
if (c == '{') {
|
||||
|
||||
StringBuilder placeholder = new StringBuilder();
|
||||
|
||||
i++;
|
||||
|
||||
while (i < length) {
|
||||
|
||||
char c1 = template.charAt(i);
|
||||
|
||||
if (c1 == '}') {
|
||||
break;
|
||||
}
|
||||
|
||||
placeholder.append(c1);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (resolver.support(placeholder.toString())) {
|
||||
|
||||
String resolved = resolver.resolve(placeholder.toString(), context);
|
||||
|
||||
result.append(resolved);
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("不支持的占位符: " + placeholder);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
result.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
// 聚合接口 聚合了多个 PlaceholderResolver
|
||||
|
||||
public interface PlaceholderResolver {
|
||||
|
||||
Boolean support(String placeholder);
|
||||
|
||||
String resolve(String placeholder, ResolveContext context);
|
||||
}
|
||||
|
||||
// 支持 java 日期时间格式化 的 PlaceholderResolver 比如 yyyy -> 2021
|
||||
|
||||
public static class CompositePlaceholderResolver implements PlaceholderResolver {
|
||||
|
||||
private List<PlaceholderResolver> resolvers = new ArrayList<>();
|
||||
|
||||
// 静态工厂方法, 从List中创建一个实例
|
||||
public static CompositePlaceholderResolver of(PlaceholderResolver... resolvers) {
|
||||
CompositePlaceholderResolver compositePlaceholderResolver =
|
||||
new CompositePlaceholderResolver();
|
||||
compositePlaceholderResolver.resolvers = Arrays.stream(resolvers).toList();
|
||||
return compositePlaceholderResolver;
|
||||
}
|
||||
|
||||
public CompositePlaceholderResolver add(PlaceholderResolver resolver) {
|
||||
resolvers.add(resolver);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean support(String placeholder) {
|
||||
return resolvers.stream().anyMatch(resolver -> resolver.support(placeholder));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(String placeholder, ResolveContext context) {
|
||||
return resolvers.stream()
|
||||
.filter(resolver -> resolver.support(placeholder))
|
||||
.findFirst()
|
||||
.get()
|
||||
.resolve(placeholder, context);
|
||||
}
|
||||
}
|
||||
|
||||
// 支持随机数的 PlaceholderResolver
|
||||
|
||||
public static class DatePlaceholderResolver implements PlaceholderResolver {
|
||||
|
||||
|
||||
// 单例
|
||||
public static final DatePlaceholderResolver INSTANCE = new DatePlaceholderResolver();
|
||||
|
||||
@Override
|
||||
public Boolean support(String placeholder) {
|
||||
try {
|
||||
|
||||
DateTimeFormatter.ofPattern(placeholder);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(String placeholder, ResolveContext context) {
|
||||
|
||||
return DateTimeFormatter.ofPattern(placeholder).format(context.getDateTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 生成上下文, 用于存储当前时间等变量
|
||||
|
||||
public static class RandomPlaceholderResolver implements PlaceholderResolver {
|
||||
|
||||
|
||||
// 单例
|
||||
public static final RandomPlaceholderResolver INSTANCE = new RandomPlaceholderResolver();
|
||||
|
||||
@Override
|
||||
public Boolean support(String placeholder) {
|
||||
return placeholder.startsWith("random");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolve(String placeholder, ResolveContext context) {
|
||||
|
||||
String[] split = placeholder.split(":");
|
||||
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("random 占位符格式错误");
|
||||
}
|
||||
|
||||
int length = Integer.parseInt(split[1]);
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.append(random.nextInt(10));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResolveContext {
|
||||
|
||||
private Map<String, Object> context = new HashMap<>();
|
||||
|
||||
|
||||
public ResolveContext() {
|
||||
this(new HashMap<>());
|
||||
}
|
||||
|
||||
public ResolveContext(Map<String, Object> context) {
|
||||
this.context = new HashMap<>(context);
|
||||
}
|
||||
|
||||
public LocalDateTime getDateTime() {
|
||||
return (LocalDateTime) context.get("dateTime");
|
||||
}
|
||||
|
||||
public void setDateTime(LocalDateTime dateTime) {
|
||||
context.put("dateTime", dateTime);
|
||||
}
|
||||
|
||||
public ResolveContext put(String key, Object value) {
|
||||
context.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object get(String key) {
|
||||
return context.get(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.controller;
|
||||
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.CreateWarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.UpdateWarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.WarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.service.WarehouseGoodsAttrService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/warehouseGoodsAttr")
|
||||
@SysLog(module = "仓库商品属性设置")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class WarehouseGoodsAttrController {
|
||||
@Autowired private WarehouseGoodsAttrService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public WarehouseGoodsAttrDto create(@RequestBody CreateWarehouseGoodsAttrDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public WarehouseGoodsAttrDto update(@RequestBody UpdateWarehouseGoodsAttrDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public WarehouseGoodsAttrDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<WarehouseGoodsAttrDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateWarehouseGoodsAttrDto extends OrgCommonDto {
|
||||
|
||||
@Comment("属性值")
|
||||
@Column(columnDefinition = "text[]")
|
||||
@Type(ListArrayType.class)
|
||||
private List<String> attrValues;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdateWarehouseGoodsAttrDto extends OrgCommonDto {
|
||||
|
||||
|
||||
@Comment("属性值")
|
||||
@Column(columnDefinition = "text[]")
|
||||
@Type(ListArrayType.class)
|
||||
private List<String> attrValues;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class WarehouseGoodsAttrDto extends OrgCommonDto {
|
||||
|
||||
|
||||
@Comment("属性值")
|
||||
@Column(columnDefinition = "text[]")
|
||||
@Type(ListArrayType.class)
|
||||
private List<String> attrValues;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(
|
||||
indexes =
|
||||
@jakarta.persistence.Index(
|
||||
name = "idx_warehouseGoodsAttr_org_id",
|
||||
columnList = "organization_id"))
|
||||
public class WarehouseGoodsAttrEntity extends OrgCommonEntity {
|
||||
|
||||
|
||||
|
||||
@Comment("属性值")
|
||||
@Column(columnDefinition = "text[]")
|
||||
@Type(ListArrayType.class)
|
||||
private List<String> attrValues;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.mapper;
|
||||
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.CreateWarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.UpdateWarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.WarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.entity.WarehouseGoodsAttrEntity;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface WarehouseGoodsAttrMapper
|
||||
extends BaseMapper<
|
||||
WarehouseGoodsAttrEntity,
|
||||
WarehouseGoodsAttrDto,
|
||||
CreateWarehouseGoodsAttrDto,
|
||||
UpdateWarehouseGoodsAttrDto> {}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.repository;
|
||||
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.entity.WarehouseGoodsAttrEntity;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface WarehouseGoodsAttrRepository extends BaseRepository<WarehouseGoodsAttrEntity> {
|
||||
@Query("select false")
|
||||
boolean isLinked(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.lihongjie.coal.warehouseGoodsAttr.service;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.CreateWarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.UpdateWarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.dto.WarehouseGoodsAttrDto;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.entity.WarehouseGoodsAttrEntity;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.mapper.WarehouseGoodsAttrMapper;
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.repository.WarehouseGoodsAttrRepository;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class WarehouseGoodsAttrService
|
||||
extends BaseService<WarehouseGoodsAttrEntity, WarehouseGoodsAttrRepository> {
|
||||
@Autowired private WarehouseGoodsAttrRepository repository;
|
||||
|
||||
@Autowired private WarehouseGoodsAttrMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public WarehouseGoodsAttrDto create(CreateWarehouseGoodsAttrDto request) {
|
||||
WarehouseGoodsAttrEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public WarehouseGoodsAttrDto update(UpdateWarehouseGoodsAttrDto request) {
|
||||
WarehouseGoodsAttrEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
boolean linked = this.repository.isLinked(request.getIds());
|
||||
|
||||
if (linked) {
|
||||
throw new BizException("数据已被关联,无法删除");
|
||||
}
|
||||
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public WarehouseGoodsAttrDto getById(String id) {
|
||||
WarehouseGoodsAttrEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<WarehouseGoodsAttrDto> list(CommonQuery query) {
|
||||
Page<WarehouseGoodsAttrEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
17
src/main/resources/scripts/dict/enum/orderNoRuleDict.groovy
Normal file
17
src/main/resources/scripts/dict/enum/orderNoRuleDict.groovy
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.orderNoRule.controller.OrderNoRuleController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(OrderNoRuleController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import cn.lihongjie.coal.warehouseGoodsAttr.controller.WarehouseGoodsAttrController
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(WarehouseGoodsAttrController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package cn.lihongjie.coal.orderNoRule.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
class RuleTemplateUtilsTest {
|
||||
|
||||
@Test
|
||||
void test1() {
|
||||
|
||||
RuleTemplateUtils.ResolveContext context = new RuleTemplateUtils.ResolveContext();
|
||||
context.setDateTime(LocalDateTime.of(2021, 1, 1, 1, 1, 1));
|
||||
|
||||
Assertions.assertEquals("20210101", RuleTemplateUtils.genNo(
|
||||
"{yyyy}{MM}{dd}",
|
||||
RuleTemplateUtils.CompositePlaceholderResolver.of(
|
||||
RuleTemplateUtils.DatePlaceholderResolver.INSTANCE),
|
||||
context));
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 生成测试
|
||||
@Test
|
||||
void test2() {
|
||||
|
||||
RuleTemplateUtils.ResolveContext context = new RuleTemplateUtils.ResolveContext();
|
||||
context.setDateTime(LocalDateTime.of(2021, 1, 1, 1, 1, 1));
|
||||
|
||||
Assertions.assertEquals("CG20210101", RuleTemplateUtils.genNo(
|
||||
"CG{yyyy}{MM}{dd}",
|
||||
RuleTemplateUtils.CompositePlaceholderResolver.of(
|
||||
RuleTemplateUtils.DatePlaceholderResolver.INSTANCE),
|
||||
context));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void test3() {
|
||||
|
||||
RuleTemplateUtils.ResolveContext context = new RuleTemplateUtils.ResolveContext();
|
||||
context.setDateTime(LocalDateTime.of(2021, 1, 1, 1, 1, 1));
|
||||
|
||||
Assertions.assertEquals("CG20210101", RuleTemplateUtils.genNo(
|
||||
"CG{yyyy}{MM}{dd}{random:3}",
|
||||
RuleTemplateUtils.CompositePlaceholderResolver.of(
|
||||
RuleTemplateUtils.DatePlaceholderResolver.INSTANCE, RuleTemplateUtils.RandomPlaceholderResolver.INSTANCE),
|
||||
context).substring(0, 10));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void test4() {
|
||||
|
||||
RuleTemplateUtils.ResolveContext context = new RuleTemplateUtils.ResolveContext();
|
||||
context.setDateTime(LocalDateTime.of(2021, 1, 1, 1, 1, 1));
|
||||
|
||||
Assertions.assertEquals("CG210101", RuleTemplateUtils.genNo(
|
||||
"CG{yy}{MM}{dd}",
|
||||
RuleTemplateUtils.CompositePlaceholderResolver.of(
|
||||
RuleTemplateUtils.DatePlaceholderResolver.INSTANCE, RuleTemplateUtils.RandomPlaceholderResolver.INSTANCE),
|
||||
context));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user