From 1a0fa068d82023675080038c8e7f7309294c01d0 Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Thu, 31 Jan 2019 15:12:54 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E8=B4=A6=E5=8D=95=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._\345\210\235\345\247\213\345\214\226.sql" | 77 +++++++++ .../com/mark/web/bill/entity/po/Account.java | 123 ++++++++++++++ .../com/mark/web/bill/entity/po/Goods.java | 101 ++++++++++++ .../com/mark/web/bill/entity/po/GoodsImg.java | 78 +++++++++ .../mark/web/bill/mapper/AccountMapper.java | 17 ++ .../mark/web/bill/mapper/GoodsImgMapper.java | 17 ++ .../com/mark/web/bill/mapper/GoodsMapper.java | 17 ++ src/main/resources/generatorConfig.xml | 3 +- .../resources/mappers/bill/AccountMapper.xml | 155 ++++++++++++++++++ .../resources/mappers/bill/GoodsImgMapper.xml | 108 ++++++++++++ .../resources/mappers/bill/GoodsMapper.xml | 130 +++++++++++++++ 11 files changed, 825 insertions(+), 1 deletion(-) create mode 100644 "doc/database/bill/campuso2o_bill_2.0_\345\210\235\345\247\213\345\214\226.sql" create mode 100644 src/main/java/com/mark/web/bill/entity/po/Account.java create mode 100644 src/main/java/com/mark/web/bill/entity/po/Goods.java create mode 100644 src/main/java/com/mark/web/bill/entity/po/GoodsImg.java create mode 100644 src/main/java/com/mark/web/bill/mapper/AccountMapper.java create mode 100644 src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java create mode 100644 src/main/java/com/mark/web/bill/mapper/GoodsMapper.java create mode 100644 src/main/resources/mappers/bill/AccountMapper.xml create mode 100644 src/main/resources/mappers/bill/GoodsImgMapper.xml create mode 100644 src/main/resources/mappers/bill/GoodsMapper.xml diff --git "a/doc/database/bill/campuso2o_bill_2.0_\345\210\235\345\247\213\345\214\226.sql" "b/doc/database/bill/campuso2o_bill_2.0_\345\210\235\345\247\213\345\214\226.sql" new file mode 100644 index 0000000..5e2c3f3 --- /dev/null +++ "b/doc/database/bill/campuso2o_bill_2.0_\345\210\235\345\247\213\345\214\226.sql" @@ -0,0 +1,77 @@ +/* +Navicat MySQL Data Transfer + +Source Server : 阿里云_mark_7561669Dong! +Source Server Version : 50722 +Source Host : 47.95.13.238:3306 +Source Database : campuso2o_bill_2.0 + +Target Server Type : MYSQL +Target Server Version : 50722 +File Encoding : 65001 + +Date: 2019-01-31 15:01:39 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for tb_bill_account +-- ---------------------------- +DROP TABLE IF EXISTS `tb_bill_account`; +CREATE TABLE `tb_bill_account` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `fk_goods_id` int(11) unsigned NOT NULL COMMENT '逻辑外键,商品id', + `fk_user_id` int(11) unsigned NOT NULL COMMENT '逻辑外键,用户id', + `quantity` int(10) DEFAULT NULL COMMENT '商品数量', + `total_price` decimal(20,2) DEFAULT NULL COMMENT '总价,单位是元,保留两位小数', + `description` varchar(100) DEFAULT NULL COMMENT '账单的描述', + `enable_status` int(4) NOT NULL COMMENT '1-未结算,2-已结算', + `create_time` datetime NOT NULL COMMENT '创建时间', + `payment_time` datetime NOT NULL COMMENT '结算时间', + `last_edit_time` datetime NOT NULL COMMENT '最后一次更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='账单信息表'; + +-- ---------------------------- +-- Records of tb_bill_account +-- ---------------------------- + +-- ---------------------------- +-- Table structure for tb_bill_goods +-- ---------------------------- +DROP TABLE IF EXISTS `tb_bill_goods`; +CREATE TABLE `tb_bill_goods` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `fk_owner_id` int(11) unsigned NOT NULL COMMENT '逻辑外键,拥有者id', + `goods_name` varchar(50) NOT NULL COMMENT '商品名称', + `price` decimal(20,2) NOT NULL COMMENT '单价,单位-元保留两位小数', + `priority` int(4) DEFAULT NULL, + `enable_status` int(4) NOT NULL COMMENT '1-可用,2-禁用', + `create_time` datetime NOT NULL COMMENT '创建时间', + `last_edit_time` datetime NOT NULL COMMENT '最后一次更新时间', + PRIMARY KEY (`id`), + UNIQUE KEY `goods_name_unique` (`goods_name`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='账单商品表'; + +-- ---------------------------- +-- Records of tb_bill_goods +-- ---------------------------- + +-- ---------------------------- +-- Table structure for tb_bill_goods_img +-- ---------------------------- +DROP TABLE IF EXISTS `tb_bill_goods_img`; +CREATE TABLE `tb_bill_goods_img` ( + `id` int(20) NOT NULL AUTO_INCREMENT COMMENT 'id', + `goods_id` int(20) DEFAULT NULL COMMENT '逻辑外键,商品id', + `img_addr` varchar(2000) NOT NULL COMMENT '地址', + `priority` int(2) DEFAULT '0' COMMENT '权重', + `enable_status` int(4) NOT NULL COMMENT '1-可用,2-禁用', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='商品资源图片表'; + +-- ---------------------------- +-- Records of tb_bill_goods_img +-- ---------------------------- diff --git a/src/main/java/com/mark/web/bill/entity/po/Account.java b/src/main/java/com/mark/web/bill/entity/po/Account.java new file mode 100644 index 0000000..d2edbe5 --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/po/Account.java @@ -0,0 +1,123 @@ +package com.mark.web.bill.entity.po; + +import java.math.BigDecimal; +import java.util.Date; + +public class Account { + private Integer id; + + private Integer fkGoodsId; + + private Integer fkUserId; + + private Integer quantity; + + private BigDecimal totalPrice; + + private String description; + + private Integer enableStatus; + + private Date createTime; + + private Date paymentTime; + + private Date lastEditTime; + + public Account(Integer id, Integer fkGoodsId, Integer fkUserId, Integer quantity, BigDecimal totalPrice, String description, Integer enableStatus, Date createTime, Date paymentTime, Date lastEditTime) { + this.id = id; + this.fkGoodsId = fkGoodsId; + this.fkUserId = fkUserId; + this.quantity = quantity; + this.totalPrice = totalPrice; + this.description = description; + this.enableStatus = enableStatus; + this.createTime = createTime; + this.paymentTime = paymentTime; + this.lastEditTime = lastEditTime; + } + + public Account() { + super(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getFkGoodsId() { + return fkGoodsId; + } + + public void setFkGoodsId(Integer fkGoodsId) { + this.fkGoodsId = fkGoodsId; + } + + public Integer getFkUserId() { + return fkUserId; + } + + public void setFkUserId(Integer fkUserId) { + this.fkUserId = fkUserId; + } + + public Integer getQuantity() { + return quantity; + } + + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + public BigDecimal getTotalPrice() { + return totalPrice; + } + + public void setTotalPrice(BigDecimal totalPrice) { + this.totalPrice = totalPrice; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + public Integer getEnableStatus() { + return enableStatus; + } + + public void setEnableStatus(Integer enableStatus) { + this.enableStatus = enableStatus; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getPaymentTime() { + return paymentTime; + } + + public void setPaymentTime(Date paymentTime) { + this.paymentTime = paymentTime; + } + + public Date getLastEditTime() { + return lastEditTime; + } + + public void setLastEditTime(Date lastEditTime) { + this.lastEditTime = lastEditTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/entity/po/Goods.java b/src/main/java/com/mark/web/bill/entity/po/Goods.java new file mode 100644 index 0000000..ed2d961 --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/po/Goods.java @@ -0,0 +1,101 @@ +package com.mark.web.bill.entity.po; + +import java.math.BigDecimal; +import java.util.Date; + +public class Goods { + private Integer id; + + private Integer fkOwnerId; + + private String goodsName; + + private BigDecimal price; + + private Integer priority; + + private Integer enableStatus; + + private Date createTime; + + private Date lastEditTime; + + public Goods(Integer id, Integer fkOwnerId, String goodsName, BigDecimal price, Integer priority, Integer enableStatus, Date createTime, Date lastEditTime) { + this.id = id; + this.fkOwnerId = fkOwnerId; + this.goodsName = goodsName; + this.price = price; + this.priority = priority; + this.enableStatus = enableStatus; + this.createTime = createTime; + this.lastEditTime = lastEditTime; + } + + public Goods() { + super(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getFkOwnerId() { + return fkOwnerId; + } + + public void setFkOwnerId(Integer fkOwnerId) { + this.fkOwnerId = fkOwnerId; + } + + public String getGoodsName() { + return goodsName; + } + + public void setGoodsName(String goodsName) { + this.goodsName = goodsName == null ? null : goodsName.trim(); + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public Integer getPriority() { + return priority; + } + + public void setPriority(Integer priority) { + this.priority = priority; + } + + public Integer getEnableStatus() { + return enableStatus; + } + + public void setEnableStatus(Integer enableStatus) { + this.enableStatus = enableStatus; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getLastEditTime() { + return lastEditTime; + } + + public void setLastEditTime(Date lastEditTime) { + this.lastEditTime = lastEditTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/entity/po/GoodsImg.java b/src/main/java/com/mark/web/bill/entity/po/GoodsImg.java new file mode 100644 index 0000000..51f229d --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/po/GoodsImg.java @@ -0,0 +1,78 @@ +package com.mark.web.bill.entity.po; + +import java.util.Date; + +public class GoodsImg { + private Integer id; + + private Integer goodsId; + + private String imgAddr; + + private Integer priority; + + private Integer enableStatus; + + private Date createTime; + + public GoodsImg(Integer id, Integer goodsId, String imgAddr, Integer priority, Integer enableStatus, Date createTime) { + this.id = id; + this.goodsId = goodsId; + this.imgAddr = imgAddr; + this.priority = priority; + this.enableStatus = enableStatus; + this.createTime = createTime; + } + + public GoodsImg() { + super(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getGoodsId() { + return goodsId; + } + + public void setGoodsId(Integer goodsId) { + this.goodsId = goodsId; + } + + public String getImgAddr() { + return imgAddr; + } + + public void setImgAddr(String imgAddr) { + this.imgAddr = imgAddr == null ? null : imgAddr.trim(); + } + + public Integer getPriority() { + return priority; + } + + public void setPriority(Integer priority) { + this.priority = priority; + } + + public Integer getEnableStatus() { + return enableStatus; + } + + public void setEnableStatus(Integer enableStatus) { + this.enableStatus = enableStatus; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/mapper/AccountMapper.java b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java new file mode 100644 index 0000000..dc564ed --- /dev/null +++ b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java @@ -0,0 +1,17 @@ +package com.mark.web.bill.mapper; + +import com.mark.web.bill.entity.po.Account; + +public interface AccountMapper { + int deleteByPrimaryKey(Integer id); + + int insert(Account record); + + int insertSelective(Account record); + + Account selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(Account record); + + int updateByPrimaryKey(Account record); +} \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java new file mode 100644 index 0000000..065410f --- /dev/null +++ b/src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java @@ -0,0 +1,17 @@ +package com.mark.web.bill.mapper; + +import com.mark.web.bill.entity.po.GoodsImg; + +public interface GoodsImgMapper { + int deleteByPrimaryKey(Integer id); + + int insert(GoodsImg record); + + int insertSelective(GoodsImg record); + + GoodsImg selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(GoodsImg record); + + int updateByPrimaryKey(GoodsImg record); +} \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java new file mode 100644 index 0000000..696efd4 --- /dev/null +++ b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java @@ -0,0 +1,17 @@ +package com.mark.web.bill.mapper; + +import com.mark.web.bill.entity.po.Goods; + +public interface GoodsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(Goods record); + + int insertSelective(Goods record); + + Goods selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(Goods record); + + int updateByPrimaryKey(Goods record); +} \ No newline at end of file diff --git a/src/main/resources/generatorConfig.xml b/src/main/resources/generatorConfig.xml index c0c1c4c..f2541ce 100644 --- a/src/main/resources/generatorConfig.xml +++ b/src/main/resources/generatorConfig.xml @@ -68,7 +68,8 @@ - +
+
diff --git a/src/main/resources/mappers/bill/AccountMapper.xml b/src/main/resources/mappers/bill/AccountMapper.xml new file mode 100644 index 0000000..cf5613a --- /dev/null +++ b/src/main/resources/mappers/bill/AccountMapper.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + id, fk_goods_id, fk_user_id, quantity, total_price, description, enable_status, create_time, + payment_time, last_edit_time + + + + delete from tb_bill_account + where id = #{id,jdbcType=INTEGER} + + + insert into tb_bill_account (id, fk_goods_id, fk_user_id, + quantity, total_price, description, + enable_status, create_time, payment_time, + last_edit_time) + values (#{id,jdbcType=INTEGER}, #{fkGoodsId,jdbcType=INTEGER}, #{fkUserId,jdbcType=INTEGER}, + #{quantity,jdbcType=INTEGER}, #{totalPrice,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR}, + #{enableStatus,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{paymentTime,jdbcType=TIMESTAMP}, + #{lastEditTime,jdbcType=TIMESTAMP}) + + + insert into tb_bill_account + + + id, + + + fk_goods_id, + + + fk_user_id, + + + quantity, + + + total_price, + + + description, + + + enable_status, + + + create_time, + + + payment_time, + + + last_edit_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{fkGoodsId,jdbcType=INTEGER}, + + + #{fkUserId,jdbcType=INTEGER}, + + + #{quantity,jdbcType=INTEGER}, + + + #{totalPrice,jdbcType=DECIMAL}, + + + #{description,jdbcType=VARCHAR}, + + + #{enableStatus,jdbcType=INTEGER}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{paymentTime,jdbcType=TIMESTAMP}, + + + #{lastEditTime,jdbcType=TIMESTAMP}, + + + + + update tb_bill_account + + + fk_goods_id = #{fkGoodsId,jdbcType=INTEGER}, + + + fk_user_id = #{fkUserId,jdbcType=INTEGER}, + + + quantity = #{quantity,jdbcType=INTEGER}, + + + total_price = #{totalPrice,jdbcType=DECIMAL}, + + + description = #{description,jdbcType=VARCHAR}, + + + enable_status = #{enableStatus,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + payment_time = #{paymentTime,jdbcType=TIMESTAMP}, + + + last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_bill_account + set fk_goods_id = #{fkGoodsId,jdbcType=INTEGER}, + fk_user_id = #{fkUserId,jdbcType=INTEGER}, + quantity = #{quantity,jdbcType=INTEGER}, + total_price = #{totalPrice,jdbcType=DECIMAL}, + description = #{description,jdbcType=VARCHAR}, + enable_status = #{enableStatus,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + payment_time = #{paymentTime,jdbcType=TIMESTAMP}, + last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mappers/bill/GoodsImgMapper.xml b/src/main/resources/mappers/bill/GoodsImgMapper.xml new file mode 100644 index 0000000..3f83fdb --- /dev/null +++ b/src/main/resources/mappers/bill/GoodsImgMapper.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + id, goods_id, img_addr, priority, enable_status, create_time + + + + delete from tb_bill_goods_img + where id = #{id,jdbcType=INTEGER} + + + insert into tb_bill_goods_img (id, goods_id, img_addr, + priority, enable_status, create_time + ) + values (#{id,jdbcType=INTEGER}, #{goodsId,jdbcType=INTEGER}, #{imgAddr,jdbcType=VARCHAR}, + #{priority,jdbcType=INTEGER}, #{enableStatus,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP} + ) + + + insert into tb_bill_goods_img + + + id, + + + goods_id, + + + img_addr, + + + priority, + + + enable_status, + + + create_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{goodsId,jdbcType=INTEGER}, + + + #{imgAddr,jdbcType=VARCHAR}, + + + #{priority,jdbcType=INTEGER}, + + + #{enableStatus,jdbcType=INTEGER}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + update tb_bill_goods_img + + + goods_id = #{goodsId,jdbcType=INTEGER}, + + + img_addr = #{imgAddr,jdbcType=VARCHAR}, + + + priority = #{priority,jdbcType=INTEGER}, + + + enable_status = #{enableStatus,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_bill_goods_img + set goods_id = #{goodsId,jdbcType=INTEGER}, + img_addr = #{imgAddr,jdbcType=VARCHAR}, + priority = #{priority,jdbcType=INTEGER}, + enable_status = #{enableStatus,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mappers/bill/GoodsMapper.xml b/src/main/resources/mappers/bill/GoodsMapper.xml new file mode 100644 index 0000000..ac382ef --- /dev/null +++ b/src/main/resources/mappers/bill/GoodsMapper.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + id, fk_owner_id, goods_name, price, priority, enable_status, create_time, last_edit_time + + + + delete from tb_bill_goods + where id = #{id,jdbcType=INTEGER} + + + insert into tb_bill_goods (id, fk_owner_id, goods_name, + price, priority, enable_status, + create_time, last_edit_time) + values (#{id,jdbcType=INTEGER}, #{fkOwnerId,jdbcType=INTEGER}, #{goodsName,jdbcType=VARCHAR}, + #{price,jdbcType=DECIMAL}, #{priority,jdbcType=INTEGER}, #{enableStatus,jdbcType=INTEGER}, + #{createTime,jdbcType=TIMESTAMP}, #{lastEditTime,jdbcType=TIMESTAMP}) + + + insert into tb_bill_goods + + + id, + + + fk_owner_id, + + + goods_name, + + + price, + + + priority, + + + enable_status, + + + create_time, + + + last_edit_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{fkOwnerId,jdbcType=INTEGER}, + + + #{goodsName,jdbcType=VARCHAR}, + + + #{price,jdbcType=DECIMAL}, + + + #{priority,jdbcType=INTEGER}, + + + #{enableStatus,jdbcType=INTEGER}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{lastEditTime,jdbcType=TIMESTAMP}, + + + + + update tb_bill_goods + + + fk_owner_id = #{fkOwnerId,jdbcType=INTEGER}, + + + goods_name = #{goodsName,jdbcType=VARCHAR}, + + + price = #{price,jdbcType=DECIMAL}, + + + priority = #{priority,jdbcType=INTEGER}, + + + enable_status = #{enableStatus,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_bill_goods + set fk_owner_id = #{fkOwnerId,jdbcType=INTEGER}, + goods_name = #{goodsName,jdbcType=VARCHAR}, + price = #{price,jdbcType=DECIMAL}, + priority = #{priority,jdbcType=INTEGER}, + enable_status = #{enableStatus,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file -- Gitee From d9d63a75ef46415ce9e7668b0badb2f1aca24f37 Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Thu, 31 Jan 2019 16:08:43 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E8=B4=A6=E5=8D=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasourceconf/MyBillDataSourceConf.java | 66 ++++++++ .../conf/datasourceconf/package-info.java | 18 +++ .../com/mark/web/bill/entity/po/Account.java | 142 ++++++------------ .../com/mark/web/bill/entity/po/Goods.java | 118 +++++---------- .../com/mark/web/bill/entity/po/GoodsImg.java | 95 +++++------- .../mark/web/bill/mapper/AccountMapper.java | 10 +- .../mark/web/bill/mapper/GoodsImgMapper.java | 10 +- .../com/mark/web/bill/mapper/GoodsMapper.java | 10 +- src/main/resources.dev/dataSource.properties | 26 ++-- .../resources/mappers/bill/AccountMapper.xml | 102 ++----------- .../resources/mappers/bill/GoodsImgMapper.xml | 56 +------ .../resources/mappers/bill/GoodsMapper.xml | 74 +-------- .../web/bill/mapper/AccountMapperTest.java | 48 ++++++ .../web/bill/mapper/GoodsImgMapperTest.java | 32 ++++ .../mark/web/bill/mapper/GoodsMapperTest.java | 31 ++++ 15 files changed, 373 insertions(+), 465 deletions(-) create mode 100644 src/main/java/com/mark/conf/datasourceconf/MyBillDataSourceConf.java create mode 100644 src/main/java/com/mark/conf/datasourceconf/package-info.java create mode 100644 src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java create mode 100644 src/test/java/com/mark/web/bill/mapper/GoodsImgMapperTest.java create mode 100644 src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java diff --git a/src/main/java/com/mark/conf/datasourceconf/MyBillDataSourceConf.java b/src/main/java/com/mark/conf/datasourceconf/MyBillDataSourceConf.java new file mode 100644 index 0000000..dcd991f --- /dev/null +++ b/src/main/java/com/mark/conf/datasourceconf/MyBillDataSourceConf.java @@ -0,0 +1,66 @@ +package com.mark.conf.datasourceconf; + +import com.alibaba.druid.pool.DruidDataSource; +import com.mark.common.utils.PropertiesUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; +/** + * @Description: 账单能模块数据库的配置 + * @Author: Mark + * @CreateDate: 2019/01/31 18:32 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Configuration +@MapperScan(basePackages = "com.mark.web.bill.mapper", sqlSessionFactoryRef = "myBillSqlSessionFactory") +@Slf4j +public class MyBillDataSourceConf { + private String className = PropertiesUtil.getDataSourceProperty("bill.database.classname"); + private String url = PropertiesUtil.getDataSourceProperty("bill.database.url"); + private String useName = PropertiesUtil.getDataSourceProperty("bill.database.username"); + private String password = PropertiesUtil.getDataSourceProperty("bill.database.password"); + private String location = PropertiesUtil.getDataSourceProperty("bill.mapper.locations"); + + @Bean(name = "myBillDataSource") + public DataSource myBillSource(){ + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setDriverClassName(className); + dataSource.setUrl(url); + dataSource.setUsername(useName); + dataSource.setPassword(password); + return dataSource; + } + + @Bean(name = "myBillTransactionManager") + public DataSourceTransactionManager myBillDataSourceTransactionManager(){ + return new DataSourceTransactionManager(this.myBillSource()); + } + + @Bean(name = "myBillSqlSessionFactory") + public SqlSessionFactory myBillSqlSessionFactory(@Qualifier("myBillDataSource") DataSource myBillDataSource) { + final SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); + //设置数据源 + sqlSessionFactoryBean.setDataSource(myBillDataSource); + ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + try { + Resource[] resources = resolver.getResources(location); + //设置mapper.XML文件 + sqlSessionFactoryBean.setMapperLocations(resources); + return sqlSessionFactoryBean.getObject(); + } catch(Exception e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/src/main/java/com/mark/conf/datasourceconf/package-info.java b/src/main/java/com/mark/conf/datasourceconf/package-info.java new file mode 100644 index 0000000..1ebf5f7 --- /dev/null +++ b/src/main/java/com/mark/conf/datasourceconf/package-info.java @@ -0,0 +1,18 @@ +/** + * @Description: 多数据源的配置 + * @Author: Mark + * @CreateDate: 2019/01/31 18:32 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + * + * 多数据源的配置的步骤: + * + * 1.建表 + * + * 2.使用generatorConfig文件自动连接数据自动生成表实体类和dao层接口以及XML文件 + * + * 3.添加数据库的连接信息到:dataSource.properties文件中 + * + * 4.在改目录下新建的配置类 + */ +package com.mark.conf.datasourceconf; \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/entity/po/Account.java b/src/main/java/com/mark/web/bill/entity/po/Account.java index d2edbe5..f22f572 100644 --- a/src/main/java/com/mark/web/bill/entity/po/Account.java +++ b/src/main/java/com/mark/web/bill/entity/po/Account.java @@ -1,123 +1,73 @@ package com.mark.web.bill.entity.po; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.math.BigDecimal; import java.util.Date; +/** + * @Description: 账单信息表对应的实体类 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor public class Account { + /** + * 主键ID + */ private Integer id; + /** + * 逻辑外键,商品id + */ private Integer fkGoodsId; + /** + * 逻辑外键,用户id + */ private Integer fkUserId; + /** + * 商品数量 + */ private Integer quantity; + /** + * 总价,单位是元,保留两位小数 + */ private BigDecimal totalPrice; + /** + * 账单的描述 + */ private String description; + /** + * 状态:1-未结算,2-已结算 + */ private Integer enableStatus; + /** + * 创建时间 + */ private Date createTime; + /** + * 结算时间 + */ private Date paymentTime; + /** + * 最后一次更新时间 + */ private Date lastEditTime; - public Account(Integer id, Integer fkGoodsId, Integer fkUserId, Integer quantity, BigDecimal totalPrice, String description, Integer enableStatus, Date createTime, Date paymentTime, Date lastEditTime) { - this.id = id; - this.fkGoodsId = fkGoodsId; - this.fkUserId = fkUserId; - this.quantity = quantity; - this.totalPrice = totalPrice; - this.description = description; - this.enableStatus = enableStatus; - this.createTime = createTime; - this.paymentTime = paymentTime; - this.lastEditTime = lastEditTime; - } - - public Account() { - super(); - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getFkGoodsId() { - return fkGoodsId; - } - - public void setFkGoodsId(Integer fkGoodsId) { - this.fkGoodsId = fkGoodsId; - } - - public Integer getFkUserId() { - return fkUserId; - } - - public void setFkUserId(Integer fkUserId) { - this.fkUserId = fkUserId; - } - - public Integer getQuantity() { - return quantity; - } - - public void setQuantity(Integer quantity) { - this.quantity = quantity; - } - - public BigDecimal getTotalPrice() { - return totalPrice; - } - - public void setTotalPrice(BigDecimal totalPrice) { - this.totalPrice = totalPrice; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description == null ? null : description.trim(); - } - - public Integer getEnableStatus() { - return enableStatus; - } - - public void setEnableStatus(Integer enableStatus) { - this.enableStatus = enableStatus; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getPaymentTime() { - return paymentTime; - } - - public void setPaymentTime(Date paymentTime) { - this.paymentTime = paymentTime; - } - - public Date getLastEditTime() { - return lastEditTime; - } - - public void setLastEditTime(Date lastEditTime) { - this.lastEditTime = lastEditTime; - } } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/entity/po/Goods.java b/src/main/java/com/mark/web/bill/entity/po/Goods.java index ed2d961..1d4bf62 100644 --- a/src/main/java/com/mark/web/bill/entity/po/Goods.java +++ b/src/main/java/com/mark/web/bill/entity/po/Goods.java @@ -1,101 +1,63 @@ package com.mark.web.bill.entity.po; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.math.BigDecimal; import java.util.Date; +/** + * @Description: 账单商品表对应的实体类 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor public class Goods { + /** + * id + */ private Integer id; + /** + * 逻辑外键,拥有者id + */ private Integer fkOwnerId; + /** + * 商品名称 + */ private String goodsName; + /** + * 单价,单位-元保留两位小数 + */ private BigDecimal price; + /** + * 排序权重 + */ private Integer priority; + /** + * 状态:1-可用,2-禁用 + */ private Integer enableStatus; + /** + * 创建时间 + */ private Date createTime; + /** + * 最后一次更新时间 + */ private Date lastEditTime; - public Goods(Integer id, Integer fkOwnerId, String goodsName, BigDecimal price, Integer priority, Integer enableStatus, Date createTime, Date lastEditTime) { - this.id = id; - this.fkOwnerId = fkOwnerId; - this.goodsName = goodsName; - this.price = price; - this.priority = priority; - this.enableStatus = enableStatus; - this.createTime = createTime; - this.lastEditTime = lastEditTime; - } - - public Goods() { - super(); - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getFkOwnerId() { - return fkOwnerId; - } - - public void setFkOwnerId(Integer fkOwnerId) { - this.fkOwnerId = fkOwnerId; - } - - public String getGoodsName() { - return goodsName; - } - - public void setGoodsName(String goodsName) { - this.goodsName = goodsName == null ? null : goodsName.trim(); - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(BigDecimal price) { - this.price = price; - } - - public Integer getPriority() { - return priority; - } - - public void setPriority(Integer priority) { - this.priority = priority; - } - - public Integer getEnableStatus() { - return enableStatus; - } - - public void setEnableStatus(Integer enableStatus) { - this.enableStatus = enableStatus; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getLastEditTime() { - return lastEditTime; - } - - public void setLastEditTime(Date lastEditTime) { - this.lastEditTime = lastEditTime; - } } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/entity/po/GoodsImg.java b/src/main/java/com/mark/web/bill/entity/po/GoodsImg.java index 51f229d..7cbb24c 100644 --- a/src/main/java/com/mark/web/bill/entity/po/GoodsImg.java +++ b/src/main/java/com/mark/web/bill/entity/po/GoodsImg.java @@ -1,78 +1,53 @@ package com.mark.web.bill.entity.po; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + import java.util.Date; +/** + * @Description: 商品资源图片表对应的实体类 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor public class GoodsImg { + + /** + * 主键ID + */ private Integer id; + /** + * 商品ID + */ private Integer goodsId; + /** + * 图片地址 + */ private String imgAddr; + /** + * 排序权重 + */ private Integer priority; + /** + * 创建时间 + */ private Integer enableStatus; + /** + * 最后一次修改时间 + */ private Date createTime; - public GoodsImg(Integer id, Integer goodsId, String imgAddr, Integer priority, Integer enableStatus, Date createTime) { - this.id = id; - this.goodsId = goodsId; - this.imgAddr = imgAddr; - this.priority = priority; - this.enableStatus = enableStatus; - this.createTime = createTime; - } - - public GoodsImg() { - super(); - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getGoodsId() { - return goodsId; - } - - public void setGoodsId(Integer goodsId) { - this.goodsId = goodsId; - } - - public String getImgAddr() { - return imgAddr; - } - - public void setImgAddr(String imgAddr) { - this.imgAddr = imgAddr == null ? null : imgAddr.trim(); - } - - public Integer getPriority() { - return priority; - } - - public void setPriority(Integer priority) { - this.priority = priority; - } - - public Integer getEnableStatus() { - return enableStatus; - } - - public void setEnableStatus(Integer enableStatus) { - this.enableStatus = enableStatus; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/mapper/AccountMapper.java b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java index dc564ed..0c0289f 100644 --- a/src/main/java/com/mark/web/bill/mapper/AccountMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java @@ -2,16 +2,20 @@ package com.mark.web.bill.mapper; import com.mark.web.bill.entity.po.Account; +/** + * @Description: 账号到dao接口定义 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ public interface AccountMapper { int deleteByPrimaryKey(Integer id); int insert(Account record); - int insertSelective(Account record); - Account selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Account record); - int updateByPrimaryKey(Account record); } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java index 065410f..3e6f29f 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsImgMapper.java @@ -2,16 +2,20 @@ package com.mark.web.bill.mapper; import com.mark.web.bill.entity.po.GoodsImg; +/** + * @Description: 商品资源图片的dao接口定义 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ public interface GoodsImgMapper { int deleteByPrimaryKey(Integer id); int insert(GoodsImg record); - int insertSelective(GoodsImg record); - GoodsImg selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(GoodsImg record); - int updateByPrimaryKey(GoodsImg record); } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java index 696efd4..ff8da01 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java @@ -2,16 +2,20 @@ package com.mark.web.bill.mapper; import com.mark.web.bill.entity.po.Goods; +/** + * @Description: 商品dao接口定义 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ public interface GoodsMapper { int deleteByPrimaryKey(Integer id); int insert(Goods record); - int insertSelective(Goods record); - Goods selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Goods record); - int updateByPrimaryKey(Goods record); } \ No newline at end of file diff --git a/src/main/resources.dev/dataSource.properties b/src/main/resources.dev/dataSource.properties index 15696e8..fcee499 100644 --- a/src/main/resources.dev/dataSource.properties +++ b/src/main/resources.dev/dataSource.properties @@ -1,27 +1,35 @@ -#数据库相关数据库的配置文件 -#读取配置文件:PropertiesUtil.getDataSourceProperty("shiro.redis.ip") +#\u6570\u636E\u5E93\u76F8\u5173\u6570\u636E\u5E93\u7684\u914D\u7F6E\u6587\u4EF6 +#\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6\uFF1APropertiesUtil.getDataSourceProperty("shiro.redis.ip") -#1.系統业务相关数据库 +#1.\u7CFB\u7D71\u4E1A\u52A1\u76F8\u5173\u6570\u636E\u5E93 sys.database.classname=com.mysql.jdbc.Driver sys.database.url=jdbc:mysql://47.95.13.238/campuso2o_v2?characterEncoding=utf-8&useSSL=false sys.database.username=mark sys.database.password=7561669Dong! -#系统模块的mapper.xml文件的搜扫描路径 +#\u7CFB\u7EDF\u6A21\u5757\u7684mapper.xml\u6587\u4EF6\u7684\u641C\u626B\u63CF\u8DEF\u5F84 sys.mapper.locations=classpath*:mappers/data/*.xml -#2.Shrio权限验证的数据库 +#2.Shrio\u6743\u9650\u9A8C\u8BC1\u7684\u6570\u636E\u5E93 shiro.database.classname=com.mysql.jdbc.Driver shiro.database.url=jdbc:mysql://47.95.13.238/campuso2o_sys_2.0?characterEncoding=utf-8&useSSL=false shiro.database.username=mark shiro.database.password=7561669Dong! -#shiro模块的mapper.xml文件的扫描路径 +#shiro\u6A21\u5757\u7684mapper.xml\u6587\u4EF6\u7684\u626B\u63CF\u8DEF\u5F84 shiro.mapper.locations=classpath*:mappers/sys/*.xml -#3.redis数据库的配置 -#存储shrio验证登录信息的redis数据库的配置 +#3.bill\u8D26\u5355\u6570\u636E\u5E93 +bill.database.classname=com.mysql.jdbc.Driver +bill.database.url=jdbc:mysql://47.95.13.238/campuso2o_bill_2.0?characterEncoding=utf-8&useSSL=false +bill.database.username=mark +bill.database.password=7561669Dong! +#bill\u8D26\u5355\u6A21\u5757\u7684mapper.xml\u6587\u4EF6\u7684\u626B\u63CF\u8DEF\u5F84 +bill.mapper.locations=classpath*:mappers/bill/*.xml + +#4.redis\u6570\u636E\u5E93\u7684\u914D\u7F6E +#\u5B58\u50A8shrio\u9A8C\u8BC1\u767B\u5F55\u4FE1\u606F\u7684redis\u6570\u636E\u5E93\u7684\u914D\u7F6E shiro.redis.ip=47.95.13.238 shiro.redis.port=6379 -#有效期:单位seconds +#\u6709\u6548\u671F\uFF1A\u5355\u4F4Dseconds shiro.redis.expire=1800 shiro.redis.timeout=0 diff --git a/src/main/resources/mappers/bill/AccountMapper.xml b/src/main/resources/mappers/bill/AccountMapper.xml index cf5613a..efa98d1 100644 --- a/src/main/resources/mappers/bill/AccountMapper.xml +++ b/src/main/resources/mappers/bill/AccountMapper.xml @@ -30,82 +30,16 @@ where id = #{id,jdbcType=INTEGER} - insert into tb_bill_account (id, fk_goods_id, fk_user_id, - quantity, total_price, description, - enable_status, create_time, payment_time, + insert into tb_bill_account (id, fk_goods_id, fk_user_id, + quantity, total_price, description, + enable_status, create_time, payment_time, last_edit_time) - values (#{id,jdbcType=INTEGER}, #{fkGoodsId,jdbcType=INTEGER}, #{fkUserId,jdbcType=INTEGER}, - #{quantity,jdbcType=INTEGER}, #{totalPrice,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR}, - #{enableStatus,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{paymentTime,jdbcType=TIMESTAMP}, - #{lastEditTime,jdbcType=TIMESTAMP}) - - - insert into tb_bill_account - - - id, - - - fk_goods_id, - - - fk_user_id, - - - quantity, - - - total_price, - - - description, - - - enable_status, - - - create_time, - - - payment_time, - - - last_edit_time, - - - - - #{id,jdbcType=INTEGER}, - - - #{fkGoodsId,jdbcType=INTEGER}, - - - #{fkUserId,jdbcType=INTEGER}, - - - #{quantity,jdbcType=INTEGER}, - - - #{totalPrice,jdbcType=DECIMAL}, - - - #{description,jdbcType=VARCHAR}, - - - #{enableStatus,jdbcType=INTEGER}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - #{paymentTime,jdbcType=TIMESTAMP}, - - - #{lastEditTime,jdbcType=TIMESTAMP}, - - + values (#{id,jdbcType=INTEGER}, #{fkGoodsId,jdbcType=INTEGER}, #{fkUserId,jdbcType=INTEGER}, + #{quantity,jdbcType=INTEGER}, #{totalPrice,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR}, + #{enableStatus,jdbcType=INTEGER}, NOW(), null, + NOW()) + update tb_bill_account @@ -133,23 +67,11 @@ payment_time = #{paymentTime,jdbcType=TIMESTAMP}, - - last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP}, - + + last_edit_time = NOW() + where id = #{id,jdbcType=INTEGER} - - update tb_bill_account - set fk_goods_id = #{fkGoodsId,jdbcType=INTEGER}, - fk_user_id = #{fkUserId,jdbcType=INTEGER}, - quantity = #{quantity,jdbcType=INTEGER}, - total_price = #{totalPrice,jdbcType=DECIMAL}, - description = #{description,jdbcType=VARCHAR}, - enable_status = #{enableStatus,jdbcType=INTEGER}, - create_time = #{createTime,jdbcType=TIMESTAMP}, - payment_time = #{paymentTime,jdbcType=TIMESTAMP}, - last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP} - where id = #{id,jdbcType=INTEGER} - + \ No newline at end of file diff --git a/src/main/resources/mappers/bill/GoodsImgMapper.xml b/src/main/resources/mappers/bill/GoodsImgMapper.xml index 3f83fdb..ee6ebae 100644 --- a/src/main/resources/mappers/bill/GoodsImgMapper.xml +++ b/src/main/resources/mappers/bill/GoodsImgMapper.xml @@ -29,52 +29,10 @@ priority, enable_status, create_time ) values (#{id,jdbcType=INTEGER}, #{goodsId,jdbcType=INTEGER}, #{imgAddr,jdbcType=VARCHAR}, - #{priority,jdbcType=INTEGER}, #{enableStatus,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP} + #{priority,jdbcType=INTEGER}, #{enableStatus,jdbcType=INTEGER}, NOW() ) - - insert into tb_bill_goods_img - - - id, - - - goods_id, - - - img_addr, - - - priority, - - - enable_status, - - - create_time, - - - - - #{id,jdbcType=INTEGER}, - - - #{goodsId,jdbcType=INTEGER}, - - - #{imgAddr,jdbcType=VARCHAR}, - - - #{priority,jdbcType=INTEGER}, - - - #{enableStatus,jdbcType=INTEGER}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - + update tb_bill_goods_img @@ -96,13 +54,5 @@ where id = #{id,jdbcType=INTEGER} - - update tb_bill_goods_img - set goods_id = #{goodsId,jdbcType=INTEGER}, - img_addr = #{imgAddr,jdbcType=VARCHAR}, - priority = #{priority,jdbcType=INTEGER}, - enable_status = #{enableStatus,jdbcType=INTEGER}, - create_time = #{createTime,jdbcType=TIMESTAMP} - where id = #{id,jdbcType=INTEGER} - + \ No newline at end of file diff --git a/src/main/resources/mappers/bill/GoodsMapper.xml b/src/main/resources/mappers/bill/GoodsMapper.xml index ac382ef..6e0a53f 100644 --- a/src/main/resources/mappers/bill/GoodsMapper.xml +++ b/src/main/resources/mappers/bill/GoodsMapper.xml @@ -32,63 +32,9 @@ create_time, last_edit_time) values (#{id,jdbcType=INTEGER}, #{fkOwnerId,jdbcType=INTEGER}, #{goodsName,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{priority,jdbcType=INTEGER}, #{enableStatus,jdbcType=INTEGER}, - #{createTime,jdbcType=TIMESTAMP}, #{lastEditTime,jdbcType=TIMESTAMP}) - - - insert into tb_bill_goods - - - id, - - - fk_owner_id, - - - goods_name, - - - price, - - - priority, - - - enable_status, - - - create_time, - - - last_edit_time, - - - - - #{id,jdbcType=INTEGER}, - - - #{fkOwnerId,jdbcType=INTEGER}, - - - #{goodsName,jdbcType=VARCHAR}, - - - #{price,jdbcType=DECIMAL}, - - - #{priority,jdbcType=INTEGER}, - - - #{enableStatus,jdbcType=INTEGER}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - #{lastEditTime,jdbcType=TIMESTAMP}, - - + NOW(), NOW()) + update tb_bill_goods @@ -110,21 +56,9 @@ create_time = #{createTime,jdbcType=TIMESTAMP}, - - last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP}, - + last_edit_time = NOW() where id = #{id,jdbcType=INTEGER} - - update tb_bill_goods - set fk_owner_id = #{fkOwnerId,jdbcType=INTEGER}, - goods_name = #{goodsName,jdbcType=VARCHAR}, - price = #{price,jdbcType=DECIMAL}, - priority = #{priority,jdbcType=INTEGER}, - enable_status = #{enableStatus,jdbcType=INTEGER}, - create_time = #{createTime,jdbcType=TIMESTAMP}, - last_edit_time = #{lastEditTime,jdbcType=TIMESTAMP} - where id = #{id,jdbcType=INTEGER} - + \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java b/src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java new file mode 100644 index 0000000..a052903 --- /dev/null +++ b/src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java @@ -0,0 +1,48 @@ +package com.mark.web.bill.mapper; + +import com.mark.BaseTest; +import com.mark.web.bill.entity.po.Account; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.math.BigDecimal; + +import static org.junit.Assert.*; + +/** + * @Description: 账号的dao接口测试 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public class AccountMapperTest extends BaseTest { + @Autowired + private AccountMapper accountMapper; + + @Test + public void deleteByPrimaryKey() { + } + + @Test + public void insert() { + Account account = new Account(); + account.setFkGoodsId(1); + account.setFkUserId(1); + account.setQuantity(10); + account.setTotalPrice(new BigDecimal(20)); + account.setDescription(""); + account.setEnableStatus(1); + int insert = accountMapper.insert(account); + Assert.assertNotEquals(0,insert); + } + + @Test + public void selectByPrimaryKey() { + } + + @Test + public void updateByPrimaryKeySelective() { + } +} \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsImgMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsImgMapperTest.java new file mode 100644 index 0000000..37e9879 --- /dev/null +++ b/src/test/java/com/mark/web/bill/mapper/GoodsImgMapperTest.java @@ -0,0 +1,32 @@ +package com.mark.web.bill.mapper; + +import com.mark.BaseTest; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @Description: 商品资源图片dao接口测试 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public class GoodsImgMapperTest extends BaseTest { + + @Test + public void deleteByPrimaryKey() { + } + + @Test + public void insert() { + } + + @Test + public void selectByPrimaryKey() { + } + + @Test + public void updateByPrimaryKeySelective() { + } +} \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java new file mode 100644 index 0000000..5665fbb --- /dev/null +++ b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java @@ -0,0 +1,31 @@ +package com.mark.web.bill.mapper; + +import com.mark.BaseTest; +import org.junit.Test; + +import static org.junit.Assert.*; +/** + * @Description: 商品dao接口测试 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/1/31 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public class GoodsMapperTest extends BaseTest { + + @Test + public void deleteByPrimaryKey() { + } + + @Test + public void insert() { + } + + @Test + public void selectByPrimaryKey() { + } + + @Test + public void updateByPrimaryKeySelective() { + } +} \ No newline at end of file -- Gitee From d433d0961392656c969a3c9e10cda81f8f5cddda Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Thu, 31 Jan 2019 18:31:43 +0800 Subject: [PATCH 03/19] =?UTF-8?q?create=20=E6=96=B0=E5=A2=9E=E8=B4=A6?= =?UTF-8?q?=E5=8D=95=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bill/controller/AccountController.java | 41 +++++++++++++++++++ .../web/bill/entity/from/AddAccountFrom.java | 35 ++++++++++++++++ .../web/bill/service/IAccountService.java | 9 ++++ .../bill/service/impl/AccountServiceImpl.java | 21 ++++++++++ 4 files changed, 106 insertions(+) create mode 100644 src/main/java/com/mark/web/bill/controller/AccountController.java create mode 100644 src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java create mode 100644 src/main/java/com/mark/web/bill/service/IAccountService.java create mode 100644 src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java diff --git a/src/main/java/com/mark/web/bill/controller/AccountController.java b/src/main/java/com/mark/web/bill/controller/AccountController.java new file mode 100644 index 0000000..57ef526 --- /dev/null +++ b/src/main/java/com/mark/web/bill/controller/AccountController.java @@ -0,0 +1,41 @@ +package com.mark.web.bill.controller; + +import com.mark.common.CurrentUser; +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.from.AddAccountFrom; +import com.mark.web.bill.entity.po.Account; +import com.mark.web.bill.service.IAccountService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; +import java.util.Objects; + +@Api(tags = "账单-我的账单模块") +@RestController +@RequestMapping(value = "/bill/account/") +public class AccountController { + + @Autowired + private IAccountService iAccountService; + + @ApiOperation(value = "添加账单") + @PostMapping(value = "add") + public ServerResponse add(@Valid AddAccountFrom addAccountFrom, BindingResult result){ + if(result.hasErrors()){ + return ServerResponse.createByErrorMessage(Objects.requireNonNull(result.getFieldError()).getDefaultMessage()); + } + Account account = new Account(); + BeanUtils.copyProperties(addAccountFrom,account); + //获取当前用户id + int currentUserId = CurrentUser.getCurrentUserId(); + account.setFkUserId(currentUserId); + return iAccountService.add(account); + } +} diff --git a/src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java b/src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java new file mode 100644 index 0000000..a255a5f --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java @@ -0,0 +1,35 @@ +package com.mark.web.bill.entity.from; + +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @Description: 新增账单时表单实体 + * @Author: Mark + * @CreateDate: 2019/01/31 18:32 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Data +@ApiModel(value = "账单新增表单") +public class AddAccountFrom { + + /** + * 逻辑外键,用户id + */ + private Integer fkGoodsId; + + /** + * 商品数量 + */ + private Integer quantity; + + /** + * 账单的描述 + */ + @NotBlank + private String description; + +} diff --git a/src/main/java/com/mark/web/bill/service/IAccountService.java b/src/main/java/com/mark/web/bill/service/IAccountService.java new file mode 100644 index 0000000..b0a7dc9 --- /dev/null +++ b/src/main/java/com/mark/web/bill/service/IAccountService.java @@ -0,0 +1,9 @@ +package com.mark.web.bill.service; + +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.po.Account; + +public interface IAccountService { + + ServerResponse add(Account account); +} diff --git a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java new file mode 100644 index 0000000..1a10316 --- /dev/null +++ b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java @@ -0,0 +1,21 @@ +package com.mark.web.bill.service.impl; + +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.po.Account; +import com.mark.web.bill.mapper.AccountMapper; +import com.mark.web.bill.service.IAccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class AccountServiceImpl implements IAccountService { + @Autowired + private AccountMapper accountMapper; + + @Override + public ServerResponse add(Account account) { + + accountMapper.insert(account); + return null; + } +} -- Gitee From 1be68d931b617e509ff2817a4cf7b932605142cb Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Fri, 1 Feb 2019 18:09:14 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E8=B4=A6=E5=8D=95=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=9A=84=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util => common/utils}/BigDecimalUtil.java | 2 +- .../com/mark/web/bill/enums/AccountEnum.java | 32 ++++++++++++++++ .../web/bill/exception/BillException.java | 8 ++++ .../bill/service/impl/AccountServiceImpl.java | 37 ++++++++++++++++++- .../data/service/impl/CartServiceImpl.java | 2 +- .../data/service/impl/OrderServiceImpl.java | 2 +- .../web/data/service/impl/PayServiceImpl.java | 1 + .../resources/mappers/bill/AccountMapper.xml | 2 +- 8 files changed, 80 insertions(+), 6 deletions(-) rename src/main/java/com/mark/{web/data/util => common/utils}/BigDecimalUtil.java (97%) create mode 100644 src/main/java/com/mark/web/bill/enums/AccountEnum.java create mode 100644 src/main/java/com/mark/web/bill/exception/BillException.java diff --git a/src/main/java/com/mark/web/data/util/BigDecimalUtil.java b/src/main/java/com/mark/common/utils/BigDecimalUtil.java similarity index 97% rename from src/main/java/com/mark/web/data/util/BigDecimalUtil.java rename to src/main/java/com/mark/common/utils/BigDecimalUtil.java index 542e4ff..f9c9176 100644 --- a/src/main/java/com/mark/web/data/util/BigDecimalUtil.java +++ b/src/main/java/com/mark/common/utils/BigDecimalUtil.java @@ -1,4 +1,4 @@ -package com.mark.web.data.util; +package com.mark.common.utils; import java.math.BigDecimal; diff --git a/src/main/java/com/mark/web/bill/enums/AccountEnum.java b/src/main/java/com/mark/web/bill/enums/AccountEnum.java new file mode 100644 index 0000000..4e61ce3 --- /dev/null +++ b/src/main/java/com/mark/web/bill/enums/AccountEnum.java @@ -0,0 +1,32 @@ +package com.mark.web.bill.enums; + + +public enum AccountEnum { + + UN_PAYMENT(1, "未结算"), + PAYMENT_ED(2,"已结算"); + private int state; + private String desc; + + AccountEnum(int state, String desc) { + this.state = state; + this.desc = desc; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + +} diff --git a/src/main/java/com/mark/web/bill/exception/BillException.java b/src/main/java/com/mark/web/bill/exception/BillException.java new file mode 100644 index 0000000..0ae167f --- /dev/null +++ b/src/main/java/com/mark/web/bill/exception/BillException.java @@ -0,0 +1,8 @@ +package com.mark.web.bill.exception; + + +public class BillException extends RuntimeException{ + public BillException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java index 1a10316..ca8a107 100644 --- a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java @@ -1,21 +1,54 @@ package com.mark.web.bill.service.impl; +import com.mark.common.Constant; import com.mark.common.ServerResponse; +import com.mark.common.utils.BigDecimalUtil; import com.mark.web.bill.entity.po.Account; +import com.mark.web.bill.entity.po.Goods; +import com.mark.web.bill.enums.AccountEnum; +import com.mark.web.bill.exception.BillException; import com.mark.web.bill.mapper.AccountMapper; +import com.mark.web.bill.mapper.GoodsMapper; import com.mark.web.bill.service.IAccountService; +import org.apache.catalina.Server; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.util.Date; + @Service public class AccountServiceImpl implements IAccountService { @Autowired private AccountMapper accountMapper; + @Autowired + private GoodsMapper goodsMapper; @Override public ServerResponse add(Account account) { + //通过商品ID获取商品信息 + Goods goods = goodsMapper.selectByPrimaryKey(account.getFkGoodsId()); + if(goods == null){ + throw new BillException("商品不存在!"); + } + if(account.getEnableStatus() == null){ + account.setEnableStatus(AccountEnum.UN_PAYMENT.getState()); + } - accountMapper.insert(account); - return null; + //如果账单的创建时间为空,则默认为今天 + if(account.getCreateTime() == null){ + account.setCreateTime(new Date()); + } + //计算总价 + BigDecimal price = goods.getPrice(); + Integer quantity = account.getQuantity(); + BigDecimal total = BigDecimalUtil.mul(price.doubleValue(), quantity.doubleValue()); + account.setTotalPrice(total); + int effectNum = accountMapper.insert(account); + if(effectNum != Constant.SUCCESS){ + throw new BillException("保存账单记录信息失败!"); + } + return ServerResponse.createBySuccess(); } + } diff --git a/src/main/java/com/mark/web/data/service/impl/CartServiceImpl.java b/src/main/java/com/mark/web/data/service/impl/CartServiceImpl.java index 33c26bd..0298b6d 100644 --- a/src/main/java/com/mark/web/data/service/impl/CartServiceImpl.java +++ b/src/main/java/com/mark/web/data/service/impl/CartServiceImpl.java @@ -10,7 +10,7 @@ import com.mark.common.exception.Campuso2oException; import com.mark.web.data.entity.po.Cart; import com.mark.web.data.entity.po.Product; import com.mark.web.data.service.ICartService; -import com.mark.web.data.util.BigDecimalUtil; +import com.mark.common.utils.BigDecimalUtil; import com.mark.common.utils.PropertiesUtil; import com.mark.web.data.entity.vo.CartProductVo; import com.mark.web.data.entity.vo.CartVo; diff --git a/src/main/java/com/mark/web/data/service/impl/OrderServiceImpl.java b/src/main/java/com/mark/web/data/service/impl/OrderServiceImpl.java index e8f789e..6f65d2c 100644 --- a/src/main/java/com/mark/web/data/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/mark/web/data/service/impl/OrderServiceImpl.java @@ -13,7 +13,7 @@ import com.mark.common.exception.Campuso2oException; import com.mark.web.data.exception.OrderException; import com.mark.web.data.entity.po.*; import com.mark.web.data.service.IOrderService; -import com.mark.web.data.util.BigDecimalUtil; +import com.mark.common.utils.BigDecimalUtil; import com.mark.common.utils.DateTimeUtil; import com.mark.common.utils.PropertiesUtil; import com.mark.web.data.entity.vo.OrderItemVo; diff --git a/src/main/java/com/mark/web/data/service/impl/PayServiceImpl.java b/src/main/java/com/mark/web/data/service/impl/PayServiceImpl.java index dbd8fe9..a30da65 100644 --- a/src/main/java/com/mark/web/data/service/impl/PayServiceImpl.java +++ b/src/main/java/com/mark/web/data/service/impl/PayServiceImpl.java @@ -13,6 +13,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.mark.common.Constant; import com.mark.common.ServerResponse; +import com.mark.common.utils.BigDecimalUtil; import com.mark.common.utils.DateTimeUtil; import com.mark.common.utils.PropertiesUtil; import com.mark.web.data.mapper.OrderItemMapper; diff --git a/src/main/resources/mappers/bill/AccountMapper.xml b/src/main/resources/mappers/bill/AccountMapper.xml index efa98d1..01b599c 100644 --- a/src/main/resources/mappers/bill/AccountMapper.xml +++ b/src/main/resources/mappers/bill/AccountMapper.xml @@ -36,7 +36,7 @@ last_edit_time) values (#{id,jdbcType=INTEGER}, #{fkGoodsId,jdbcType=INTEGER}, #{fkUserId,jdbcType=INTEGER}, #{quantity,jdbcType=INTEGER}, #{totalPrice,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR}, - #{enableStatus,jdbcType=INTEGER}, NOW(), null, + #{enableStatus,jdbcType=INTEGER},#{createTime}, null, NOW()) -- Gitee From cfa8c39c4ae560e584a13308b56580801264479e Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Sun, 3 Feb 2019 09:57:36 +0800 Subject: [PATCH 05/19] =?UTF-8?q?create=20=20=E5=8A=A0=E5=B7=A5=E9=9B=B6?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mark/conf/MySwagger2Conf.java | 5 +- .../web/bill/controller/GoodsController.java | 59 +++++++++++++++++++ .../web/bill/entity/from/AddGoodsFrom.java | 35 +++++++++++ .../com/mark/web/bill/enums/AccountEnum.java | 8 ++- .../com/mark/web/bill/enums/GoodsEnum.java | 38 ++++++++++++ .../com/mark/web/bill/mapper/GoodsMapper.java | 5 ++ .../mark/web/bill/service/IGoodsService.java | 21 +++++++ .../bill/service/impl/AccountServiceImpl.java | 6 +- .../bill/service/impl/GoodsServiceImpi.java | 45 ++++++++++++++ .../resources/mappers/bill/GoodsMapper.xml | 5 ++ src/test/java/com/mark/BaseTest.java | 1 + .../mark/web/bill/mapper/GoodsMapperTest.java | 14 +++++ .../web/bill/service/IGoodsServiceTest.java | 36 +++++++++++ 13 files changed, 272 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/mark/web/bill/controller/GoodsController.java create mode 100644 src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java create mode 100644 src/main/java/com/mark/web/bill/enums/GoodsEnum.java create mode 100644 src/main/java/com/mark/web/bill/service/IGoodsService.java create mode 100644 src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpi.java create mode 100644 src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java diff --git a/src/main/java/com/mark/conf/MySwagger2Conf.java b/src/main/java/com/mark/conf/MySwagger2Conf.java index 6d39094..2375e72 100644 --- a/src/main/java/com/mark/conf/MySwagger2Conf.java +++ b/src/main/java/com/mark/conf/MySwagger2Conf.java @@ -35,10 +35,13 @@ public class MySwagger2Conf { final String basePackagePath = "com.mark.web.data.controller"; //shiro权限控制的相关的控制器包的路径 final String sysBashPackagePath = "com.mark.web.sys.controller"; + //账单模块的控制器包路径 + final String billBashPackagePath = "com.mark.web.bill.controller"; + return new Docket(DocumentationType.SWAGGER_2) .apiInfo(this.getApiInfo()) .select() - .apis(basePackage(basePackagePath+SPLITOR+sysBashPackagePath)) + .apis(basePackage(basePackagePath+SPLITOR+sysBashPackagePath+SPLITOR+billBashPackagePath)) .paths(PathSelectors.any()) .build(); } diff --git a/src/main/java/com/mark/web/bill/controller/GoodsController.java b/src/main/java/com/mark/web/bill/controller/GoodsController.java new file mode 100644 index 0000000..c2a6f76 --- /dev/null +++ b/src/main/java/com/mark/web/bill/controller/GoodsController.java @@ -0,0 +1,59 @@ +package com.mark.web.bill.controller; + +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.from.AddGoodsFrom; +import com.mark.web.bill.entity.po.Goods; +import com.mark.web.bill.service.IGoodsService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @Description: 记账模块的加工零件控制 + * @Author: Mark + * @CreateDate: 2019/2/2 22:39 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Api(tags = "账单-加工零件模块") +@RestController +@RequestMapping(value = "/bill/goods/") +public class GoodsController { + + @Autowired + private IGoodsService iGoodsService; + + @ApiOperation(value = "添加加工零件") + @PostMapping(value = "add") + public ServerResponse add(@Valid AddGoodsFrom addGoodsFrom, BindingResult result){ + if(result.hasErrors()){ + return ServerResponse.createByErrorMessage(Objects.requireNonNull(result.getFieldError()).getDefaultMessage()); + } + Goods goods = new Goods(); + BeanUtils.copyProperties(addGoodsFrom,goods); + //获取当前用户id + //int currentUserId = CurrentUser.getCurrentUserId(); + //商品的ID先固定 + int currentUserId = 1000; + goods.setFkOwnerId(currentUserId); + return iGoodsService.add(goods); + } + + @ApiOperation(value = "获取加工零件名称和对应ID") + @GetMapping(value = "getOptionInfo") + public ServerResponse>> getOptionInfo(){ + return iGoodsService.getOptionInfo(); + } + +} diff --git a/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java b/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java new file mode 100644 index 0000000..d9b8d72 --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java @@ -0,0 +1,35 @@ +package com.mark.web.bill.entity.from; + +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.math.BigDecimal; + +/** + * @Description: 添加加工零件的表单验证 + * @Author: Mark + * @CreateDate: 2019/2/2 22:41 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Data +@ApiModel(value = "账单新增表单") +public class AddGoodsFrom { + + /** + * 商品名称 + */ + @NotBlank + private String goodsName; + + /** + * 单价,单位-元保留两位小数 + */ + private BigDecimal price; + + /** + * 排序权重 + */ + private Integer priority; +} diff --git a/src/main/java/com/mark/web/bill/enums/AccountEnum.java b/src/main/java/com/mark/web/bill/enums/AccountEnum.java index 4e61ce3..3c6b221 100644 --- a/src/main/java/com/mark/web/bill/enums/AccountEnum.java +++ b/src/main/java/com/mark/web/bill/enums/AccountEnum.java @@ -1,6 +1,12 @@ package com.mark.web.bill.enums; - +/** + * @Description: 账单信息的枚举值 + * @Author: Mark + * @CreateDate: 2019/2/2 22:53 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ public enum AccountEnum { UN_PAYMENT(1, "未结算"), diff --git a/src/main/java/com/mark/web/bill/enums/GoodsEnum.java b/src/main/java/com/mark/web/bill/enums/GoodsEnum.java new file mode 100644 index 0000000..4bb5f70 --- /dev/null +++ b/src/main/java/com/mark/web/bill/enums/GoodsEnum.java @@ -0,0 +1,38 @@ +package com.mark.web.bill.enums; + +/** + * @Description: 加工零件商品的枚举值 + * @Author: Mark + * @CreateDate: 2019/2/2 22:53 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public enum GoodsEnum { + + AVAILABLE(1, "可用"), + FORBIDDEN(2,"禁用"); + + private int state; + private String desc; + + GoodsEnum(int state, String desc) { + this.state = state; + this.desc = desc; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } +} diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java index ff8da01..3dcc6cb 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java @@ -2,6 +2,9 @@ package com.mark.web.bill.mapper; import com.mark.web.bill.entity.po.Goods; +import java.util.List; +import java.util.Map; + /** * @Description: 商品dao接口定义 * @Author: Kingsley: 08:46 @@ -16,6 +19,8 @@ public interface GoodsMapper { Goods selectByPrimaryKey(Integer id); + List> selectAllGoods(); + int updateByPrimaryKeySelective(Goods record); } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/service/IGoodsService.java b/src/main/java/com/mark/web/bill/service/IGoodsService.java new file mode 100644 index 0000000..3965b4c --- /dev/null +++ b/src/main/java/com/mark/web/bill/service/IGoodsService.java @@ -0,0 +1,21 @@ +package com.mark.web.bill.service; + +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.po.Goods; + +import java.util.List; +import java.util.Map; + +/** + * @Description: 加工零件管理的service业务层接口定义 + * @Author: Mark + * @CreateDate: 2019/2/2 22:42 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public interface IGoodsService { + + ServerResponse add(Goods goods); + + ServerResponse>> getOptionInfo(); +} diff --git a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java index ca8a107..136c7c5 100644 --- a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java @@ -6,11 +6,9 @@ import com.mark.common.utils.BigDecimalUtil; import com.mark.web.bill.entity.po.Account; import com.mark.web.bill.entity.po.Goods; import com.mark.web.bill.enums.AccountEnum; -import com.mark.web.bill.exception.BillException; import com.mark.web.bill.mapper.AccountMapper; import com.mark.web.bill.mapper.GoodsMapper; import com.mark.web.bill.service.IAccountService; -import org.apache.catalina.Server; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,7 +27,7 @@ public class AccountServiceImpl implements IAccountService { //通过商品ID获取商品信息 Goods goods = goodsMapper.selectByPrimaryKey(account.getFkGoodsId()); if(goods == null){ - throw new BillException("商品不存在!"); + ServerResponse.createByErrorMessage("商品不存在!"); } if(account.getEnableStatus() == null){ account.setEnableStatus(AccountEnum.UN_PAYMENT.getState()); @@ -46,7 +44,7 @@ public class AccountServiceImpl implements IAccountService { account.setTotalPrice(total); int effectNum = accountMapper.insert(account); if(effectNum != Constant.SUCCESS){ - throw new BillException("保存账单记录信息失败!"); + ServerResponse.createByErrorMessage("保存信息失败!"); } return ServerResponse.createBySuccess(); } diff --git a/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpi.java b/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpi.java new file mode 100644 index 0000000..9649bc1 --- /dev/null +++ b/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpi.java @@ -0,0 +1,45 @@ +package com.mark.web.bill.service.impl; + +import com.mark.common.Constant; +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.po.Goods; +import com.mark.web.bill.enums.GoodsEnum; +import com.mark.web.bill.mapper.GoodsMapper; +import com.mark.web.bill.service.IGoodsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * @Description: 商品加工零件的业务层接口实现 + * @Author: Mark + * @CreateDate: 2019/2/2 22:51 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Service +public class GoodsServiceImpi implements IGoodsService { + @Autowired + private GoodsMapper goodsMapper; + + @Override + public ServerResponse add(Goods goods) { + //账单的状态默认为可用 + goods.setEnableStatus(GoodsEnum.AVAILABLE.getState()); + int affectNum = goodsMapper.insert(goods); + if (affectNum != Constant.SUCCESS) { + ServerResponse.createByErrorMessage("保存信息失败!"); + } + return ServerResponse.createBySuccessMessage("添加加工零件成功!"); + } + + @Override + public ServerResponse>> getOptionInfo() { + List> result = goodsMapper.selectAllGoods(); + return ServerResponse.createBySuccess(result); + } + + +} diff --git a/src/main/resources/mappers/bill/GoodsMapper.xml b/src/main/resources/mappers/bill/GoodsMapper.xml index 6e0a53f..de58c9f 100644 --- a/src/main/resources/mappers/bill/GoodsMapper.xml +++ b/src/main/resources/mappers/bill/GoodsMapper.xml @@ -22,6 +22,11 @@ from tb_bill_goods where id = #{id,jdbcType=INTEGER} + + + delete from tb_bill_goods where id = #{id,jdbcType=INTEGER} diff --git a/src/test/java/com/mark/BaseTest.java b/src/test/java/com/mark/BaseTest.java index d9f3790..fa2223d 100644 --- a/src/test/java/com/mark/BaseTest.java +++ b/src/test/java/com/mark/BaseTest.java @@ -1,5 +1,6 @@ package com.mark; +import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java index 5665fbb..32bc49a 100644 --- a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java @@ -1,7 +1,13 @@ package com.mark.web.bill.mapper; import com.mark.BaseTest; +import org.junit.Assert; import org.junit.Test; +import org.omg.CORBA.PUBLIC_MEMBER; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; +import java.util.Map; import static org.junit.Assert.*; /** @@ -12,6 +18,8 @@ import static org.junit.Assert.*; * @Copyright : 豆浆油条个人非正式工作室 */ public class GoodsMapperTest extends BaseTest { + @Autowired + private GoodsMapper goodsMapper; @Test public void deleteByPrimaryKey() { @@ -28,4 +36,10 @@ public class GoodsMapperTest extends BaseTest { @Test public void updateByPrimaryKeySelective() { } + + @Test + public void selectAllGoods(){ + List> maps = goodsMapper.selectAllGoods(); + Assert.assertNotEquals(0,maps.size()); + } } \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java b/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java new file mode 100644 index 0000000..6f1616e --- /dev/null +++ b/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java @@ -0,0 +1,36 @@ +package com.mark.web.bill.service; + +import com.mark.BaseTest; +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.po.Goods; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.math.BigDecimal; + +import static org.junit.Assert.*; + +/** + * @Description: 加工零件的service层接口测试 + * @Author: Mark + * @CreateDate: 2019/2/2 23:01 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public class IGoodsServiceTest extends BaseTest { + + @Autowired + private IGoodsService iGoodsService; + + @Test + public void testAdd(){ + Goods goods = new Goods(); + goods.setFkOwnerId(1); + goods.setGoodsName("测试记录"); + goods.setPrice(new BigDecimal(0.02)); + goods.setPriority(1); + ServerResponse add = iGoodsService.add(goods); + Assert.assertNotNull(add); + } +} \ No newline at end of file -- Gitee From 863b8aaf910e9a08f823bf904aea50e394b307ae Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Sun, 3 Feb 2019 17:29:37 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E8=B4=A6=E5=8D=95?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bill/controller/AccountController.java | 29 +++++++ .../web/bill/entity/from/AddAccountFrom.java | 12 ++- .../mark/web/bill/entity/vo/AccountVo.java | 83 +++++++++++++++++++ .../com/mark/web/bill/enums/AccountEnum.java | 9 ++ .../mark/web/bill/mapper/AccountMapper.java | 26 ++++++ .../web/bill/service/IAccountService.java | 9 ++ .../bill/service/impl/AccountServiceImpl.java | 54 ++++++++++-- .../resources/mappers/bill/AccountMapper.xml | 24 ++++++ .../web/bill/mapper/AccountMapperTest.java | 13 +++ 9 files changed, 253 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/mark/web/bill/entity/vo/AccountVo.java diff --git a/src/main/java/com/mark/web/bill/controller/AccountController.java b/src/main/java/com/mark/web/bill/controller/AccountController.java index 57ef526..11ba99b 100644 --- a/src/main/java/com/mark/web/bill/controller/AccountController.java +++ b/src/main/java/com/mark/web/bill/controller/AccountController.java @@ -1,20 +1,27 @@ package com.mark.web.bill.controller; +import com.github.pagehelper.PageInfo; import com.mark.common.CurrentUser; import com.mark.common.ServerResponse; import com.mark.web.bill.entity.from.AddAccountFrom; import com.mark.web.bill.entity.po.Account; +import com.mark.web.bill.entity.vo.AccountVo; import com.mark.web.bill.service.IAccountService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; +import java.util.Date; +import java.util.Map; import java.util.Objects; @Api(tags = "账单-我的账单模块") @@ -33,9 +40,31 @@ public class AccountController { } Account account = new Account(); BeanUtils.copyProperties(addAccountFrom,account); + account.setCreateTime(new Date(addAccountFrom.getCreateTime())); //获取当前用户id int currentUserId = CurrentUser.getCurrentUserId(); account.setFkUserId(currentUserId); return iAccountService.add(account); } + + @ApiOperation("获取基本信息:总额,总付款,总未付款,个数") + @PostMapping(value = "getStatisticalInfo") + public ServerResponse> getStatisticalInfo(@RequestParam(value = "timestamps[0]") Long start, + @RequestParam(value = "timestamps[1]") Long end){ + return iAccountService.getStatisticalInfo(start,end,CurrentUser.getCurrentUserId()); + } + + + @ApiOperation(value = "获取搜索时间范围内账单信息") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum",value = "当前的页数",defaultValue = "1"), + @ApiImplicitParam(name = "pageSize",value = "页面大小",defaultValue = "10") + }) + @PostMapping(value = "getAccounts") + public ServerResponse> getAccountListBySearchTime(@RequestParam(value = "timestamps[0]") Long start, + @RequestParam(value = "timestamps[1]") Long end, + @RequestParam(value = "pageNum",defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize",defaultValue = "10") int pageSize){ + return iAccountService.getAccountListBySearchTime(start,end,pageNum,pageSize,CurrentUser.getCurrentUserId()); + } } diff --git a/src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java b/src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java index a255a5f..1c56173 100644 --- a/src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java +++ b/src/main/java/com/mark/web/bill/entity/from/AddAccountFrom.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel; import lombok.Data; import javax.validation.constraints.NotBlank; +import java.util.Date; /** * @Description: 新增账单时表单实体 @@ -16,6 +17,11 @@ import javax.validation.constraints.NotBlank; @ApiModel(value = "账单新增表单") public class AddAccountFrom { + /** + * 该账单的所属时间 + */ + private long createTime; + /** * 逻辑外键,用户id */ @@ -26,10 +32,14 @@ public class AddAccountFrom { */ private Integer quantity; + /** + * 账单的状态:1:未结算,2:已结算 + */ + private Integer enableStatus; + /** * 账单的描述 */ - @NotBlank private String description; } diff --git a/src/main/java/com/mark/web/bill/entity/vo/AccountVo.java b/src/main/java/com/mark/web/bill/entity/vo/AccountVo.java new file mode 100644 index 0000000..d3aa36f --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/vo/AccountVo.java @@ -0,0 +1,83 @@ +package com.mark.web.bill.entity.vo; + +import com.mark.common.utils.DateTimeUtil; +import com.mark.web.bill.entity.po.Account; +import com.mark.web.bill.entity.po.Goods; +import com.mark.web.bill.enums.AccountEnum; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @Description: 我的账单vo实体 + * @Author: Mark + * @CreateDate: 2019/2/3 12:00 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Data +public class AccountVo { + /** + * 主键ID + */ + private Integer id; + + /** + * 逻辑外键,商品id + */ + private Integer fkGoodsId; + + /** + * 加工的零件名称 + */ + private String goodsName; + + /** + * 加工零件的单价 + */ + private BigDecimal price; + + /** + * 加工零件的数量 + */ + private Integer quantity; + + /** + * 总价,单位是元,保留两位小数 + */ + private BigDecimal totalPrice; + + /** + * 账单的描述 + */ + private String description; + + /** + * 状态:1-未结算,2-已结算 + */ + private String enableStatus; + + /** + * 创建时间 + */ + private String createTime; + + /** + * 结算时间 + */ + private String paymentTime; + + public AccountVo(Account account, Goods goods){ + this.id = account.getId(); + this.fkGoodsId = account.getFkGoodsId(); + this.goodsName = goods.getGoodsName(); + this.price = goods.getPrice(); + this.quantity = account.getQuantity(); + this.totalPrice = account.getTotalPrice(); + this.description = account.getDescription(); + this.enableStatus = AccountEnum.stateOf(account.getEnableStatus()); + this.createTime = DateTimeUtil.dateToStr2(account.getCreateTime()); + this.paymentTime = DateTimeUtil.dateToStr2(account.getPaymentTime()); + } + +} diff --git a/src/main/java/com/mark/web/bill/enums/AccountEnum.java b/src/main/java/com/mark/web/bill/enums/AccountEnum.java index 3c6b221..2c03dae 100644 --- a/src/main/java/com/mark/web/bill/enums/AccountEnum.java +++ b/src/main/java/com/mark/web/bill/enums/AccountEnum.java @@ -19,6 +19,15 @@ public enum AccountEnum { this.desc = desc; } + public static String stateOf(int state){ + for(AccountEnum accountEnum :values()){ + if(accountEnum.getState() == state){ + return accountEnum.getDesc(); + } + } + return "未知!"; + } + public int getState() { return state; } diff --git a/src/main/java/com/mark/web/bill/mapper/AccountMapper.java b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java index 0c0289f..d21a1aa 100644 --- a/src/main/java/com/mark/web/bill/mapper/AccountMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java @@ -1,6 +1,11 @@ package com.mark.web.bill.mapper; import com.mark.web.bill.entity.po.Account; +import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; /** * @Description: 账号到dao接口定义 @@ -18,4 +23,25 @@ public interface AccountMapper { int updateByPrimaryKeySelective(Account record); + /** + * 根据搜索的时间戳获取个人的账单信息 + * @param startDate :开始时间 + * @param endDate : 结束时间 + * @param currentUserId :当用用户id + * @return : + */ + List selectAccountsBySearchTime(@Param("startDate") Date startDate, + @Param("endDate") Date endDate, + @Param("currentUserId") int currentUserId); + + + BigDecimal getTotalPrice(@Param("startDate") Date startDate, + @Param("endDate") Date endDate, + @Param("state") Integer state, + @Param("currentUserId") int currentUserId); + + int getTotalQuantity(@Param("startDate") Date startDate, + @Param("endDate") Date endDate, + @Param("currentUserId") int currentUserId); + } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/service/IAccountService.java b/src/main/java/com/mark/web/bill/service/IAccountService.java index b0a7dc9..6d10bc5 100644 --- a/src/main/java/com/mark/web/bill/service/IAccountService.java +++ b/src/main/java/com/mark/web/bill/service/IAccountService.java @@ -1,9 +1,18 @@ package com.mark.web.bill.service; +import com.github.pagehelper.PageInfo; import com.mark.common.ServerResponse; import com.mark.web.bill.entity.po.Account; +import com.mark.web.bill.entity.vo.AccountVo; + +import java.util.Map; public interface IAccountService { ServerResponse add(Account account); + + ServerResponse> getAccountListBySearchTime(Long start, Long end, int pageNum, int pageSize, int currentUserId); + + ServerResponse> getStatisticalInfo(Long start, Long end, int currentUserId); } + diff --git a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java index 136c7c5..fa37265 100644 --- a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java @@ -1,10 +1,15 @@ package com.mark.web.bill.service.impl; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.mark.common.Constant; import com.mark.common.ServerResponse; import com.mark.common.utils.BigDecimalUtil; import com.mark.web.bill.entity.po.Account; import com.mark.web.bill.entity.po.Goods; +import com.mark.web.bill.entity.vo.AccountVo; import com.mark.web.bill.enums.AccountEnum; import com.mark.web.bill.mapper.AccountMapper; import com.mark.web.bill.mapper.GoodsMapper; @@ -14,20 +19,26 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.Date; +import java.util.List; +import java.util.Map; @Service public class AccountServiceImpl implements IAccountService { + private final AccountMapper accountMapper; + private final GoodsMapper goodsMapper; + @Autowired - private AccountMapper accountMapper; - @Autowired - private GoodsMapper goodsMapper; + public AccountServiceImpl(AccountMapper accountMapper, GoodsMapper goodsMapper) { + this.accountMapper = accountMapper; + this.goodsMapper = goodsMapper; + } @Override public ServerResponse add(Account account) { //通过商品ID获取商品信息 Goods goods = goodsMapper.selectByPrimaryKey(account.getFkGoodsId()); if(goods == null){ - ServerResponse.createByErrorMessage("商品不存在!"); + return ServerResponse.createByErrorMessage("账单中的加工零件不存在!"); } if(account.getEnableStatus() == null){ account.setEnableStatus(AccountEnum.UN_PAYMENT.getState()); @@ -46,7 +57,40 @@ public class AccountServiceImpl implements IAccountService { if(effectNum != Constant.SUCCESS){ ServerResponse.createByErrorMessage("保存信息失败!"); } - return ServerResponse.createBySuccess(); + return ServerResponse.createBySuccessMessage("添加账单记录成功!"); + } + + @Override + public ServerResponse> getAccountListBySearchTime(Long start, Long end, int pageNum, int pageSize, int currentUserId) { + PageHelper.startPage(pageNum, pageSize); + Date startDate = new Date(start); + Date endDate = new Date(end); + List accountList = accountMapper.selectAccountsBySearchTime(startDate,endDate,currentUserId); + List accountVoList = Lists.newArrayList(); + for(Account account : accountList){ + Goods goods = goodsMapper.selectByPrimaryKey(account.getFkGoodsId()); + AccountVo accountVo = new AccountVo(account, goods); + accountVoList.add(accountVo); + } + PageInfo result = new PageInfo<>(accountVoList); + result.setTotal(new PageInfo<>(accountList).getTotal()); + return ServerResponse.createBySuccess(result); + } + + @Override + public ServerResponse> getStatisticalInfo(Long start, Long end, int currentUserId) { + Date startDate = new Date(start); + Date endDate = new Date(end); + BigDecimal totalPrice = accountMapper.getTotalPrice(startDate, endDate, null, currentUserId); + BigDecimal unPayTotalPrice = accountMapper.getTotalPrice(startDate, endDate, AccountEnum.UN_PAYMENT.getState(), currentUserId); + BigDecimal payTotalPrice = accountMapper.getTotalPrice(startDate, endDate, AccountEnum.PAYMENT_ED.getState(), currentUserId); + int totalQuantity = accountMapper.getTotalQuantity(startDate, endDate, currentUserId); + Map resultMap = Maps.newHashMap(); + resultMap.put("totalPrice",totalPrice == null ? 0.00 : totalPrice); + resultMap.put("unPayPrice",unPayTotalPrice == null ? 0.00 : unPayTotalPrice); + resultMap.put("payedPrice",payTotalPrice == null ? 0.00 : payTotalPrice); + resultMap.put("totalQuantity",totalQuantity); + return ServerResponse.createBySuccess(resultMap); } } diff --git a/src/main/resources/mappers/bill/AccountMapper.xml b/src/main/resources/mappers/bill/AccountMapper.xml index 01b599c..3ef82b6 100644 --- a/src/main/resources/mappers/bill/AccountMapper.xml +++ b/src/main/resources/mappers/bill/AccountMapper.xml @@ -74,4 +74,28 @@ where id = #{id,jdbcType=INTEGER} + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java b/src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java index a052903..dc6085c 100644 --- a/src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/AccountMapperTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import java.math.BigDecimal; +import java.util.Date; import static org.junit.Assert.*; @@ -45,4 +46,16 @@ public class AccountMapperTest extends BaseTest { @Test public void updateByPrimaryKeySelective() { } + + @Test + public void getTotalPrice(){ + BigDecimal totalPrice = accountMapper.getTotalPrice(new Date(),new Date(),null,5); + Assert.assertNotNull(totalPrice); + } + + @Test + public void getTotalQuantity(){ + Integer totalQuantity = accountMapper.getTotalQuantity(new Date(),new Date(),5); + Assert.assertNotNull(totalQuantity); + } } \ No newline at end of file -- Gitee From 738aff1418ba091508e47e70198b21fed6ba7a1d Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Mon, 11 Feb 2019 18:02:40 +0800 Subject: [PATCH 07/19] =?UTF-8?q?create=20=E5=8A=A0=E5=B7=A5=E9=9B=B6?= =?UTF-8?q?=E4=BB=B6=E7=A7=8D=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/bill/controller/GoodsController.java | 15 +++-- .../com/mark/web/bill/entity/po/Goods.java | 5 ++ .../web/bill/entity/po/GoodsCategory.java | 35 +++++++++++ .../mark/web/bill/mapper/AccountMapper.java | 2 +- .../web/bill/mapper/GoodsCategoryMapper.java | 14 +++++ .../bill/service/impl/AccountServiceImpl.java | 4 +- src/main/resources/generatorConfig.xml | 3 +- .../mappers/bill/GoodsCategoryMapper.xml | 61 +++++++++++++++++++ .../resources/mappers/bill/GoodsMapper.xml | 12 +++- .../bill/mapper/GoodsCategoryMapperTest.java | 38 ++++++++++++ 10 files changed, 173 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java create mode 100644 src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java create mode 100644 src/main/resources/mappers/bill/GoodsCategoryMapper.xml create mode 100644 src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java diff --git a/src/main/java/com/mark/web/bill/controller/GoodsController.java b/src/main/java/com/mark/web/bill/controller/GoodsController.java index c2a6f76..6a4372e 100644 --- a/src/main/java/com/mark/web/bill/controller/GoodsController.java +++ b/src/main/java/com/mark/web/bill/controller/GoodsController.java @@ -1,5 +1,6 @@ package com.mark.web.bill.controller; +import com.mark.common.CurrentUser; import com.mark.common.ServerResponse; import com.mark.web.bill.entity.from.AddGoodsFrom; import com.mark.web.bill.entity.po.Goods; @@ -9,11 +10,11 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import sun.misc.MessageUtils; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.util.List; import java.util.Map; @@ -36,16 +37,14 @@ public class GoodsController { @ApiOperation(value = "添加加工零件") @PostMapping(value = "add") - public ServerResponse add(@Valid AddGoodsFrom addGoodsFrom, BindingResult result){ + public ServerResponse add(@Valid AddGoodsFrom addGoodsFrom, BindingResult result, @RequestParam(value = "goodsImage",required = false)MultipartFile goodsImage){ if(result.hasErrors()){ return ServerResponse.createByErrorMessage(Objects.requireNonNull(result.getFieldError()).getDefaultMessage()); } Goods goods = new Goods(); BeanUtils.copyProperties(addGoodsFrom,goods); //获取当前用户id - //int currentUserId = CurrentUser.getCurrentUserId(); - //商品的ID先固定 - int currentUserId = 1000; + int currentUserId = CurrentUser.getCurrentUserId(); goods.setFkOwnerId(currentUserId); return iGoodsService.add(goods); } diff --git a/src/main/java/com/mark/web/bill/entity/po/Goods.java b/src/main/java/com/mark/web/bill/entity/po/Goods.java index 1d4bf62..6315ffa 100644 --- a/src/main/java/com/mark/web/bill/entity/po/Goods.java +++ b/src/main/java/com/mark/web/bill/entity/po/Goods.java @@ -30,6 +30,11 @@ public class Goods { */ private Integer fkOwnerId; + /** + * 逻辑外键,加工零件id + */ + private Integer fkCategoryId; + /** * 商品名称 */ diff --git a/src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java b/src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java new file mode 100644 index 0000000..0bc1550 --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java @@ -0,0 +1,35 @@ +package com.mark.web.bill.entity.po; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Date; +/** + * @Description: 加工零件种类对应的实体类 + * @Author: Kingsley: 08:46 + * @CreateDate: 2019/01/11 15:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class GoodsCategory { + + private Integer id; + + private Integer parentId; + + private String goodsCategoryName; + + private Integer enableStatus; + + private Integer priority; + + private Date createTime; + + private Date lastEditTime; +} \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/mapper/AccountMapper.java b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java index d21a1aa..7a24069 100644 --- a/src/main/java/com/mark/web/bill/mapper/AccountMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/AccountMapper.java @@ -40,7 +40,7 @@ public interface AccountMapper { @Param("state") Integer state, @Param("currentUserId") int currentUserId); - int getTotalQuantity(@Param("startDate") Date startDate, + Integer getTotalQuantity(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("currentUserId") int currentUserId); diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java new file mode 100644 index 0000000..8b12cdc --- /dev/null +++ b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java @@ -0,0 +1,14 @@ +package com.mark.web.bill.mapper; + +import com.mark.web.bill.entity.po.GoodsCategory; + +public interface GoodsCategoryMapper { + int deleteByPrimaryKey(Integer id); + + int insert(GoodsCategory record); + + GoodsCategory selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(GoodsCategory record); + +} \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java index fa37265..fdb3d2b 100644 --- a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java @@ -84,12 +84,12 @@ public class AccountServiceImpl implements IAccountService { BigDecimal totalPrice = accountMapper.getTotalPrice(startDate, endDate, null, currentUserId); BigDecimal unPayTotalPrice = accountMapper.getTotalPrice(startDate, endDate, AccountEnum.UN_PAYMENT.getState(), currentUserId); BigDecimal payTotalPrice = accountMapper.getTotalPrice(startDate, endDate, AccountEnum.PAYMENT_ED.getState(), currentUserId); - int totalQuantity = accountMapper.getTotalQuantity(startDate, endDate, currentUserId); + Integer totalQuantity = accountMapper.getTotalQuantity(startDate, endDate, currentUserId); Map resultMap = Maps.newHashMap(); resultMap.put("totalPrice",totalPrice == null ? 0.00 : totalPrice); resultMap.put("unPayPrice",unPayTotalPrice == null ? 0.00 : unPayTotalPrice); resultMap.put("payedPrice",payTotalPrice == null ? 0.00 : payTotalPrice); - resultMap.put("totalQuantity",totalQuantity); + resultMap.put("totalQuantity",totalQuantity == null ? 0.00 : totalQuantity); return ServerResponse.createBySuccess(resultMap); } diff --git a/src/main/resources/generatorConfig.xml b/src/main/resources/generatorConfig.xml index f2541ce..f3e2588 100644 --- a/src/main/resources/generatorConfig.xml +++ b/src/main/resources/generatorConfig.xml @@ -68,8 +68,7 @@ -
-
+
diff --git a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml new file mode 100644 index 0000000..6d6ebe4 --- /dev/null +++ b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + id, parent_id, goods_category_name, enable_status, priority, create_time, last_edit_time + + + + delete from tb_bill_goods_category + where id = #{id,jdbcType=INTEGER} + + + + insert into tb_bill_goods_category (id, parent_id, goods_category_name, + enable_status, priority, create_time, + last_edit_time) + values (#{id,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, #{goodsCategoryName,jdbcType=VARCHAR}, + #{enableStatus,jdbcType=INTEGER}, #{priority,jdbcType=INTEGER}, NOW(), + NOW()) + + + + update tb_bill_goods_category + + + parent_id = #{parentId,jdbcType=INTEGER}, + + + goods_category_name = #{goodsCategoryName,jdbcType=VARCHAR}, + + + enable_status = #{enableStatus,jdbcType=Integer}, + + + priority = #{priority,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + last_edit_time = NOW() + + where id = #{id,jdbcType=INTEGER} + + + \ No newline at end of file diff --git a/src/main/resources/mappers/bill/GoodsMapper.xml b/src/main/resources/mappers/bill/GoodsMapper.xml index de58c9f..db7be59 100644 --- a/src/main/resources/mappers/bill/GoodsMapper.xml +++ b/src/main/resources/mappers/bill/GoodsMapper.xml @@ -5,6 +5,7 @@ + @@ -14,7 +15,7 @@ - id, fk_owner_id, goods_name, price, priority, enable_status, create_time, last_edit_time + id, fk_owner_id,fk_category_id, goods_name, price, priority, enable_status, create_time, last_edit_time + + + + + + + + + + + + + + + + + + delete from tb_bill_goods where id = #{id,jdbcType=INTEGER} diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java index 32bc49a..9a5a397 100644 --- a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java @@ -1,6 +1,7 @@ package com.mark.web.bill.mapper; import com.mark.BaseTest; +import com.mark.web.bill.entity.dto.GoodsDetail; import org.junit.Assert; import org.junit.Test; import org.omg.CORBA.PUBLIC_MEMBER; @@ -42,4 +43,10 @@ public class GoodsMapperTest extends BaseTest { List> maps = goodsMapper.selectAllGoods(); Assert.assertNotEquals(0,maps.size()); } + + @Test + public void searchGoodsDetailList(){ + List goodsDetails = goodsMapper.searchGoodsDetailList(null,5); + Assert.assertNotEquals(0,goodsDetails.size()); + } } \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java b/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java index a18d0c6..3578bc0 100644 --- a/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java +++ b/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java @@ -28,7 +28,7 @@ public class IGoodsServiceTest extends BaseTest { goods.setGoodsName("测试记录"); goods.setPrice(new BigDecimal(0.02)); goods.setPriority(1); - ServerResponse add = iGoodsService.add(goods, goodsImage); + ServerResponse add = iGoodsService.add(goods, null); Assert.assertNotNull(add); } } \ No newline at end of file -- Gitee From 328818460dadc0a9b508373b75e6bdd8d9dd7469 Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Wed, 13 Feb 2019 15:51:50 +0800 Subject: [PATCH 10/19] =?UTF-8?q?update=20for=20BigDecimalUtil.java?= =?UTF-8?q?=EF=BC=88"=E6=B7=BB=E5=8A=A0=E4=BF=9D=E7=95=99=E4=B8=A4?= =?UTF-8?q?=E4=BD=8D=E5=B0=8F=E6=95=B0=E7=9A=84=E5=B7=A5=E5=85=B7=E7=B1=BB?= =?UTF-8?q?=E6=96=B9=E6=B3=95"=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mark/common/utils/BigDecimalUtil.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/mark/common/utils/BigDecimalUtil.java b/src/main/java/com/mark/common/utils/BigDecimalUtil.java index f9c9176..d530a64 100644 --- a/src/main/java/com/mark/common/utils/BigDecimalUtil.java +++ b/src/main/java/com/mark/common/utils/BigDecimalUtil.java @@ -1,6 +1,7 @@ package com.mark.common.utils; import java.math.BigDecimal; +import java.math.RoundingMode; /** * @Description: 计算商品价格的工具类 @@ -35,4 +36,15 @@ public class BigDecimalUtil { BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.divide(b2,2,BigDecimal.ROUND_HALF_UP);//四舍五入,保留2位小数 } + + /** + * BigDecimal参数格式化:保留两位小数 + * @param bigDecimal :原始value :eg 2.9 + * @return :格式化的value:eg 2.90 + */ + public static BigDecimal saveScale2(BigDecimal bigDecimal){ + return bigDecimal.setScale(2, RoundingMode.HALF_UP); + } + + } -- Gitee From e7d0bf9c044a7b140cf1e8c56508beecf7aa7087 Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Sat, 16 Feb 2019 16:49:40 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=96=91=E9=97=AE=E8=AE=B0=E5=BD=95=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "src/main/java/com/mark/web/bill/doc/\347\226\221\351\227\256" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "src/main/java/com/mark/web/bill/doc/\347\226\221\351\227\256" diff --git "a/src/main/java/com/mark/web/bill/doc/\347\226\221\351\227\256" "b/src/main/java/com/mark/web/bill/doc/\347\226\221\351\227\256" new file mode 100644 index 0000000..2539eb4 --- /dev/null +++ "b/src/main/java/com/mark/web/bill/doc/\347\226\221\351\227\256" @@ -0,0 +1,3 @@ +# 2019-02-16 +问题:账单信息的单价和总价,BigDecimal类型的1.10返回到前端的时候被显示为1.0? +解决:把BigDecimal转换为String类型 -- Gitee From dc83bbaf67d21210b78cb797f16a531c140d154d Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Sat, 16 Feb 2019 16:51:23 +0800 Subject: [PATCH 12/19] =?UTF-8?q?update=20for=20=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E8=B4=A6=E5=8D=95=E4=BF=A1=E6=81=AF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=88=E2=80=9C=E5=8A=A0=E5=B7=A5=E9=9B=B6=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E4=BB=B7=E5=92=8C=E6=80=BB=E4=BB=B7=E7=B2=BE?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E5=AD=98=E5=88=B0=E5=B0=8F=E6=95=B0=E7=82=B9?= =?UTF-8?q?=E5=90=8E=E4=B8=A4=E4=BD=8D=E2=80=9D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mark/web/bill/entity/vo/AccountVo.java | 27 ++++++++++++++----- .../web/bill/service/IAccountService.java | 21 +++++++++++++++ .../bill/service/impl/AccountServiceImpl.java | 11 ++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mark/web/bill/entity/vo/AccountVo.java b/src/main/java/com/mark/web/bill/entity/vo/AccountVo.java index d3aa36f..ee7ac32 100644 --- a/src/main/java/com/mark/web/bill/entity/vo/AccountVo.java +++ b/src/main/java/com/mark/web/bill/entity/vo/AccountVo.java @@ -1,12 +1,12 @@ package com.mark.web.bill.entity.vo; +import com.mark.common.utils.BigDecimalUtil; import com.mark.common.utils.DateTimeUtil; import com.mark.web.bill.entity.po.Account; import com.mark.web.bill.entity.po.Goods; import com.mark.web.bill.enums.AccountEnum; import lombok.Data; - -import java.math.BigDecimal; +import org.apache.commons.lang3.StringUtils; /** * @Description: 我的账单vo实体 @@ -35,7 +35,7 @@ public class AccountVo { /** * 加工零件的单价 */ - private BigDecimal price; + private String price; /** * 加工零件的数量 @@ -45,7 +45,7 @@ public class AccountVo { /** * 总价,单位是元,保留两位小数 */ - private BigDecimal totalPrice; + private String totalPrice; /** * 账单的描述 @@ -71,13 +71,26 @@ public class AccountVo { this.id = account.getId(); this.fkGoodsId = account.getFkGoodsId(); this.goodsName = goods.getGoodsName(); - this.price = goods.getPrice(); + this.price = BigDecimalUtil.saveScale2(goods.getPrice()).toString(); this.quantity = account.getQuantity(); - this.totalPrice = account.getTotalPrice(); + this.totalPrice = BigDecimalUtil.saveScale2(account.getTotalPrice()).toString(); this.description = account.getDescription(); this.enableStatus = AccountEnum.stateOf(account.getEnableStatus()); this.createTime = DateTimeUtil.dateToStr2(account.getCreateTime()); - this.paymentTime = DateTimeUtil.dateToStr2(account.getPaymentTime()); + + //支持时间的赋值 + String paymentTimeStr = DateTimeUtil.dateToStr2(account.getPaymentTime()); + if(StringUtils.isBlank(paymentTimeStr)) { + paymentTimeStr = "未定"; + } + this.paymentTime = paymentTimeStr; + + //描述属性赋值 + String descriptionStr = account.getDescription(); + if(StringUtils.isBlank(descriptionStr)){ + descriptionStr = "无"; + } + this.description = descriptionStr; } } diff --git a/src/main/java/com/mark/web/bill/service/IAccountService.java b/src/main/java/com/mark/web/bill/service/IAccountService.java index 6d10bc5..532f468 100644 --- a/src/main/java/com/mark/web/bill/service/IAccountService.java +++ b/src/main/java/com/mark/web/bill/service/IAccountService.java @@ -9,10 +9,31 @@ import java.util.Map; public interface IAccountService { + /** + * 添加一条个人账单信息 + * @param account :个人账单信息 + * @return : + */ ServerResponse add(Account account); + /** + * 查找搜索时间范围内的账单信息列表 + * @param start :搜索开始时间戳 + * @param end :搜索结束时间戳 + * @param pageNum :页数 + * @param pageSize :页面大小 + * @param currentUserId :当前用户ID + * @return :返回当前用户的在搜索时间范围内的个人账单信息列表 + */ ServerResponse> getAccountListBySearchTime(Long start, Long end, int pageNum, int pageSize, int currentUserId); + /** + * 查找搜索时间范围内的账单统计信息(总额,已经结算总额,未结算总额,总加工零件数量) + * @param start :搜索开始时间 + * @param end :搜索结束时间 + * @param currentUserId :当前用户ID + * @return :找搜索时间范围内的账单统计信息 + */ ServerResponse> getStatisticalInfo(Long start, Long end, int currentUserId); } diff --git a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java index fdb3d2b..4738506 100644 --- a/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/AccountServiceImpl.java @@ -33,6 +33,7 @@ public class AccountServiceImpl implements IAccountService { this.goodsMapper = goodsMapper; } + //region 添加一条个人账单信息 @Override public ServerResponse add(Account account) { //通过商品ID获取商品信息 @@ -59,7 +60,9 @@ public class AccountServiceImpl implements IAccountService { } return ServerResponse.createBySuccessMessage("添加账单记录成功!"); } + //endregion + //region 查找时间范围内的账单信息列表 @Override public ServerResponse> getAccountListBySearchTime(Long start, Long end, int pageNum, int pageSize, int currentUserId) { PageHelper.startPage(pageNum, pageSize); @@ -76,7 +79,9 @@ public class AccountServiceImpl implements IAccountService { result.setTotal(new PageInfo<>(accountList).getTotal()); return ServerResponse.createBySuccess(result); } + //endregion + //region 查找搜索时间范围内的账单统计信息(总额,已经结算总额,未结算总额,总加工零件数量) @Override public ServerResponse> getStatisticalInfo(Long start, Long end, int currentUserId) { Date startDate = new Date(start); @@ -85,12 +90,18 @@ public class AccountServiceImpl implements IAccountService { BigDecimal unPayTotalPrice = accountMapper.getTotalPrice(startDate, endDate, AccountEnum.UN_PAYMENT.getState(), currentUserId); BigDecimal payTotalPrice = accountMapper.getTotalPrice(startDate, endDate, AccountEnum.PAYMENT_ED.getState(), currentUserId); Integer totalQuantity = accountMapper.getTotalQuantity(startDate, endDate, currentUserId); + Map resultMap = Maps.newHashMap(); + //总额 resultMap.put("totalPrice",totalPrice == null ? 0.00 : totalPrice); + //未支付总额 resultMap.put("unPayPrice",unPayTotalPrice == null ? 0.00 : unPayTotalPrice); + //已支付总额 resultMap.put("payedPrice",payTotalPrice == null ? 0.00 : payTotalPrice); + //总加工零件个数 resultMap.put("totalQuantity",totalQuantity == null ? 0.00 : totalQuantity); return ServerResponse.createBySuccess(resultMap); } + //endregion } -- Gitee From 3f3fc7e5b2e5c51bc06c74c12d1512a71b4a2f64 Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Sat, 16 Feb 2019 23:50:13 +0800 Subject: [PATCH 13/19] =?UTF-8?q?create=20=E5=8A=A0=E5=B7=A5=E9=9B=B6?= =?UTF-8?q?=E4=BB=B6=E7=A7=8D=E7=B1=BB=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bill/controller/GoodsCateController.java | 44 ++++++++++++++++++ .../web/bill/controller/GoodsController.java | 3 -- .../web/bill/entity/po/GoodsCategory.java | 2 + .../web/bill/entity/vo/GoodsCategoryVo.java | 44 ++++++++++++++++++ .../web/bill/enums/GoodsCategoryEnum.java | 46 +++++++++++++++++++ .../web/bill/mapper/GoodsCategoryMapper.java | 16 ++++++- .../web/bill/service/IGoodsCateService.java | 18 ++++++++ .../service/impl/GoodsCateServiceImpl.java | 33 +++++++++++++ .../mappers/bill/GoodsCategoryMapper.xml | 45 ++++++++++++------ .../bill/mapper/GoodsCategoryMapperTest.java | 11 ++++- 10 files changed, 241 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/mark/web/bill/controller/GoodsCateController.java create mode 100644 src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java create mode 100644 src/main/java/com/mark/web/bill/enums/GoodsCategoryEnum.java create mode 100644 src/main/java/com/mark/web/bill/service/IGoodsCateService.java create mode 100644 src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java diff --git a/src/main/java/com/mark/web/bill/controller/GoodsCateController.java b/src/main/java/com/mark/web/bill/controller/GoodsCateController.java new file mode 100644 index 0000000..edb6d9f --- /dev/null +++ b/src/main/java/com/mark/web/bill/controller/GoodsCateController.java @@ -0,0 +1,44 @@ +package com.mark.web.bill.controller; + +import com.github.pagehelper.PageInfo; +import com.mark.common.CurrentUser; +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.vo.GoodsCategoryVo; +import com.mark.web.bill.entity.vo.GoodsDetailVo; +import com.mark.web.bill.service.IGoodsCateService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @Description: 加工零件种类控制器 + * @Author: Mark + * @CreateDate: 2019/2/16 21:13 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Api(tags = "账单-加工零件种类模块") +@RestController +@RequestMapping(value = "/bill/goodsCate/") +public class GoodsCateController { + + @Autowired + private IGoodsCateService iGoodsCateService; + + @ApiOperation(value = "获取加工零件同一个父级的种类信息") + @ApiImplicitParams({ + @ApiImplicitParam(name = "parentId",value = "种类父级ID",defaultValue = "0") + }) + @PostMapping(value = "getGoodsCates") + public ServerResponse> getGoodsCateList(@RequestParam(value = "parentId",defaultValue = "0") int parentId){ + return iGoodsCateService.getGoodsCateList(parentId); + } +} diff --git a/src/main/java/com/mark/web/bill/controller/GoodsController.java b/src/main/java/com/mark/web/bill/controller/GoodsController.java index 10ef169..00c193f 100644 --- a/src/main/java/com/mark/web/bill/controller/GoodsController.java +++ b/src/main/java/com/mark/web/bill/controller/GoodsController.java @@ -5,7 +5,6 @@ import com.mark.common.CurrentUser; import com.mark.common.ServerResponse; import com.mark.web.bill.entity.from.AddGoodsFrom; import com.mark.web.bill.entity.po.Goods; -import com.mark.web.bill.entity.vo.AccountVo; import com.mark.web.bill.entity.vo.GoodsDetailVo; import com.mark.web.bill.service.IGoodsService; import io.swagger.annotations.Api; @@ -17,9 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import sun.misc.MessageUtils; -import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.util.List; import java.util.Map; diff --git a/src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java b/src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java index 0bc1550..ca9529d 100644 --- a/src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java +++ b/src/main/java/com/mark/web/bill/entity/po/GoodsCategory.java @@ -27,6 +27,8 @@ public class GoodsCategory { private Integer enableStatus; + private Integer level; + private Integer priority; private Date createTime; diff --git a/src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java b/src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java new file mode 100644 index 0000000..202bc01 --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java @@ -0,0 +1,44 @@ +package com.mark.web.bill.entity.vo; + +import com.mark.common.utils.DateTimeUtil; +import com.mark.web.bill.entity.po.GoodsCategory; +import com.mark.web.bill.enums.GoodsCategoryEnum; +import lombok.Data; + +/** + * @Description: 用户头像POJO类 + * @Author: Mark + * @CreateDate: 2019/2/16 21:06 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Data +public class GoodsCategoryVo { + + private Integer id; + + private Integer parentId; + + private String goodsCategoryName; + + private String enableStatus; + + private Integer level; + + private Integer priority; + + private String createTime; + + private String lastEditTime; + + public GoodsCategoryVo(GoodsCategory goodsCategory){ + this.id = goodsCategory.getId(); + this.parentId = goodsCategory.getParentId(); + this.goodsCategoryName = goodsCategory.getGoodsCategoryName(); + this.enableStatus = GoodsCategoryEnum.stateOf(goodsCategory.getEnableStatus()); + this.level = goodsCategory.getLevel(); + this.priority = goodsCategory.getPriority(); + this.createTime = DateTimeUtil.dateToStr(goodsCategory.getCreateTime()); + this.lastEditTime = DateTimeUtil.dateToStr(goodsCategory.getLastEditTime()); + } +} diff --git a/src/main/java/com/mark/web/bill/enums/GoodsCategoryEnum.java b/src/main/java/com/mark/web/bill/enums/GoodsCategoryEnum.java new file mode 100644 index 0000000..49056ed --- /dev/null +++ b/src/main/java/com/mark/web/bill/enums/GoodsCategoryEnum.java @@ -0,0 +1,46 @@ +package com.mark.web.bill.enums; + +/** + * @Description: 加工零件种类的枚举信息 + * @Author: Mark + * @CreateDate: 2019/2/16 21:08 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public enum GoodsCategoryEnum { + AVAILABLE(1, "可用"), + FORBIDDEN(2,"禁用"); + + private int state; + private String desc; + + GoodsCategoryEnum(int state, String desc) { + this.state = state; + this.desc = desc; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public static String stateOf(int state){ + for(GoodsCategoryEnum goodsCategoryEnum :values()){ + if(goodsCategoryEnum.getState() == state){ + return goodsCategoryEnum.getDesc(); + } + } + return "未知!"; + } +} diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java index 8b12cdc..9aa9569 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java @@ -2,13 +2,25 @@ package com.mark.web.bill.mapper; import com.mark.web.bill.entity.po.GoodsCategory; +import java.util.List; + public interface GoodsCategoryMapper { - int deleteByPrimaryKey(Integer id); int insert(GoodsCategory record); - GoodsCategory selectByPrimaryKey(Integer id); + int deleteByPrimaryKey(Integer id); int updateByPrimaryKeySelective(GoodsCategory record); + GoodsCategory selectByPrimaryKey(Integer id); + + + + /** + * 根据父级种类的ID获取子加工零件种类列表信息 + * @param parentId :父级ID + * @return : + */ + List selectSubGoodsCatesByParentId(Integer parentId); + } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/service/IGoodsCateService.java b/src/main/java/com/mark/web/bill/service/IGoodsCateService.java new file mode 100644 index 0000000..b16190a --- /dev/null +++ b/src/main/java/com/mark/web/bill/service/IGoodsCateService.java @@ -0,0 +1,18 @@ +package com.mark.web.bill.service; + +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.vo.GoodsCategoryVo; + +import java.util.List; + +/** + * @Description: 加工零件种类业务接口定义 + * @Author: Mark + * @CreateDate: 2019/2/16 21:14 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public interface IGoodsCateService { + + ServerResponse> getGoodsCateList(int parentId); +} diff --git a/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java new file mode 100644 index 0000000..0a2f0ae --- /dev/null +++ b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java @@ -0,0 +1,33 @@ +package com.mark.web.bill.service.impl; + +import com.google.common.collect.Lists; +import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.po.GoodsCategory; +import com.mark.web.bill.entity.vo.GoodsCategoryVo; +import com.mark.web.bill.mapper.GoodsCategoryMapper; +import com.mark.web.bill.service.IGoodsCateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Description: 加工零件种类的业务实现 + * @Author: Mark + * @CreateDate: 2019/2/16 21:18 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Service +public class GoodsCateServiceImpl implements IGoodsCateService { + @Autowired + private GoodsCategoryMapper goodsCategoryMapper; + + @Override + public ServerResponse> getGoodsCateList(int parentId) { + List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(parentId); + List result = Lists.newArrayList(); + goodsCategoryList.forEach(goodsCategory -> result.add(new GoodsCategoryVo(goodsCategory))); + return ServerResponse.createBySuccess(result); + } +} diff --git a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml index 6d6ebe4..ed55046 100644 --- a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml +++ b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml @@ -7,34 +7,31 @@ + - id, parent_id, goods_category_name, enable_status, priority, create_time, last_edit_time + id, parent_id, goods_category_name, enable_status,level,priority, create_time, last_edit_time - - - delete from tb_bill_goods_category - where id = #{id,jdbcType=INTEGER} - + - insert into tb_bill_goods_category (id, parent_id, goods_category_name, - enable_status, priority, create_time, + insert into tb_bill_goods_category (id, parent_id, goods_category_name, + enable_status,level, priority, create_time, last_edit_time) - values (#{id,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, #{goodsCategoryName,jdbcType=VARCHAR}, - #{enableStatus,jdbcType=INTEGER}, #{priority,jdbcType=INTEGER}, NOW(), + values (#{id,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, #{goodsCategoryName,jdbcType=VARCHAR}, + #{enableStatus,jdbcType=INTEGER}, #{level,jdbcType=INTEGER},#{priority,jdbcType=INTEGER}, NOW(), NOW()) + + delete from tb_bill_goods_category + where id = #{id,jdbcType=INTEGER} + + update tb_bill_goods_category @@ -47,6 +44,9 @@ enable_status = #{enableStatus,jdbcType=Integer}, + + priority = #{level,jdbcType=INTEGER}, + priority = #{priority,jdbcType=INTEGER}, @@ -58,4 +58,19 @@ where id = #{id,jdbcType=INTEGER} + + + + + \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java index 38e71e5..ec7d44f 100644 --- a/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java @@ -6,6 +6,8 @@ import org.junit.Assert; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; + /** * @Description: 加工零件种类操作数据库的dao层接口 * @Author: Kingsley: 08:46 @@ -25,8 +27,9 @@ public class GoodsCategoryMapperTest extends BaseTest { public void insert() { GoodsCategory category = new GoodsCategory(); category.setParentId(0); - category.setGoodsCategoryName("上丝类"); + category.setGoodsCategoryName("毛扣类"); category.setEnableStatus(1); + category.setLevel(0); category.setPriority(0); int effectNum = goodsCategoryMapper.insert(category); Assert.assertNotEquals(0,effectNum); @@ -35,4 +38,10 @@ public class GoodsCategoryMapperTest extends BaseTest { @Test public void selectByPrimaryKey() { } + + @Test + public void selectSubGoodsCatesByParentId(){ + List goodsCategories = goodsCategoryMapper.selectSubGoodsCatesByParentId(0); + Assert.assertNotEquals(0,goodsCategories.size()); + } } \ No newline at end of file -- Gitee From 1b858fccd48236849823a4251c06be8e2fcda0ea Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Sun, 17 Feb 2019 12:16:26 +0800 Subject: [PATCH 14/19] =?UTF-8?q?update=E7=A7=8D=E7=B1=BB=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=EF=BC=88=E2=80=9C=E6=96=B0=E5=A2=9E=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=A7=8D=E7=B1=BB=E6=8E=A5=E5=8F=A3=E2=80=9D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bill/controller/GoodsCateController.java | 34 ++++++++-- .../bill/entity/from/AddGoodsCateFrom.java | 35 ++++++++++ .../web/bill/mapper/GoodsCategoryMapper.java | 6 ++ .../web/bill/service/IGoodsCateService.java | 6 ++ .../service/impl/GoodsCateServiceImpl.java | 67 ++++++++++++++++++- .../mappers/bill/GoodsCategoryMapper.xml | 8 +++ .../bill/mapper/GoodsCategoryMapperTest.java | 10 ++- .../bill/service/IGoodsCateServiceTest.java | 30 +++++++++ 8 files changed, 187 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java create mode 100644 src/test/java/com/mark/web/bill/service/IGoodsCateServiceTest.java diff --git a/src/main/java/com/mark/web/bill/controller/GoodsCateController.java b/src/main/java/com/mark/web/bill/controller/GoodsCateController.java index edb6d9f..6810da6 100644 --- a/src/main/java/com/mark/web/bill/controller/GoodsCateController.java +++ b/src/main/java/com/mark/web/bill/controller/GoodsCateController.java @@ -1,22 +1,27 @@ package com.mark.web.bill.controller; -import com.github.pagehelper.PageInfo; import com.mark.common.CurrentUser; import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.from.AddAccountFrom; +import com.mark.web.bill.entity.from.AddGoodsCateFrom; +import com.mark.web.bill.entity.po.Account; +import com.mark.web.bill.entity.po.GoodsCategory; import com.mark.web.bill.entity.vo.GoodsCategoryVo; -import com.mark.web.bill.entity.vo.GoodsDetailVo; import com.mark.web.bill.service.IGoodsCateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; +import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.Objects; /** * @Description: 加工零件种类控制器 @@ -41,4 +46,21 @@ public class GoodsCateController { public ServerResponse> getGoodsCateList(@RequestParam(value = "parentId",defaultValue = "0") int parentId){ return iGoodsCateService.getGoodsCateList(parentId); } + + @ApiOperation(value = "获取渲染种类Cascader级联选择器的数据") + @GetMapping(value = "getGoodsCateCascader") + public ServerResponse>> getGoodsCateCascader(){ + return iGoodsCateService.getGoodsCateCascader(); + } + + @ApiOperation(value = "添加种类") + @PostMapping(value = "add") + public ServerResponse add(@Valid AddGoodsCateFrom addGoodsCateFrom, BindingResult result){ + if(result.hasErrors()){ + return ServerResponse.createByErrorMessage(Objects.requireNonNull(result.getFieldError()).getDefaultMessage()); + } + GoodsCategory goodsCategory = new GoodsCategory(); + BeanUtils.copyProperties(addGoodsCateFrom,goodsCategory); + return iGoodsCateService.add(goodsCategory); + } } diff --git a/src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java b/src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java new file mode 100644 index 0000000..e7a7928 --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java @@ -0,0 +1,35 @@ +package com.mark.web.bill.entity.from; + +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.util.Date; + +/** + * @Description: 新增加工零件种类 + * @Author: Mark + * @CreateDate: 2019/2/17 11:03 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Data +@ApiModel(value = "种类新增表单") +public class AddGoodsCateFrom { + /** + * 父级种类Id + */ + private Integer parentId; + + /** + * 种类名 + */ + @NotBlank(message = "加工零件种类名称必填") + private String goodsCategoryName; + + /** + * 权重 + */ + private Integer priority; + +} diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java index 9aa9569..ea0eb50 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java @@ -23,4 +23,10 @@ public interface GoodsCategoryMapper { */ List selectSubGoodsCatesByParentId(Integer parentId); + /** + * 获取所有可用种类 + * @return :状态为可用的种类 + */ + List selectAllGoodsCates(); + } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/service/IGoodsCateService.java b/src/main/java/com/mark/web/bill/service/IGoodsCateService.java index b16190a..50e7aaf 100644 --- a/src/main/java/com/mark/web/bill/service/IGoodsCateService.java +++ b/src/main/java/com/mark/web/bill/service/IGoodsCateService.java @@ -1,9 +1,11 @@ package com.mark.web.bill.service; import com.mark.common.ServerResponse; +import com.mark.web.bill.entity.po.GoodsCategory; import com.mark.web.bill.entity.vo.GoodsCategoryVo; import java.util.List; +import java.util.Map; /** * @Description: 加工零件种类业务接口定义 @@ -15,4 +17,8 @@ import java.util.List; public interface IGoodsCateService { ServerResponse> getGoodsCateList(int parentId); + + ServerResponse>> getGoodsCateCascader(); + + ServerResponse add(GoodsCategory goodsCategory); } diff --git a/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java index 0a2f0ae..79cba31 100644 --- a/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java @@ -1,15 +1,20 @@ package com.mark.web.bill.service.impl; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.mark.common.Constant; import com.mark.common.ServerResponse; import com.mark.web.bill.entity.po.GoodsCategory; import com.mark.web.bill.entity.vo.GoodsCategoryVo; +import com.mark.web.bill.enums.GoodsCategoryEnum; +import com.mark.web.bill.exception.BillException; import com.mark.web.bill.mapper.GoodsCategoryMapper; import com.mark.web.bill.service.IGoodsCateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Map; /** * @Description: 加工零件种类的业务实现 @@ -20,9 +25,14 @@ import java.util.List; */ @Service public class GoodsCateServiceImpl implements IGoodsCateService { + private final GoodsCategoryMapper goodsCategoryMapper; + @Autowired - private GoodsCategoryMapper goodsCategoryMapper; + public GoodsCateServiceImpl(GoodsCategoryMapper goodsCategoryMapper) { + this.goodsCategoryMapper = goodsCategoryMapper; + } + //region 获取同一个父级的零件种类 @Override public ServerResponse> getGoodsCateList(int parentId) { List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(parentId); @@ -30,4 +40,59 @@ public class GoodsCateServiceImpl implements IGoodsCateService { goodsCategoryList.forEach(goodsCategory -> result.add(new GoodsCategoryVo(goodsCategory))); return ServerResponse.createBySuccess(result); } + //endregion + + //region 获取渲染Cascader组件的属性数据 + @Override + public ServerResponse>> getGoodsCateCascader() { + List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(0); + + List> result = buildGoodsCateCascader(0,goodsCategoryList); + return ServerResponse.createBySuccess(result); + } + + private List> buildGoodsCateCascader(int parentId, List goodsCategoryList) { + List> result = Lists.newArrayList(); + for(GoodsCategory goodsCategory : goodsCategoryList){ + if(goodsCategory.getParentId() == parentId){ + Map childrenMap = Maps.newHashMap(); + childrenMap.put("value", goodsCategory.getId()); + childrenMap.put("label", goodsCategory.getGoodsCategoryName()); + List subGoodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(goodsCategory.getId()); + if(subGoodsCategoryList != null && subGoodsCategoryList.size() > 0){ + List> children = buildGoodsCateCascader(goodsCategory.getId(), subGoodsCategoryList); + childrenMap.put("children", children); + } + result.add(childrenMap); + } + } + return result; + } + //endregion + + //region 新增一条种类记录 + @Override + public ServerResponse add(GoodsCategory goodsCategory) { + //状态默认为可用 + goodsCategory.setEnableStatus(GoodsCategoryEnum.AVAILABLE.getState()); + + //层级属性的设置:如果父级ID为0,则level为1。否则取父级种类的level+1 + if(goodsCategory.getParentId() == 0 || goodsCategory.getParentId()==null){ + goodsCategory.setLevel(1); + }else{ + GoodsCategory parentCate = goodsCategoryMapper.selectByPrimaryKey(goodsCategory.getParentId()); + if(parentCate == null){ + throw new BillException("父级种类不存在!"); + } + goodsCategory.setLevel(parentCate.getLevel()); + } + + //插入数据库 + int insert = goodsCategoryMapper.insert(goodsCategory); + if(insert != Constant.SUCCESS){ + return ServerResponse.createByErrorMessage("保存数据失败!"); + } + return ServerResponse.createBySuccessMessage("新增种类成功!"); + } + //endregion } diff --git a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml index ed55046..6d01faf 100644 --- a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml +++ b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml @@ -73,4 +73,12 @@ WHERE parent_id = #{parentId} + + + \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java index ec7d44f..667283d 100644 --- a/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java @@ -26,8 +26,8 @@ public class GoodsCategoryMapperTest extends BaseTest { @Test public void insert() { GoodsCategory category = new GoodsCategory(); - category.setParentId(0); - category.setGoodsCategoryName("毛扣类"); + category.setParentId(3); + category.setGoodsCategoryName("子上丝类1"); category.setEnableStatus(1); category.setLevel(0); category.setPriority(0); @@ -44,4 +44,10 @@ public class GoodsCategoryMapperTest extends BaseTest { List goodsCategories = goodsCategoryMapper.selectSubGoodsCatesByParentId(0); Assert.assertNotEquals(0,goodsCategories.size()); } + + @Test + public void selectAllGoodsCates(){ + List goodsCategories = goodsCategoryMapper.selectAllGoodsCates(); + Assert.assertNotEquals(0,goodsCategories.size()); + } } \ No newline at end of file diff --git a/src/test/java/com/mark/web/bill/service/IGoodsCateServiceTest.java b/src/test/java/com/mark/web/bill/service/IGoodsCateServiceTest.java new file mode 100644 index 0000000..f7798d7 --- /dev/null +++ b/src/test/java/com/mark/web/bill/service/IGoodsCateServiceTest.java @@ -0,0 +1,30 @@ +package com.mark.web.bill.service; + +import com.mark.BaseTest; +import com.mark.common.ServerResponse; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * @Description: 加工零件种类的测试 + * @Author: Mark + * @CreateDate: 2019/2/17 0:32 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public class IGoodsCateServiceTest extends BaseTest { + @Autowired + private IGoodsCateService iGoodsCateService; + + @Test + public void getGoodsCateCascader(){ + ServerResponse>> goodsCateCascader = iGoodsCateService.getGoodsCateCascader(); + Assert.assertNotEquals(0,goodsCateCascader.getData().size()); + } +} \ No newline at end of file -- Gitee From 1e388a828ba83d4d8827ff5470b57c8ac86b8435 Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Mon, 18 Feb 2019 22:30:06 +0800 Subject: [PATCH 15/19] =?UTF-8?q?uopdate=20for=20=E7=A7=8D=E7=B1=BB?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=88=E2=80=9C=E7=A7=8D=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E2=80=9D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bill/controller/GoodsCateController.java | 22 +++++++ .../bill/entity/from/AddGoodsCateFrom.java | 1 - .../bill/entity/from/EditGoodsCateFrom.java | 42 +++++++++++++ .../web/bill/entity/vo/GoodsCategoryVo.java | 4 ++ .../web/bill/mapper/GoodsCategoryMapper.java | 7 ++- .../web/bill/service/IGoodsCateService.java | 5 ++ .../service/impl/GoodsCateServiceImpl.java | 60 +++++++++++++++---- .../mappers/bill/GoodsCategoryMapper.xml | 14 ++++- .../bill/mapper/GoodsCategoryMapperTest.java | 2 +- 9 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java diff --git a/src/main/java/com/mark/web/bill/controller/GoodsCateController.java b/src/main/java/com/mark/web/bill/controller/GoodsCateController.java index 6810da6..b4f12e0 100644 --- a/src/main/java/com/mark/web/bill/controller/GoodsCateController.java +++ b/src/main/java/com/mark/web/bill/controller/GoodsCateController.java @@ -4,6 +4,7 @@ import com.mark.common.CurrentUser; import com.mark.common.ServerResponse; import com.mark.web.bill.entity.from.AddAccountFrom; import com.mark.web.bill.entity.from.AddGoodsCateFrom; +import com.mark.web.bill.entity.from.EditGoodsCateFrom; import com.mark.web.bill.entity.po.Account; import com.mark.web.bill.entity.po.GoodsCategory; import com.mark.web.bill.entity.vo.GoodsCategoryVo; @@ -47,6 +48,16 @@ public class GoodsCateController { return iGoodsCateService.getGoodsCateList(parentId); } + @ApiOperation(value = "搜索获取加工零件同一个父级的种类信息") + @ApiImplicitParams({ + @ApiImplicitParam(name = "parentId",value = "搜索种类父级ID"), + @ApiImplicitParam(name = "CategoryName",value = "搜索种类名称") + }) + @PostMapping(value = "getSearchGoodsCates") + public ServerResponse> getGoodsCateList(Integer parentId,String CategoryName){ + return iGoodsCateService.getSearchGoodsCates(parentId,CategoryName); + } + @ApiOperation(value = "获取渲染种类Cascader级联选择器的数据") @GetMapping(value = "getGoodsCateCascader") public ServerResponse>> getGoodsCateCascader(){ @@ -63,4 +74,15 @@ public class GoodsCateController { BeanUtils.copyProperties(addGoodsCateFrom,goodsCategory); return iGoodsCateService.add(goodsCategory); } + + @ApiOperation(value = "编辑种类") + @PostMapping(value = "edit") + public ServerResponse edit(@Valid EditGoodsCateFrom editGoodsCateFrom, BindingResult result){ + if(result.hasErrors()){ + return ServerResponse.createByErrorMessage(Objects.requireNonNull(result.getFieldError()).getDefaultMessage()); + } + GoodsCategory goodsCategory = new GoodsCategory(); + BeanUtils.copyProperties(editGoodsCateFrom,goodsCategory); + return iGoodsCateService.edit(goodsCategory); + } } diff --git a/src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java b/src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java index e7a7928..4e74cee 100644 --- a/src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java +++ b/src/main/java/com/mark/web/bill/entity/from/AddGoodsCateFrom.java @@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModel; import lombok.Data; import javax.validation.constraints.NotBlank; -import java.util.Date; /** * @Description: 新增加工零件种类 diff --git a/src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java b/src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java new file mode 100644 index 0000000..ba65f7b --- /dev/null +++ b/src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java @@ -0,0 +1,42 @@ +package com.mark.web.bill.entity.from; + +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; + +/** + * @Description: 编辑种类的验证表单 + * @Author: Mark + * @CreateDate: 2019/2/18 21:16 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@Data +public class EditGoodsCateFrom { + + /** + * 编辑记录的id + */ + @Min(1) + private Integer id; + + /** + * 父级种类Id + */ + @Min(0) + private Integer parentId; + + /** + * 种类名 + */ + @NotBlank(message = "加工零件种类名称必填") + private String goodsCategoryName; + + /** + * 权重 + */ + @Min(1) + private Integer priority; + +} diff --git a/src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java b/src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java index 202bc01..1ec8f96 100644 --- a/src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java +++ b/src/main/java/com/mark/web/bill/entity/vo/GoodsCategoryVo.java @@ -27,6 +27,8 @@ public class GoodsCategoryVo { private Integer priority; + private boolean hasParent; + private String createTime; private String lastEditTime; @@ -34,6 +36,8 @@ public class GoodsCategoryVo { public GoodsCategoryVo(GoodsCategory goodsCategory){ this.id = goodsCategory.getId(); this.parentId = goodsCategory.getParentId(); + //如果父级ID为0,则表示该种类没有父类,为种类信息的根种类 + this.hasParent = this.parentId == 0; this.goodsCategoryName = goodsCategory.getGoodsCategoryName(); this.enableStatus = GoodsCategoryEnum.stateOf(goodsCategory.getEnableStatus()); this.level = goodsCategory.getLevel(); diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java index ea0eb50..cc49826 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java @@ -1,6 +1,7 @@ package com.mark.web.bill.mapper; import com.mark.web.bill.entity.po.GoodsCategory; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -17,11 +18,11 @@ public interface GoodsCategoryMapper { /** - * 根据父级种类的ID获取子加工零件种类列表信息 + * 根据父级种类的ID以及种类名称模糊搜索 获取子加工零件种类列表信息 * @param parentId :父级ID * @return : */ - List selectSubGoodsCatesByParentId(Integer parentId); + List selectSubGoodsCatesByParentId(@Param("parentId") Integer parentId,@Param("categoryName") String categoryName); /** * 获取所有可用种类 @@ -29,4 +30,6 @@ public interface GoodsCategoryMapper { */ List selectAllGoodsCates(); + + } \ No newline at end of file diff --git a/src/main/java/com/mark/web/bill/service/IGoodsCateService.java b/src/main/java/com/mark/web/bill/service/IGoodsCateService.java index 50e7aaf..ef5f7aa 100644 --- a/src/main/java/com/mark/web/bill/service/IGoodsCateService.java +++ b/src/main/java/com/mark/web/bill/service/IGoodsCateService.java @@ -21,4 +21,9 @@ public interface IGoodsCateService { ServerResponse>> getGoodsCateCascader(); ServerResponse add(GoodsCategory goodsCategory); + + ServerResponse> getSearchGoodsCates(Integer parentId, String categoryName); + + ServerResponse edit(GoodsCategory goodsCategory); + } diff --git a/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java index 79cba31..2ba906c 100644 --- a/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java @@ -10,6 +10,7 @@ import com.mark.web.bill.enums.GoodsCategoryEnum; import com.mark.web.bill.exception.BillException; import com.mark.web.bill.mapper.GoodsCategoryMapper; import com.mark.web.bill.service.IGoodsCateService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -35,7 +36,7 @@ public class GoodsCateServiceImpl implements IGoodsCateService { //region 获取同一个父级的零件种类 @Override public ServerResponse> getGoodsCateList(int parentId) { - List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(parentId); + List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(parentId,null); List result = Lists.newArrayList(); goodsCategoryList.forEach(goodsCategory -> result.add(new GoodsCategoryVo(goodsCategory))); return ServerResponse.createBySuccess(result); @@ -45,7 +46,7 @@ public class GoodsCateServiceImpl implements IGoodsCateService { //region 获取渲染Cascader组件的属性数据 @Override public ServerResponse>> getGoodsCateCascader() { - List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(0); + List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(0,null); List> result = buildGoodsCateCascader(0,goodsCategoryList); return ServerResponse.createBySuccess(result); @@ -58,7 +59,7 @@ public class GoodsCateServiceImpl implements IGoodsCateService { Map childrenMap = Maps.newHashMap(); childrenMap.put("value", goodsCategory.getId()); childrenMap.put("label", goodsCategory.getGoodsCategoryName()); - List subGoodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(goodsCategory.getId()); + List subGoodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(goodsCategory.getId(),null); if(subGoodsCategoryList != null && subGoodsCategoryList.size() > 0){ List> children = buildGoodsCateCascader(goodsCategory.getId(), subGoodsCategoryList); childrenMap.put("children", children); @@ -77,6 +78,52 @@ public class GoodsCateServiceImpl implements IGoodsCateService { goodsCategory.setEnableStatus(GoodsCategoryEnum.AVAILABLE.getState()); //层级属性的设置:如果父级ID为0,则level为1。否则取父级种类的level+1 + setCategoryLevel(goodsCategory); + + //插入数据库 + int insert = goodsCategoryMapper.insert(goodsCategory); + if(insert != Constant.SUCCESS){ + return ServerResponse.createByErrorMessage("新增种类失败!"); + } + return ServerResponse.createBySuccessMessage("新增种类成功!"); + } + //endregion + + //region 根据父级种类ID和种类名称模糊搜索 + @Override + public ServerResponse> getSearchGoodsCates(Integer parentId, String categoryName) { + if (StringUtils.isNotBlank(categoryName)) { + categoryName = "%" + categoryName + "%"; + } + List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(parentId, categoryName); + List result = Lists.newArrayList(); + goodsCategoryList.forEach(goodsCategory -> result.add(new GoodsCategoryVo(goodsCategory))); + return ServerResponse.createBySuccess(result); + } + //endregion + + //region 编辑种类 + @Override + public ServerResponse edit(GoodsCategory goodsCategory) { + //层级属性的设置:如果父级ID为0,则level为1。否则取父级种类的level+1 + setCategoryLevel(goodsCategory); + int update = goodsCategoryMapper.updateByPrimaryKeySelective(goodsCategory); + if(update != Constant.SUCCESS){ + return ServerResponse.createByErrorMessage("更新种类失败!"); + } + return ServerResponse.createBySuccessMessage("更新种类成功!"); + } + //endregion + + /* + * ------------------------------------------- 公用私用方法抽取 -------------------------------------------------------------------- + */ + //region 新增或者编辑时种类等级的设置 + /** + * 层级属性的设置:如果父级ID为0,则level为1。否则取父级种类的level+1 + * @param goodsCategory : + */ + private void setCategoryLevel(GoodsCategory goodsCategory) { if(goodsCategory.getParentId() == 0 || goodsCategory.getParentId()==null){ goodsCategory.setLevel(1); }else{ @@ -86,13 +133,6 @@ public class GoodsCateServiceImpl implements IGoodsCateService { } goodsCategory.setLevel(parentCate.getLevel()); } - - //插入数据库 - int insert = goodsCategoryMapper.insert(goodsCategory); - if(insert != Constant.SUCCESS){ - return ServerResponse.createByErrorMessage("保存数据失败!"); - } - return ServerResponse.createBySuccessMessage("新增种类成功!"); } //endregion } diff --git a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml index 6d01faf..8b75f8e 100644 --- a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml +++ b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml @@ -65,12 +65,20 @@ where id = #{id,jdbcType=INTEGER} - - SELECT FROM tb_bill_goods_category - WHERE parent_id = #{parentId} + + + parent_id = #{parentId} + + + AND goods_category_name LIKE #{categoryName} + + + diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java index 667283d..52be339 100644 --- a/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/GoodsCategoryMapperTest.java @@ -41,7 +41,7 @@ public class GoodsCategoryMapperTest extends BaseTest { @Test public void selectSubGoodsCatesByParentId(){ - List goodsCategories = goodsCategoryMapper.selectSubGoodsCatesByParentId(0); + List goodsCategories = goodsCategoryMapper.selectSubGoodsCatesByParentId(null,"%类%"); Assert.assertNotEquals(0,goodsCategories.size()); } -- Gitee From e51c6c379dba159509dfd747ba52ef34281d7aaa Mon Sep 17 00:00:00 2001 From: huasheng_yi <1685368363@qq.com> Date: Tue, 19 Feb 2019 23:10:21 +0800 Subject: [PATCH 16/19] =?UTF-8?q?update=20=E5=8A=A0=E5=B7=A5=E9=9B=B6?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E5=9D=97=EF=BC=88=E2=80=9C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=AD=97=E6=AE=B5=E2=80=9D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mark/web/bill/controller/GoodsController.java | 9 ++++++--- .../java/com/mark/web/bill/entity/from/AddGoodsFrom.java | 6 ++++-- .../com/mark/web/bill/entity/from/EditGoodsCateFrom.java | 6 +++--- src/main/java/com/mark/web/bill/mapper/GoodsMapper.java | 3 ++- .../java/com/mark/web/bill/service/IGoodsService.java | 3 ++- .../com/mark/web/bill/service/impl/GoodsServiceImpl.java | 8 ++++++-- src/main/resources/mappers/bill/GoodsMapper.xml | 3 +++ .../java/com/mark/web/bill/mapper/GoodsMapperTest.java | 2 +- 8 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/mark/web/bill/controller/GoodsController.java b/src/main/java/com/mark/web/bill/controller/GoodsController.java index 00c193f..03952b3 100644 --- a/src/main/java/com/mark/web/bill/controller/GoodsController.java +++ b/src/main/java/com/mark/web/bill/controller/GoodsController.java @@ -39,7 +39,8 @@ public class GoodsController { @ApiOperation(value = "添加加工零件") @PostMapping(value = "add") - public ServerResponse add(@Valid AddGoodsFrom addGoodsFrom, BindingResult result, @RequestParam(value = "goodsImage",required = false)MultipartFile goodsImage){ + public ServerResponse add(@Valid AddGoodsFrom addGoodsFrom, BindingResult result, + @RequestParam(value = "goodsImage",required = false)MultipartFile goodsImage){ if(result.hasErrors()){ return ServerResponse.createByErrorMessage(Objects.requireNonNull(result.getFieldError()).getDefaultMessage()); } @@ -64,8 +65,10 @@ public class GoodsController { @PostMapping(value = "getGoods") public ServerResponse> getAccountList(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum, @RequestParam(value = "pageSize",defaultValue = "12") int pageSize, - Integer categoryId){ - return iGoodsService.getGoodsList(pageNum,pageSize,CurrentUser.getCurrentUserId(),categoryId); + Integer categoryId,String searchGoodsName){ + return iGoodsService.getGoodsList(pageNum,pageSize,CurrentUser.getCurrentUserId(),categoryId,searchGoodsName); } + + } diff --git a/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java b/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java index 3109c74..915f7d7 100644 --- a/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java +++ b/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java @@ -3,6 +3,7 @@ package com.mark.web.bill.entity.from; import io.swagger.annotations.ApiModel; import lombok.Data; +import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import java.math.BigDecimal; @@ -20,7 +21,7 @@ public class AddGoodsFrom { /** * 商品名称 */ - @NotBlank + @NotBlank(message = "输入的商品名称不能空!") private String goodsName; /** @@ -31,11 +32,12 @@ public class AddGoodsFrom { /** * 排序权重 */ + @Min(value = 1,message = "权重值应该大于1") private Integer priority; /** * 逻辑外键,加工零件id */ - // TODO: 2019/2/12 默认赋值 + @Min(value = 0,message = "输入种类id应大于0") private Integer fkCategoryId = 1; } diff --git a/src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java b/src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java index ba65f7b..68ee806 100644 --- a/src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java +++ b/src/main/java/com/mark/web/bill/entity/from/EditGoodsCateFrom.java @@ -18,13 +18,13 @@ public class EditGoodsCateFrom { /** * 编辑记录的id */ - @Min(1) + @Min(value = 1,message = "编辑的种类ID应大于1") private Integer id; /** * 父级种类Id */ - @Min(0) + @Min(value = 0,message = "父级种类ID需要大于0") private Integer parentId; /** @@ -36,7 +36,7 @@ public class EditGoodsCateFrom { /** * 权重 */ - @Min(1) + @Min(value = 1,message = "权重值应该大于1") private Integer priority; } diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java index 777a854..a7a8ac9 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java @@ -24,7 +24,8 @@ public interface GoodsMapper { List> selectAllGoods(); List searchGoodsDetailList(@Param("categoryId") Integer categoryId, - @Param("currentUserId") Integer currentUserId); + @Param("currentUserId") Integer currentUserId, + @Param("searchGoodsName") String searchGoodsName); int updateByPrimaryKeySelective(Goods record); diff --git a/src/main/java/com/mark/web/bill/service/IGoodsService.java b/src/main/java/com/mark/web/bill/service/IGoodsService.java index f5f21a6..b1e6282 100644 --- a/src/main/java/com/mark/web/bill/service/IGoodsService.java +++ b/src/main/java/com/mark/web/bill/service/IGoodsService.java @@ -22,6 +22,7 @@ public interface IGoodsService { ServerResponse>> getOptionInfo(); - ServerResponse> getGoodsList(int pageNum, int pageSize, int currentUserId, Integer categoryId); + ServerResponse> getGoodsList(int pageNum, int pageSize, int currentUserId, + Integer categoryId,String searchGoodsName); } diff --git a/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java index 22c6d58..323853f 100644 --- a/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java @@ -13,6 +13,7 @@ import com.mark.web.bill.enums.GoodsEnum; import com.mark.web.bill.mapper.GoodsMapper; import com.mark.web.bill.service.IGoodsImgService; import com.mark.web.bill.service.IGoodsService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -64,9 +65,12 @@ public class GoodsServiceImpl implements IGoodsService { @Override public ServerResponse> getGoodsList(int pageNum, int pageSize, - int currentUserId, Integer categoryId) { + int currentUserId, Integer categoryId,String searchGoodsName) { PageHelper.startPage(pageNum, pageSize); - List goodsDetailList = goodsMapper.searchGoodsDetailList(categoryId, currentUserId); + if(StringUtils.isNotBlank(searchGoodsName)){ + searchGoodsName = "%" + searchGoodsName + "%"; + } + List goodsDetailList = goodsMapper.searchGoodsDetailList(categoryId, currentUserId,searchGoodsName); List goodsDetailVoList = Lists.newArrayList(); for(GoodsDetail goodsDetail : goodsDetailList){ GoodsDetailVo goodsDetailVo = new GoodsDetailVo(goodsDetail); diff --git a/src/main/resources/mappers/bill/GoodsMapper.xml b/src/main/resources/mappers/bill/GoodsMapper.xml index 5157d82..e33f6da 100644 --- a/src/main/resources/mappers/bill/GoodsMapper.xml +++ b/src/main/resources/mappers/bill/GoodsMapper.xml @@ -57,6 +57,9 @@ AND a.fk_owner_id = #{currentUserId} + + AND a.goods_name = #{searchGoodsName} + diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java index 9a5a397..3775e52 100644 --- a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java @@ -46,7 +46,7 @@ public class GoodsMapperTest extends BaseTest { @Test public void searchGoodsDetailList(){ - List goodsDetails = goodsMapper.searchGoodsDetailList(null,5); + List goodsDetails = goodsMapper.searchGoodsDetailList(null,5,null); Assert.assertNotEquals(0,goodsDetails.size()); } } \ No newline at end of file -- Gitee From 7312d97954a4b6b4a07bdb1dc8d313e881d67cc5 Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Wed, 20 Feb 2019 14:00:23 +0800 Subject: [PATCH 17/19] =?UTF-8?q?update=20for=20=E5=8A=A0=E5=B7=A5?= =?UTF-8?q?=E9=9B=B6=E4=BB=B6=E6=A8=A1=E5=9D=97=EF=BC=88=E2=80=9C1.like?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9A=84%=20=E5=9C=A8XML=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E6=8B=BC=202.=E8=8E=B7=E5=8F=96=E5=8A=A0=E5=B7=A5?= =?UTF-8?q?=E9=9B=B6=E4=BB=B6=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0=E7=A7=8D?= =?UTF-8?q?=E7=B1=BB=E5=AD=97=E6=AE=B5=E7=9A=84=E7=AD=9B=E9=80=89=E2=80=9D?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/bill/controller/GoodsController.java | 9 ++++++-- .../web/bill/entity/from/AddGoodsFrom.java | 1 + .../web/bill/mapper/GoodsCategoryMapper.java | 3 ++- .../com/mark/web/bill/mapper/GoodsMapper.java | 2 +- .../mark/web/bill/service/IGoodsService.java | 23 ++++++++++++++++++- .../service/impl/GoodsCateServiceImpl.java | 3 --- .../bill/service/impl/GoodsServiceImpl.java | 14 ++++++----- .../mappers/bill/GoodsCategoryMapper.xml | 2 +- .../resources/mappers/bill/GoodsMapper.xml | 14 +++++++---- .../mark/web/bill/mapper/GoodsMapperTest.java | 4 +--- .../web/bill/service/IGoodsServiceTest.java | 9 ++++++++ 11 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/mark/web/bill/controller/GoodsController.java b/src/main/java/com/mark/web/bill/controller/GoodsController.java index 03952b3..efee05c 100644 --- a/src/main/java/com/mark/web/bill/controller/GoodsController.java +++ b/src/main/java/com/mark/web/bill/controller/GoodsController.java @@ -51,10 +51,15 @@ public class GoodsController { return iGoodsService.add(goods,goodsImage); } + /** + * 根据种类ID获取加工零件列表 + * @param categoryId :种类ID,非必传,是查询所有的加工零件不想指定类型则传null + * @return : + */ @ApiOperation(value = "获取加工零件名称和对应ID") @GetMapping(value = "getOptionInfo") - public ServerResponse>> getOptionInfo(){ - return iGoodsService.getOptionInfo(); + public ServerResponse>> getOptionInfo(Integer categoryId){ + return iGoodsService.getOptionInfo(categoryId); } @ApiOperation(value = "分页筛选加工零件列表信息") diff --git a/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java b/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java index 915f7d7..f0ed968 100644 --- a/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java +++ b/src/main/java/com/mark/web/bill/entity/from/AddGoodsFrom.java @@ -27,6 +27,7 @@ public class AddGoodsFrom { /** * 单价,单位-元保留两位小数 */ + @Min(value = 0,message = "单价应该大于0") private BigDecimal price; /** diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java index cc49826..49a35d6 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsCategoryMapper.java @@ -22,7 +22,8 @@ public interface GoodsCategoryMapper { * @param parentId :父级ID * @return : */ - List selectSubGoodsCatesByParentId(@Param("parentId") Integer parentId,@Param("categoryName") String categoryName); + List selectSubGoodsCatesByParentId(@Param("parentId") Integer parentId, + @Param("categoryName") String categoryName); /** * 获取所有可用种类 diff --git a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java index a7a8ac9..09fecf4 100644 --- a/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java +++ b/src/main/java/com/mark/web/bill/mapper/GoodsMapper.java @@ -21,7 +21,7 @@ public interface GoodsMapper { Goods selectByPrimaryKey(Integer id); - List> selectAllGoods(); + List> selectAllGoodsByCate(@Param("categoryId") Integer categoryId); List searchGoodsDetailList(@Param("categoryId") Integer categoryId, @Param("currentUserId") Integer currentUserId, diff --git a/src/main/java/com/mark/web/bill/service/IGoodsService.java b/src/main/java/com/mark/web/bill/service/IGoodsService.java index b1e6282..2bd02ab 100644 --- a/src/main/java/com/mark/web/bill/service/IGoodsService.java +++ b/src/main/java/com/mark/web/bill/service/IGoodsService.java @@ -18,10 +18,31 @@ import java.util.Map; */ public interface IGoodsService { + /** + * 添加一条加工零件 + * @param goods :加工零件记录 + * @param goodsImage :加工零件图片 + * @return : + */ ServerResponse add(Goods goods, MultipartFile goodsImage); - ServerResponse>> getOptionInfo(); + /** + * 根据种类id查询加工零件列表信息,如果categoryId为null查询的是所有的零件信息 + * @param categoryId :种类id,非必传 + * @return : + */ + ServerResponse>> getOptionInfo(Integer categoryId); + + /** + * 分页查询加工零件列表信息 + * @param pageNum :当前页数 + * @param pageSize :页面大小 + * @param currentUserId :当前用户id + * @param categoryId :种类id + * @param searchGoodsName :搜索的加工零件的名称 + * @return : + */ ServerResponse> getGoodsList(int pageNum, int pageSize, int currentUserId, Integer categoryId,String searchGoodsName); diff --git a/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java index 2ba906c..a0a74f1 100644 --- a/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/GoodsCateServiceImpl.java @@ -92,9 +92,6 @@ public class GoodsCateServiceImpl implements IGoodsCateService { //region 根据父级种类ID和种类名称模糊搜索 @Override public ServerResponse> getSearchGoodsCates(Integer parentId, String categoryName) { - if (StringUtils.isNotBlank(categoryName)) { - categoryName = "%" + categoryName + "%"; - } List goodsCategoryList = goodsCategoryMapper.selectSubGoodsCatesByParentId(parentId, categoryName); List result = Lists.newArrayList(); goodsCategoryList.forEach(goodsCategory -> result.add(new GoodsCategoryVo(goodsCategory))); diff --git a/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java b/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java index 323853f..4fdeb18 100644 --- a/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java +++ b/src/main/java/com/mark/web/bill/service/impl/GoodsServiceImpl.java @@ -13,7 +13,6 @@ import com.mark.web.bill.enums.GoodsEnum; import com.mark.web.bill.mapper.GoodsMapper; import com.mark.web.bill.service.IGoodsImgService; import com.mark.web.bill.service.IGoodsService; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -40,6 +39,7 @@ public class GoodsServiceImpl implements IGoodsService { } + //region 添加一个加工零件记录 @Override public ServerResponse add(Goods goods, MultipartFile goodsImage) { //账单的状态默认为可用 @@ -56,20 +56,21 @@ public class GoodsServiceImpl implements IGoodsService { } return ServerResponse.createBySuccessMessage("添加加工零件成功!"); } + //endregion + //region 根据种类id查询加工零件列表信息 @Override - public ServerResponse>> getOptionInfo() { - List> result = goodsMapper.selectAllGoods(); + public ServerResponse>> getOptionInfo(Integer categoryId) { + List> result = goodsMapper.selectAllGoodsByCate(categoryId); return ServerResponse.createBySuccess(result); } + //endregion + //region 分页查询加工零件信息 @Override public ServerResponse> getGoodsList(int pageNum, int pageSize, int currentUserId, Integer categoryId,String searchGoodsName) { PageHelper.startPage(pageNum, pageSize); - if(StringUtils.isNotBlank(searchGoodsName)){ - searchGoodsName = "%" + searchGoodsName + "%"; - } List goodsDetailList = goodsMapper.searchGoodsDetailList(categoryId, currentUserId,searchGoodsName); List goodsDetailVoList = Lists.newArrayList(); for(GoodsDetail goodsDetail : goodsDetailList){ @@ -80,5 +81,6 @@ public class GoodsServiceImpl implements IGoodsService { result.setTotal(new PageInfo<>(goodsDetailList).getTotal()); return ServerResponse.createBySuccess(result); } + //endregion } diff --git a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml index 8b75f8e..f28b125 100644 --- a/src/main/resources/mappers/bill/GoodsCategoryMapper.xml +++ b/src/main/resources/mappers/bill/GoodsCategoryMapper.xml @@ -75,7 +75,7 @@ parent_id = #{parentId} - AND goods_category_name LIKE #{categoryName} + AND goods_category_name LIKE CONCAT('%',#{categoryName},'%') diff --git a/src/main/resources/mappers/bill/GoodsMapper.xml b/src/main/resources/mappers/bill/GoodsMapper.xml index e33f6da..a395965 100644 --- a/src/main/resources/mappers/bill/GoodsMapper.xml +++ b/src/main/resources/mappers/bill/GoodsMapper.xml @@ -24,8 +24,14 @@ where id = #{id,jdbcType=INTEGER} - + SELECT goods_name name,id value FROM tb_bill_goods + + + AND fk_category_id= #{categoryId} + + + ORDER BY priority @@ -57,8 +63,8 @@ AND a.fk_owner_id = #{currentUserId} - - AND a.goods_name = #{searchGoodsName} + + AND a.goods_name like CONCAT('%',#{searchGoodsName},'%') diff --git a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java index 3775e52..0cbad5f 100644 --- a/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java +++ b/src/test/java/com/mark/web/bill/mapper/GoodsMapperTest.java @@ -4,13 +4,11 @@ import com.mark.BaseTest; import com.mark.web.bill.entity.dto.GoodsDetail; import org.junit.Assert; import org.junit.Test; -import org.omg.CORBA.PUBLIC_MEMBER; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Map; -import static org.junit.Assert.*; /** * @Description: 商品dao接口测试 * @Author: Kingsley: 08:46 @@ -40,7 +38,7 @@ public class GoodsMapperTest extends BaseTest { @Test public void selectAllGoods(){ - List> maps = goodsMapper.selectAllGoods(); + List> maps = goodsMapper.selectAllGoodsByCate(1); Assert.assertNotEquals(0,maps.size()); } diff --git a/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java b/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java index 3578bc0..76ad6f1 100644 --- a/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java +++ b/src/test/java/com/mark/web/bill/service/IGoodsServiceTest.java @@ -1,8 +1,10 @@ package com.mark.web.bill.service; +import com.github.pagehelper.PageInfo; import com.mark.BaseTest; import com.mark.common.ServerResponse; import com.mark.web.bill.entity.po.Goods; +import com.mark.web.bill.entity.vo.GoodsDetailVo; import org.junit.Assert; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -31,4 +33,11 @@ public class IGoodsServiceTest extends BaseTest { ServerResponse add = iGoodsService.add(goods, null); Assert.assertNotNull(add); } + + @Test + public void getGoodsList(){ + ServerResponse> goodsList = iGoodsService.getGoodsList(1, 1, + 1,1, "ee"); + Assert.assertNotNull(goodsList); + } } \ No newline at end of file -- Gitee From 4fdd10a9fb847ce7318c4e0a84681de9226d3ab3 Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Thu, 21 Feb 2019 09:24:02 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E6=B7=BB=E5=8A=A0todo=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/mark/web/bill/doc/Todo | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/java/com/mark/web/bill/doc/Todo diff --git a/src/main/java/com/mark/web/bill/doc/Todo b/src/main/java/com/mark/web/bill/doc/Todo new file mode 100644 index 0000000..7b1370d --- /dev/null +++ b/src/main/java/com/mark/web/bill/doc/Todo @@ -0,0 +1,3 @@ +#2019-02-21 +1.编辑加工零件 +2.删除加工零件(删除OSS中的图片) \ No newline at end of file -- Gitee From a34c9853ff039998ae967be02ecaf4e6a044acff Mon Sep 17 00:00:00 2001 From: chengdong_yi Date: Thu, 21 Feb 2019 17:55:38 +0800 Subject: [PATCH 19/19] =?UTF-8?q?update=20for=20=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB=EF=BC=88=E2=80=9C=E6=B7=BB=E5=8A=A0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E5=B7=A5=E5=85=B7=E7=B1=BB=E2=80=9D?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mark/common/utils/DownloadFileUtil.java | 108 ++++++++++++++++++ src/main/java/com/mark/conf/ShiroConfig.java | 3 + .../controller/FileDownloadController.java | 31 +++++ 3 files changed, 142 insertions(+) create mode 100644 src/main/java/com/mark/common/utils/DownloadFileUtil.java create mode 100644 src/main/java/com/mark/web/common/controller/FileDownloadController.java diff --git a/src/main/java/com/mark/common/utils/DownloadFileUtil.java b/src/main/java/com/mark/common/utils/DownloadFileUtil.java new file mode 100644 index 0000000..0500ae1 --- /dev/null +++ b/src/main/java/com/mark/common/utils/DownloadFileUtil.java @@ -0,0 +1,108 @@ +package com.mark.common.utils; + +import sun.misc.BASE64Encoder; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +/** + * @Description: 下载文件的工具类 + * @Author: Mark + * @CreateDate: 2019/2/21 16:29 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +public class DownloadFileUtil { + + /** + * 下载文件 + * + * @param originalFileName :下载文件的原始文件名 + * @param file :下载的文件 + * @param response :相应对象 + */ + public static void downloadFile(String originalFileName, File file, HttpServletResponse response, HttpServletRequest request) { + // TODO: 2019/2/21 数据校验 + + //相应头的处理 + //清空response中的输出流 + response.reset(); + //设置文件大小 + response.setContentLength((int) file.length()); + //设置Content-Type头 + response.setContentType("application/octet-stream;charset=UTF-8"); + //设置Content-Disposition头 以附件形式解析 + String encodedFilename = getEncodedFilename(request, originalFileName); + response.addHeader("Content-Disposition", "attchment;filename=" + encodedFilename); + + //将来文件流写入response中 + FileInputStream fileInputStream = null; + ServletOutputStream outputStream = null; + try { + //获取文件输入流 + fileInputStream = new FileInputStream(file); + //创建数据缓冲区 + byte[] buffers = new byte[1024]; + //通过response中获取ServletOutputStream输出流 + outputStream = response.getOutputStream(); + int length; + while ((length = fileInputStream.read(buffers)) > 0) { + //写入到输出流中 + outputStream.write(buffers, 0, length); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + //流的关闭 + if(fileInputStream != null){ + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (outputStream != null) { + try { + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + private static String getEncodedFilename(HttpServletRequest request, String originalFileName) { + String encodedFilename = null; + String agent = request.getHeader("User-Agent"); + if(agent.contains("MSIE")){ + //IE浏览器 + try { + encodedFilename = URLEncoder.encode(originalFileName, "utf-8"); + encodedFilename = encodedFilename.replace("+", " "); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + }else if(agent.contains("Firefox")){ + //火狐浏览器 + BASE64Encoder base64Encoder = new BASE64Encoder(); + encodedFilename = "=?utf-8?B?" + base64Encoder.encode(originalFileName.getBytes(StandardCharsets.UTF_8))+"?="; + }else{ + //其他浏览器 + try { + encodedFilename = URLEncoder.encode(originalFileName, "utf-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + return encodedFilename; + } +} diff --git a/src/main/java/com/mark/conf/ShiroConfig.java b/src/main/java/com/mark/conf/ShiroConfig.java index 05f5772..f4320cc 100644 --- a/src/main/java/com/mark/conf/ShiroConfig.java +++ b/src/main/java/com/mark/conf/ShiroConfig.java @@ -126,6 +126,9 @@ public class ShiroConfig { //访问路径 Map filterChanDefinitionMap = new LinkedHashMap<>(); + // TODO: 2019/2/21 测试完成记得儿删除 + //测试用放行路径 + filterChanDefinitionMap.put("/common/file/**", "anon"); //Swagger2-UI的访问路径的放行 filterChanDefinitionMap.put("/swagger-ui.html", "anon"); filterChanDefinitionMap.put("/swagger/**", "anon"); diff --git a/src/main/java/com/mark/web/common/controller/FileDownloadController.java b/src/main/java/com/mark/web/common/controller/FileDownloadController.java new file mode 100644 index 0000000..b52c0ad --- /dev/null +++ b/src/main/java/com/mark/web/common/controller/FileDownloadController.java @@ -0,0 +1,31 @@ +package com.mark.web.common.controller; + +import com.mark.common.utils.DownloadFileUtil; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; + +/** + * @Description: 通用文件上传类 + * @Author: Kingsley + * @CreateDate: 2019/2/21 20:22 + * @Version: 2.0 + * @Copyright : 豆浆油条个人非正式工作室 + */ +@RestController() +@RequestMapping("/common/file/") +public class FileDownloadController { + + /** + * 下载文件的demo + */ + @RequestMapping(value = "download") + public void downloadFile(HttpServletRequest request, HttpServletResponse response) { + File file = new File("C:\\Users\\Mark\\Desktop\\bak\\test.png"); + String fileName = "测试文件下载.png"; + DownloadFileUtil.downloadFile(fileName,file,response,request); + } +} -- Gitee