Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
3828b23df5
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.ghy.web.controller.order;
|
||||||
|
|
||||||
|
import com.ghy.common.core.controller.BaseController;
|
||||||
|
import com.ghy.order.domain.OrderTemplate;
|
||||||
|
import com.ghy.order.service.OrderTemplateService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("order/template")
|
||||||
|
public class OrderTemplateController extends BaseController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrderTemplateService orderTemplateService;
|
||||||
|
|
||||||
|
@PostMapping("insert")
|
||||||
|
public int insert(OrderTemplate orderTemplate) {
|
||||||
|
Long userId = getUserId();
|
||||||
|
Assert.notNull(userId, "UserId is null !");
|
||||||
|
orderTemplate.setUserId(userId);
|
||||||
|
return orderTemplateService.insert(orderTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("delete")
|
||||||
|
public int delete(Long id) {
|
||||||
|
return orderTemplateService.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("update")
|
||||||
|
public int update(OrderTemplate orderTemplate) {
|
||||||
|
return orderTemplateService.update(orderTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@GetMapping("selectByUserId")
|
||||||
|
public List<OrderTemplate> selectByUserId() {
|
||||||
|
Long userId = getUserId();
|
||||||
|
return orderTemplateService.selectByUserId(userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
package com.ghy.order.domain;
|
package com.ghy.order.domain;
|
||||||
|
|
||||||
|
import com.ghy.common.core.domain.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单模板
|
* 订单模板
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class OrderTemplate {
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class OrderTemplate extends BaseEntity {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
private Long userId;
|
private Long userId;
|
||||||
// 模板名称
|
// 模板名称
|
||||||
private String templateName;
|
private String templateName;
|
||||||
// 商品ID
|
|
||||||
private Long goodsId;
|
|
||||||
// 商品类型ID(第三层)
|
|
||||||
private Long deptGoodsCategoryId;
|
|
||||||
// 商品品牌
|
// 商品品牌
|
||||||
private String goodsBrand;
|
private String goodsBrand;
|
||||||
// 商品规格
|
// 商品规格
|
||||||
|
|
@ -44,8 +45,6 @@ public class OrderTemplate {
|
||||||
private Integer informationFee;
|
private Integer informationFee;
|
||||||
// 奖励金(限制整数)
|
// 奖励金(限制整数)
|
||||||
private Integer bonus;
|
private Integer bonus;
|
||||||
// 备注
|
|
||||||
private String remark;
|
|
||||||
// 物流单号
|
// 物流单号
|
||||||
private String logisticsCode;
|
private String logisticsCode;
|
||||||
// 是否需要拉货
|
// 是否需要拉货
|
||||||
|
|
@ -54,4 +53,7 @@ public class OrderTemplate {
|
||||||
private int needCarry;
|
private int needCarry;
|
||||||
// 楼层
|
// 楼层
|
||||||
private Integer floor;
|
private Integer floor;
|
||||||
|
|
||||||
|
// 商品
|
||||||
|
private List<OrderTemplateGoods> goods;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.ghy.order.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class OrderTemplateGoods {
|
||||||
|
|
||||||
|
// 订单模板Id
|
||||||
|
private Long orderTemplateId;
|
||||||
|
// 商品ID
|
||||||
|
private Long goodsId;
|
||||||
|
// 商品名称
|
||||||
|
private String goodsName;
|
||||||
|
// 商品类型ID(第三层)
|
||||||
|
private Long deptGoodsCategoryId;
|
||||||
|
// 商品数量
|
||||||
|
private Long number;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.ghy.order.mapper;
|
||||||
|
|
||||||
|
import com.ghy.order.domain.OrderTemplate;
|
||||||
|
import com.ghy.order.domain.OrderTemplateGoods;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单模板Mapper
|
||||||
|
*/
|
||||||
|
public interface OrderTemplateMapper {
|
||||||
|
|
||||||
|
int insert(OrderTemplate orderTemplate);
|
||||||
|
|
||||||
|
int update(OrderTemplate orderTemplate);
|
||||||
|
|
||||||
|
int delete(Long id);
|
||||||
|
|
||||||
|
int batchDelete(Set<Long> ids);
|
||||||
|
|
||||||
|
OrderTemplate selectById(Long id);
|
||||||
|
|
||||||
|
List<OrderTemplate> selectByIds(Set<Long> ids);
|
||||||
|
|
||||||
|
List<OrderTemplate> select(OrderTemplate orderTemplate);
|
||||||
|
|
||||||
|
// OrderTemplateGoods 接口
|
||||||
|
|
||||||
|
int deleteGoods(Long orderTemplateId);
|
||||||
|
|
||||||
|
List<OrderTemplateGoods> selectGoods(Long orderTemplateId);
|
||||||
|
|
||||||
|
int insertGoods(OrderTemplateGoods goods);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.ghy.order.service;
|
||||||
|
|
||||||
|
import com.ghy.order.domain.OrderTemplate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface OrderTemplateService {
|
||||||
|
|
||||||
|
int insert(OrderTemplate orderTemplate);
|
||||||
|
|
||||||
|
int update(OrderTemplate orderTemplate);
|
||||||
|
|
||||||
|
int delete(Long id);
|
||||||
|
|
||||||
|
int batchDelete(Set<Long> ids);
|
||||||
|
|
||||||
|
OrderTemplate selectById(Long id);
|
||||||
|
|
||||||
|
List<OrderTemplate> select(OrderTemplate orderTemplate);
|
||||||
|
|
||||||
|
List<OrderTemplate> selectByUserId(Long userId);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
package com.ghy.order.service.impl;
|
||||||
|
|
||||||
|
import com.ghy.order.domain.OrderTemplate;
|
||||||
|
import com.ghy.order.domain.OrderTemplateGoods;
|
||||||
|
import com.ghy.order.mapper.OrderTemplateMapper;
|
||||||
|
import com.ghy.order.service.OrderTemplateService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OrderTemplateServiceImpl implements OrderTemplateService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrderTemplateMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public int insert(OrderTemplate orderTemplate) {
|
||||||
|
int count = mapper.insert(orderTemplate);
|
||||||
|
// 保存选中的商品信息
|
||||||
|
saveGoods(orderTemplate);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public int update(OrderTemplate orderTemplate) {
|
||||||
|
int count = mapper.update(orderTemplate);
|
||||||
|
// 全量替换模板的商品信息
|
||||||
|
mapper.deleteGoods(orderTemplate.getId());
|
||||||
|
saveGoods(orderTemplate);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存订单模板中选中的商品信息
|
||||||
|
*/
|
||||||
|
private void saveGoods(OrderTemplate orderTemplate) {
|
||||||
|
List<OrderTemplateGoods> goods = orderTemplate.getGoods();
|
||||||
|
if (!CollectionUtils.isEmpty(goods)) {
|
||||||
|
for (OrderTemplateGoods x : goods) {
|
||||||
|
x.setOrderTemplateId(orderTemplate.getId());
|
||||||
|
mapper.insertGoods(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public int delete(Long id) {
|
||||||
|
// 删除模板关联的商品信息
|
||||||
|
mapper.deleteGoods(id);
|
||||||
|
// 删除模板
|
||||||
|
return mapper.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public int batchDelete(Set<Long> ids) {
|
||||||
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
ids.forEach(x -> mapper.deleteGoods(x));
|
||||||
|
return mapper.batchDelete(ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderTemplate selectById(Long id) {
|
||||||
|
List<OrderTemplateGoods> goods = mapper.selectGoods(id);
|
||||||
|
OrderTemplate orderTemplate = mapper.selectById(id);
|
||||||
|
orderTemplate.setGoods(goods);
|
||||||
|
return orderTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OrderTemplate> select(OrderTemplate orderTemplate) {
|
||||||
|
List<OrderTemplate> list = mapper.select(orderTemplate);
|
||||||
|
for (OrderTemplate item : list) {
|
||||||
|
List<OrderTemplateGoods> goods = mapper.selectGoods(item.getId());
|
||||||
|
item.setGoods(goods);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OrderTemplate> selectByUserId(Long userId) {
|
||||||
|
OrderTemplate param = new OrderTemplate();
|
||||||
|
param.setUserId(userId);
|
||||||
|
return select(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
<?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.ghy.order.mapper.OrderTemplateMapper">
|
||||||
|
|
||||||
|
<resultMap id="ColumnMap" type="com.ghy.order.domain.OrderTemplate">
|
||||||
|
<id property="id" column="id"/>
|
||||||
|
<result property="userId" column="user_id"/>
|
||||||
|
<result property="templateName" column="template_name"/>
|
||||||
|
<result property="goodsBrand" column="goods_brand"/>
|
||||||
|
<result property="goodsSpecification" column="goods_specification"/>
|
||||||
|
<result property="videoUrl" column="video_url"/>
|
||||||
|
<result property="imageUrl" column="image_url"/>
|
||||||
|
<result property="addressId" column="address_id"/>
|
||||||
|
<result property="streetId" column="street_id"/>
|
||||||
|
<result property="fullAddress" column="full_address"/>
|
||||||
|
<result property="customerName" column="customer_name"/>
|
||||||
|
<result property="customerPhone" column="customer_phone"/>
|
||||||
|
<result property="orderMode" column="order_mode"/>
|
||||||
|
<result property="price" column="price"/>
|
||||||
|
<result property="agencyFund" column="agency_fund"/>
|
||||||
|
<result property="informationFee" column="information_fee"/>
|
||||||
|
<result property="bonus" column="bonus"/>
|
||||||
|
<result property="logisticsCode" column="logistics_code"/>
|
||||||
|
<result property="needWagon" column="need_wagon"/>
|
||||||
|
<result property="needCarry" column="need_carry"/>
|
||||||
|
<result property="floor" column="floor"/>
|
||||||
|
<result property="createBy" column="create_by"/>
|
||||||
|
<result property="createTime" column="create_time"/>
|
||||||
|
<result property="updateBy" column="update_by"/>
|
||||||
|
<result property="updateTime" column="update_time"/>
|
||||||
|
<result property="remark" column="remark"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.ghy.order.domain.OrderTemplate">
|
||||||
|
UPDATE order_template
|
||||||
|
<set>
|
||||||
|
<if test="templateName != null and templateName != 0">template_name = #{templateName},</if>
|
||||||
|
<if test="goodsBrand != null and goodsBrand != 0">goods_brand = #{goodsBrand},</if>
|
||||||
|
<if test="goodsSpecification != null and goodsSpecification != 0">goods_specification = #{goodsSpecification},</if>
|
||||||
|
<if test="videoUrl != null and videoUrl != 0">video_url = #{videoUrl},</if>
|
||||||
|
<if test="imageUrl != null and imageUrl != 0">image_url = #{imageUrl},</if>
|
||||||
|
<if test="addressId != null and addressId != 0">address_id = #{addressId},</if>
|
||||||
|
<if test="streetId != null and streetId != 0">street_id = #{streetId},</if>
|
||||||
|
<if test="fullAddress != null and fullAddress != 0">full_address = #{fullAddress},</if>
|
||||||
|
<if test="customerName != null and customerName != 0">customer_name = #{customerName},</if>
|
||||||
|
<if test="customerPhone != null and customerPhone != 0">customer_phone = #{customerPhone},</if>
|
||||||
|
<if test="orderMode != null and orderMode != 0">order_mode = #{orderMode},</if>
|
||||||
|
<if test="price != null and price != 0">price = #{price},</if>
|
||||||
|
<if test="agencyFund != null and agencyFund != 0">agency_fund = #{agencyFund},</if>
|
||||||
|
<if test="informationFee != null and informationFee != 0">information_fee = #{informationFee},</if>
|
||||||
|
<if test="bonus != null and bonus != 0">bonus = #{bonus},</if>
|
||||||
|
<if test="logisticsCode != null and logisticsCode != 0">logistics_code = #{logisticsCode},</if>
|
||||||
|
<if test="needWagon != null and needWagon != 0">need_wagon = #{needWagon},</if>
|
||||||
|
<if test="needCarry != null and needCarry != 0">need_carry = #{needCarry},</if>
|
||||||
|
<if test="floor != null and floor != 0">floor = #{floor},</if>
|
||||||
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||||
|
update_time = SYSDATE()
|
||||||
|
</set>
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<insert id="insert" parameterType="com.ghy.order.domain.OrderTemplate" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
INSERT INTO order_template(
|
||||||
|
user_id,
|
||||||
|
<if test="templateName != null and templateName != 0">template_name,</if>
|
||||||
|
<if test="goodsBrand != null and goodsBrand != 0">goods_brand,</if>
|
||||||
|
<if test="goodsSpecification != null and goodsSpecification != 0">goods_specification = #{goodsSpecification},</if>
|
||||||
|
<if test="videoUrl != null and videoUrl != 0">video_url,</if>
|
||||||
|
<if test="imageUrl != null and imageUrl != 0">image_url,</if>
|
||||||
|
<if test="addressId != null and addressId != 0">address_id,</if>
|
||||||
|
<if test="streetId != null and streetId != 0">street_id,</if>
|
||||||
|
<if test="fullAddress != null and fullAddress != 0">full_address,</if>
|
||||||
|
<if test="customerName != null and customerName != 0">customer_name,</if>
|
||||||
|
<if test="customerPhone != null and customerPhone != 0">customer_phone,</if>
|
||||||
|
<if test="orderMode != null and orderMode != 0">order_mode,</if>
|
||||||
|
<if test="price != null and price != 0">price,</if>
|
||||||
|
<if test="agencyFund != null and agencyFund != 0">agency_fund,</if>
|
||||||
|
<if test="informationFee != null and informationFee != 0">information_fee,</if>
|
||||||
|
<if test="bonus != null and bonus != 0">bonus,</if>
|
||||||
|
<if test="logisticsCode != null and logisticsCode != 0">logistics_code,</if>
|
||||||
|
<if test="needWagon != null and needWagon != 0">need_wagon,</if>
|
||||||
|
<if test="needCarry != null and needCarry != 0">need_carry,</if>
|
||||||
|
<if test="floor != null and floor != 0">floor,</if>
|
||||||
|
create_time
|
||||||
|
)VALUES(
|
||||||
|
#{userId},
|
||||||
|
<if test="templateName != null and templateName != 0">#{templateName},</if>
|
||||||
|
<if test="goodsBrand != null and goodsBrand != 0">#{goodsBrand},</if>
|
||||||
|
<if test="goodsSpecification != null and goodsSpecification != 0">goods_specification = #{goodsSpecification},</if>
|
||||||
|
<if test="videoUrl != null and videoUrl != 0">#{videoUrl},</if>
|
||||||
|
<if test="imageUrl != null and imageUrl != 0">#{imageUrl},</if>
|
||||||
|
<if test="addressId != null and addressId != 0">#{addressId},</if>
|
||||||
|
<if test="streetId != null and streetId != 0">#{streetId},</if>
|
||||||
|
<if test="fullAddress != null and fullAddress != 0">#{fullAddress},</if>
|
||||||
|
<if test="customerName != null and customerName != 0">#{customerName},</if>
|
||||||
|
<if test="customerPhone != null and customerPhone != 0">#{customerPhone},</if>
|
||||||
|
<if test="orderMode != null and orderMode != 0">#{orderMode},</if>
|
||||||
|
<if test="price != null and price != 0">#{price},</if>
|
||||||
|
<if test="agencyFund != null and agencyFund != 0">#{agencyFund},</if>
|
||||||
|
<if test="informationFee != null and informationFee != 0">#{informationFee},</if>
|
||||||
|
<if test="bonus != null and bonus != 0">#{bonus},</if>
|
||||||
|
<if test="logisticsCode != null and logisticsCode != 0">#{logisticsCode},</if>
|
||||||
|
<if test="needWagon != null and needWagon != 0">#{needWagon},</if>
|
||||||
|
<if test="needCarry != null and needCarry != 0">#{needCarry},</if>
|
||||||
|
<if test="floor != null and floor != 0">#{floor},</if>
|
||||||
|
SYSDATE()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<select id="select" parameterType="com.ghy.order.domain.OrderTemplate" resultMap="ColumnMap">
|
||||||
|
<include refid="selectColumns"/>
|
||||||
|
<where>
|
||||||
|
<if test="userId != null and userId != 0">
|
||||||
|
AND user_id = #{userId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectById" parameterType="long" resultMap="ColumnMap">
|
||||||
|
<include refid="selectColumns"/> WHERE id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByIds" resultType="com.ghy.order.domain.OrderTemplate">
|
||||||
|
<include refid="selectColumns"/> WHERE id IN
|
||||||
|
<foreach collection="array" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<delete id="delete" parameterType="Long">
|
||||||
|
DELETE FROM order_template WHERE id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="batchDelete">
|
||||||
|
DELETE FROM order_template WHERE id IN
|
||||||
|
<foreach collection="array" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<sql id="selectColumns">
|
||||||
|
SELECT id, user_id, template_name,goods_brand, goods_specification, video_url, image_url,
|
||||||
|
address_id, street_id, full_address, customer_name, customer_phone, order_mode,
|
||||||
|
price, agency_fund, information_fee, bonus, logistics_code, need_wagon, need_carry, floor,
|
||||||
|
create_by, create_time, update_by, update_time, remark
|
||||||
|
FROM order_template
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- order_template_goods SQL -->
|
||||||
|
|
||||||
|
<insert id="insertGoods">
|
||||||
|
INSERT INTO order_template_goods(order_template_id, goods_id, goods_name, dept_goodscategory_id, number)
|
||||||
|
VALUES(#{orderTemplateId}, #{goodsId}, #{goodsName}, #{deptGoodsCategoryId}, #{number})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<delete id="deleteGoods" parameterType="Long">
|
||||||
|
DELETE FROM order_template_goods WHERE order_template_id = #{orderTemplateId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="selectGoods" resultType="com.ghy.order.domain.OrderTemplateGoods">
|
||||||
|
SELECT order_template_id AS orderTemplateId,
|
||||||
|
goods_id AS goodsId,
|
||||||
|
goods_name AS goodsName,
|
||||||
|
dept_goodscategory_id AS deptGoodsCategoryId,
|
||||||
|
number
|
||||||
|
FROM order_template_goods
|
||||||
|
WHERE order_template_id = #{orderTemplateId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue