【计算机毕业设计】流浪宠物管理系统

Java SpringBoot流浪宠物管理系统

项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。

项目技术:

Springboot + mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。

2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;

3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可

4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;

5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

6.数据库:MySql 5.7/8.0等版本均可;

技术栈

后端:Springboot mybatis

前端:vue+css+javascript+jQuery+easyUI+highcharts

使用说明

使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;

3.管理员账号:abo 密码:abo

4.开发环境为Eclipse/idea,数据库为mysql 使用java语言开发。

5.运行SpringbootSchemaApplication.java 即可打开首页

6.数据库连接src\main\resources\application.yml中修改

7.maven包版本apache-maven-3.3.9.

8.后台路径地址:localhost:8080/项目名称/admin
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

package com.config;

import java.util.Date;

import org.apache.ibatis.reflection.MetaObject;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;

/**
 * 自定义填充处理器
 */
public class MyMetaObjectHandler extends MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("ctime", new Date(), metaObject);
    }

    @Override
    public boolean openUpdateFill() {
        return false;
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 关闭更新填充、这里不执行
    }
}


package com.controller;

import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;

import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;

/**
 * 商品评价
 * 后端接口
 * @author
 * @email
*/
@RestController
@Controller
@RequestMapping("/chongwuyongpinCommentback")
public class ChongwuyongpinCommentbackController {
    private static final Logger logger = LoggerFactory.getLogger(ChongwuyongpinCommentbackController.class);

    @Autowired
    private ChongwuyongpinCommentbackService chongwuyongpinCommentbackService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;

    //级联表service
    @Autowired
    private ChongwuyongpinService chongwuyongpinService;
    @Autowired
    private YonghuService yonghuService;



    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永不会进入");
        else if("用户".equals(role))
            params.put("yonghuId",request.getSession().getAttribute("userId"));
        if(params.get("orderBy")==null || params.get("orderBy")==""){
            params.put("orderBy","id");
        }
        PageUtils page = chongwuyongpinCommentbackService.queryPage(params);

        //字典表数据转换
        List<ChongwuyongpinCommentbackView> list =(List<ChongwuyongpinCommentbackView>)page.getList();
        for(ChongwuyongpinCommentbackView c:list){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c, request);
        }
        return R.ok().put("data", page);
    }

    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        ChongwuyongpinCommentbackEntity chongwuyongpinCommentback = chongwuyongpinCommentbackService.selectById(id);
        if(chongwuyongpinCommentback !=null){
            //entity转view
            ChongwuyongpinCommentbackView view = new ChongwuyongpinCommentbackView();
            BeanUtils.copyProperties( chongwuyongpinCommentback , view );//把实体数据重构到view中

                //级联表
                ChongwuyongpinEntity chongwuyongpin = chongwuyongpinService.selectById(chongwuyongpinCommentback.getChongwuyongpinId());
                if(chongwuyongpin != null){
                    BeanUtils.copyProperties( chongwuyongpin , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setChongwuyongpinId(chongwuyongpin.getId());
                }
                //级联表
                YonghuEntity yonghu = yonghuService.selectById(chongwuyongpinCommentback.getYonghuId());
                if(yonghu != null){
                    BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setYonghuId(yonghu.getId());
                }
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody ChongwuyongpinCommentbackEntity chongwuyongpinCommentback, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,chongwuyongpinCommentback:{}",this.getClass().getName(),chongwuyongpinCommentback.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永远不会进入");
        else if("用户".equals(role))
            chongwuyongpinCommentback.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));

        chongwuyongpinCommentback.setInsertTime(new Date());
        chongwuyongpinCommentback.setCreateTime(new Date());
        chongwuyongpinCommentbackService.insert(chongwuyongpinCommentback);
        return R.ok();
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody ChongwuyongpinCommentbackEntity chongwuyongpinCommentback, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,chongwuyongpinCommentback:{}",this.getClass().getName(),chongwuyongpinCommentback.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(false)
//            return R.error(511,"永远不会进入");
//        else if("用户".equals(role))
//            chongwuyongpinCommentback.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
        //根据字段查询是否有相同数据
        Wrapper<ChongwuyongpinCommentbackEntity> queryWrapper = new EntityWrapper<ChongwuyongpinCommentbackEntity>()
            .eq("id",0)
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        ChongwuyongpinCommentbackEntity chongwuyongpinCommentbackEntity = chongwuyongpinCommentbackService.selectOne(queryWrapper);
        chongwuyongpinCommentback.setUpdateTime(new Date());
        if(chongwuyongpinCommentbackEntity==null){
            chongwuyongpinCommentbackService.updateById(chongwuyongpinCommentback);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        chongwuyongpinCommentbackService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        try {
            List<ChongwuyongpinCommentbackEntity> chongwuyongpinCommentbackList = new ArrayList<>();//上传的东西
            Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
            Date date = new Date();
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                return R.error(511,"该文件没有后缀");
            }else{
                String suffix = fileName.substring(lastIndexOf);
                if(!".xls".equals(suffix)){
                    return R.error(511,"只支持后缀为xls的excel文件");
                }else{
                    URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
                    File file = new File(resource.getFile());
                    if(!file.exists()){
                        return R.error(511,"找不到上传文件,请联系管理员");
                    }else{
                        List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
                        dataList.remove(0);//删除第一行,因为第一行是提示
                        for(List<String> data:dataList){
                            //循环
                            ChongwuyongpinCommentbackEntity chongwuyongpinCommentbackEntity = new ChongwuyongpinCommentbackEntity();
//                            chongwuyongpinCommentbackEntity.setChongwuyongpinId(Integer.valueOf(data.get(0)));   //商品 要改的
//                            chongwuyongpinCommentbackEntity.setYonghuId(Integer.valueOf(data.get(0)));   //用户 要改的
//                            chongwuyongpinCommentbackEntity.setChongwuyongpinCommentbackText(data.get(0));                    //评价内容 要改的
//                            chongwuyongpinCommentbackEntity.setReplyText(data.get(0));                    //回复内容 要改的
//                            chongwuyongpinCommentbackEntity.setInsertTime(date);//时间
//                            chongwuyongpinCommentbackEntity.setUpdateTime(new Date(data.get(0)));          //回复时间 要改的
//                            chongwuyongpinCommentbackEntity.setCreateTime(date);//时间
                            chongwuyongpinCommentbackList.add(chongwuyongpinCommentbackEntity);


                            //把要查询是否重复的字段放入map中
                        }

                        //查询是否重复
                        chongwuyongpinCommentbackService.insertBatch(chongwuyongpinCommentbackList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }





    /**
    * 前端列表
    */
    @IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));

        // 没有指定排序字段就默认id倒序
        if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
            params.put("orderBy","id");
        }
        PageUtils page = chongwuyongpinCommentbackService.queryPage(params);

        //字典表数据转换
        List<ChongwuyongpinCommentbackView> list =(List<ChongwuyongpinCommentbackView>)page.getList();
        for(ChongwuyongpinCommentbackView c:list)
            dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
        return R.ok().put("data", page);
    }

    /**
    * 前端详情
    */
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        ChongwuyongpinCommentbackEntity chongwuyongpinCommentback = chongwuyongpinCommentbackService.selectById(id);
            if(chongwuyongpinCommentback !=null){


                //entity转view
                ChongwuyongpinCommentbackView view = new ChongwuyongpinCommentbackView();
                BeanUtils.copyProperties( chongwuyongpinCommentback , view );//把实体数据重构到view中

                //级联表
                    ChongwuyongpinEntity chongwuyongpin = chongwuyongpinService.selectById(chongwuyongpinCommentback.getChongwuyongpinId());
                if(chongwuyongpin != null){
                    BeanUtils.copyProperties( chongwuyongpin , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setChongwuyongpinId(chongwuyongpin.getId());
                }
                //级联表
                    YonghuEntity yonghu = yonghuService.selectById(chongwuyongpinCommentback.getYonghuId());
                if(yonghu != null){
                    BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setYonghuId(yonghu.getId());
                }
                //修改对应字典表字段
                dictionaryService.dictionaryConvert(view, request);
                return R.ok().put("data", view);
            }else {
                return R.error(511,"查不到数据");
            }
    }


    /**
    * 前端保存
    */
    @RequestMapping("/add")
    public R add(@RequestBody ChongwuyongpinCommentbackEntity chongwuyongpinCommentback, HttpServletRequest request){
        logger.debug("add方法:,,Controller:{},,chongwuyongpinCommentback:{}",this.getClass().getName(),chongwuyongpinCommentback.toString());
        chongwuyongpinCommentback.setInsertTime(new Date());
        chongwuyongpinCommentback.setCreateTime(new Date());
        chongwuyongpinCommentbackService.insert(chongwuyongpinCommentback);
        return R.ok();
        }


}


package com.controller;

import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;

import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;

/**
 * 商品订单
 * 后端接口
 * @author
 * @email
*/
@RestController
@Controller
@RequestMapping("/chongwuyongpinOrder")
public class ChongwuyongpinOrderController {
    private static final Logger logger = LoggerFactory.getLogger(ChongwuyongpinOrderController.class);

    @Autowired
    private ChongwuyongpinOrderService chongwuyongpinOrderService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;

    //级联表service
    @Autowired
    private AddressService addressService;
    @Autowired
    private ChongwuyongpinService chongwuyongpinService;
    @Autowired
    private YonghuService yonghuService;
@Autowired
private CartService cartService;
@Autowired
private ChongwuyongpinCommentbackService chongwuyongpinCommentbackService;



    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永不会进入");
        else if("用户".equals(role))
            params.put("yonghuId",request.getSession().getAttribute("userId"));
        if(params.get("orderBy")==null || params.get("orderBy")==""){
            params.put("orderBy","id");
        }
        PageUtils page = chongwuyongpinOrderService.queryPage(params);

        //字典表数据转换
        List<ChongwuyongpinOrderView> list =(List<ChongwuyongpinOrderView>)page.getList();
        for(ChongwuyongpinOrderView c:list){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c, request);
        }
        return R.ok().put("data", page);
    }

    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        ChongwuyongpinOrderEntity chongwuyongpinOrder = chongwuyongpinOrderService.selectById(id);
        if(chongwuyongpinOrder !=null){
            //entity转view
            ChongwuyongpinOrderView view = new ChongwuyongpinOrderView();
            BeanUtils.copyProperties( chongwuyongpinOrder , view );//把实体数据重构到view中

                //级联表
                AddressEntity address = addressService.selectById(chongwuyongpinOrder.getAddressId());
                if(address != null){
                    BeanUtils.copyProperties( address , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "yonghuId"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setAddressId(address.getId());
                    view.setAddressYonghuId(address.getYonghuId());
                }
                //级联表
                ChongwuyongpinEntity chongwuyongpin = chongwuyongpinService.selectById(chongwuyongpinOrder.getChongwuyongpinId());
                if(chongwuyongpin != null){
                    BeanUtils.copyProperties( chongwuyongpin , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setChongwuyongpinId(chongwuyongpin.getId());
                }
                //级联表
                YonghuEntity yonghu = yonghuService.selectById(chongwuyongpinOrder.getYonghuId());
                if(yonghu != null){
                    BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setYonghuId(yonghu.getId());
                }
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody ChongwuyongpinOrderEntity chongwuyongpinOrder, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,chongwuyongpinOrder:{}",this.getClass().getName(),chongwuyongpinOrder.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永远不会进入");
        else if("用户".equals(role))
            chongwuyongpinOrder.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));

        chongwuyongpinOrder.setInsertTime(new Date());
        chongwuyongpinOrder.setCreateTime(new Date());
        chongwuyongpinOrderService.insert(chongwuyongpinOrder);
        return R.ok();
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody ChongwuyongpinOrderEntity chongwuyongpinOrder, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,chongwuyongpinOrder:{}",this.getClass().getName(),chongwuyongpinOrder.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(false)
//            return R.error(511,"永远不会进入");
//        else if("用户".equals(role))
//            chongwuyongpinOrder.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
        //根据字段查询是否有相同数据
        Wrapper<ChongwuyongpinOrderEntity> queryWrapper = new EntityWrapper<ChongwuyongpinOrderEntity>()
            .eq("id",0)
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        ChongwuyongpinOrderEntity chongwuyongpinOrderEntity = chongwuyongpinOrderService.selectOne(queryWrapper);
        if(chongwuyongpinOrderEntity==null){
            chongwuyongpinOrderService.updateById(chongwuyongpinOrder);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        chongwuyongpinOrderService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        try {
            List<ChongwuyongpinOrderEntity> chongwuyongpinOrderList = new ArrayList<>();//上传的东西
            Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
            Date date = new Date();
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                return R.error(511,"该文件没有后缀");
            }else{
                String suffix = fileName.substring(lastIndexOf);
                if(!".xls".equals(suffix)){
                    return R.error(511,"只支持后缀为xls的excel文件");
                }else{
                    URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
                    File file = new File(resource.getFile());
                    if(!file.exists()){
                        return R.error(511,"找不到上传文件,请联系管理员");
                    }else{
                        List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
                        dataList.remove(0);//删除第一行,因为第一行是提示
                        for(List<String> data:dataList){
                            //循环
                            ChongwuyongpinOrderEntity chongwuyongpinOrderEntity = new ChongwuyongpinOrderEntity();
//                            chongwuyongpinOrderEntity.setChongwuyongpinOrderUuidNumber(data.get(0));                    //订单号 要改的
//                            chongwuyongpinOrderEntity.setAddressId(Integer.valueOf(data.get(0)));   //送货地址 要改的
//                            chongwuyongpinOrderEntity.setChongwuyongpinId(Integer.valueOf(data.get(0)));   //商品 要改的
//                            chongwuyongpinOrderEntity.setYonghuId(Integer.valueOf(data.get(0)));   //用户 要改的
//                            chongwuyongpinOrderEntity.setBuyNumber(Integer.valueOf(data.get(0)));   //购买数量 要改的
//                            chongwuyongpinOrderEntity.setChongwuyongpinOrderTruePrice(data.get(0));                    //实付价格 要改的
//                            chongwuyongpinOrderEntity.setChongwuyongpinOrderTypes(Integer.valueOf(data.get(0)));   //订单类型 要改的
//                            chongwuyongpinOrderEntity.setChongwuyongpinOrderPaymentTypes(Integer.valueOf(data.get(0)));   //支付类型 要改的
//                            chongwuyongpinOrderEntity.setInsertTime(date);//时间
//                            chongwuyongpinOrderEntity.setCreateTime(date);//时间
                            chongwuyongpinOrderList.add(chongwuyongpinOrderEntity);


                            //把要查询是否重复的字段放入map中
                                //订单号
                                if(seachFields.containsKey("chongwuyongpinOrderUuidNumber")){
                                    List<String> chongwuyongpinOrderUuidNumber = seachFields.get("chongwuyongpinOrderUuidNumber");
                                    chongwuyongpinOrderUuidNumber.add(data.get(0));//要改的
                                }else{
                                    List<String> chongwuyongpinOrderUuidNumber = new ArrayList<>();
                                    chongwuyongpinOrderUuidNumber.add(data.get(0));//要改的
                                    seachFields.put("chongwuyongpinOrderUuidNumber",chongwuyongpinOrderUuidNumber);
                                }
                        }

                        //查询是否重复
                         //订单号
                        List<ChongwuyongpinOrderEntity> chongwuyongpinOrderEntities_chongwuyongpinOrderUuidNumber = chongwuyongpinOrderService.selectList(new EntityWrapper<ChongwuyongpinOrderEntity>().in("chongwuyongpin_order_uuid_number", seachFields.get("chongwuyongpinOrderUuidNumber")));
                        if(chongwuyongpinOrderEntities_chongwuyongpinOrderUuidNumber.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(ChongwuyongpinOrderEntity s:chongwuyongpinOrderEntities_chongwuyongpinOrderUuidNumber){
                                repeatFields.add(s.getChongwuyongpinOrderUuidNumber());
                            }
                            return R.error(511,"数据库的该表中的 [订单号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                        chongwuyongpinOrderService.insertBatch(chongwuyongpinOrderList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }





    /**
    * 前端列表
    */
    @IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));

        // 没有指定排序字段就默认id倒序
        if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
            params.put("orderBy","id");
        }
        PageUtils page = chongwuyongpinOrderService.queryPage(params);

        //字典表数据转换
        List<ChongwuyongpinOrderView> list =(List<ChongwuyongpinOrderView>)page.getList();
        for(ChongwuyongpinOrderView c:list)
            dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
        return R.ok().put("data", page);
    }

    /**
    * 前端详情
    */
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        ChongwuyongpinOrderEntity chongwuyongpinOrder = chongwuyongpinOrderService.selectById(id);
            if(chongwuyongpinOrder !=null){


                //entity转view
                ChongwuyongpinOrderView view = new ChongwuyongpinOrderView();
                BeanUtils.copyProperties( chongwuyongpinOrder , view );//把实体数据重构到view中

                //级联表
                    AddressEntity address = addressService.selectById(chongwuyongpinOrder.getAddressId());
                if(address != null){
                    BeanUtils.copyProperties( address , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setAddressId(address.getId());
                }
                //级联表
                    ChongwuyongpinEntity chongwuyongpin = chongwuyongpinService.selectById(chongwuyongpinOrder.getChongwuyongpinId());
                if(chongwuyongpin != null){
                    BeanUtils.copyProperties( chongwuyongpin , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setChongwuyongpinId(chongwuyongpin.getId());
                }
                //级联表
                    YonghuEntity yonghu = yonghuService.selectById(chongwuyongpinOrder.getYonghuId());
                if(yonghu != null){
                    BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setYonghuId(yonghu.getId());
                }
                //修改对应字典表字段
                dictionaryService.dictionaryConvert(view, request);
                return R.ok().put("data", view);
            }else {
                return R.error(511,"查不到数据");
            }
    }


    /**
    * 前端保存
    */
    @RequestMapping("/add")
    public R add(@RequestBody ChongwuyongpinOrderEntity chongwuyongpinOrder, HttpServletRequest request){
        logger.debug("add方法:,,Controller:{},,chongwuyongpinOrder:{}",this.getClass().getName(),chongwuyongpinOrder.toString());
            ChongwuyongpinEntity chongwuyongpinEntity = chongwuyongpinService.selectById(chongwuyongpinOrder.getChongwuyongpinId());
            if(chongwuyongpinEntity == null){
                return R.error(511,"查不到该商品");
            }
            // Double chongwuyongpinNewMoney = chongwuyongpinEntity.getChongwuyongpinNewMoney();

            if(false){
            }
            else if((chongwuyongpinEntity.getChongwuyongpinKucunNumber() -chongwuyongpinOrder.getBuyNumber())<0){
                return R.error(511,"购买数量不能大于库存数量");
            }
            else if(chongwuyongpinEntity.getChongwuyongpinNewMoney() == null){
                return R.error(511,"商品价格不能为空");
            }

            //计算所获得积分
            Double buyJifen =0.0;
            Integer userId = (Integer) request.getSession().getAttribute("userId");
            YonghuEntity yonghuEntity = yonghuService.selectById(userId);
            if(yonghuEntity == null)
                return R.error(511,"用户不能为空");
            if(yonghuEntity.getNewMoney() == null)
                return R.error(511,"用户金额不能为空");
            double balance = yonghuEntity.getNewMoney() - chongwuyongpinEntity.getChongwuyongpinNewMoney()*chongwuyongpinOrder.getBuyNumber();//余额
            buyJifen = new BigDecimal(chongwuyongpinEntity.getChongwuyongpinPrice()).multiply(new BigDecimal(chongwuyongpinOrder.getBuyNumber())).doubleValue();//所获积分
            if(balance<0)
                return R.error(511,"余额不够支付");
            chongwuyongpinOrder.setChongwuyongpinOrderTypes(3); //设置订单状态为已支付
            chongwuyongpinOrder.setChongwuyongpinOrderTruePrice(chongwuyongpinEntity.getChongwuyongpinNewMoney()*chongwuyongpinOrder.getBuyNumber()); //设置实付价格
            chongwuyongpinOrder.setYonghuId(userId); //设置订单支付人id
            chongwuyongpinOrder.setChongwuyongpinOrderPaymentTypes(1);
            chongwuyongpinOrder.setInsertTime(new Date());
            chongwuyongpinOrder.setCreateTime(new Date());
                chongwuyongpinEntity.setChongwuyongpinKucunNumber( chongwuyongpinEntity.getChongwuyongpinKucunNumber() -chongwuyongpinOrder.getBuyNumber());
                chongwuyongpinService.updateById(chongwuyongpinEntity);
                chongwuyongpinOrderService.insert(chongwuyongpinOrder);//新增订单
            yonghuEntity.setNewMoney(balance);//设置金额
            yonghuService.updateById(yonghuEntity);
            return R.ok();
    }
    /**
     * 添加订单
     */
    @RequestMapping("/order")
    public R add(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("order方法:,,Controller:{},,params:{}",this.getClass().getName(),params.toString());
        String chongwuyongpinOrderUuidNumber = String.valueOf(new Date().getTime());

        //获取当前登录用户的id
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        Integer addressId = Integer.valueOf(String.valueOf(params.get("addressId")));

        Integer chongwuyongpinOrderPaymentTypes = Integer.valueOf(String.valueOf(params.get("chongwuyongpinOrderPaymentTypes")));//支付类型

        String data = String.valueOf(params.get("chongwuyongpins"));
        JSONArray jsonArray = JSON.parseArray(data);
        List<Map> chongwuyongpins = JSON.parseObject(jsonArray.toString(), List.class);

        //获取当前登录用户的个人信息
        YonghuEntity yonghuEntity = yonghuService.selectById(userId);

        //当前订单表
        List<ChongwuyongpinOrderEntity> chongwuyongpinOrderList = new ArrayList<>();
        //商品表
        List<ChongwuyongpinEntity> chongwuyongpinList = new ArrayList<>();
        //购物车ids
        List<Integer> cartIds = new ArrayList<>();

        BigDecimal zhekou = new BigDecimal(1.0);

        //循环取出需要的数据
        for (Map<String, Object> map : chongwuyongpins) {
           //取值
            Integer chongwuyongpinId = Integer.valueOf(String.valueOf(map.get("chongwuyongpinId")));//商品id
            Integer buyNumber = Integer.valueOf(String.valueOf(map.get("buyNumber")));//购买数量
            ChongwuyongpinEntity chongwuyongpinEntity = chongwuyongpinService.selectById(chongwuyongpinId);//购买的商品
            String id = String.valueOf(map.get("id"));
            if(StringUtil.isNotEmpty(id))
                cartIds.add(Integer.valueOf(id));

            //判断商品的库存是否足够
            if(chongwuyongpinEntity.getChongwuyongpinKucunNumber() < buyNumber){
                //商品库存不足直接返回
                return R.error(chongwuyongpinEntity.getChongwuyongpinName()+"的库存不足");
            }else{
                //商品库存充足就减库存
                chongwuyongpinEntity.setChongwuyongpinKucunNumber(chongwuyongpinEntity.getChongwuyongpinKucunNumber() - buyNumber);
            }

            //订单信息表增加数据
            ChongwuyongpinOrderEntity chongwuyongpinOrderEntity = new ChongwuyongpinOrderEntity<>();

            //赋值订单信息
            chongwuyongpinOrderEntity.setChongwuyongpinOrderUuidNumber(chongwuyongpinOrderUuidNumber);//订单号
            chongwuyongpinOrderEntity.setAddressId(addressId);//送货地址
            chongwuyongpinOrderEntity.setChongwuyongpinId(chongwuyongpinId);//商品
            chongwuyongpinOrderEntity.setYonghuId(userId);//用户
            chongwuyongpinOrderEntity.setBuyNumber(buyNumber);//购买数量 ??????
            chongwuyongpinOrderEntity.setChongwuyongpinOrderTypes(3);//订单类型
            chongwuyongpinOrderEntity.setChongwuyongpinOrderPaymentTypes(chongwuyongpinOrderPaymentTypes);//支付类型
            chongwuyongpinOrderEntity.setInsertTime(new Date());//订单创建时间
            chongwuyongpinOrderEntity.setCreateTime(new Date());//创建时间

            //判断是什么支付方式 1代表余额 2代表积分
            if(chongwuyongpinOrderPaymentTypes == 1){//余额支付
                //计算金额
                Double money = new BigDecimal(chongwuyongpinEntity.getChongwuyongpinNewMoney()).multiply(new BigDecimal(buyNumber)).multiply(zhekou).doubleValue();

                if(yonghuEntity.getNewMoney() - money <0 ){
                    return R.error("余额不足,请充值!!!");
                }else{
                    //计算所获得积分
                    Double buyJifen =0.0;
                        buyJifen = new BigDecimal(chongwuyongpinEntity.getChongwuyongpinPrice()).multiply(new BigDecimal(buyNumber)).doubleValue();
                    yonghuEntity.setNewMoney(yonghuEntity.getNewMoney() - money); //设置金额


                    chongwuyongpinOrderEntity.setChongwuyongpinOrderTruePrice(money);

                }
            }
            chongwuyongpinOrderList.add(chongwuyongpinOrderEntity);
            chongwuyongpinList.add(chongwuyongpinEntity);

        }
        chongwuyongpinOrderService.insertBatch(chongwuyongpinOrderList);
        chongwuyongpinService.updateBatchById(chongwuyongpinList);
        yonghuService.updateById(yonghuEntity);
        if(cartIds != null && cartIds.size()>0)
            cartService.deleteBatchIds(cartIds);
        return R.ok();
    }











    /**
    * 退款
    */
    @RequestMapping("/refund")
    public R refund(Integer id, HttpServletRequest request){
        logger.debug("refund方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        String role = String.valueOf(request.getSession().getAttribute("role"));

            ChongwuyongpinOrderEntity chongwuyongpinOrder = chongwuyongpinOrderService.selectById(id);
            Integer buyNumber = chongwuyongpinOrder.getBuyNumber();
            Integer chongwuyongpinOrderPaymentTypes = chongwuyongpinOrder.getChongwuyongpinOrderPaymentTypes();
            Integer chongwuyongpinId = chongwuyongpinOrder.getChongwuyongpinId();
            if(chongwuyongpinId == null)
                return R.error(511,"查不到该商品");
            ChongwuyongpinEntity chongwuyongpinEntity = chongwuyongpinService.selectById(chongwuyongpinId);
            if(chongwuyongpinEntity == null)
                return R.error(511,"查不到该商品");
            Double chongwuyongpinNewMoney = chongwuyongpinEntity.getChongwuyongpinNewMoney();
            if(chongwuyongpinNewMoney == null)
                return R.error(511,"商品价格不能为空");

            Integer userId = (Integer) request.getSession().getAttribute("userId");
            YonghuEntity yonghuEntity = yonghuService.selectById(userId);
            if(yonghuEntity == null)
                return R.error(511,"用户不能为空");
            if(yonghuEntity.getNewMoney() == null)
                return R.error(511,"用户金额不能为空");

            Double zhekou = 1.0;


            //判断是什么支付方式 1代表余额 2代表积分
            if(chongwuyongpinOrderPaymentTypes == 1){//余额支付
                //计算金额
                Double money = chongwuyongpinEntity.getChongwuyongpinNewMoney() * buyNumber  * zhekou;
                //计算所获得积分
                Double buyJifen = 0.0;
                buyJifen = new BigDecimal(chongwuyongpinEntity.getChongwuyongpinPrice()).multiply(new BigDecimal(buyNumber)).doubleValue();
                yonghuEntity.setNewMoney(yonghuEntity.getNewMoney() + money); //设置金额


            }

            chongwuyongpinEntity.setChongwuyongpinKucunNumber(chongwuyongpinEntity.getChongwuyongpinKucunNumber() + buyNumber);



            chongwuyongpinOrder.setChongwuyongpinOrderTypes(2);//设置订单状态为退款
            chongwuyongpinOrderService.updateById(chongwuyongpinOrder);//根据id更新
            yonghuService.updateById(yonghuEntity);//更新用户信息
            chongwuyongpinService.updateById(chongwuyongpinEntity);//更新订单中商品的信息
            return R.ok();
    }


    /**
     * 发货
     */
    @RequestMapping("/deliver")
    public R deliver(Integer id ){
        logger.debug("refund:,,Controller:{},,ids:{}",this.getClass().getName(),id.toString());
        ChongwuyongpinOrderEntity  chongwuyongpinOrderEntity = new  ChongwuyongpinOrderEntity();;
        chongwuyongpinOrderEntity.setId(id);
        chongwuyongpinOrderEntity.setChongwuyongpinOrderTypes(4);
        boolean b =  chongwuyongpinOrderService.updateById( chongwuyongpinOrderEntity);
        if(!b){
            return R.error("发货出错");
        }
        return R.ok();
    }









    /**
     * 收货
     */
    @RequestMapping("/receiving")
    public R receiving(Integer id){
        logger.debug("refund:,,Controller:{},,ids:{}",this.getClass().getName(),id.toString());
        ChongwuyongpinOrderEntity  chongwuyongpinOrderEntity = new  ChongwuyongpinOrderEntity();
        chongwuyongpinOrderEntity.setId(id);
        chongwuyongpinOrderEntity.setChongwuyongpinOrderTypes(5);
        boolean b =  chongwuyongpinOrderService.updateById( chongwuyongpinOrderEntity);
        if(!b){
            return R.error("收货出错");
        }
        return R.ok();
    }



    /**
    * 评价
    */
    @RequestMapping("/commentback")
    public R commentback(Integer id, String commentbackText, Integer chongwuyongpinCommentbackPingfenNumber, HttpServletRequest request){
        logger.debug("commentback方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
            ChongwuyongpinOrderEntity chongwuyongpinOrder = chongwuyongpinOrderService.selectById(id);
        if(chongwuyongpinOrder == null)
            return R.error(511,"查不到该订单");
        if(chongwuyongpinOrder.getChongwuyongpinOrderTypes() != 5)
            return R.error(511,"您不能评价");
        Integer chongwuyongpinId = chongwuyongpinOrder.getChongwuyongpinId();
        if(chongwuyongpinId == null)
            return R.error(511,"查不到该商品");

        ChongwuyongpinCommentbackEntity chongwuyongpinCommentbackEntity = new ChongwuyongpinCommentbackEntity();
            chongwuyongpinCommentbackEntity.setId(id);
            chongwuyongpinCommentbackEntity.setChongwuyongpinId(chongwuyongpinId);
            chongwuyongpinCommentbackEntity.setYonghuId((Integer) request.getSession().getAttribute("userId"));
            chongwuyongpinCommentbackEntity.setChongwuyongpinCommentbackText(commentbackText);
            chongwuyongpinCommentbackEntity.setReplyText(null);
            chongwuyongpinCommentbackEntity.setInsertTime(new Date());
            chongwuyongpinCommentbackEntity.setUpdateTime(null);
            chongwuyongpinCommentbackEntity.setCreateTime(new Date());
            chongwuyongpinCommentbackService.insert(chongwuyongpinCommentbackEntity);

            chongwuyongpinOrder.setChongwuyongpinOrderTypes(1);//设置订单状态为已评价
            chongwuyongpinOrderService.updateById(chongwuyongpinOrder);//根据id更新
            return R.ok();
    }







}

package com.controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSON;
import com.utils.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.annotation.IgnoreAuth;
import com.baidu.aip.face.AipFace;
import com.baidu.aip.face.MatchRequest;
import com.baidu.aip.util.Base64Util;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.ConfigEntity;
import com.service.CommonService;
import com.service.ConfigService;
import com.utils.BaiduUtil;
import com.utils.FileUtil;
import com.utils.R;

/**
 * 通用接口
 */
@RestController
public class CommonController{
	private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
	@Autowired
	private CommonService commonService;
	
	@Autowired
	private ConfigService configService;
	
	private static AipFace client = null;
	
	private static String BAIDU_DITU_AK = null;
	
	@RequestMapping("/location")
	public R location(String lng,String lat) {
		if(BAIDU_DITU_AK==null) {
			BAIDU_DITU_AK = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "baidu_ditu_ak")).getValue();
			if(BAIDU_DITU_AK==null) {
				return R.error("请在配置管理中正确配置baidu_ditu_ak");
			}
		}
		Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat);
		return R.ok().put("data", map);
	}
	
	/**
	 * 人脸比对
	 * 
	 * @param face1 人脸1
	 * @param face2 人脸2
	 * @return
	 */
	@RequestMapping("/matchFace")
	public R matchFace(String face1, String face2, HttpServletRequest request) {
		if(client==null) {
			/*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
			String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
			String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
			String token = BaiduUtil.getAuth(APIKey, SecretKey);
			if(token==null) {
				return R.error("请在配置管理中正确配置APIKey和SecretKey");
			}
			client = new AipFace(null, APIKey, SecretKey);
			client.setConnectionTimeoutInMillis(2000);
			client.setSocketTimeoutInMillis(60000);
		}
		JSONObject res = null;
		try {
			File file1 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face1);
			File file2 = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+face2);
			String img1 = Base64Util.encode(FileUtil.FileToByte(file1));
			String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
			MatchRequest req1 = new MatchRequest(img1, "BASE64");
			MatchRequest req2 = new MatchRequest(img2, "BASE64");
			ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
			requests.add(req1);
			requests.add(req2);
			res = client.match(requests);
			System.out.println(res.get("result"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return R.error("文件不存在");
		} catch (IOException e) {
			e.printStackTrace();
		} 
		return R.ok().put("data", com.alibaba.fastjson.JSONObject.parse(res.get("result").toString()));
	}
    
	/**
	 * 获取table表中的column列表(联动接口)
	 * @return
	 */
	@RequestMapping("/option/{tableName}/{columnName}")
	@IgnoreAuth
	public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("table", tableName);
		params.put("column", columnName);
		if(StringUtils.isNotBlank(level)) {
			params.put("level", level);
		}
		if(StringUtils.isNotBlank(parent)) {
			params.put("parent", parent);
		}
		List<String> data = commonService.getOption(params);
		return R.ok().put("data", data);
	}
	
	/**
	 * 根据table中的column获取单条记录
	 * @return
	 */
	@RequestMapping("/follow/{tableName}/{columnName}")
	@IgnoreAuth
	public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("table", tableName);
		params.put("column", columnName);
		params.put("columnValue", columnValue);
		Map<String, Object> result = commonService.getFollowByOption(params);
		return R.ok().put("data", result);
	}
	
	/**
	 * 修改table表的sfsh状态
	 * @param map
	 * @return
	 */
	@RequestMapping("/sh/{tableName}")
	public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
		map.put("table", tableName);
		commonService.sh(map);
		return R.ok();
	}
	
	/**
	 * 获取需要提醒的记录数
	 * @param tableName
	 * @param columnName
	 * @param type 1:数字 2:日期
	 * @param map
	 * @return
	 */
	@RequestMapping("/remind/{tableName}/{columnName}/{type}")
	@IgnoreAuth
	public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, 
						 @PathVariable("type") String type,@RequestParam Map<String, Object> map) {
		map.put("table", tableName);
		map.put("column", columnName);
		map.put("type", type);
		
		if(type.equals("2")) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar c = Calendar.getInstance();
			Date remindStartDate = null;
			Date remindEndDate = null;
			if(map.get("remindstart")!=null) {
				Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
				c.setTime(new Date()); 
				c.add(Calendar.DAY_OF_MONTH,remindStart);
				remindStartDate = c.getTime();
				map.put("remindstart", sdf.format(remindStartDate));
			}
			if(map.get("remindend")!=null) {
				Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
				c.setTime(new Date());
				c.add(Calendar.DAY_OF_MONTH,remindEnd);
				remindEndDate = c.getTime();
				map.put("remindend", sdf.format(remindEndDate));
			}
		}
		
		int count = commonService.remindCount(map);
		return R.ok().put("count", count);
	}

	/**
	 * 圖表统计
	 */
	@IgnoreAuth
	@RequestMapping("/group/{tableName}")
	public R group1(@PathVariable("tableName") String tableName, @RequestParam Map<String,Object> params) {
		params.put("table1", tableName);
		List<Map<String, Object>> result = commonService.chartBoth(params);
		return R.ok().put("data", result);
	}


	/**
	 * 单列求和
	 */
	@RequestMapping("/cal/{tableName}/{columnName}")
	@IgnoreAuth
	public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("table", tableName);
		params.put("column", columnName);
		Map<String, Object> result = commonService.selectCal(params);
		return R.ok().put("data", result);
	}
	
	/**
	 * 分组统计
	 */
	@RequestMapping("/group/{tableName}/{columnName}")
	@IgnoreAuth
	public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("table", tableName);
		params.put("column", columnName);
		List<Map<String, Object>> result = commonService.selectGroup(params);
		return R.ok().put("data", result);
	}
	
	/**
	 * (按值统计)
	 */
	@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
	@IgnoreAuth
	public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("table", tableName);
		params.put("xColumn", xColumnName);
		params.put("yColumn", yColumnName);
		List<Map<String, Object>> result = commonService.selectValue(params);
		return R.ok().put("data", result);
	}


	/**
	 * 下面为新加的
	 *
	 *
	 *
	 */

	/**
	 * 查询字典表的分组求和
	 * tableName  		表名
	 * groupColumn  		分组字段
	 * sumCloum			统计字段
	 * @return
	 */
	@RequestMapping("/newSelectGroupSum")
	public R newSelectGroupSum(@RequestParam Map<String,Object> params) {
		logger.debug("newSelectGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params);
		List<Map<String, Object>> result = commonService.newSelectGroupSum(params);
		return R.ok().put("data", result);
	}


    /**
     tableName 查询表
     condition1 条件1
     condition1Value 条件1值
     average 计算平均评分

     取值
        有值 Number(res.data.value.toFixed(1))
        无值 if(res.data){}
     * */
    @IgnoreAuth
    @RequestMapping("/queryScore")
    public R queryScore(@RequestParam Map<String, Object> params) {
        logger.debug("queryScore:,,Controller:{},,params:{}",this.getClass().getName(),params);
        Map<String, Object> queryScore = commonService.queryScore(params);
        return R.ok().put("data", queryScore);
    }

	/**
	 * 查询字典表的分组统计总条数
	 *  tableName  		表名
	 *	groupColumn  	分组字段
	 * @return
	 */
	@RequestMapping("/newSelectGroupCount")
	public R newSelectGroupCount(@RequestParam Map<String,Object> params) {
		logger.debug("newSelectGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params);
		List<Map<String, Object>> result = commonService.newSelectGroupCount(params);
		return R.ok().put("data", result);
	}


	/**
	 * 当前表的日期分组求和
	 * tableName  		表名
	 * groupColumn  		分组字段
	 * sumCloum			统计字段
	 * dateFormatType	日期格式化类型   1:年 2:月 3:日
	 * @return
	 */
	@RequestMapping("/newSelectDateGroupSum")
	public R newSelectDateGroupSum(@RequestParam Map<String,Object> params) {
		logger.debug("newSelectDateGroupSum:,,Controller:{},,params:{}",this.getClass().getName(),params);
		String dateFormatType = String.valueOf(params.get("dateFormatType"));
		if("1".equals(dateFormatType)){
			params.put("dateFormat", "%Y");
		}else if("2".equals(dateFormatType)){
			params.put("dateFormat", "%Y-%m");
		}else if("3".equals(dateFormatType)){
			params.put("dateFormat", "%Y-%m-%d");
		}else{
			R.error("日期格式化不正确");
		}
		List<Map<String, Object>> result = commonService.newSelectDateGroupSum(params);
		return R.ok().put("data", result);
	}

	/**
	 *
	 * 查询字典表的分组统计总条数
	 * tableName  		表名
	 * groupColumn  		分组字段
	 * dateFormatType	日期格式化类型   1:年 2:月 3:日
	 * @return
	 */
	@RequestMapping("/newSelectDateGroupCount")
	public R newSelectDateGroupCount(@RequestParam Map<String,Object> params) {
		logger.debug("newSelectDateGroupCount:,,Controller:{},,params:{}",this.getClass().getName(),params);
		String dateFormatType = String.valueOf(params.get("dateFormatType"));
		if("1".equals(dateFormatType)){
			params.put("dateFormat", "%Y");
		}else if("2".equals(dateFormatType)){
			params.put("dateFormat", "%Y-%m");
		}else if("3".equals(dateFormatType)){
			params.put("dateFormat", "%Y-%m-%d");
		}else{
			R.error("日期格式化类型不正确");
		}
		List<Map<String, Object>> result = commonService.newSelectDateGroupCount(params);
		return R.ok().put("data", result);
	}
/**
 * 饼状图
 * -- 饼状图  查询当前表
 -- 				查询字典表【月】
 -- 				 统计   -- 查询某个月的每个类型的订单销售数量
 -- 				 求和   -- 查询某个月的每个类型的订单销售额
 -- 				查询某个字符串【月】
 -- 				 统计   -- 查询某个月的每个员工的订单销售数量
 -- 				 求和   -- 查询某个月的每个员工的订单销售额
 -- 				查询时间【年】
 -- 				 统计 	-- 查询每个月的订单销售数量
 -- 				 求和 	-- 查询每个月的订单销售额
 -- 饼状图  查询级联表
 -- 				查询字典表
 -- 				 统计  	-- 查询某个月的每个类型的订单销售数量
 -- 				 求和   -- 查询某个月的每个类型的订单销售额
 -- 				查询某个字符串
 -- 				 统计   -- 查询某个月的每个员工的订单销售数量
 -- 				 求和   -- 查询某个月的每个员工的订单销售额
 -- 				查询时间
 -- 				 统计 	-- 统计每个月的订单销售数量
 -- 				 求和 	-- 查询每个月的订单销售额
 */


/**
 * 柱状图
 -- 柱状图  查询当前表
 --             某个【年,月】
 -- 			 当前表 2 级联表 1
 -- 						统计
 --   						【日期,字符串,下拉框】
 -- 						求和
 --   						【日期,字符串,下拉框】
 -- 柱状图  查询级联表
 -- 					某个【年,月】
 -- 						统计
 --   						【日期,字符串,下拉框】
 -- 						求和
 --   						【日期,字符串,下拉框】
 */

    /**
     * 柱状图求和
     */
    @RequestMapping("/barSum")
    public R barSum(@RequestParam Map<String,Object> params) {
        logger.debug("barSum方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params));
        Boolean isJoinTableFlag =  false;//是否有级联表相关
        String one =  "";//第一优先
        String two =  "";//第二优先

		//处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组
			//当前表
			Map<String,Object> thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class);
			params.put("thisTable",thisTable);

			//级联表
			String joinTableString = String.valueOf(params.get("joinTable"));
			if(StringUtil.isNotEmpty(joinTableString)) {
				Map<String, Object> joinTable = JSON.parseObject(joinTableString, Map.class);
				params.put("joinTable", joinTable);
				isJoinTableFlag = true;
			}

		if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期
			thisTable.put("date",String.valueOf(thisTable.get("date")).split(","));
			one = "thisDate0";
		}
		if(isJoinTableFlag){//级联表日期
			Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
			if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){
				joinTable.put("date",String.valueOf(joinTable.get("date")).split(","));
				if(StringUtil.isEmpty(one)){
					one ="joinDate0";
				}else{
					if(StringUtil.isEmpty(two)){
						two ="joinDate0";
					}
				}
			}
		}
		if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串
			thisTable.put("string",String.valueOf(thisTable.get("string")).split(","));
			if(StringUtil.isEmpty(one)){
				one ="thisString0";
			}else{
				if(StringUtil.isEmpty(two)){
					two ="thisString0";
				}
			}
		}
		if(isJoinTableFlag){//级联表字符串
			Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
			if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){
				joinTable.put("string",String.valueOf(joinTable.get("string")).split(","));
				if(StringUtil.isEmpty(one)){
					one ="joinString0";
				}else{
					if(StringUtil.isEmpty(two)){
						two ="joinString0";
					}
				}
			}
		}
		if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型
			thisTable.put("types",String.valueOf(thisTable.get("types")).split(","));
			if(StringUtil.isEmpty(one)){
				one ="thisTypes0";
			}else{
				if(StringUtil.isEmpty(two)){
					two ="thisTypes0";
				}
			}
		}
		if(isJoinTableFlag){//级联表类型
			Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
			if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){
				joinTable.put("types",String.valueOf(joinTable.get("types")).split(","));
				if(StringUtil.isEmpty(one)){
					one ="joinTypes0";
				}else{
					if(StringUtil.isEmpty(two)){
						two ="joinTypes0";
					}
				}

			}
		}

		List<Map<String, Object>> result = commonService.barSum(params);

		List<String> xAxis = new ArrayList<>();//报表x轴
		List<List<String>> yAxis = new ArrayList<>();//y轴
		List<String> legend = new ArrayList<>();//标题

		if(StringUtil.isEmpty(two)){//不包含第二列
			List<String> yAxis0 = new ArrayList<>();
			yAxis.add(yAxis0);
			legend.add("数值");
			for(Map<String, Object> map :result){
				String oneValue = String.valueOf(map.get(one));
				String value = String.valueOf(map.get("value"));
				xAxis.add(oneValue);
				yAxis0.add(value);
			}
		}else{//包含第二列
			Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
			if(StringUtil.isNotEmpty(two)){
				for(Map<String, Object> map :result){
					String oneValue = String.valueOf(map.get(one));
					String twoValue = String.valueOf(map.get(two));
					String value = String.valueOf(map.get("value"));
					if(!legend.contains(twoValue)){
						legend.add(twoValue);//添加完成后 就是最全的第二列的类型
					}
					if(dataMap.containsKey(oneValue)){
						dataMap.get(oneValue).put(twoValue,value);
					}else{
						HashMap<String, String> oneData = new HashMap<>();
						oneData.put(twoValue,value);
						dataMap.put(oneValue,oneData);
					}

				}
			}

			for(int i =0; i<legend.size(); i++){
				yAxis.add(new ArrayList<String>());
			}

			Set<String> keys = dataMap.keySet();
			for(String key:keys){
				xAxis.add(key);
				HashMap<String, String> map = dataMap.get(key);
				for(int i =0; i<legend.size(); i++){
					List<String> data = yAxis.get(i);
					if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
						data.add(map.get(legend.get(i)));
					}else{
						data.add("0");
					}
				}
			}
			System.out.println();
		}

		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("xAxis",xAxis);
		resultMap.put("yAxis",yAxis);
		resultMap.put("legend",legend);
		return R.ok().put("data", resultMap);
    }
	
	/**
     * 柱状图统计
     */
    @RequestMapping("/barCount")
    public R barCount(@RequestParam Map<String,Object> params) {
        logger.debug("barCount方法:,,Controller:{},,params:{}",this.getClass().getName(), com.alibaba.fastjson.JSONObject.toJSONString(params));
        Boolean isJoinTableFlag =  false;//是否有级联表相关
        String one =  "";//第一优先
        String two =  "";//第二优先

		//处理thisTable和joinTable 处理内容是把json字符串转为Map并把带有,的切割为数组
			//当前表
			Map<String,Object> thisTable = JSON.parseObject(String.valueOf(params.get("thisTable")),Map.class);
			params.put("thisTable",thisTable);

			//级联表
			String joinTableString = String.valueOf(params.get("joinTable"));
			if(StringUtil.isNotEmpty(joinTableString)) {
				Map<String, Object> joinTable = JSON.parseObject(joinTableString, Map.class);
				params.put("joinTable", joinTable);
				isJoinTableFlag = true;
			}

		if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("date")))){//当前表日期
			thisTable.put("date",String.valueOf(thisTable.get("date")).split(","));
			one = "thisDate0";
		}
		if(isJoinTableFlag){//级联表日期
			Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
			if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("date")))){
				joinTable.put("date",String.valueOf(joinTable.get("date")).split(","));
				if(StringUtil.isEmpty(one)){
					one ="joinDate0";
				}else{
					if(StringUtil.isEmpty(two)){
						two ="joinDate0";
					}
				}
			}
		}
		if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("string")))){//当前表字符串
			thisTable.put("string",String.valueOf(thisTable.get("string")).split(","));
			if(StringUtil.isEmpty(one)){
				one ="thisString0";
			}else{
				if(StringUtil.isEmpty(two)){
					two ="thisString0";
				}
			}
		}
		if(isJoinTableFlag){//级联表字符串
			Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
			if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("string")))){
				joinTable.put("string",String.valueOf(joinTable.get("string")).split(","));
				if(StringUtil.isEmpty(one)){
					one ="joinString0";
				}else{
					if(StringUtil.isEmpty(two)){
						two ="joinString0";
					}
				}
			}
		}
		if(StringUtil.isNotEmpty(String.valueOf(thisTable.get("types")))){//当前表类型
			thisTable.put("types",String.valueOf(thisTable.get("types")).split(","));
			if(StringUtil.isEmpty(one)){
				one ="thisTypes0";
			}else{
				if(StringUtil.isEmpty(two)){
					two ="thisTypes0";
				}
			}
		}
		if(isJoinTableFlag){//级联表类型
			Map<String, Object> joinTable = (Map<String, Object>) params.get("joinTable");
			if(StringUtil.isNotEmpty(String.valueOf(joinTable.get("types")))){
				joinTable.put("types",String.valueOf(joinTable.get("types")).split(","));
				if(StringUtil.isEmpty(one)){
					one ="joinTypes0";
				}else{
					if(StringUtil.isEmpty(two)){
						two ="joinTypes0";
					}
				}

			}
		}

		List<Map<String, Object>> result = commonService.barCount(params);

		List<String> xAxis = new ArrayList<>();//报表x轴
		List<List<String>> yAxis = new ArrayList<>();//y轴
		List<String> legend = new ArrayList<>();//标题

		if(StringUtil.isEmpty(two)){//不包含第二列
			List<String> yAxis0 = new ArrayList<>();
			yAxis.add(yAxis0);
			legend.add("数值");
			for(Map<String, Object> map :result){
				String oneValue = String.valueOf(map.get(one));
				String value = String.valueOf(map.get("value"));
				xAxis.add(oneValue);
				yAxis0.add(value);
			}
		}else{//包含第二列
			Map<String, HashMap<String, String>> dataMap = new LinkedHashMap<>();
			if(StringUtil.isNotEmpty(two)){
				for(Map<String, Object> map :result){
					String oneValue = String.valueOf(map.get(one));
					String twoValue = String.valueOf(map.get(two));
					String value = String.valueOf(map.get("value"));
					if(!legend.contains(twoValue)){
						legend.add(twoValue);//添加完成后 就是最全的第二列的类型
					}
					if(dataMap.containsKey(oneValue)){
						dataMap.get(oneValue).put(twoValue,value);
					}else{
						HashMap<String, String> oneData = new HashMap<>();
						oneData.put(twoValue,value);
						dataMap.put(oneValue,oneData);
					}

				}
			}

			for(int i =0; i<legend.size(); i++){
				yAxis.add(new ArrayList<String>());
			}

			Set<String> keys = dataMap.keySet();
			for(String key:keys){
				xAxis.add(key);
				HashMap<String, String> map = dataMap.get(key);
				for(int i =0; i<legend.size(); i++){
					List<String> data = yAxis.get(i);
					if(StringUtil.isNotEmpty(map.get(legend.get(i)))){
						data.add(map.get(legend.get(i)));
					}else{
						data.add("0");
					}
				}
			}
			System.out.println();
		}

		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("xAxis",xAxis);
		resultMap.put("yAxis",yAxis);
		resultMap.put("legend",legend);
		return R.ok().put("data", resultMap);
    }
}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JAVA编码选手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值