基于springboot vue前后端分离蛋糕甜品销售商城平台

近年来随着经济的飞速发展,互联网成为了大家开展信息传达的关键专用工具,与此同时, 一种一个全新的商贸活动已经产生,即通过网络进行一定的经贸买卖。电商这一一个全新的交易方式打破传统运营模式,根据蛋糕甜品商城开展网络购物早已成为人们工作中生活不可或缺的一部分,大众的生活方法发生了很好地更改。它是以快速的物流速度、便捷的买东西方式、较好的售后维修服务,日益变成信息化、全球经济一体化 一个重要主要用途。近些年在我国信息化基本建设尤其快速,在我国用户数量巨大,可是 在我国蛋糕甜品商城的应用远远不如欧美国家。能够推断在我国经济发展蛋糕甜品商城,发展趋势潜 力极大,市场潜力也非常大。意识到蛋糕甜品器件经贸的发展前景和价格的优势,许多企业都 应用网络平台销售蛋糕甜品。根据服务提供商如淘宝所提供的服务平台商城来搭建自已的在网上商 城非常简单,可是公司极为重要的信息如网站域名、蛋糕甜品信息都能通过第三方位消费者展现,因 此这种公司的信息安全性存有极大安全隐患,对以后发展趋势也会产生不良的影响。因而,蛋糕甜品商城自主的开发营销推广刻不容缓。

该系统是一个根据Web的销售平台,关键完成了一个灵便、可扩展性、界面友好的市场销售管理系统。系统带来了强悍的数据库管理、精确高效率的数据分析、迅速灵活多变的数据统计、客户管理等服务。前端采用 VUE等技术来设计一个界面简洁、易用性高和用户 友好性好的人机交互界面; 后面采用SpringbBoot Mybatis等新技术来建设一个易管理方法、易上手、安全系数高、灵便,拓展和信息高效、动态性、互动浏览的管理系统;整体完成一个数据可视化、专业化和简洁变的产品销售管理平台。

关键字: 电商平台;前后端分离;SpringBoot Vue;Mysql

【721】基于springboot vue前后端分离蛋糕甜品销售商城平台源码和论文含代码讲解

ABSTRACT

In recent years, with the rapid development of social economy, Internet technology has become an important and commonly used tool for everyone to carry out information transmission. In addition, a new economic and trade activity has been created, that is, certain economic and trade transactions are conducted through the Internet. E-commerce, a new trading rule, has changed the traditional business model. Online shopping based on e-commerce malls has become an indispensable part of everyone's work and life, and the public's lifestyle has changed better. With fast logistics speed, convenient shopping methods and better after-sales service, it has increasingly become an important application scope of information technology and world economic integration. In recent years, the informatization infrastructure projects in China are especially rapid, with a large number of users in China, but the application in electronic malls in China is far less than that in European and American countries. It can be inferred that in China's social and economic development of electronic malls, the development trend has huge potential and market prospects are also very large. Aware of the advantages of price in the future development trend of electronic component economy and trade, many enterprises use the Internet platform to sell products. It is relatively simple to build your own online mall based on the comprehensive service platform mall system provided by service providers such as Taobao. However, the crucial information of enterprises, such as domain names and product information, can be presented to customers through a third party. Therefore, the information security coefficient of such companies has a great security risk, which will also have a negative impact on the future development trend. Therefore, it is imperative for E-mall to develop network marketing independently。

This system is a sales website based on the Web, which realizes a flexible, extensible and user-friendly industry sales system. The system software adds powerful data management, accurate and more efficient data statistics and analysis, fast and flexible data analysis, customer relationship management and other work. In the front, VUE and other new technologies are selected to design a simple, convenient and user-friendly human-computer interaction; Later, SpringbBoot Mybatis and other technologies are selected to build an intelligent management system that is easy to manage, easy to operate, high in security performance, flexible, efficient in expansion and information, dynamic, interactive communication and access; In general, a big data visualization, systematization and simplification become commodity sales management system。

Keywords: e-commerce platform; Static page; SpringBoot Vue; Mysql

package com.example.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.auth0.jwt.JWT;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.dto.PreOrderQo;
import com.example.entity.*;
import com.example.exception.CustomException;
import com.example.service.*;
import org.json.JSONException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/order")
public class OrderController {
    @Resource
    private OrderService orderService;
    @Resource
    private HttpServletRequest request;
    @Resource
    private UserService userService;
    @Resource
    private CartService cartService;
    @Resource
    private OrderGoodsService orderGoodsService;
    @Resource
    private GoodsService goodsService;

    public User getUser() {
        String token = request.getHeader("token");
        String username = JWT.decode(token).getAudience().get(0);
        return userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, username));
    }

    @Transactional
    @PostMapping
    public Result<?> save(@RequestBody Order order) {
        order.setUserId(getUser().getId());
        order.setOrderNo(DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomNumbers(6));
        order.setCreateTime(DateUtil.now());

        String cartsStr = order.getCarts();
        List<Cart> carts = JSONUtil.toBean(cartsStr, new TypeReference<List<Cart>>() {
        }, true);
        orderService.save(order);

        for (Cart cart : carts) {
            Integer count = cart.getCount();
            Long goodsId = cart.getGoodsId();

            // 扣库存
            Goods goods = goodsService.getById(goodsId);
            if(goods.getStore() - cart.getCount() < 0) {
                throw new CustomException("-1", "库存不足");
            }
            goods.setStore(goods.getStore() - cart.getCount());
            goods.setSales(goods.getSales() + cart.getCount());
            goodsService.updateById(goods);

            OrderGoods orderGoods = new OrderGoods();
            orderGoods.setOrderId(order.getId());
            orderGoods.setGoodsId(goodsId);
            orderGoods.setCount(count);
            orderGoodsService.save(orderGoods);
        }

        if (order.getType() == 1) {  // 1表示购物车,0表示直接购买
            // 提交订单时清空个人的购物车商品
            cartService.remove(Wrappers.<Cart>lambdaUpdate().eq(Cart::getUserId, getUser().getId()));
        }

        return Result.success(order);
    }

    @PutMapping
    public Result<?> update(@RequestBody Order order) {
        orderService.updateById(order);
        return Result.success();
    }

    /**
     * 付款
     * @param id
     * @return
     */
    @Transactional
    @PutMapping("/pay/{id}")
    public Result<?> pay(@PathVariable Long id) {
        Order order = orderService.getById(id);
        BigDecimal totalPrice = order.getTotalPrice();

        Long userId = getUser().getId();
        User user = userService.findById(userId);

        if (user.getAccount().compareTo(totalPrice) <= 0) {
            throw new CustomException("-1", "余额不足");
        }

        user.setAccount(user.getAccount().subtract(totalPrice)); // 设置用户余额
        userService.updateById(user);
        order.setState("待发货");
        orderService.updateById(order);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        orderService.removeById(id);
        return Result.success();
    }

    /**
     * 获取订单的确认信息
     *
     * @return
     */
    @PostMapping("/pre")
    public Result<?> pre(@RequestBody PreOrderQo preOrderQo) throws JSONException {
        String cartsStr = preOrderQo.getCarts();
        // 讲前台传来的json字符串转换成 list对象
        List<Cart> carts = JSONUtil.toBean(cartsStr, new TypeReference<List<Cart>>() {
        }, true);
        Map<String, Object> all = cartService.findAll(carts);
        return Result.success(all);
    }

    @GetMapping("/{id}")
    public Result<?> findById(@PathVariable Long id) {
        return Result.success(orderService.getById(id));
    }

    @GetMapping
    public Result<?> findAll() {
        List<Order> list = orderService.list();
        return Result.success(list);
    }

    @GetMapping("/page")
    public Result<?> findPage(@RequestParam(required = false, defaultValue = "") String name,
                              @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<Order> query = Wrappers.<Order>lambdaQuery().orderByDesc(Order::getId);
        if (StrUtil.isNotBlank(name)) {
            query.like(Order::getOrderNo, name);
        }
        IPage<Order> page = orderService.page(new Page<>(pageNum, pageSize), query);
        return Result.success(page);
    }

    /**
     * 前台查询订单列表
     * @param state
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page/front")
    public Result<?> findPageFront(@RequestParam(required = false, defaultValue = "") String state,
                                   @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                   @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<Order> query = Wrappers.<Order>lambdaQuery().orderByDesc(Order::getId);
        query.eq(Order::getUserId, getUser().getId());
        // 根据状态查询
        if (StrUtil.isNotBlank(state)) {
            query.eq(Order::getState, state);
        }
        IPage<Order> page = orderService.page(new Page<>(pageNum, pageSize), query);

        for (Order order : page.getRecords()) {
            Long orderId = order.getId();
            List<Cart> carts = orderGoodsService.findByOrderId(orderId);
            order.setCarts(JSONUtil.toJsonStr(carts));
        }
        return Result.success(page);
    }

}

 


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("/yuangong")
public class YuangongController {
    private static final Logger logger = LoggerFactory.getLogger(YuangongController.class);

    private static final String TABLE_NAME = "yuangong";

    @Autowired
    private YuangongService yuangongService;


    @Autowired
    private TokenService tokenService;

    @Autowired
    private DanganService danganService;//档案
    @Autowired
    private DictionaryService dictionaryService;//字典
    @Autowired
    private GonggaoService gonggaoService;//公告
    @Autowired
    private MenuService menuService;//菜单
    @Autowired
    private QiandaoService qiandaoService;//员工签到
    @Autowired
    private XinziService xinziService;//薪资
    @Autowired
    private YuangongchuchaiService yuangongchuchaiService;//员工出差
    @Autowired
    private YuangongqingjiaService yuangongqingjiaService;//员工请假
    @Autowired
    private UsersService usersService;//管理员


    /**
    * 后端列表
    */
    @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("yuangongId",request.getSession().getAttribute("userId"));
        CommonUtil.checkMap(params);
        PageUtils page = yuangongService.queryPage(params);

        //字典表数据转换
        List<YuangongView> list =(List<YuangongView>)page.getList();
        for(YuangongView 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);
        YuangongEntity yuangong = yuangongService.selectById(id);
        if(yuangong !=null){
            //entity转view
            YuangongView view = new YuangongView();
            BeanUtils.copyProperties( yuangong , view );//把实体数据重构到view中
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

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

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永远不会进入");

        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            .or()
            .eq("yuangong_id_number", yuangong.getYuangongIdNumber())
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if(yuangongEntity==null){
            yuangong.setCreateTime(new Date());
            yuangong.setPassword("123456");
            yuangongService.insert(yuangong);
            return R.ok();
        }else {
            return R.error(511,"账户或者员工手机号或者员工身份证号已经被使用");
        }
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody YuangongEntity yuangong, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        logger.debug("update方法:,,Controller:{},,yuangong:{}",this.getClass().getName(),yuangong.toString());
        YuangongEntity oldYuangongEntity = yuangongService.selectById(yuangong.getId());//查询原先数据

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(false)
//            return R.error(511,"永远不会进入");
        if("".equals(yuangong.getYuangongPhoto()) || "null".equals(yuangong.getYuangongPhoto())){
                yuangong.setYuangongPhoto(null);
        }

            yuangongService.updateById(yuangong);//根据id更新
            return R.ok();
    }



    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        List<YuangongEntity> oldYuangongList =yuangongService.selectBatchIds(Arrays.asList(ids));//要删除的数据
        yuangongService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName, HttpServletRequest request){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        Integer yuangongId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
        try {
            List<YuangongEntity> yuangongList = 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){
                            //循环
                            YuangongEntity yuangongEntity = new YuangongEntity();
//                            yuangongEntity.setUsername(data.get(0));                    //账户 要改的
//                            yuangongEntity.setPassword("123456");//密码
//                            yuangongEntity.setYuangongUuidNumber(data.get(0));                    //工号 要改的
//                            yuangongEntity.setYuangongName(data.get(0));                    //员工姓名 要改的
//                            yuangongEntity.setYuangongPhone(data.get(0));                    //员工手机号 要改的
//                            yuangongEntity.setYuangongIdNumber(data.get(0));                    //员工身份证号 要改的
//                            yuangongEntity.setYuangongPhoto("");//详情和图片
//                            yuangongEntity.setSexTypes(Integer.valueOf(data.get(0)));   //性别 要改的
//                            yuangongEntity.setYuangongEmail(data.get(0));                    //员工邮箱 要改的
//                            yuangongEntity.setBumenTypes(Integer.valueOf(data.get(0)));   //部门 要改的
//                            yuangongEntity.setZhiweiTypes(Integer.valueOf(data.get(0)));   //职位 要改的
//                            yuangongEntity.setJinyongTypes(Integer.valueOf(data.get(0)));   //账户状态 要改的
//                            yuangongEntity.setCreateTime(date);//时间
                            yuangongList.add(yuangongEntity);


                            //把要查询是否重复的字段放入map中
                                //账户
                                if(seachFields.containsKey("username")){
                                    List<String> username = seachFields.get("username");
                                    username.add(data.get(0));//要改的
                                }else{
                                    List<String> username = new ArrayList<>();
                                    username.add(data.get(0));//要改的
                                    seachFields.put("username",username);
                                }
                                //工号
                                if(seachFields.containsKey("yuangongUuidNumber")){
                                    List<String> yuangongUuidNumber = seachFields.get("yuangongUuidNumber");
                                    yuangongUuidNumber.add(data.get(0));//要改的
                                }else{
                                    List<String> yuangongUuidNumber = new ArrayList<>();
                                    yuangongUuidNumber.add(data.get(0));//要改的
                                    seachFields.put("yuangongUuidNumber",yuangongUuidNumber);
                                }
                                //员工手机号
                                if(seachFields.containsKey("yuangongPhone")){
                                    List<String> yuangongPhone = seachFields.get("yuangongPhone");
                                    yuangongPhone.add(data.get(0));//要改的
                                }else{
                                    List<String> yuangongPhone = new ArrayList<>();
                                    yuangongPhone.add(data.get(0));//要改的
                                    seachFields.put("yuangongPhone",yuangongPhone);
                                }
                                //员工身份证号
                                if(seachFields.containsKey("yuangongIdNumber")){
                                    List<String> yuangongIdNumber = seachFields.get("yuangongIdNumber");
                                    yuangongIdNumber.add(data.get(0));//要改的
                                }else{
                                    List<String> yuangongIdNumber = new ArrayList<>();
                                    yuangongIdNumber.add(data.get(0));//要改的
                                    seachFields.put("yuangongIdNumber",yuangongIdNumber);
                                }
                        }

                        //查询是否重复
                         //账户
                        List<YuangongEntity> yuangongEntities_username = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("username", seachFields.get("username")));
                        if(yuangongEntities_username.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_username){
                                repeatFields.add(s.getUsername());
                            }
                            return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                         //工号
                        List<YuangongEntity> yuangongEntities_yuangongUuidNumber = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("yuangong_uuid_number", seachFields.get("yuangongUuidNumber")));
                        if(yuangongEntities_yuangongUuidNumber.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_yuangongUuidNumber){
                                repeatFields.add(s.getYuangongUuidNumber());
                            }
                            return R.error(511,"数据库的该表中的 [工号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                         //员工手机号
                        List<YuangongEntity> yuangongEntities_yuangongPhone = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("yuangong_phone", seachFields.get("yuangongPhone")));
                        if(yuangongEntities_yuangongPhone.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_yuangongPhone){
                                repeatFields.add(s.getYuangongPhone());
                            }
                            return R.error(511,"数据库的该表中的 [员工手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                         //员工身份证号
                        List<YuangongEntity> yuangongEntities_yuangongIdNumber = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("yuangong_id_number", seachFields.get("yuangongIdNumber")));
                        if(yuangongEntities_yuangongIdNumber.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_yuangongIdNumber){
                                repeatFields.add(s.getYuangongIdNumber());
                            }
                            return R.error(511,"数据库的该表中的 [员工身份证号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                        yuangongService.insertBatch(yuangongList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }

    /**
    * 登录
    */
    @IgnoreAuth
    @RequestMapping(value = "/login")
    public R login(String username, String password, String captcha, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("username", username));
        if(yuangong==null || !yuangong.getPassword().equals(password))
            return R.error("账号或密码不正确");
        else if(yuangong.getJinyongTypes() != 1)
            return R.error("账户已被禁用");
        String token = tokenService.generateToken(yuangong.getId(),username, "yuangong", "员工");
        R r = R.ok();
        r.put("token", token);
        r.put("role","员工");
        r.put("username",yuangong.getYuangongName());
        r.put("tableName","yuangong");
        r.put("userId",yuangong.getId());
        return r;
    }

    /**
    * 注册
    */
    @IgnoreAuth
    @PostMapping(value = "/register")
    public R register(@RequestBody YuangongEntity yuangong, HttpServletRequest request) {
//    	ValidatorUtils.validateEntity(user);
        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            .or()
            .eq("yuangong_id_number", yuangong.getYuangongIdNumber())
            ;
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if(yuangongEntity != null)
            return R.error("账户或者员工手机号或者员工身份证号已经被使用");
        yuangong.setYuangongUuidNumber(String.valueOf(new Date().getTime()));
        yuangong.setJinyongTypes(1);//启用
        yuangong.setCreateTime(new Date());
        yuangongService.insert(yuangong);

        return R.ok();
    }

    /**
     * 重置密码
     */
    @GetMapping(value = "/resetPassword")
    public R resetPassword(Integer  id, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectById(id);
        yuangong.setPassword("123456");
        yuangongService.updateById(yuangong);
        return R.ok();
    }

	/**
	 * 修改密码
	 */
	@GetMapping(value = "/updatePassword")
	public R updatePassword(String  oldPassword, String  newPassword, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectById((Integer)request.getSession().getAttribute("userId"));
		if(newPassword == null){
			return R.error("新密码不能为空") ;
		}
		if(!oldPassword.equals(yuangong.getPassword())){
			return R.error("原密码输入错误");
		}
		if(newPassword.equals(yuangong.getPassword())){
			return R.error("新密码不能和原密码一致") ;
		}
        yuangong.setPassword(newPassword);
		yuangongService.updateById(yuangong);
		return R.ok();
	}



    /**
     * 忘记密码
     */
    @IgnoreAuth
    @RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("username", username));
        if(yuangong!=null){
            yuangong.setPassword("123456");
            yuangongService.updateById(yuangong);
            return R.ok();
        }else{
           return R.error("账号不存在");
        }
    }


    /**
    * 获取用户的session用户信息
    */
    @RequestMapping("/session")
    public R getCurrYuangong(HttpServletRequest request){
        Integer id = (Integer)request.getSession().getAttribute("userId");
        YuangongEntity yuangong = yuangongService.selectById(id);
        if(yuangong !=null){
            //entity转view
            YuangongView view = new YuangongView();
            BeanUtils.copyProperties( yuangong , view );//把实体数据重构到view中

            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }
    }


    /**
    * 退出
    */
    @GetMapping(value = "logout")
    public R logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return R.ok("退出成功");
    }



}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

程序猿毕业分享网

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

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

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

打赏作者

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

抵扣说明:

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

余额充值