Skip to content
Snippets Groups Projects
Commit ad03a310 authored by Zetian Huang's avatar Zetian Huang
Browse files

Update method: query order by user_id

parent 9866e3e3
No related branches found
No related tags found
No related merge requests found
Showing
with 172 additions and 10 deletions
......@@ -133,6 +133,7 @@ public class StockedGoodsController {
Integer CId = (new ValidationChecker()).str2int(categoryId,1);
Idlist.add(CId);
}
if(Idlist.isEmpty()) Idlist.add(-1);
return RespBuilder.create(stockedGoodsService.getRandomGoods(Idlist), VerifyRule.COLLECTION_NOT_EMPTY,"success","fail");
}
......
......@@ -47,18 +47,21 @@ public class UserController {
}
}
@GetMapping("/user/update_address")
public JSONObject updateUserAddress(@RequestParam("user_id") Integer userId,
public JSONObject updateUserAddress(@RequestParam("user_id") String userId,
@RequestParam("address") String address){
Integer userIdInt = (new ValidationChecker()).str2int(userId,1);
User user = new User();
user.setId(userId);
user.setId(userIdInt);
user.setLocation(address);
userService.updateUserSelective(user);
return RespBuilder.create(userService.getUserById(userId), VerifyRule.NOT_NULL,"success","Update fail");
return RespBuilder.create(userService.getUserById(userIdInt), VerifyRule.NOT_NULL,"success","Update fail");
}
@GetMapping("/user/{user_id}/orders")
public JSONObject serachUserOrders(@PathVariable("user_id") Integer id){
return RespBuilder.create(orderService.getOrderByUserId(id),VerifyRule.COLLECTION_NOT_EMPTY,"success","Query error");
@GetMapping("/user/orders")
public JSONObject searchUserOrders(@RequestParam("user_id") String userId,@RequestParam("position") String position){
Integer userIdInt = (new ValidationChecker()).str2int(userId,1);
Integer positionInt = (new ValidationChecker()).str2int(position,1);
return RespBuilder.create(orderService.getOrderByUserId(userIdInt,positionInt),VerifyRule.COLLECTION_NOT_EMPTY,"success","Query error");
}
@PostMapping("/login")
......
package com.example.freshonline.dao;
import com.example.freshonline.dto.OrderDetail;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface OrderDetailMapper {
List<OrderDetail> selectByOrderId(@Param("order_id") Integer orderId);
List<OrderDetail> selectByUserId(@Param("user_id") Integer userId, Integer position);
}
package com.example.freshonline.dao;
import com.example.freshonline.dto.SaledGoodsDetail;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SaledGoodsDetailMapper {
public List<SaledGoodsDetail> selectByOrderId(@Param("order_id") Integer orderId);
}
package com.example.freshonline.dto;
import com.example.freshonline.model.Order;
import lombok.*;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderDetail extends Order {
@Getter
@Setter
public List<SaledGoodsDetail> goodsList;
}
package com.example.freshonline.dto;
import com.example.freshonline.model.SaledGoods;
import lombok.*;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SaledGoodsDetail extends SaledGoods {
@Getter
@Setter
public String name;
}
package com.example.freshonline.service;
import com.example.freshonline.dao.OrderDetailMapper;
import com.example.freshonline.dao.OrderMapper;
import com.example.freshonline.dto.OrderDetail;
import com.example.freshonline.model.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -11,9 +13,9 @@ import java.util.List;
public class OrderService {
@Autowired
private OrderMapper orderMapper;
private OrderDetailMapper orderDetailMapper;
public List<Order> getOrderByUserId(Integer userId){
return orderMapper.selectByUserId(userId);
public List<OrderDetail> getOrderByUserId(Integer userId, Integer position){
return orderDetailMapper.selectByUserId(userId,position);
}
}
spring.datasource.url=jdbc:mysql://localhost:3306/FreshOnline?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=
spring.datasource.password=root
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.example.freshonline.dao
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.freshonline.dao.OrderDetailMapper">
<resultMap id="BaseResultMap" type="com.example.freshonline.dto.OrderDetail">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
<id column="order_id" jdbcType="INTEGER" property="orderId" />
<result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="payment_method_id" jdbcType="INTEGER" property="paymentMethodId" />
<result column="order_time" jdbcType="TIMESTAMP" property="orderTime" />
<result column="pay_time" jdbcType="TIMESTAMP" property="payTime" />
<result column="finish_time" jdbcType="TIMESTAMP" property="finishTime" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="location" jdbcType="VARCHAR" property="location" />
<collection property="goodsList" javaType="java.util.ArrayList" ofType="com.example.freshonline.dto.SaledGoodsDetail"
select="com.example.freshonline.dao.SaledGoodsDetailMapper.selectByOrderId" column="{order_id=order_id}"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
order_id, user_id, payment_method_id, order_time, pay_time, finish_time, status,
location
</sql>
<select id="selectByOrderId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
select
<include refid="Base_Column_List" />
from `order`
where order_id = #{order_id,jdbcType=INTEGER}
</select>
<select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
select
<include refid="Base_Column_List" />
from `order`
where user_id = #{user_id,jdbcType=INTEGER}
limit #{position,jdbcType=INTEGER} , 5
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.freshonline.dao.SaledGoodsDetailMapper">
<resultMap id="BaseResultMap" type="com.example.freshonline.dto.SaledGoodsDetail">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
<id column="order_id" jdbcType="INTEGER" property="orderId" />
<id column="goods_id" jdbcType="INTEGER" property="goodsId" />
<result column="price" jdbcType="DECIMAL" property="price" />
<result column="count" jdbcType="DECIMAL" property="count" />
<result column="rate" jdbcType="INTEGER" property="rate" />
<result column="name" jdbcType="VARCHAR" property="name" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.example.freshonline.dto.SaledGoodsDetail">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
<result column="comment" jdbcType="LONGVARCHAR" property="comment" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
a.order_id, a.goods_id, a.price, a.count, a.rate, b.name
</sql>
<sql id="Blob_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
comment
</sql>
<select id="selectByOrderId" parameterType="map" resultMap="ResultMapWithBLOBs">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sun Feb 06 18:37:56 EST 2022.
-->
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from saled_goods a left join stocked_goods b on a.goods_id=b.id
where order_id = #{order_id,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment