dcs 3 months ago
parent
commit
7f7b82d4e4

+ 1 - 1
virgo.api/src/main/java/com/bosshand/virgo/api/Application.java

@@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @SpringBootApplication
 //@EnableEurekaClient
 @EnableTransactionManagement
-@MapperScan("com.bosshand.virgo.core.dao,com.bosshand.virgo.api.dao,com.bosshand.virgo.api.operate.dao,com.bosshand.virgo.api.test.dao")
+@MapperScan("com.bosshand.virgo.core.dao,com.bosshand.virgo.api.dao,com.bosshand.virgo.api.operate.dao,com.bosshand.virgo.api.test.dao,com.bosshand.virgo.api.workark.dao")
 @ComponentScan(basePackages = {"com.bosshand"})
 public class Application {
 	public static void main(String[] args) {

+ 52 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/ProductController.java

@@ -0,0 +1,52 @@
+package com.bosshand.virgo.api.workark.controller;
+
+import com.bosshand.virgo.api.workark.model.Product;
+import com.bosshand.virgo.api.workark.service.ProductService;
+import com.bosshand.virgo.core.response.Response;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping({"workark-product"})
+@Api(tags = {"商品管理"})
+public class ProductController {
+
+    @Autowired
+    ProductService productService;
+
+    @ApiOperation("保存")
+    @RequestMapping(value = "", method = RequestMethod.POST)
+    public Response insert(@RequestBody Product product) {
+        productService.save(product);
+        return Response.ok();
+    }
+
+    @ApiOperation("更新")
+    @RequestMapping(value = "/update", method = RequestMethod.PUT)
+    public Response update(@RequestBody Product product) {
+        productService.update(product);
+        return Response.ok();
+    }
+
+    @ApiOperation("删除")
+    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
+    public Response delete(@PathVariable long id) {
+        productService.delete(id);
+        return Response.ok();
+    }
+
+    @ApiOperation("查询")
+    @RequestMapping(value = "/query", method = RequestMethod.POST)
+    public Response getList(@RequestBody Product product) {
+        return Response.ok(productService.getList(product));
+    }
+
+    @ApiOperation("详情")
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public Response get(@PathVariable long id) {
+        return Response.ok(productService.get(id));
+    }
+
+}

+ 52 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/ProductLevelController.java

@@ -0,0 +1,52 @@
+package com.bosshand.virgo.api.workark.controller;
+
+import com.bosshand.virgo.api.workark.model.ProductLevel;
+import com.bosshand.virgo.api.workark.service.ProductLevelService;
+import com.bosshand.virgo.core.response.Response;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("workark-product-level")
+@Api(tags = {"商品目录"})
+public class ProductLevelController {
+
+    @Autowired
+    ProductLevelService productLevelService;
+
+    @ApiOperation(value = "获取", notes = "获取")
+    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
+    public Response get(@PathVariable long id) {
+        return Response.ok(productLevelService.get(id));
+    }
+
+    @ApiOperation(value = "获取列表", notes = "获取列表")
+    @RequestMapping(value = "", method = RequestMethod.GET)
+    public Response getList() {
+        return Response.ok(productLevelService.getRoot());
+    }
+
+    @ApiOperation(value = "新增", notes = "新增")
+    @RequestMapping(value = "", method = RequestMethod.POST)
+    public Response save(@RequestBody ProductLevel productLevel) {
+        productLevelService.save(productLevel);
+        return Response.ok();
+    }
+
+    @ApiOperation(value = "修改", notes = "修改")
+    @RequestMapping(value = "", method = RequestMethod.PUT)
+    public Response update(@RequestBody ProductLevel productLevel) {
+        productLevelService.update(productLevel);
+        return Response.ok();
+    }
+
+    @ApiOperation(value = "删除", notes = "删除")
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    public Response delete(@PathVariable long id) {
+        productLevelService.delete(id);
+        return Response.ok();
+    }
+
+}

+ 21 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/ProductDao.java

@@ -0,0 +1,21 @@
+package com.bosshand.virgo.api.workark.dao;
+
+import com.bosshand.virgo.api.workark.model.Product;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface ProductDao {
+
+    void delete(long id);
+
+    void save(Product product);
+
+    void update(Product product);
+
+    List<Product> getList(Product product);
+
+    Product get(long id);
+
+}

+ 20 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/ProductLevelDao.java

@@ -0,0 +1,20 @@
+package com.bosshand.virgo.api.workark.dao;
+
+import com.bosshand.virgo.api.workark.model.ProductLevel;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface ProductLevelDao {
+
+    public List<ProductLevel> getRoot();
+
+    public int save(ProductLevel productLevel);
+
+    public int update(ProductLevel productLevel);
+
+    public int delete(long id);
+
+    List<ProductLevel> getList();
+}

+ 127 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/Product.java

@@ -0,0 +1,127 @@
+package com.bosshand.virgo.api.workark.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+
+/**
+ * 商品
+ */
+public class Product {
+
+    private Long id;
+
+    /**
+     * 状态
+     */
+    private Integer state;
+
+    /**
+     * 类型
+     */
+    private Long type;
+
+    /**
+     * 目录Id
+     */
+    private long productLevelId;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date updateTime;
+
+    /**
+     * 商品名称
+     */
+    private String name;
+
+    /**
+     * 价格(分)
+     */
+    private Integer price;
+
+    /**
+     * 介绍
+     */
+    private String intro;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Integer getState() {
+        return state;
+    }
+
+    public void setState(Integer state) {
+        this.state = state;
+    }
+
+    public Long getType() {
+        return type;
+    }
+
+    public void setType(Long type) {
+        this.type = type;
+    }
+
+    public long getProductLevelId() {
+        return productLevelId;
+    }
+
+    public void setProductLevelId(long productLevelId) {
+        this.productLevelId = productLevelId;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getPrice() {
+        return price;
+    }
+
+    public void setPrice(Integer price) {
+        this.price = price;
+    }
+
+    public String getIntro() {
+        return intro;
+    }
+
+    public void setIntro(String intro) {
+        this.intro = intro;
+    }
+}

+ 56 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/ProductLevel.java

@@ -0,0 +1,56 @@
+package com.bosshand.virgo.api.workark.model;
+
+import java.util.List;
+
+public class ProductLevel {
+
+    private long id;
+
+    private String name;
+
+    private long parentId;
+
+    private String remark;
+
+    private List<ProductLevel> children;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(long parentId) {
+        this.parentId = parentId;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public List<ProductLevel> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<ProductLevel> children) {
+        this.children = children;
+    }
+}

+ 78 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/ProductLevelService.java

@@ -0,0 +1,78 @@
+package com.bosshand.virgo.api.workark.service;
+
+import com.bosshand.virgo.api.workark.dao.ProductLevelDao;
+import com.bosshand.virgo.api.workark.model.ProductLevel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class ProductLevelService {
+
+
+    @Autowired
+    ProductLevelDao productLevelDao;
+
+    public ProductLevel get(long id) {
+        List<ProductLevel> ls = productLevelDao.getList();
+        return this.getNodeTreeById(id, ls);
+    }
+
+    public List<ProductLevel> getRoot() {
+        List<ProductLevel> list = new ArrayList<>();
+        List<ProductLevel> roots = productLevelDao.getRoot();
+        List<ProductLevel> ls = productLevelDao.getList();
+        for (ProductLevel model : roots) {
+            list.add(this.getNodeTreeById(model.getId(), ls));
+        }
+        return list;
+    }
+
+    public int save(ProductLevel productLevel) {
+        return productLevelDao.save(productLevel);
+    }
+
+    public int update(ProductLevel productLevel) {
+        return productLevelDao.update(productLevel);
+    }
+
+    public int delete(long id) {
+        return productLevelDao.delete(id);
+    }
+
+    private ProductLevel getNodeTreeById(long id, List<ProductLevel> list) {
+        ProductLevel node = null;
+        List<ProductLevel> productLevelList = list;
+        for (ProductLevel data : productLevelList) {
+            if (data.getId() == id) {
+                node = data;
+                break;
+            }
+        }
+        if (node != null) {
+            node.setChildren(getChildNode(node.getId(), productLevelList));
+        }
+        return node;
+    }
+
+    private List<ProductLevel> getChildNode(long parentId, List<ProductLevel> list) {
+        List<ProductLevel> nodeList = new ArrayList<>();
+        nodeList.clear();
+        for (ProductLevel data : list) {
+            if (data.getParentId() == parentId) {
+                nodeList.add(data);
+            }
+        }
+        if (nodeList.size() > 0) {
+            for (ProductLevel data : nodeList) {
+                List<ProductLevel> childList = getChildNode(data.getId(), list);
+                data.setChildren(childList);
+            }
+        }
+        return nodeList;
+    }
+
+
+}

+ 36 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/ProductService.java

@@ -0,0 +1,36 @@
+package com.bosshand.virgo.api.workark.service;
+
+import com.bosshand.virgo.api.workark.dao.ProductDao;
+import com.bosshand.virgo.api.workark.model.Product;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ProductService {
+
+    @Autowired
+    ProductDao productDao;
+
+    public void delete(long id) {
+        productDao.delete(id);
+    }
+
+    public void save(Product product){
+        productDao.save(product);
+    }
+
+    public void update(Product product) {
+        productDao.update(product);
+    }
+
+    public List<Product> getList(Product product){
+        return productDao.getList(product);
+    }
+
+    public Product get(long id){
+        return productDao.get(id);
+    }
+
+}

+ 39 - 0
virgo.api/src/main/resources/mapper/ProductLevelMapper.xml

@@ -0,0 +1,39 @@
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.bosshand.virgo.api.workark.dao.ProductLevelDao">
+
+    <resultMap type="com.bosshand.virgo.api.workark.model.ProductLevel" id="result" >
+        <id column="id" property="id"/>
+        <result column="name" property="name"/>
+        <result column="parentId" property="parentId"/>
+        <result column="remark" property="remark"/>
+    </resultMap>
+
+    <select id="getList" resultMap="result">
+        select * from workark_product_level
+    </select>
+
+    <select id="getRoot" resultMap="result">
+        select * from workark_product_level where parentId = -1
+    </select>
+
+    <insert id="save" parameterType="com.bosshand.virgo.api.workark.model.ProductLevel" useGeneratedKeys="true" keyProperty="id">
+        INSERT into workark_product_level(name, parentId, remark) values(#{name}, #{parentId}, #{remark})
+    </insert>
+
+    <update id="update" parameterType="com.bosshand.virgo.api.workark.model.ProductLevel">
+        UPDATE workark_product_level
+        <trim prefix="set" suffixOverrides=",">
+            <if test="name!=null">name=#{name},</if>
+            <if test="remark!=null">remark=#{remark},</if>
+        </trim>
+        WHERE id=#{id}
+    </update>
+
+    <delete id="delete">
+        DELETE FROM workark_product_level where id = #{id}
+    </delete>
+
+</mapper>

+ 63 - 0
virgo.api/src/main/resources/mapper/ProductMapper.xml

@@ -0,0 +1,63 @@
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.bosshand.virgo.api.workark.dao.ProductDao">
+
+    <resultMap type="com.bosshand.virgo.api.workark.model.Product" id="result">
+        <id column="id" property="id"/>
+        <result column="state" property="state"/>
+        <result column="type" property="type"/>
+        <result column="productLevelId" property="productLevelId"/>
+        <result column="createTime" property="createTime"/>
+        <result column="updateTime" property="updateTime"/>
+        <result column="name" property="name"/>
+        <result column="price" property="price"/>
+        <result column="intro" property="intro"/>
+    </resultMap>
+
+    <select id="get" resultMap="result">
+        select * from workark_product where id = #{id}
+    </select>
+
+    <select id="getList" resultMap="result">
+        select * from workark_product
+        <where>
+            <if test="name != null">
+                and name = #{name}
+            </if>
+            <if test="state != null">
+                and state = #{state}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="productLevelId != 0">
+                and productLevelId = #{productLevelId}
+            </if>
+        </where>
+    </select>
+
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO workark_product (type, productLevelId, createTime, name, price, intro) VALUES (#{type}, #{productLevelId}, now(), #{name}, #{price}, #{intro})
+    </insert>
+
+    <update id="update" parameterType="com.bosshand.virgo.api.workark.model.Product">
+        UPDATE workark_product
+        <trim prefix="set" suffixOverrides=",">
+            <if test="type!=null">type=#{type},</if>
+            <if test="productLevelId!=0">productLevelId=#{productLevelId},</if>
+            <if test="name!=null">name=#{name},</if>
+            <if test="price!=0">price=#{price},</if>
+            <if test="intro!=null">intro=#{intro},</if>
+            <if test="updateTime==null">updateTime=now(),</if>
+            <if test="state!=null">state=#{state},</if>
+        </trim>
+        WHERE id=#{id}
+    </update>
+
+    <delete id="delete">
+        DELETE FROM workark_product WHERE id = #{id}
+    </delete>
+
+</mapper>