src/main/java/cn/pzhu/pserson/controller/GiveController.java

(完整代码) 2KB

package cn.pzhu.pserson.controller;

import cn.pzhu.pserson.domain.Give;
import cn.pzhu.pserson.domain.Logistic;
import cn.pzhu.pserson.service.GiveService;
import cn.pzhu.pserson.service.LogisticService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@Controller
public class GiveController {

    @Autowired
    private GiveService giveService;

    @Autowired
    private LogisticService logisticService;

    @RequestMapping(value = "/give/list", method = RequestMethod.GET)
    public String index(Model model, String content, int pageNum, int pageSize) {
        Map<String, Object> map = null;
        List<Give> give_list = null;
        if (content != null) {
            map = giveService.get_GiveLikeList(content, pageNum, pageSize);
            give_list = (List<Give>) map.get("list");
        } else {
            map = giveService.get_GiveList(pageNum, pageSize);
            give_list = (List<Give>) map.get("list");
        }
        int size = (int) map.get("size");
        model.addAttribute("size", size);
        model.addAttribute("list", give_list);
        model.addAttribute("pageNum", pageNum);
        model.addAttribute("nums", size / pageSize + 1);
        return "give/list";
    }

    @RequestMapping(value = "/give/add", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject add(@RequestBody Give give, Integer id) {
        JSONObject jsonObject = new JSONObject();
        giveService.insert_GiveInfo(give);
        Logistic logistic = logisticService.get_LogisticInfo(give.getProductId());
        int count = (Integer.parseInt(logistic.getProductCountSave()) - Integer.parseInt(give.getProductCount()));
        logistic.setProductCountSave(Integer.toString(count));
        logistic.setStatus("4");
        logisticService.update_LogisticInfo(logistic);
        jsonObject.put("code", "200");
        jsonObject.put("msg", "分发成功!");
        return jsonObject;
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。