• 牧场系统设计与实现-计算机毕业设计源码+LW文档


    关键代码

    package com.example.controller;
    import cn.hutool.core.collection.CollUtil;
    import cn.hutool.core.collection.CollectionUtil;
    import cn.hutool.core.io.IoUtil;
    import cn.hutool.core.util.ObjectUtil;
    import cn.hutool.core.util.StrUtil;
    import cn.hutool.crypto.SecureUtil;
    import cn.hutool.json.JSONObject;
    import cn.hutool.poi.excel.ExcelUtil;
    import cn.hutool.poi.excel.ExcelWriter;
    import com.example.common.Result;
    import com.example.common.ResultCode;
    import com.example.entity.YaopinrukuInfo;
    import com.example.dao.YaopinrukuInfoDao;
    import com.example.service.YaopinrukuInfoService;
    import com.example.exception.CustomException;
    import com.example.common.ResultCode;
    import com.example.vo.EchartsData;
    import com.example.vo.YaopinrukuInfoVo;
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import com.example.service.*;
    import org.springframework.web.bind.annotation.*;
    import org.springframework.beans.factory.annotation.Value;
    import cn.hutool.core.util.StrUtil;
    import org.springframework.web.multipart.MultipartFile;
    import javax.annotation.Resource;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.util.*;
    import java.util.stream.Collectors;

    @RestController
    @RequestMapping(value = "/yaopinrukuInfo")
    public class YaopinrukuInfoController {

        @Resource
        private YaopinrukuInfoService yaopinrukuInfoService;
    @Resource
        private YaopinrukuInfoDao yaopinrukuInfoDao;

        @PostMapping
        public Result add(@RequestBody YaopinrukuInfoVo yaopinrukuInfo) {
            
    //mixmajixami
    yaopinrukuInfoService.add(yaopinrukuInfo);
            return Result.success(yaopinrukuInfo);
        }

    //youtixing1
        //youtixing2

        @DeleteMapping("/{id}")
        public Result delete(@PathVariable Long id) {
            yaopinrukuInfoService.delete(id);
            return Result.success();
        }

        @PutMapping
        public Result update(@RequestBody YaopinrukuInfoVo yaopinrukuInfo) {
            yaopinrukuInfoService.update(yaopinrukuInfo);
            return Result.success();
        }
        //@PutMapping("/update2")
    //    public Result update2(@RequestBody YaopinrukuInfoVo yaopinrukuInfo) {
    //        yaopinrukuInfoService.update2(yaopinrukuInfo);
    //        return Result.success();
    //    }
        @GetMapping("/{id}")
        public Result detail(@PathVariable Long id) {
            YaopinrukuInfo yaopinrukuInfo = yaopinrukuInfoService.findById(id);
            return Result.success(yaopinrukuInfo);
        }
        @GetMapping("/changeStatus/{id}")
        public Result changeStatus(@PathVariable Long id) {
            yaopinrukuInfoService.changeStatus(id);
            return Result.success();
        }


        @GetMapping
        public Result> all() {
            return Result.success(yaopinrukuInfoService.findAll());
        }

        @GetMapping("/page/{name}")
        public Result> page(@PathVariable String name,
                                                    @RequestParam(defaultValue = "1") Integer pageNum,
                                                    @RequestParam(defaultValue = "5") Integer pageSize,
                                                    HttpServletRequest request) {
            return Result.success(yaopinrukuInfoService.findPage(name, pageNum, pageSize, request));
        }

    @GetMapping("/pageqt/{name}")
        public Result> pageqt(@PathVariable String name,
                                                    @RequestParam(defaultValue = "1") Integer pageNum,
                                                    @RequestParam(defaultValue = "8") Integer pageSize,
                                                    HttpServletRequest request) {
            return Result.success(yaopinrukuInfoService.findPageqt(name, pageNum, pageSize, request));
        }

       // @PostMapping("/register")
    //    public Result register(@RequestBody YaopinrukuInfo yaopinrukuInfo) {
    //        if (StrUtil.isBlank(yaopinrukuInfo.getName()) || StrUtil.isBlank(yaopinrukuInfo.getPassword())) {
    //            throw new CustomException(ResultCode.PARAM_ERROR);
    //        }
    //        return Result.success(yaopinrukuInfoService.add(yaopinrukuInfo));
    //    }

        /**
        * 批量通过excel添加信息
        * @param file excel文件
        * @throws IOException
        */
        @PostMapping("/upload")
        public Result upload(MultipartFile file) throws IOException {

            List infoList = ExcelUtil.getReader(file.getInputStream()).readAll(YaopinrukuInfo.class);
            if (!CollectionUtil.isEmpty(infoList)) {
                // 处理一下空数据
                List resultList = infoList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getYaopinmingcheng())).collect(Collectors.toList());
                for (YaopinrukuInfo info : resultList) {
                    yaopinrukuInfoService.add(info);
                }
            }
            return Result.success();
        }
    //yoxutonxgjitu
        @GetMapping("/getExcelModel")
        public void getExcelModel(HttpServletResponse response) throws IOException {
            // 1. 生成excel
            Map row = new LinkedHashMap<>();
    row.put("yaopinbianhao", "A药品编号");
    row.put("yaopinmingcheng", "A药品名称");
    row.put("kucun", "A库存");
    row.put("rukushuliang", "A入库数量");
    row.put("rukushijian", "A入库时间");
    row.put("beizhu", "A备注");
    row.put("caozuoren", "A操作人"); row.put("status", "是");
    row.put("level", "yaopinruku");

            List> list = CollUtil.newArrayList(row);

            // 2. 写excel
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.write(list, true);

            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            response.setHeader("Content-Disposition","attachment;filename=yaopinrukuInfoModel.xlsx");

            ServletOutputStream out = response.getOutputStream();
            writer.flush(out, true);
            writer.close();
            IoUtil.close(System.out);
        }
    @GetMapping("/getExcel")
        public void getExcel(HttpServletResponse response) throws IOException {
            // 1. 生成excel
            Map row = new LinkedHashMap<>();
            row.put("yaopinbianhao", "A药品编号");
    row.put("yaopinmingcheng", "A药品名称");
    row.put("kucun", "A库存");
    row.put("rukushuliang", "A入库数量");
    row.put("rukushijian", "A入库时间");
    row.put("beizhu", "A备注");
    row.put("caozuoren", "A操作人"); 
            row.put("status", "是");
            row.put("level", "权限");
            List> list = CollUtil.newArrayList(row);
            List> daochuexcellist = yaopinrukuInfoDao.daochuexcel();
            Map typeMap = new HashMap<>();
            for (Map map : daochuexcellist) {
                list.add(map);
            }
            // 2. 写excel
            ExcelWriter writer = ExcelUtil.getWriter(true);
            writer.write(list, true);

            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            response.setHeader("Content-Disposition","attachment;filename=yaopinrukuInfo.xlsx");

            ServletOutputStream out = response.getOutputStream();
            writer.flush(out, true);
            writer.close();
            IoUtil.close(System.out);
        }
    private void getPieData(String name, List pieList, Map dataMap) {
            EchartsData pieData = new EchartsData();
            EchartsData.Series series = new EchartsData.Series();

            Map titleMap = new HashMap<>(2);
            titleMap.put("text", name);
            pieData.setTitle(titleMap);

            series.setName(name + "比例");
            series.setType("pie");
            series.setRadius("55%");

            List objects = new ArrayList<>();
            List legendList = new ArrayList<>();
            for (String key : dataMap.keySet()) {
                Double value = dataMap.get(key);
                objects.add(new JSONObject().putOpt("name", key).putOpt("value", value));
                legendList.add(key);
            }
            series.setData(objects);

            pieData.setSeries(Collections.singletonList(series));
            Map map = new HashMap<>();
            map.put("show", true);
            pieData.setTooltip(map);

            Map legendMap = new HashMap<>(4);
            legendMap.put("orient", "vertical");
            legendMap.put("x", "left");
            legendMap.put("y", "center");
            legendMap.put("data", legendList);
            pieData.setLegend(legendMap);

            pieList.add(pieData);
        }

        private void getBarData(String name, List barList, Map dataMap) {
            EchartsData barData = new EchartsData();
            EchartsData.Series series = new EchartsData.Series();

            List seriesObjs = new ArrayList<>();
            List xAxisObjs = new ArrayList<>();
            for (String key : dataMap.keySet()) {
                Double value = dataMap.get(key);
                xAxisObjs.add(key);
                seriesObjs.add(value);
            }

            series.setType("bar");
            series.setName(name);
            series.setData(seriesObjs);
            barData.setSeries(Collections.singletonList(series));

            Map xAxisMap = new HashMap<>(1);
            xAxisMap.put("data", xAxisObjs);
            barData.setxAxis(xAxisMap);

            barData.setyAxis(new HashMap<>());

            Map legendMap = new HashMap<>(1);
            legendMap.put("data", Collections.singletonList(name));
            barData.setLegend(legendMap);

            Map map = new HashMap<>(1);
            map.put("show", true);
            barData.setTooltip(map);

            Map titleMap = new HashMap<>(1);
            titleMap.put("text", name);
            barData.setTitle(titleMap);

            barList.add(barData);
        }
    }

     

     

     

     

  • 相关阅读:
    架构自治服务:构建数据驱动的架构洞察
    DDS协议介绍
    ACID事务理论
    Paddle GPU版本需要安装CUDA、CUDNN
    SpringBoot 服务接口限流
    《职场求生攻略》
    Android应用内组件通讯之EventBus源码分析之post流程(三)
    【数据结构】C语言实现队列
    java - 包装类
    mac m1上安装centos8时遇到的docker 镜像问题 - 系统架构和docker镜像的关系
  • 原文地址:https://blog.csdn.net/qq_375279829/article/details/127941656