接口优化

This commit is contained in:
2026-07-29 09:00:41 +08:00
parent 4fd371b8eb
commit dc68cda5d5
8 changed files with 72 additions and 26 deletions

View File

@@ -91,7 +91,6 @@ public class RepoRecordController extends BaseController {
if(ObjectUtil.isNotNull( products)){ if(ObjectUtil.isNotNull( products)){
repoRecordVO.setFoodProductNum(products.getNum()); repoRecordVO.setFoodProductNum(products.getNum());
repoRecordVO.setFoodProductName(products.getName()); repoRecordVO.setFoodProductName(products.getName());
repoRecordVO.setUnitName(products.getUnitLabel());
repoRecordVO.setPrice(products.getPrice()); repoRecordVO.setPrice(products.getPrice());
} }
} }

View File

@@ -5,25 +5,26 @@ import cn.hutool.core.util.ObjectUtil;
import com.zf.foodpurchase.common.constant.FoodStatusConstants; import com.zf.foodpurchase.common.constant.FoodStatusConstants;
import com.zf.foodpurchase.common.core.domain.AjaxResult; import com.zf.foodpurchase.common.core.domain.AjaxResult;
import com.zf.foodpurchase.common.core.domain.entity.SysUser; import com.zf.foodpurchase.common.core.domain.entity.SysUser;
import com.zf.foodpurchase.common.utils.DateUtils;
import com.zf.foodpurchase.common.utils.StringUtils;
import com.zf.foodpurchase.common.utils.bean.BeanUtils; import com.zf.foodpurchase.common.utils.bean.BeanUtils;
import com.zf.foodpurchase.fdsafe.entity.FoodProduct; import com.zf.foodpurchase.fdsafe.entity.FoodProduct;
import com.zf.foodpurchase.fdsafe.entity.FoodProductMaterial; import com.zf.foodpurchase.fdsafe.entity.FoodProductMaterial;
import com.zf.foodpurchase.fdsafe.entity.XhCreate;
import com.zf.foodpurchase.fdsafe.mapper.FoodProductMapper; import com.zf.foodpurchase.fdsafe.mapper.FoodProductMapper;
import com.zf.foodpurchase.fdsafe.mapper.XhMapper;
import com.zf.foodpurchase.fdsafe.service.IFoodProductService; import com.zf.foodpurchase.fdsafe.service.IFoodProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zf.foodpurchase.fdsafe.vo.FoodProductCKVO; import com.zf.foodpurchase.fdsafe.vo.FoodProductCKVO;
import com.zf.foodpurchase.fdsafe.vo.FoodProductVO; import com.zf.foodpurchase.fdsafe.vo.FoodProductVO;
import com.zf.foodpurchase.fdsafe.vo.XhCreateVO;
import com.zf.foodpurchase.system.mapper.FoodProductMaterialMapper; import com.zf.foodpurchase.system.mapper.FoodProductMaterialMapper;
import com.zf.foodpurchase.system.service.ISysUserService; import com.zf.foodpurchase.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
@@ -39,9 +40,10 @@ public class FoodProductServiceImpl extends ServiceImpl<FoodProductMapper, FoodP
private ISysUserService sysUserService; private ISysUserService sysUserService;
@Autowired @Autowired
private FoodProductMapper foodProductMapper; private FoodProductMapper foodProductMapper;
@Autowired @Autowired
private FoodProductMaterialMapper foodProductMaterialMapper; private FoodProductMaterialMapper foodProductMaterialMapper;
@Autowired
private XhMapper xhMapper;
@Override @Override
public List<FoodProductVO> queryFoodProductVO(FoodProductVO foodProductVO) { public List<FoodProductVO> queryFoodProductVO(FoodProductVO foodProductVO) {
@@ -68,6 +70,38 @@ public class FoodProductServiceImpl extends ServiceImpl<FoodProductMapper, FoodP
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public AjaxResult supplierAdd(FoodProductVO foodProductVO) { public AjaxResult supplierAdd(FoodProductVO foodProductVO) {
FoodProduct foodProduct = dealSupplierProductAdd(foodProductVO); FoodProduct foodProduct = dealSupplierProductAdd(foodProductVO);
Date date = new Date();
String dateStr = DateUtils.getShortYearMonth( date);
XhCreate xhCreate = new XhCreate();
Long deptId = foodProductVO.getSupplierId().longValue();
xhCreate.setDeptId(deptId);
xhCreate.setTimeStr(dateStr);
XhCreateVO xhCreateVO = new XhCreateVO();
org.springframework.beans.BeanUtils.copyProperties(xhCreate,xhCreateVO);
XhCreate xhCreateNew = xhMapper.queryXhCreate(xhCreateVO);
if(StringUtils.isBlank(foodProductVO.getNum())){
String productNum = "";
if(ObjectUtil.isNull(xhCreateNew)){
Integer deptNum = xhMapper.selectMaxDeptNum();
Integer num = 1;
if(ObjectUtil.isNotNull(deptNum)){
num = deptNum+1;
}
xhCreate.setDeptNum(num);
xhCreate.setXh(1);
xhMapper.insertXhCreate(xhCreate);
productNum = StringUtils.formatNumThree(num)+dateStr+"001";
}else{
Integer deptNum = xhCreateNew.getDeptNum();
Integer xhNum = xhCreateNew.getXh()+1;
String xhNumStr = StringUtils.formatNumThree(xhNum);
productNum = StringUtils.formatNumThree(deptNum)+dateStr+xhNumStr;
xhCreateNew.setXh(xhNum);
xhMapper.updateXhCreate(xhCreateNew);
}
foodProduct.setNum(productNum);
}
boolean save = save(foodProduct); boolean save = save(foodProduct);
List<FoodProductMaterial> list = foodProductVO.getFoodProductMaterials(); List<FoodProductMaterial> list = foodProductVO.getFoodProductMaterials();
if(CollectionUtil.isNotEmpty(list)){ if(CollectionUtil.isNotEmpty(list)){
@@ -86,25 +120,18 @@ public class FoodProductServiceImpl extends ServiceImpl<FoodProductMapper, FoodP
* @return * @return
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult supplierUpdate(FoodProductVO foodProductVO) { public AjaxResult supplierUpdate(FoodProductVO foodProductVO) {
FoodProduct old = getById(foodProductVO.getFoodProductId()); FoodProduct old = getById(foodProductVO.getFoodProductId());
if (old == null) { if (old == null) {
return AjaxResult.error("商品不存在,无法修改"); return AjaxResult.error("商品不存在,无法修改");
} }
//FoodProduct foodProduct = dealSupplierProductUpdate(foodProductVO); List<FoodProductMaterial> list = foodProductVO.getFoodProductMaterials();
// 判断商品审核状态:审核不通过,修改信息重新发起审核;审核通过修改价格重新发起审核 foodProductMaterialMapper.deleteByFoodProductId(foodProductVO.getFoodProductId());
/*boolean isCheck = false; list.forEach(f ->{
// if (old.getCheckStatus() == 2) { f.setFoodProductId(foodProductVO.getFoodProductId());
if (FoodStatusConstants.PRODUCT_CHECK_NO_PASS.equals(old.getCheckStatus())) { });
// 待审核状态 foodProductMaterialMapper.batchInsert( list);
foodProduct.setCheckStatus(FoodStatusConstants.PRODUCT_WAIT_CHECK);
isCheck = true;
}
// 审核通过,如果价格变动就重新发起审核;
else if (FoodStatusConstants.PRODUCT_CHECK_NO_PASS.equals(old.getCheckStatus()) && old.getPrice().compareTo(foodProductVO.getPrice()) != 0) {
foodProduct.setCheckStatus(FoodStatusConstants.PRODUCT_WAIT_CHECK);
isCheck = true;
}*/
FoodProduct foodProduct = new FoodProduct(); FoodProduct foodProduct = new FoodProduct();
BeanUtils.copyProperties(foodProductVO, foodProduct); BeanUtils.copyProperties(foodProductVO, foodProduct);
boolean update = updateById(foodProduct); boolean update = updateById(foodProduct);

View File

@@ -64,6 +64,7 @@ public class RepoRecordServiceImpl extends ServiceImpl<RepoRecordMapper, RepoRec
repoRecord.setCategoryId(categoryId); repoRecord.setCategoryId(categoryId);
repoRecord.setStatus(1); repoRecord.setStatus(1);
repoRecord.setOperId(user.getUserId()); repoRecord.setOperId(user.getUserId());
repoRecord.setOrderNo(orderNo);
BigDecimal price = inRepoVO.getPrice() == null ? BigDecimal.ZERO : inRepoVO.getPrice(); BigDecimal price = inRepoVO.getPrice() == null ? BigDecimal.ZERO : inRepoVO.getPrice();
BigDecimal totalCost = price.multiply(new BigDecimal(productNum)); BigDecimal totalCost = price.multiply(new BigDecimal(productNum));
repoRecord.setTotalCost(totalCost); repoRecord.setTotalCost(totalCost);
@@ -119,8 +120,9 @@ public class RepoRecordServiceImpl extends ServiceImpl<RepoRecordMapper, RepoRec
repoRecord.setRepoId(repoId); repoRecord.setRepoId(repoId);
repoRecord.setProductNum(productNum); repoRecord.setProductNum(productNum);
repoRecord.setCategoryId(categoryId); repoRecord.setCategoryId(categoryId);
repoRecord.setStatus(1); repoRecord.setStatus(0);
repoRecord.setOperId(user.getUserId()); repoRecord.setOperId(user.getUserId());
repoRecord.setMsg(foodProductCKVO.getMsg());
BigDecimal price = foodProductCKVO.getPrice() == null ? BigDecimal.ZERO : foodProductCKVO.getPrice(); BigDecimal price = foodProductCKVO.getPrice() == null ? BigDecimal.ZERO : foodProductCKVO.getPrice();
BigDecimal totalCost = price.multiply(new BigDecimal(productNum)); BigDecimal totalCost = price.multiply(new BigDecimal(productNum));
repoRecord.setTotalCost(totalCost); repoRecord.setTotalCost(totalCost);

View File

@@ -81,4 +81,6 @@ public class RepoRecordVO {
private String unitName; private String unitName;
private BigDecimal price; private BigDecimal price;
private String orderNo;
} }

View File

@@ -11,4 +11,6 @@ public interface FoodProductMaterialMapper {
void batchInsert(List<FoodProductMaterial> records); void batchInsert(List<FoodProductMaterial> records);
List<FoodProductMaterial> selectByFoodProductId(Long foodProductId); List<FoodProductMaterial> selectByFoodProductId(Long foodProductId);
int deleteByFoodProductId(Long foodProductId);
} }

View File

@@ -24,4 +24,7 @@
</foreach> </foreach>
</insert> </insert>
<delete id="deleteByFoodProductId" parameterType="Long">
delete from food_product_material where food_product_id = #{foodProductId}
</delete>
</mapper> </mapper>

View File

@@ -17,18 +17,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result column="msg" property="msg"/> <result column="msg" property="msg"/>
<result column="dept_id" property="deptId"/> <result column="dept_id" property="deptId"/>
<result column="oper_id" property="operId"/> <result column="oper_id" property="operId"/>
<result column="order_no" property="orderNo"/>
</resultMap> </resultMap>
<select id="selectRepoRecordByRepoRecordId" resultType="com.zf.foodpurchase.fdsafe.vo.RepoRecordVO"> <select id="selectRepoRecordByRepoRecordId" resultType="com.zf.foodpurchase.fdsafe.vo.RepoRecordVO">
select re.id,re.apply_date,re.supplier_id,re.category_id,re.repo_id,re.product_id, select re.id,re.apply_date,re.supplier_id,re.category_id,re.repo_id,re.product_id,
re.product_num,p.name,re.total_cost,re.status,re.msg,fd.type_label categoryName, re.product_num,p.name,re.total_cost,re.status,re.msg,fd.type_label categoryName,
sd.dept_name merchantName, rep.repo_name repoName,re.total_cost totalCost,re.oper_id operId,su.user_name operName from repo_record re sd.dept_name merchantName, rep.repo_name repoName,re.total_cost totalCost,
re.oper_id operId,su.user_name operName,fu.unit_label unitName,re.order_no orderNo from repo_record re
left join food_type fd on re.category_id=fd.type_id left join food_type fd on re.category_id=fd.type_id
left join sys_dept sd on re.supplier_id=sd.dept_id left join sys_dept sd on re.supplier_id=sd.dept_id
left join repository rep on re.repo_id = rep.id left join repository rep on re.repo_id = rep.id
left join sys_user su on re.oper_id=su.user_id left join sys_user su on re.oper_id=su.user_id
left join food_product p on re.product_id=p.food_product_id WHERE re.id = #{repoRecordId} left join food_product p on re.product_id=p.food_product_id
left join food_unit fu on p.unit_id=fu.unit_id
WHERE re.id = #{repoRecordId}
</select> </select>
<insert id="insertRepoRecord" useGeneratedKeys="true" keyProperty="id" keyColumn="id"> <insert id="insertRepoRecord" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
@@ -45,6 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="msg != null and msg != ''">msg,</if> <if test="msg != null and msg != ''">msg,</if>
<if test="deptId != null">dept_id,</if> <if test="deptId != null">dept_id,</if>
<if test="operId != null">oper_id,</if> <if test="operId != null">oper_id,</if>
<if test="orderNo != null">order_no,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="applyDate != null">#{applyDate},</if> <if test="applyDate != null">#{applyDate},</if>
@@ -58,18 +63,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="msg != null and msg != ''">#{msg,jdbcType=VARCHAR},</if> <if test="msg != null and msg != ''">#{msg,jdbcType=VARCHAR},</if>
<if test="deptId != null">#{deptId,jdbcType=BIGINT},</if> <if test="deptId != null">#{deptId,jdbcType=BIGINT},</if>
<if test="operId != null">#{operId,jdbcType=BIGINT},</if> <if test="operId != null">#{operId,jdbcType=BIGINT},</if>
<if test="orderNo != null and orderNo != ''">#{orderNo,jdbcType=VARCHAR},</if>
</trim> </trim>
</insert> </insert>
<select id="selectRepoRecordList" resultType="com.zf.foodpurchase.fdsafe.vo.RepoRecordVO"> <select id="selectRepoRecordList" resultType="com.zf.foodpurchase.fdsafe.vo.RepoRecordVO">
select re.id,re.apply_date,re.supplier_id,re.category_id,re.repo_id,re.product_id, select re.id,re.apply_date,re.supplier_id,re.category_id,re.repo_id,re.product_id,
re.product_num,p.name,re.total_cost,re.status,re.msg,fd.type_label categoryName, re.product_num,p.name,re.total_cost,re.status,re.msg,fd.type_label categoryName,
sd.dept_name merchantName, rep.repo_name repoName,re.total_cost totalCost,re.oper_id operId,su.user_name operName from repo_record re sd.dept_name merchantName, rep.repo_name repoName,re.total_cost totalCost,
re.oper_id operId,su.user_name operName,fu.unit_label unitName,re.order_no orderNo from repo_record re
left join food_type fd on re.category_id=fd.type_id left join food_type fd on re.category_id=fd.type_id
left join sys_dept sd on re.supplier_id=sd.dept_id left join sys_dept sd on re.supplier_id=sd.dept_id
left join repository rep on re.repo_id = rep.id left join repository rep on re.repo_id = rep.id
left join food_product p on re.product_id=p.food_product_id left join food_product p on re.product_id=p.food_product_id
left join sys_user su on re.oper_id=su.user_id left join sys_user su on re.oper_id=su.user_id
left join food_unit fu on p.unit_id=fu.unit_id
<where> <where>
<if test="repoId != null"> <if test="repoId != null">
AND re.repo_id = #{repoId,jdbcType=INTEGER} AND re.repo_id = #{repoId,jdbcType=INTEGER}
@@ -98,12 +106,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectRepoRecordListByProductId" resultType="com.zf.foodpurchase.fdsafe.vo.RepoRecordVO"> <select id="selectRepoRecordListByProductId" resultType="com.zf.foodpurchase.fdsafe.vo.RepoRecordVO">
select re.id,re.apply_date,re.supplier_id,re.category_id,re.repo_id,re.product_id, select re.id,re.apply_date,re.supplier_id,re.category_id,re.repo_id,re.product_id,
re.product_num,p.name,re.total_cost,re.status,re.msg,fd.type_label categoryName, re.product_num,p.name,re.total_cost,re.status,re.msg,fd.type_label categoryName,
sd.dept_name merchantName, rep.repo_name repoName,re.total_cost totalCost,re.oper_id operId,su.user_name operName from repo_record re sd.dept_name merchantName, rep.repo_name repoName,re.total_cost totalCost,re.oper_id operId,
su.user_name operName,fu.unit_label unitName,re.order_no orderNo from repo_record re
left join food_type fd on re.category_id=fd.type_id left join food_type fd on re.category_id=fd.type_id
left join sys_dept sd on re.supplier_id=sd.dept_id left join sys_dept sd on re.supplier_id=sd.dept_id
left join repository rep on re.repo_id = rep.id left join repository rep on re.repo_id = rep.id
left join food_product p on re.product_id=p.food_product_id left join food_product p on re.product_id=p.food_product_id
left join sys_user su on re.oper_id=su.user_id left join sys_user su on re.oper_id=su.user_id
left join food_unit fu on p.unit_id=fu.unit_id
where re.product_id = #{productId} where re.product_id = #{productId}
</select> </select>

View File

@@ -9,13 +9,14 @@
<select id="querySchoolOrderItemVO" resultType="com.zf.foodpurchase.fdsafe.vo.SchoolOrderItemVO" <select id="querySchoolOrderItemVO" resultType="com.zf.foodpurchase.fdsafe.vo.SchoolOrderItemVO"
parameterType="com.zf.foodpurchase.fdsafe.vo.SchoolOrderItemVO"> parameterType="com.zf.foodpurchase.fdsafe.vo.SchoolOrderItemVO">
select soi.order_item_no, soi.order_no,soi.food_id, soi.school_id, soi.edu_id, soi.supplier_id, soi.food_product_id, soi.food_name, soi.price, soi.product_num, soi.type_id, soi.unit_id, soi.order_item_status, soi.create_time, soi.update_time, soi.order_item_remark,soi.refund_num, select soi.order_item_no, soi.order_no,soi.food_id, soi.school_id, soi.edu_id, soi.supplier_id, soi.food_product_id, soi.food_name, soi.price, soi.product_num, soi.type_id, soi.unit_id, soi.order_item_status, soi.create_time, soi.update_time, soi.order_item_remark,soi.refund_num,
ft.type_label,fu.unit_label,fp.remark as food_product_remark,sup.supplier_name supplierName,fu.unit_label modelName,fp.num ft.type_label,fu.unit_label,fp.remark as food_product_remark,sup.supplier_name supplierName,fs.spec_label modelName,fp.num
from school_order_item soi from school_order_item soi
left join supplier sup on soi.supplier_id=sup.supplier_id left join supplier sup on soi.supplier_id=sup.supplier_id
left join school_order so on soi.order_no = so.order_no left join school_order so on soi.order_no = so.order_no
left join food_product fp on soi.food_product_id = fp.food_product_id left join food_product fp on soi.food_product_id = fp.food_product_id
left join food_type ft on ft.type_id = fp.type_id left join food_type ft on ft.type_id = fp.type_id
left join food_unit fu on fu.unit_id = fp.unit_id left join food_unit fu on fu.unit_id = fp.unit_id
left join food_spec fs on fp.spec_id = fs.spec_id
<where> <where>
<if test="orderItemNo != null and orderItemNo != ''"> <if test="orderItemNo != null and orderItemNo != ''">
and soi.order_item_no = #{orderItemNo} and soi.order_item_no = #{orderItemNo}