[auto parts management system - administrator - parts management module] parts management classification

1. Left menu query

1.1 database design

1.2 pojo layer

package com.ap.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

@Data
@Accessors(chain = true)
@TableName("car")
public class Car extends BasePojo{
    @TableId(type = IdType.AUTO)//Primary key auto increment
    private Integer id;
    private String name;
    private Integer parentId;
    private String path;
    private Integer level;
    private String path1;
    private Boolean status;
    private String no1;
    private String no2;
    private String no3;
    @TableField(exist = false)     //Property is not a table field
    private List<Shop> children; //Is not an inherent property of the table
}

1.3 Mapper interface

package com.ap.mapper;

import com.ap.pojo.Car;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

public interface CarMapper extends BaseMapper<Car> {
    List<Car> getShopList();
}


1.4 Mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ap.mapper.CarMapper">

    <select id="getShopList" resultMap="rightsRM">
        SELECT  p.id,p.name,p.parent_id,p.path,p.level,p.created,p.updated,p.path1,
                c.id c_id,c.name c_name,c.parent_id c_parent_id,
                c.path c_path,c.level c_level,c.created c_created,
                c.updated c_updated,c.path1 c_path1	 FROM
                (SELECT * FROM car WHERE parent_id = 0)p
                    LEFT JOIN
            car c
            ON
                p.id = c.parent_id
    </select>

    <!--
        Complete data encapsulation 1 of the menu list on the left-2 level
    -->
    <resultMap id="rightsRM" type="Car" autoMapping="true">
        <id property="id" column="id"></id>
        <!--Encapsulate one to many data-->
        <collection property="children" ofType="Car">
            <id property="id" column="c_id"/>
            <result property="name" column="c_name"/>
            <result property="parentId" column="c_parent_id"/>
            <result property="path" column="c_path"/>
            <result property="level" column="c_level"/>
            <result property="created" column="c_created"/>
            <result property="updated" column="c_updated"/>
            <result property="path1" column="c_path1"/>
        </collection>
    </resultMap>
</mapper>

1.5 ServiceImpl layer

package com.ap.service;

import com.ap.mapper.CarMapper;
import com.ap.pojo.Car;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService{
    @Autowired
    private CarMapper carMapper;

    @Override
    public List<Car> getShopList() {
        return carMapper.getShopList();
    }
}

1.6 Controller layer

package com.ap.controller;

import com.ap.pojo.Car;
import com.ap.service.CarService;
import com.ap.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("car")
public class CarController {
    @Autowired
    private CarService carService;

    @GetMapping("/getShopList")
    public SysResult getShopList(){
        List<Car> car=carService.getShopList();
        return SysResult.success(car);
    }
}

2. Display

2.0 database

2.1 front end page analysis

2.1.1 life cycle function
updated() {
       if(this.i !== this.queryItemInfo.id){
         this.queryItemInfo.id = this.i
          this.getItemList()
       }
    },
2.1.2 get data function
//Realize pagination query of commodity information
      //2. Call this.getItemList()
      async getItemList() {
        const {
          data: result
        } = await this.$http.get("/car/getItemList", {
          params: this.queryItemInfo  //Pass paging object to background
        })
        if (result.status !== 200) return this.$message.error("Commodity list query failed")
        this.itemList = result.data.rows //Get the product list information and pass it to itemList
        this.total = result.data.total   //Gets the total number of data in the item list
      },

2.2 interface documents

  • Request path: / car / getitemlist? Query = & pagenum = 1 & PageSize = 10
  • Request type: Get
  • Request parameters: receive using pageResult object
Parameter nameParameter descriptionRemark information
queryData queried by userNullable
pageNumNumber of pages for paged queriesCannot be null
pageSizeNumber of paged queriesCannot be null
  • Business description: query three-level classification menu data, requiring three-level nested structure
  • Return value: SysResult object
Parameter nameParameter descriptionRemark information
statusstatus information 200 indicates that the server request is successful, and 201 indicates that the server is abnormal
msgPrompt information returned by the serverCan be null
dataBusiness permissions returned by the serverLevel 3 commodity classification information

2.3 realization

2.3.1 Controller layer
package com.ap.controller;

import com.ap.pojo.ItemCopy;
import com.ap.service.ItemCopyService;
import com.ap.vo.PageResult;
import com.ap.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/*Vehicle specific data*/
@RestController
@CrossOrigin
@RequestMapping("/car/")
public class ItemCopyController {
    @Autowired
    private ItemCopyService itemCopyService;
    /**
     * Request path: / car / getitemlist? Query = & pagenum = 1 & PageSize = 10
     * Request type: Get
     * Request parameters: receive using pageResult object
     */
    @GetMapping("/getItemList")
    public SysResult getItemList(PageResult pageResult){
        pageResult=itemCopyService.getItemList(pageResult);
        return SysResult.success(pageResult);
    }
    
}

2.3.2 Service layer
package com.ap.service;

import com.ap.vo.PageResult;

public interface ItemCopyService {
    PageResult getItemList(PageResult pageResult);
}

2.3.3 ServiceImpl layer
package com.ap.service;

import com.ap.mapper.ItemCopyMapper;
import com.ap.pojo.Item;
import com.ap.pojo.ItemCopy;
import com.ap.vo.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ItemCopyServiceImpl implements ItemCopyService{
    @Autowired
    private ItemCopyMapper itemCopyMapper;

    /**
     * Requirement: 3 + 2 (total records, paging results)
     * Parameter 1: paging object provided by page mp
     * Parameter 2: condition constructor
     */
    @Override
    public PageResult getItemList(PageResult pageResult) {
        //1. Build paging object, parameter 1: page number, parameter 2: how many
        Page<ItemCopy> page=new Page<>(pageResult.getPageNum(),pageResult.getPageSize());
        //2. Preparation condition constructor
        QueryWrapper<ItemCopy> queryWrapper = new QueryWrapper();
        String query=pageResult.getQuery();
        boolean flag = StringUtils.hasLength(query);
        queryWrapper.eq("item_cat_id", pageResult.getId());
        queryWrapper.like(flag,"title",query);

        //3. Realize the automatic encapsulation of paging data according to MP query
        page=itemCopyMapper.selectPage(page, queryWrapper);

        //4. Get the data and return the paging object
        long total = page.getTotal();
        //Get paging results
        List<ItemCopy> rows = page.getRecords();
        return pageResult.setTotal(total).setRows(rows);
    }


}

2.3.4 pojo layer
package com.ap.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
@TableName("item_copy")
public class ItemCopy extends BasePojo{
    @TableId(type = IdType.AUTO)
    private Integer id;         //Item Id No
    private String title;       //Item title information
    private String sellPoint;   //Selling point information
    private Integer price;      //commodity price
    private Integer pricerow;      //Original price of goods
    private Integer num;        //Quantity of goods
    private String images;       //Product picture
    private Integer itemCatId;  //Commodity classification ID number
    private Boolean status;     //Status information 0 off shelf 1 on shelf
    private Boolean display;
    private String title2;
    private String title3;
    private String images2;       //Product picture
    private String images3;       //Product picture
}


3. NEW

3.1 front end page analysis

//Define new objects for commodity classification
        itemCatForm: {
          name: '', //Define commodity classification name
          parentId: 0, //Default parent ID=0
          level: 1 //The default is the first level menu
        }
async addItemCatForm() {
        //Verify the whole form first
        this.$refs.itemCatFormRef.validate(async validate => {
          if (!validate) return
          const {
            data: result
          } = await this.$http.post("/itemCat/saveItemCat", this.itemCatForm)
          if (result.status !== 200) return this.$message.error("Failed to add commodity classification")
          this.$message.success("Successfully added commodity classification!!!")
          //If the addition is successful, the classification list information will be refreshed
          this.findItemCatList();
          this.addItemCatDialogVisible = false
        })
      },

3.2 interface documents

  • Request path: / shop/saveItemCat
  • Request type: POST
  • Request parameter: form data
Parameter nameParameter descriptionRemark information
nameCommodity classification nameCannot be null
parentIdUser parent idCannot be null
levelClassification category1 2 3 commodity classification
  • Return value: SysResult object
Parameter nameParameter descriptionRemark information
statusstatus information 200 indicates that the server request is successful, and 201 indicates that the server is abnormal
msgPrompt information returned by the serverCan be null
dataBusiness permissions returned by the serverLevel 3 commodity classification information

3.3 realization

3.3.1 Controller layer
/*
     * Business requirements: add a new commodity classification
     * URL:  /shop/saveItemCat
     * Type: post
     * Return value: SysResult object
     */
    @PostMapping("/saveItemCat")
    public SysResult saveItem(@RequestBody Shop shop){
        shopService.saveItem(shop);
        return SysResult.success();
    }
3.3.2 ServiceImpl layer
	@Override
    @Transactional //Thing control
    public void saveItem(Shop shop) {
        Date date = new Date();
        shop.setStatus(true).setCreated(date).setUpdated(date);//start-up
        shopMapper.insert(shop);
    }

4. Delete

4.1 front end page analysis

       async deleteItemBtn(item) {
        //Message confirmation box
        this.$confirm('This action will permanently delete the file, Continue?', 'Tips', {
          confirmButtonText: 'determine',
          cancelButtonText: 'cancel',
          type: 'warning'
        }).then(async () => {
          //Delete data by id
          const {
            data: result
          } = await this.$http.delete("/car/deleteItemById", {
            params: {
              id: item.id
            }
          })
          if (result.status !== 200) return this.$message.error("Failed to delete product")
          this.$message.success("Product deleted successfully")
          //Retrieve product list information
          this.getItemList()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: 'Deletion cancelled'
          });
        });
      },

4.2 interface documents

  • Request path: / shop/deleteItemCat

  • Request type: DELETE

  • Return value: SysResult object

Parameter nameParameter descriptionRemark information
statusstatus information 200 indicates that the server request is successful, and 201 indicates that the server is abnormal
msgPrompt information returned by the serverCan be null
dataBusiness permissions returned by the serverLevel 3 commodity classification information

4.3 realization

4.3.1 Controller layer
    /**
     * Request path: / car/deleteItemById
     * Request type: DELETE
     * Request parameter: user ID
     */
    @DeleteMapping("/deleteItemById")
    public SysResult deleteItemById(Integer id){
        itemCopyService.deleteItemById(id);
        return SysResult.success();
    }
4.3.2 ServiceImpl layer
@Override
    public void deleteItemCat(Integer id, Integer level) {
        //Judge whether it is a level 3 menu. If yes, delete it directly
        if(level==3){
            shopMapper.deleteById(id);
        }
        //Judge whether it is a secondary menu. If yes, delete the tertiary data first and delete yourself
        if(level==2){
            QueryWrapper<Shop> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("parent_id", id)
                        .or()
                        .eq("id", id);
            shopMapper.delete(queryWrapper);
        }
        if (level==1){
            QueryWrapper<Shop> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("parent_id", id);
            List twoId = shopMapper.selectObjs(queryWrapper);
            //wipe data 
            queryWrapper.clear();
            //If the secondary menu has a value, it will be deleted
            queryWrapper.in(twoId.size()>0, "parent_id",twoId)
                        .or()
                        .in(twoId.size()>0, "id",twoId)
                        .or()
                        .eq("id",id);
            shopMapper.delete(queryWrapper);
        }
    }

5. Modification

5.1 front end page analysis

//Modify commodity classification information
      async updateItem(){
       let item= {}
       item.id=this.updateUserModel.id
       item.title=this.updateUserModel.title
       item.title2=this.updateUserModel.title2
       item.title3=this.updateUserModel.title3
       item.sellPoint=this.updateUserModel.sellPoint
       item.price=this.updateUserModel.price
       item.pricerow=this.updateUserModel.pricerow
       item.num=this.updateUserModel.num
       item.images=this.updateUserModel.images
       item.images2=this.updateUserModel.images2
       item.images3=this.updateUserModel.images3
       const {
         data: result
       } = await this.$http.put('/car/updateItem', item)
       if (result.status !== 200) return this.$message.error("Failed to update product")
       this.$message.success("Update product succeeded")
       this.updateDialogVisible = false
       this.getItemList()
      }

5.2 interface documents

  • Request path: / car/updateItemCat
  • Request type: PUT
  • Request parameter: form data object
  • Return value: SysResult object
Parameter nameParameter descriptionRemark information
statusstatus information 200 indicates that the server request is successful, and 201 indicates that the server is abnormal
msgPrompt information returned by the serverCan be null
dataBusiness permissions returned by the serverLevel 3 commodity classification information

5.3 realization

5.3.1 Controller layer
/**
     * Request path: / yingliangbang1/updateItem
     * Demand: modify commodity information
     * Request type: PUT
     * Return value: SysResult object
     */
    @PutMapping("/updateItem")
    public SysResult updateItem(@RequestBody ItemCopy itemCopy){
        itemCopyService.updateItem(itemCopy);
        return SysResult.success();
    }
5.3.2 ServiceImpl layer
@Override
    public void updateItem(ItemCopy itemCopy) {
        itemCopyMapper.updateById(itemCopy);
    }

Tags: AI Data Mining

Posted on Sun, 05 Dec 2021 01:29:21 -0500 by puckeye