THEMIS---Alpha Sprint Essays 5

THEMIS—Alpha Sprint Essays 5


The Link MY Class2301-MUSE社区-CSDN社区云
The Link of Requirement of This Assignment Teamwork——Alpha Sprint-CSDN社区
Team NameTHEMIS
The Aim of This AssignmentAlpha Sprint–Implement campus rental platform
Other Reference DocumentsNULL


1. Task overview

  • 完成剩余页面所需的端口开发以及前后端之间的调试;
  • 整合mysql所有数据列表并删除冗余的数据表;

2. Partial code presentation

I.Goods_category

GoodsCategoryController.java

/**
 * @Author Jiayi Lu
        */
@RestController
@RequestMapping("/api/category")
public class GoodsCategoryController {
    @Autowired
    private GoodsCategoryService goodsCategoryService;

    //add
    @PostMapping
    public ResultVo add(@RequestBody GoodsCategory goodsCategory) {
        if (goodsCategoryService.save(goodsCategory)) {
            return ResultUtils.success("新增成功!");
        }
        return ResultUtils.error("新增失败!");
    }

    //edit
    ...(similar to the previous one)
    //delete
	...
    //list
    @GetMapping("/list")
    public ResultVo list(ListParm parm) {
        //construct pagination object
        IPage<GoodsCategory> page = new Page<>(parm.getCurrentPage(), parm.getPageSize());
        //query conditions
        QueryWrapper<GoodsCategory> query = new QueryWrapper<>();
        query.lambda().like(StringUtils.isNotEmpty(parm.getCategoryName()), GoodsCategory::getCategoryName, parm.getCategoryName())
                .orderByDesc(GoodsCategory::getOrderNum);
        //querying data
        IPage<GoodsCategory> list = goodsCategoryService.page(page, query);
        return ResultUtils.success("查询成功", list);

    }

    //小程序分类
    @GetMapping("/getSelectList")
    public ResultVo getSelectList() {
        //query category
        QueryWrapper<GoodsCategory> query = new QueryWrapper<>();
        query.lambda().orderByAsc(GoodsCategory::getOrderNum);
        List<GoodsCategory> list = goodsCategoryService.list(query);
        //save the type
        List<SelectType> selectList = new ArrayList<>();
        //construct the type
        Optional.ofNullable(list).orElse(new ArrayList<>())
                .stream()
                .forEach(item -> {
                    SelectType type = new SelectType();
                    type.setLabel(item.getCategoryName());
                    type.setValue(item.getCategoryId());
                    selectList.add(type);
                });
        return ResultUtils.success("查询成功", selectList);
    }

    //Category Interface
    @GetMapping("/getCateList")
    public ResultVo getCateList(){
        List<GoodsCategory> list = goodsCategoryService.list();
        return ResultUtils.success("查询成功",list);
    }
}

This section primarily focuses on the implementation of Goods Category Management, encompassing functionalities such as adding, editing, deleting, listing, fetching dropdown selection lists required for a mini-program, and obtaining a list of categories for the mini-program.

  1. Add:
    • Responsible for receiving the GoodsCategory object sent from the frontend and saving it to the database using the goodsCategoryService.save() method.
  2. Edit:
    • Receives the modified GoodsCategory object from the frontend and updates the corresponding record in the database using the goodsCategoryService.updateById() method.
  3. Delete:
    • Accepts the Goods Category ID from the frontend and removes the corresponding Goods Category from the database using the goodsCategoryService.removeById() method.
  4. List Query:
    • Accepts pagination parameters and condition parameters from the frontend, constructs a QueryWrapper object, and uses the goodsCategoryService.page() method to implement a paginated query with conditions.
  5. Get Dropdown Selection List for Mini-program:
    • Retrieves the list of Goods Categories from the database, then transforms it into a list of SelectType objects required for a mini-program dropdown selection and returns it to the frontend.
  6. Get Category List:
    • Directly queries the database to obtain the list of Goods Categories and returns it to the frontend.

In summary, this controller implements basic management functionalities for Goods Categories and provides data interfaces required for a mini-program.

II.Good_collect

GoodsCollectController.java
public class GoodsCollectController {
    @Autowired
    private GoodsCollectService goodsCollectService;

    // Collect goods
    @PostMapping("/collect")
    public ResultVo collect(@RequestBody GoodsCollect goodsCollect){
        // Check if already collected
        QueryWrapper<GoodsCollect> query = new QueryWrapper<>();
        query.lambda().eq(GoodsCollect::getGoodsId,goodsCollect.getGoodsId())
                .eq(GoodsCollect::getUserId,goodsCollect.getUserId());
        GoodsCollect one = goodsCollectService.getOne(query);
        if(one == null){ // Not collected, so add to collection
            goodsCollect.setCollectTime(new Date());
            if(goodsCollectService.save(goodsCollect)){
                return ResultUtils.success("Collection success!");
            }
            return ResultUtils.error("Collection failed!");
        }else{ // Already collected, so remove from collection (cancel)
            if(goodsCollectService.remove(query)){
              return ResultUtils.success("Collection cancelled successfully!");
            }
            return ResultUtils.error("Collection cancellation failed!");
        }
    }

    // Check if goods are already collected
    @GetMapping("/hasCollect")
    public ResultVo hasCollect(GoodsCollect goodsCollect){
        // Check if goods are already collected
        QueryWrapper<GoodsCollect> query = new QueryWrapper<>();
        query.lambda().eq(GoodsCollect::getGoodsId,goodsCollect.getGoodsId())
                .eq(GoodsCollect::getUserId,goodsCollect.getUserId());
        GoodsCollect one = goodsCollectService.getOne(query);
        if(one != null){ // Already collected
            return ResultUtils.success("Query successful","1");
        }else{ // Not collected
            return ResultUtils.success("Query successful","0");
        }
    }

    // Get user's collection list for the mobile app
    @GetMapping("/getMyCollect")
    public ResultVo getMyCollect(CollectParm parm){
        IPage<Goods> list = goodsCollectService.getMyCollect(parm);
        return ResultUtils.success("Query successful",list);
    }

    // Cancel goods collection
    @PostMapping("/cancel")
    public ResultVo cancel(@RequestBody GoodsCollect collect){
        if(goodsCollectService.removeById(collect.getCollectId())){
            return ResultUtils.success("Cancellation successful!");
        }
        return ResultUtils.error("Cancellation failed!");
    }
}

Explanation:

  1. @PostMapping("/collect"): Handles the collection (add or cancel) of goods based on whether the user has already collected them.
  2. @GetMapping("/hasCollect"): Checks if goods are already collected by the user.
  3. @GetMapping("/getMyCollect"): Retrieves the user’s collection list for the mobile app.
  4. @PostMapping("/cancel"): Cancels the collection of goods.

These endpoints are designed for a mobile app to interact with a backend system to manage user goods collections. They use the ResultVo class for standardized response messages.

GoodsCollectService/GoodsCollectServicelmpl
public interface GoodsCollectService extends IService<GoodsCollect> {
    IPage<Goods> getMyCollect(CollectParm parm);
}

public class GoodsCollectServiceImpl extends ServiceImpl<GoodsCollectMapper, GoodsCollect> implements GoodsCollectService {

    /**
     * Get the user's list of collected goods
     * @param parm Collection parameter object
     * @return Paginated list of collected goods
     */
    @Override
    public IPage<Goods> getMyCollect(CollectParm parm) {
        // Create a pagination object
        IPage<Goods> page = new Page<>(parm.getCurrentPage(), parm.getPageSize());
        // Call the getMyCollect method in GoodsCollectMapper, passing pagination parameters and user ID
        return this.baseMapper.getMyCollect(page, parm.getUserId());
    }
}

Explanation:

  1. GoodsCollectServiceImpl class: It implements the GoodsCollectService interface and extends the ServiceImpl class from MyBatis-Plus. The generic parameters are GoodsCollectMapper and GoodsCollect, indicating the use of GoodsCollectMapper as the data access layer interface and GoodsCollect as the entity.
  2. getMyCollect method: It implements the method defined in the interface to get the list of goods collected by the user. The method constructs a pagination object and calls the getMyCollect method in GoodsCollectMapper, passing pagination parameters and user ID to retrieve the paginated list of collected goods.
  3. GoodsCollectServiceImpl class: It implements the GoodsCollectService interface and extends the ServiceImpl class from MyBatis-Plus. The generic parameters are GoodsCollectMapper and GoodsCollect, indicating the use of GoodsCollectMapper as the data access layer interface and GoodsCollect as the entity.
  4. getMyCollect method: It implements the method defined in the interface to get the list of goods collected by the user. The method constructs a pagination object and calls the getMyCollect method in GoodsCollectMapper, passing pagination parameters and user ID to retrieve the paginated list of collected goods.

This service implementation class is primarily used to handle business logic related to goods collection. It utilizes the generic database operation methods provided by MyBatis-Plus and implements a custom goods collection query method through GoodsCollectMapper.

III. Evaluation

GoodsEvaluate.java
/**
 * Entity class for goods evaluations.
 * @Author Zhipeng Wang
 * @Version 1.0.0
 */
@Data
@TableName("goods_evaluate")
public class GoodsEvaluate {

    // Auto-generated ID with IdType.AUTO strategy
    @TableId(type = IdType.AUTO)
    private Long id;

    // User ID associated with the evaluation
    private Long userId;

    // Goods ID associated with the evaluation
    private Long goodsId;

    // Content of the evaluation
    private String content;

    // Date and time when the evaluation was created, formatted using JSON serialization
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
    private Date createTime;

    // Field that does not persist in the database (used for additional information, possibly in queries)
    @TableField(exist = false)
    private String userName;
}

This class uses the Lombok library annotations such as @Data to automatically generate getter and setter methods, @TableName to specify the table name, and @JsonFormat to control the JSON serialization format of the createTime field.

The @TableField(exist = false) annotation on the userName field indicates that this field is not mapped to any column in the database but is used for transient purposes, possibly for displaying additional information in the application.

GoodsEvaluateMapper.java
/**
 * MyBatis Plus mapper interface for handling CRUD operations on GoodsEvaluate entities.
 * @Author Zhipeng Wang
 * @Version 1.0.0
 */
public interface GoodsEvaluateMapper extends BaseMapper<GoodsEvaluate> {
    // Additional custom queries or methods related to goods evaluations can be added here.
}

We’ve shared a MyBatis Plus mapper interface named GoodsEvaluateMapper that extends BaseMapper<GoodsEvaluate>. This interface provides basic CRUD (Create, Read, Update, Delete) operations for the GoodsEvaluate entity.

This interface extends BaseMapper<GoodsEvaluate>, which means it inherits common CRUD methods from the MyBatis Plus framework for the GoodsEvaluate entity.

IV. Goods_Report

GoodsReportController.java

package com.itmk.web.goods_report.controller;

/**
 * @Author Hongming Chen
 */
@RequestMapping("/api/report")
@RestController
public class GoodsReportController {
    @Autowired
    private GoodsReportService goodsReportService;

    //举报
    @PostMapping("/report")
    public ResultVo report(@RequestBody GoodsReport report){
        //判断是否已经举报
        QueryWrapper<GoodsReport> query = new QueryWrapper<>();
        query.lambda().eq(GoodsReport::getGoodsId,report.getGoodsId())
                .eq(GoodsReport::getReportUser,report.getReportUser());
        GoodsReport one = goodsReportService.getOne(query);
        if(one != null){
            return ResultUtils.error("您已经举报,不用重复举报!");
        }
        report.setReportTime(new Date());
        if(goodsReportService.save(report)){
            return ResultUtils.success("举报成功!");
        }
        return ResultUtils.error("举报失败!");
    }

    //查询是否已经举报
    @GetMapping("/hasReport")
    public ResultVo hasReport(Long userId,Long goodsId){
        QueryWrapper<GoodsReport> query = new QueryWrapper<>();
        query.lambda().eq(GoodsReport::getGoodsId,goodsId)
                .eq(GoodsReport::getReportUser,userId);
        GoodsReport one = goodsReportService.getOne(query);
        if(one != null){ //已经举报
            return ResultUtils.success("查询成功","1");
        }else{
            return ResultUtils.success("查询成功","0");
        }
    }

    //查询列表
    @GetMapping("/getList")
    public ResultVo getList(ReportParm parm){
        IPage<ReportVo> list = goodsReportService.getList(parm);
        return ResultUtils.success("查询成功",list);
    }

    //处理举报内容
    @PostMapping("/doReport")
    public ResultVo doReport(@RequestBody GoodsReport report){
        UpdateWrapper<GoodsReport> update = new UpdateWrapper<>();
        update.lambda().set(GoodsReport::getStatus,"1")
                .eq(GoodsReport::getReportId,report.getReportId());
        if(goodsReportService.update(update)){
            return ResultUtils.success("处理成功!");
        }
        return ResultUtils.error("处理失败!");
    }

}

This code represents a controller class for a web application developed using the Spring Boot framework, primarily responsible for handling the reporting functionality of goods. Here is a brief overview of the main functionalities:

  1. Report Goods Endpoint:
    • URL: /api/report/report
    • Method: POST
    • Purpose: Handles the reporting of goods.
    • Checks if the user has already reported the goods before allowing a new report.
    • Responds with success or error messages.
  2. Check If Already Reported Endpoint:
    • URL: /api/report/hasReport
    • Method: GET
    • Purpose: Checks whether a user has already reported specific goods.
    • Responds with a success message and a flag indicating if the user has reported or not.
  3. Get List of Reports Endpoint:
    • URL: /api/report/getList
    • Method: GET
    • Purpose: Retrieves a list of reported goods based on specified parameters.
    • Responds with a success message and the list of reported goods.
  4. Handle Reported Goods Endpoint:
    • URL: /api/report/doReport
    • Method: POST
    • Purpose: Handles the processing of reported goods, possibly marking them as handled.
    • Responds with success or error messages.

It’s important to note that the code uses the MyBatis Plus library for database operations (QueryWrapper, UpdateWrapper). The controller is also annotated with @RestController from Spring, indicating that it is a controller handling RESTful endpoints.

V. Home

TotalVo.java
package com.itmk.web.home.entity;

import lombok.Data;

/**
 * @Author Zhou Wenxuan
 * @Version 1.0.0
 */
@Data
public class TotalVo {
    private int doTotal;
    private int userTotal;
    private int unusedTotal;
    private int buyTotal;
}

This is a total list class, TotalVo, typically used to check the status of total number of pending items, users, unused goods and buy goods.

  • doTotal: Used to store the total number of pending items.
  • userTotal: Used to store the total number of users.
  • unusedTotal: Used to store the total number of unused goods.
  • buyTotal: Used to store the total number of goods have bought.
HomeController.java
/**
 * @Author Zhou Wenxuan
 * @Version 1.0.0
 */
@RequestMapping("/api/home")
@RestController
public class HomeController {
    @Autowired
    private GoodsReportService goodsReportService;
    @Autowired
    private WxUserService wxUserService;
    @Autowired
    private GoodsService goodsService;

    @Auth
    @GetMapping("/getTotal")
    public ResultVo getTotal() {
        TotalVo vo = new TotalVo();
        //查询待处理数量
        QueryWrapper<GoodsReport> query = new QueryWrapper<>();
        query.lambda().eq(GoodsReport::getStatus, "0");
        int doTotal = goodsReportService.count(query);
        vo.setDoTotal(doTotal);
        //会员总数
        int userCount = wxUserService.count();
        vo.setUserTotal(userCount);
        //闲置总数
        QueryWrapper<Goods> uquery = new QueryWrapper<>();
        uquery.lambda().eq(Goods::getImage, "0");
        int uncount = goodsService.count(uquery);
        vo.setUnusedTotal(uncount);
        //求购总数
        QueryWrapper<Goods> buyquery = new QueryWrapper<>();
        uquery.lambda().eq(Goods::getImage, "1");
        int buycount = goodsService.count(buyquery);
        vo.setBuyTotal(buycount);
        return ResultUtils.success("查询成功", vo);
    }

    //查询投诉列表
    @Auth
    @GetMapping("/getDoReport")
    public ResultVo getDoReport() {
        QueryWrapper<GoodsReport> query = new QueryWrapper<>();
        query.lambda().eq(GoodsReport::getStatus, "0")
                .orderByDesc(GoodsReport::getReportTime)
                .last(" limit 8");
        List<GoodsReport> list = goodsReportService.list(query);
        if(list.size() >0){
            for (int i=0;i<list.size();i++){
                Goods goods = goodsService.getById(list.get(i).getGoodsId());
                list.get(i).setGoodsName(goods.getGoodsName());
            }
        }
        return ResultUtils.success("查询成功", list);
    }
}

This section mainly concentrates on checking different kinds of items such as those pending goods, the totoal number of users, unused goods or buy goods from the database. In addition, the service quality of goods are also checked.

  1. getTotal:
    • Constructs a QueryWrapper object GoodsReport and Good to directly check the database to obtain the total number of pending goods, users, unused goods and buy goods.
  2. getDoReport:
    • Constructs a QueryWrapper object GoodsReport to directly check the database to obtain quality of services, if the service quality is not qualified, then list the items.

3. The feeling of this cycle

I. Jiayi Lu

Exploring and implementing the Goods Category Controller provided a hands-on experience in efficiently managing and manipulating data. Crafting functionalities for adding, editing, deleting categories, and seamlessly interfacing with a mini-program showcased the harmony of logic and execution in software development. This journey not only enhanced technical skills but also fostered a deeper appreciation for the intricacies of backend systems.

II. Daming Fu

In this cycle, I mainly worked on the GoodsCollectController entity, which deepened my understanding of the back-end. The challenges I encountered were mainly database transfers, and my coding skills improved after this work.

III. Hongming Chen

I have learned and written the control class, entity class, and Mapper interface related to reporting. This has given me a deep understanding of implementing goods reporting functionality using the Spring Boot framework. The control class manages request-response, the entity class maps to the database structure, and the Mapper interface handles database operations. The integration of MyBatis Plus has streamlined database interactions. This learning process has enhanced my proficiency in utilizing frameworks and tools, providing robust support for practical project development.

IV. Zhipeng Wang

“During this cycle, crafting the GoodsEvaluate entity deepened my understanding of Java and MyBatis Plus. Challenges encountered included database mapping and implementing custom queries. Overcoming these difficulties enhanced my coding skills and instilled confidence to tackle future development tasks.”

V. Wenxuan Zhou

During this part, my task is to do query from database, it is relatively pure. There is some challenges when doing database mapping and query work. Overcoming those difficulties makes me experience the sense of achievements. It improves my skills in coding and makes me do not fear the unknown. Of course, it helps me know the back-end development a little more.

  • 19
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值