商品查询修改

This commit is contained in:
wangguocheng 2024-05-17 10:28:43 +08:00
parent 7b259ba55f
commit 1c6ccb7d10
13 changed files with 247 additions and 38 deletions

View File

@ -88,6 +88,15 @@ public class OrderController {
orderVo.setUserId(jsonObject.getString("staffId"));
return orderService.createOrder(orderVo,clientType,token);
}
@PostMapping("/createBackOrder")
public Result createBackOrder(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType, @RequestBody OrderVo orderVo){
JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
String userId = jsonObject.getString("accountId");
orderVo.setMerchantId(Integer.valueOf(userId));
orderVo.setUserId(jsonObject.getString("staffId"));
return orderService.createBackOrder(orderVo,clientType,token);
}
@PostMapping("/packall")
public Result packall(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType, @RequestBody CartVo cartVo){

View File

@ -30,18 +30,28 @@ public class ProductController {
@RequestParam("categoryId") String categoryId,
@RequestParam("commdityName") String commdityName,
@RequestParam("masterId") String masterId,
@RequestParam("page") int page,
@RequestParam("pageSize") int pageSize
int page,
int pageSize
){
return productService.queryCommodityInfo(shopId,categoryId,commdityName,page,pageSize,masterId);
}
@GetMapping(value = "queryNewCommodityInfo")
public Result queryNewCommodityInfo(
@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType,
@RequestParam("shopId") String shopId,
@RequestParam("categoryId") String categoryId,
@RequestParam("commdityName") String commdityName,
@RequestParam("masterId") String masterId,
@RequestParam("page") int page,
@RequestParam("pageSize") int pageSize
){
return productService.queryNewCommodityInfo(shopId,categoryId,commdityName,page,pageSize,masterId);
}
@GetMapping(value = "queryCategory")
public Result queryCategory( @RequestHeader("token") String token,

View File

@ -41,4 +41,6 @@ public interface TbOrderDetailMapper {
BigDecimal selectByOrderId(String orderId);
int batchInsert(@Param("list") List<TbOrderDetail> list,@Param("orderId") String orderId);
TbOrderDetail selectByOrderIdAndSkuId(@Param("orderId") int orderId, @Param("skuId") Integer skuId);
}

View File

@ -30,4 +30,6 @@ public interface TbOrderInfoMapper {
List<OrderPo> selectAllByShop(@Param("shopId") Integer shopId, @Param("orderType") String orderType,
@Param("day") String day, @Param("orderNo") String orderNo);
TbOrderInfo selectByTradeAndMasterId(@Param("day")String day, @Param("masterId")String masterId, @Param("shopId")Integer shopId);
}

View File

@ -17,6 +17,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -48,6 +49,10 @@ public class OrderService {
@Autowired
TbOrderInfoMapper tbOrderInfoMapper;
@Autowired
private OrderChildDetailMapper orderChildDetailMapper;
@Autowired
private OrderChildInfoMapper orderChildInfoMapper;
@Autowired
TbOrderDetailMapper orderDetailMapper;
@Autowired
TbProductSkuResultMapper tbProductSkuResultMapper;
@ -600,11 +605,16 @@ public class OrderService {
orderId = Integer.valueOf(cashierCart.getOrderId());
}
}
if (orderId > 0) {
tbOrderInfoMapper.updateStatusById(orderId, "cancelled");
orderDetailMapper.updateStatusByOrderId(orderId, "cancelled");
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
if (Objects.nonNull(orderInfo) && !orderInfo.getStatus().equals("pending")){
tbOrderInfoMapper.updateStatusById(orderId, "cancelled");
orderDetailMapper.updateStatusByOrderId(orderId, "cancelled");
cashierCartMapper.deleteBymasterId(cartVo.getMasterId(), Integer.valueOf(cartVo.getShopId()), day, "create", cartVo.getUuid());
}
}
cashierCartMapper.deleteBymasterId(cartVo.getMasterId(), Integer.valueOf(cartVo.getShopId()), day, "create", cartVo.getUuid());
return Result.success(CodeEnum.SUCCESS);
}
@ -648,4 +658,130 @@ public class OrderService {
}
return Result.success(CodeEnum.SUCCESS, orderInfo);
}
public Result createBackOrder(OrderVo orderVo, String clientType, String token) {
String day = DateUtils.getDay();
List<TbCashierCart> list = cashierCartMapper.selectAllCreateOrder(orderVo.getMasterId(), orderVo.getShopId(), day, "create", orderVo.getUuid());
if(ObjectUtil.isEmpty(list)||ObjectUtil.isNull(list)||list.size()<=0){
return Result.fail(CARTEXIST);
}
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal packAMount = BigDecimal.ZERO;
BigDecimal feeAmount = BigDecimal.ZERO;
BigDecimal saleAmount = BigDecimal.ZERO;
Map<Integer, TbProductSku> skuMap = new HashMap<>();
List<TbOrderDetail> orderDetails = new ArrayList<>();
List<TbOrderDetail> modityOrderDetails = new ArrayList<>();
String masterId = "";
int orderId = 0;
if (list.size()<1 || list.isEmpty()){
return Result.fail(CARTEXIST);
}
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByTradeAndMasterId(day,orderVo.getMasterId(),orderVo.getShopId());
if (Objects.nonNull(orderInfo)){
orderId = orderInfo.getId();
}
for (TbCashierCart cashierCart : list) {
TbProductSkuWithBLOBs tbProduct = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId()));
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
packAMount = packAMount.add(cashierCart.getPackFee());
feeAmount = cashierCart.getPackFee();
if (Objects.nonNull(tbProduct)) {
saleAmount = saleAmount.add(tbProduct.getSalePrice());
}
skuMap.put(tbProduct.getId(), tbProduct);
TbOrderDetail orderDetail = orderDetailMapper.selectByOrderIdAndSkuId(orderId,Integer.valueOf(cashierCart.getSkuId()));
if (Objects.nonNull(orderDetail)){
orderDetail.setNum(orderDetail.getNum()+cashierCart.getNumber());
orderDetail.setPriceAmount(orderDetail.getPriceAmount().add(cashierCart.getTotalAmount()));
orderDetail.setPackAmount(orderDetail.getPackAmount().add(cashierCart.getPackFee()));
modityOrderDetails.add(orderDetail);
}else {
orderDetail = new TbOrderDetail();
orderDetail.setCreateTime(new Date());
orderDetail.setNum(cashierCart.getNumber());
orderDetail.setPrice(cashierCart.getSalePrice());
orderDetail.setPriceAmount(cashierCart.getTotalAmount());
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId()));
orderDetail.setProductSkuName(tbProduct.getSpecSnap());
orderDetail.setProductName(cashierCart.getName());
orderDetail.setShopId(orderVo.getShopId());
orderDetail.setPackAmount(cashierCart.getPackFee());
orderDetail.setStatus("unpaid");
orderDetail.setProductImg(cashierCart.getCoverImg());
masterId = cashierCart.getMasterId();
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
orderId = Integer.valueOf(cashierCart.getOrderId());
}
}
orderDetails.add(orderDetail);
}
String orderNo = generateOrderNumber();
TbToken tbToken = tokenMapper.selectByToken(token);
if (orderId > 0) {
orderDetailMapper.deleteByOUrderId(orderId);
orderInfo.setUpdatedAt(System.currentTimeMillis());
orderInfo.setSettlementAmount(orderInfo.getSettlementAmount().add(totalAmount));
orderInfo.setAmount(orderInfo.getAmount().add(totalAmount));
orderInfo.setOriginAmount(orderInfo.getOriginAmount().add(totalAmount));
orderInfo.setStatus("unpaid");
orderInfo.setOrderAmount(orderInfo.getOrderAmount().add(totalAmount));
orderInfo.setFreightAmount(orderInfo.getFreightAmount().add(feeAmount));
orderInfo.setProductAmount(orderInfo.getProductAmount().add(saleAmount));
orderInfo.setTradeDay(DateUtils.getDay());
orderInfo.setUserId(orderVo.getUserId());
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
} else {
orderInfo = new TbOrderInfo(orderNo, totalAmount, packAMount, totalAmount, saleAmount, totalAmount, feeAmount, "",
"table", "cash", orderVo.getMerchantId().toString(), orderVo.getShopId().toString(),
"", (byte) 1, day, masterId);
orderInfo.setMasterId(masterId);
orderInfo.setRemark(orderVo.getRemark());
orderInfo.setUserId(orderVo.getUserId());
if (Objects.nonNull(tbToken)){
orderInfo.setTokenId(tbToken.getId());
}
tbOrderInfoMapper.insert(orderInfo);
orderId = orderInfo.getId();
}
OrderChildInfo orderChildInfo = new OrderChildInfo(orderNo, totalAmount, packAMount, totalAmount, saleAmount, totalAmount, feeAmount, "",
"table", "cash", orderVo.getMerchantId().toString(), orderVo.getShopId().toString(),
"", (byte) 1, day, masterId);
orderChildInfo.setMasterId(masterId);
orderChildInfo.setRemark(orderVo.getRemark());
orderChildInfo.setUserId(orderVo.getUserId());
orderChildInfo.setParentorderno(orderNo);
orderChildInfo.setOrderNo(orderNo+"-"+1);
orderChildInfoMapper.insert(orderChildInfo);
List<OrderChildDetail> childDetailList = new ArrayList<>();
for (TbOrderDetail orderDetail : orderDetails) {
orderDetail.setOrderId(orderId);
orderDetailMapper.insert(orderDetail);
OrderChildDetail orderChildDetail = new OrderChildDetail();
BeanUtils.copyProperties(orderDetail,orderChildDetail);
childDetailList.add(orderChildDetail);
}
for (OrderChildDetail orderChildDetail:childDetailList){
orderChildDetail.setOrderId(orderChildInfo.getId());
orderChildDetailMapper.insert(orderChildDetail);
}
boolean flag = true;
for (TbCashierCart cashierCart : list) {
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
flag = false;
}
cashierCart.setOrderId(orderId + "");
cashierCart.setStatus("closed");
cashierCart.setUpdatedAt(System.currentTimeMillis());
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
}
if (flag) {
redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + orderVo.getShopId() + ":" + day + orderVo.getUserId());
}
return Result.success(CodeEnum.SUCCESS, orderInfo);
}
}

View File

@ -46,6 +46,46 @@ public class ProductService {
public Result queryCommodityInfo(String shopId, String categoryId, String commdityName, Integer page, Integer pageSize, String masterId){
List<TbProductWithBLOBs> tbProductWithBLOBs=null;
if(ObjectUtil.isEmpty(categoryId)){
tbProductWithBLOBs=tbProductMapper.selectByShopId(shopId,commdityName);
}else {
tbProductWithBLOBs=tbProductMapper.selectByShopIdAndShopType(shopId,categoryId,commdityName);
}
String day = DateUtils.getDay();
if(ObjectUtil.isNotEmpty(tbProductWithBLOBs)){
tbProductWithBLOBs.parallelStream().forEach(it->{
Integer orderCount=tbProductMapper.countOrderByshopIdAndProductId(it.getShopId(),it.getId().toString(),masterId,day);
it.setOrderCount((ObjectUtil.isNull(orderCount)||ObjectUtil.isEmpty(orderCount))?0:orderCount);
TbProductSpec tbProductSpec= tbProductSpecMapper.selectByPrimaryKey(it.getSpecId());
if(ObjectUtil.isEmpty(tbProductSpec)){
tbProductSpec=new TbProductSpec();
}
it.setTbProductSpec(tbProductSpec);
TbProductSkuResult skuResult=tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
if(ObjectUtil.isEmpty(skuResult)){
skuResult=new TbProductSkuResult();
}
it.setProductSkuResult(skuResult);
});
}
return Result.success(CodeEnum.SUCCESS,tbProductWithBLOBs);
}
public Result queryProductSku(String shopId, String productId, String spec_tag){
if(ObjectUtil.isEmpty(shopId)||ObjectUtil.isEmpty(productId)){
return Result.fail(CodeEnum.PARAM);
}
TbProductSkuWithBLOBs tbProductSkuWithBLOBs= tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId,productId,spec_tag);
return Result.success(CodeEnum.SUCCESS,tbProductSkuWithBLOBs);
}
public Result queryNewCommodityInfo(String shopId, String categoryId, String commdityName, int page, int pageSize, String masterId) {
List<TbProductWithBLOBs> tbProductWithBLOBs=null;
if(ObjectUtil.isEmpty(categoryId)){
PageHelper.startPage(page, pageSize);
@ -73,18 +113,7 @@ public class ProductService {
it.setProductSkuResult(skuResult);
});
}
return Result.success(CodeEnum.SUCCESS,tbProductWithBLOBs);
}
public Result queryProductSku(String shopId, String productId, String spec_tag){
if(ObjectUtil.isEmpty(shopId)||ObjectUtil.isEmpty(productId)){
return Result.fail(CodeEnum.PARAM);
}
TbProductSkuWithBLOBs tbProductSkuWithBLOBs= tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId,productId,spec_tag);
return Result.success(CodeEnum.SUCCESS,tbProductSkuWithBLOBs);
PageInfo pageInfo=new PageInfo(tbProductWithBLOBs);
return Result.success(CodeEnum.SUCCESS,pageInfo);
}
}

View File

@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
@ -117,7 +118,7 @@ public class JSONUtil {
}
/**
* 字符串转为JSON对象,注意数组类型会抛异常[{name:\"Stone\"}]
* 字符串转为JSON对象,注意数组类型会抛异常[{name:"Stone"}]
* 假设json字符串多了某个字段可能是新加上去的显然转换成JSONObject时会有这个字段因为JSONObject就相当于map
*
* @param jsonStr 传入的JSON字串
@ -133,7 +134,7 @@ public class JSONUtil {
}
/**
* 字符串转为JSON数组,注意对象类型,非数组的会抛异常{name:\"Stone\"}
* 字符串转为JSON数组,注意对象类型,非数组的会抛异常{name:"Stone"}
* 假设json字符串多了某个字段可能是新加上去的显然转换成JSONArray时其元素会有这个字段因为JSONArray的元素JSONObject就相当于map
*
* @param jsonStr 传入的JSON字串
@ -166,6 +167,12 @@ public class JSONUtil {
}
}
public static void main(String[] args) {
String sss = "{\"bizData\":{\"amount\":1,\"currency\":\"cny\",\"ifCode\":\"sxfpay\",\"mchOrderNo\":\"CZ1715744291232\",\"mercNo\":\"B240510702030\",\"note\":\"等待用户付款\",\"payOrderId\":\"O1790587460614225921\",\"payType\":\"WECHAT\",\"settlementType\":\"D1\",\"state\":\"TRADE_AWAIT\",\"storeId\":\"S2405103298\",\"subject\":\"测试支付\",\"tradeFee\":0},\"code\":\"000000\",\"msg\":\"请求成功\",\"sign\":\"40710a3c293eeac3c7f4a1b0696a2bf6\",\"signType\":\"MD5\",\"timestamp\":\"20240515113813\"}";
// TypeReference<PublicResp<MainScanResp>> typeRef = new TypeReference<PublicResp<MainScanResp>>(){};
// PublicResp<MainScanResp> response = JSON.parseObject(sss, typeRef);
System.out.println("pm");
}
/**
* 字符串转为某个类的列表
* 日期字段不管是时间戳形式还是yyyy-MM-dd HH:mm:ss的形式都能成功转换

View File

@ -1,10 +1,12 @@
server:
port: 10587
spring:
application:
name: cashierService
datasource:
url: jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
username: root
password: mysqlroot@123
url: jdbc:mysql://101.37.12.135:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
username: fycashier
password: Twc6MrzzjBiWSsjh
driver-class-name: com.mysql.cj.jdbc.Driver
initialSize: 5
minIdle: 5

View File

@ -1,6 +1,6 @@
spring:
profiles:
active: hph
active: prod2
server:
servlet:
context-path: /cashier-client/

View File

@ -6,7 +6,7 @@
<generatorConfiguration>
<!-- 需要指明数据库连接器的绝对路径 -->
<!-- <classPathEntry location="C:\Users\admin\.m1\repository\mysql\mysql-connector-java\8.0.20\mysql-connector-java-8.0.20.jar" />-->
<classPathEntry location="E:\app\maven\repository\mysql\mysql-connector-java\8.0.17\mysql-connector-java-8.0.17.jar"/>
<classPathEntry location="/Users/wangguocheng/Desktop/app/maven/repository/mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar"/>
<context id="msqlTables" targetRuntime="MyBatis3">
<!-- 生成的pojo将implements Serializable-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
@ -19,8 +19,8 @@
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection connectionURL="jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=GMT%2B8"
driverClass="com.mysql.cj.jdbc.Driver" password="mysqlroot@123" userId="root" >
<jdbcConnection connectionURL="jdbc:mysql://101.37.12.135:3306/fycashier?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=GMT%2B8"
driverClass="com.mysql.cj.jdbc.Driver" password="Twc6MrzzjBiWSsjh" userId="fycashier" >
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
@ -37,28 +37,31 @@
也可以使用“MAVEN”来自动生成这样生成的代码会在target/generatord-source目录下
-->
<!--<javaModelGenerator targetPackage="com.forezp.entity" targetProject="MAVEN">-->
<javaModelGenerator targetPackage="com.chaozhanggui.system.cashierservice.entity" targetProject="src\main\java">
<javaModelGenerator targetPackage="com.chaozhanggui.system.cashierservice.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="mapper" targetProject="src\main\resources">
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.chaozhanggui.system.cashierservice.dao" targetProject="src\main\java">
<javaClientGenerator type="XMLMAPPER" targetPackage="com.chaozhanggui.system.cashierservice.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<!-- <table tableName="%" schema="fycashier" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table>-->
<table tableName="tb_shop_user_duty_pay" domainObjectName="ShopUserDutyPay"
<table tableName="tb_order_child_info" domainObjectName="OrderChildInfo"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="tb_order_child_detail" domainObjectName="OrderChildDetail"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
</context>
</generatorConfiguration>

View File

@ -228,6 +228,10 @@
<select id="selectByOrderId" resultType="java.math.BigDecimal">
select IFNULL(sum(price_amount),0) from tb_order_detail where order_id=#{orderId} and `status`='refund'
</select>
<select id="selectByOrderIdAndSkuId"
resultType="com.chaozhanggui.system.cashierservice.entity.TbOrderDetail">
select * from tb_order_detail where order_id = #{orderId} and product_sku_id = #{skuId}
</select>
<update id="updateStatusByOrderIdAndStatus">
update tb_order_detail set status = #{status} where order_id = #{orderId} and status='unpaid'

View File

@ -537,4 +537,9 @@
<select id="selectAllByStatus" resultMap="BaseResultMap">
select * from tb_order_info where `status`=#{status} and order_type !='miniapp'
</select>
<select id="selectByTradeAndMasterId"
resultType="com.chaozhanggui.system.cashierservice.entity.TbOrderInfo">
select * from tb_order_info where trade_day = #{day} and table_id = #{masterId} and shop_id = #{shopId}
</select>
</mapper>

View File

@ -883,7 +883,7 @@
</update>
<select id="selectByShopId" resultMap="ResultMapWithBLOBs">
select * from tb_product where shop_id=#{shopId} and status=1 and is_show_cash = 1
select * from tb_product where shop_id=#{shopId} and status=1 and is_show_cash = 1 and type_enum in ('normal','sku','currentPrice','weight')
<if test="commdityName != null and commdityName!='' ">
and name like CONCAT('%',#{commdityName},'%')
</if>
@ -893,7 +893,7 @@
<select id="selectByShopIdAndShopType" resultMap="ResultMapWithBLOBs">
select * from tb_product where shop_id=#{shopId} and status=1 and category_id=#{categoryId} and is_show_cash = 1
select * from tb_product where shop_id=#{shopId} and status=1 and category_id=#{categoryId} and is_show_cash = 1 and type_enum in ('normal','sku','currentPrice','weight')
<if test="commdityName != null and commdityName!='' ">
and name like CONCAT('%',#{commdityName},'%')