添加货品分类信息增加ancestors属性

This commit is contained in:
Administrator 2023-04-15 18:11:02 +08:00
parent ad8e9f4991
commit ac955351e2
9 changed files with 104 additions and 12 deletions

View File

@ -65,13 +65,7 @@ public class StuffDetailController {
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
Result<IPage<StuffDetail>> result = new Result<IPage<StuffDetail>>();
QueryWrapper<StuffDetail> queryWrapper = QueryGenerator.initQueryWrapper(stuffDetail, req.getParameterMap());
Page<StuffDetail> page = new Page<StuffDetail>(pageNo, pageSize);
IPage<StuffDetail> pageList = stuffDetailService.page(page, queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
return stuffDetailService.queryPageList(stuffDetail,pageNo,pageSize,req);
}
/**

View File

@ -110,7 +110,17 @@ public class StuffTypeController {
public Result<StuffType> add(@RequestBody StuffType stuffType) {
Result<StuffType> result = new Result<StuffType>();
try {
boolean top = stuffType.getParentId() == null || stuffType.getParentId() == 0;
if (top) {
stuffType.setParentId(0L);
stuffType.setAncestors("0");
}
stuffTypeService.save(stuffType);
if (!top) {
StuffType p = stuffTypeService.getById(stuffType.getParentId());
stuffType.setAncestors(p.getAncestors() + "," + p.getId());
stuffTypeService.updateById(stuffType);
}
result.success("添加成功!");
} catch (Exception e) {
e.printStackTrace();

View File

@ -1,6 +1,7 @@
package com.zhgd.xmgl.modules.stuff.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
@ -11,6 +12,7 @@ import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 货品
@ -35,7 +37,7 @@ public class StuffDetail implements Serializable {
*/
@Excel(name = "货品分类id", width = 15)
@ApiModelProperty(value = "货品分类id")
private java.lang.Integer stuffTypeId;
private java.lang.Long stuffTypeId;
/**
* 货号
*/
@ -118,4 +120,26 @@ public class StuffDetail implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间")
private java.util.Date updateTime;
@ApiModelProperty(value = "数量")
private Integer quantity;
@TableField(exist = false)
@ApiModelProperty(value = "仓库id")
private Long stuffWarehouseId;
@TableField(exist = false)
@ApiModelProperty(value = "仓库名称")
private String warehouseNames;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "开始时间")
private Date startTime;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "结束时间")
private Date endTime;
}

View File

@ -85,6 +85,10 @@ public class StuffType implements Serializable {
@ApiModelProperty(value = "项目sn")
private java.lang.String projectSn;
@ApiModelProperty(value = "祖级列表")
private java.lang.String ancestors;
@TableField(exist = false)
private List<StuffType> children;
}

View File

@ -1,8 +1,13 @@
package com.zhgd.xmgl.modules.stuff.mapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.xmgl.modules.stuff.entity.StuffDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @Description: 货品
@ -13,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface StuffDetailMapper extends BaseMapper<StuffDetail> {
IPage<StuffDetail> queryPageList(StuffDetail stuffDetail, Page<StuffDetail> page,@Param(Constants.WRAPPER) QueryWrapper<StuffDetail> queryWrapper);
}

View File

@ -2,4 +2,15 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhgd.xmgl.modules.stuff.mapper.StuffDetailMapper">
<select id="queryPageList" resultType="com.zhgd.xmgl.modules.stuff.entity.StuffDetail">
SELECT
sd.*,
GROUP_CONCAT(sw.warehouse_name) warehouse_names
FROM
stuff_detail sd
LEFT JOIN stuff_warehouse_stuff_detail swsd ON swsd.stuff_detail_id = sd.id
LEFT JOIN `stuff_warehouse` sw ON swsd.stuff_warehouse_id = sw.id
${ew.customSqlSegment}
GROUP BY sd.id
</select>
</mapper>

View File

@ -1,8 +1,12 @@
package com.zhgd.xmgl.modules.stuff.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.stuff.entity.StuffDetail;
import javax.servlet.http.HttpServletRequest;
/**
* @Description: 货品
* @author pds
@ -11,4 +15,5 @@ import com.zhgd.xmgl.modules.stuff.entity.StuffDetail;
*/
public interface IStuffDetailService extends IService<StuffDetail> {
Result<IPage<StuffDetail>> queryPageList(StuffDetail stuffDetail, Integer pageNo, Integer pageSize, HttpServletRequest req);
}

View File

@ -1,11 +1,20 @@
package com.zhgd.xmgl.modules.stuff.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.stuff.entity.StuffDetail;
import com.zhgd.xmgl.modules.stuff.mapper.StuffDetailMapper;
import com.zhgd.xmgl.modules.stuff.service.IStuffDetailService;
import com.zhgd.xmgl.util.ReflectionUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
/**
* @Description: 货品
* @author pds
@ -14,5 +23,29 @@ import org.springframework.stereotype.Service;
*/
@Service
public class StuffDetailServiceImpl extends ServiceImpl<StuffDetailMapper, StuffDetail> implements IStuffDetailService {
@Autowired
StuffDetailMapper stuffDetailMapper;
@Override
public Result<IPage<StuffDetail>> queryPageList(StuffDetail stuffDetail, Integer pageNo, Integer pageSize, HttpServletRequest req) {
Result<IPage<StuffDetail>> result = new Result<>();
QueryWrapper<StuffDetail> queryWrapper = new QueryWrapper<>();
String stuffDetailAlias = "sd.";
String warehouseAlias = "sw.";
queryWrapper
.eq(StringUtils.isNotBlank(stuffDetail.getProjectSn()), stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getProjectSn), stuffDetail.getProjectSn())
.eq(stuffDetail.getStuffTypeId() != null, stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getStuffTypeId), stuffDetail.getStuffTypeId())
.eq(stuffDetail.getStuffWarehouseId() != null, warehouseAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getStuffWarehouseId), stuffDetail.getStuffWarehouseId())
.le(stuffDetail.getEndTime() != null, stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getUpdateTime), stuffDetail.getEndTime())
.ge(stuffDetail.getStartTime() != null, stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getUpdateTime), stuffDetail.getStartTime())
.like(StringUtils.isNotBlank(stuffDetail.getStuffNumber()), stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getStuffNumber), stuffDetail.getStuffNumber())
.like(StringUtils.isNotBlank(stuffDetail.getLookupCode()), stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getLookupCode), stuffDetail.getLookupCode())
.like(StringUtils.isNotBlank(stuffDetail.getName()), stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getName), stuffDetail.getName())
.like(StringUtils.isNotBlank(stuffDetail.getSpecification()), stuffDetailAlias + ReflectionUtil.getFieldNameToUlc(StuffDetail::getSpecification), stuffDetail.getSpecification());
Page<StuffDetail> page = new Page<StuffDetail>(pageNo, pageSize);
IPage<StuffDetail> pageList = stuffDetailMapper.queryPageList(stuffDetail, page, queryWrapper);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
}

View File

@ -1,5 +1,6 @@
package com.zhgd.xmgl.util;
import cn.hutool.core.util.StrUtil;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@ -20,6 +21,14 @@ public class ReflectionUtil {
private static Map<SerializableFunction<?, ?>, Field> cache = new ConcurrentHashMap<>();
public static <T, R> List<String> getFieldNameList(SerializableFunction<T, R>... functions) {
return Arrays.stream(functions).map(ReflectionUtil::getFieldName).collect(Collectors.toList());
}
public static <T, R> String getFieldNameToUlc(SerializableFunction<T, R> function) {
return StrUtil.toUnderlineCase(getFieldName(function));
}
/**
* 方法引用获取属性名
*
@ -33,10 +42,6 @@ public class ReflectionUtil {
return field.getName();
}
public static <T, R> List<String> getFieldNameList(SerializableFunction<T, R>... functions) {
return Arrays.stream(functions).map(ReflectionUtil::getFieldName).collect(Collectors.toList());
}
public static <T, R> Field getField(SerializableFunction<T, R> function) {
return cache.computeIfAbsent(function, ReflectionUtil::findField);
}