山东大学暑期项目实训第三周(2)

本周主要完成的一个功能点就是实现对于超市联盟的管理。

主要问题是添加超市联盟时,因为是新建的联盟,而现有的超市都是已经拥有了联盟的,所以新建联盟在不创建新的超市的情况下就没有办法为联盟同时选择一个龙头,而这一操作可能会导致超市端发生错误,为了避免错误的发生,在创建新联盟的同时加入了创建新超市的操作来为联盟添加龙头。

以下是相关的代码:

@RequestMapping(value = "/addsuperunion",method = RequestMethod.POST)
    public Map addSuperUnion(@RequestBody Object obj, HttpServletRequest request){
        Map para = (Map) obj;
        HttpSession session = request.getSession();
        List<Admin_SuperUnion> list = admin_superUnionDao.findAllSuperUnion();
        String super_union_name = (String)para.get("super_union_name");
        String checkstring1 = admin_superUnionDao.checkSuperUnionisexist(super_union_name);
        Map data = new HashMap();
        boolean isexist1 = false;
        if (checkstring1==null){
            isexist1 = true;
        }
        if (isexist1==false){
            data.put("status","-1");
            data.put("message","联盟用户名已存在,添加失败");
            data.put("sessionId",session.getId());
            return data;
        }
        String super_user_name = (String)para.get("super_user_name");
        String super_user_password = (String)para.get("super_user_password");
        String super_phone = (String)para.get("super_phone");
        String super_address = (String)para.get("super_address");
        String checkstring2 = superUserDao.checkSuperUserisexist(super_user_name);
        boolean isexist2 = false;
        if (checkstring2==null){
            isexist2 = true;
        }
        if (isexist2==false){
            data.put("status","-1");
            data.put("message","超市用户名已存在,添加失败");
            data.put("sessionId",session.getId());
            return data;
        }
        if(!list.contains(super_union_name)&&isexist1!=false&&isexist2!=false){
            String sql1 = "insert into super_union(super_union_name,super_union_leaderid) values('"+super_union_name+"',-1 )";
            this.jdbcTemplate.update(sql1);
            int super_union_id = admin_superUnionDao.findSuperUnionIdBySuperUnionname(super_union_name);
            String sql2 = "insert into super_user(super_user_name,super_user_password,super_union_id," +
                    "super_phone,super_address) values('"+super_user_name+"','"+super_user_password+"'," +
                    "'"+super_union_id+"','"+super_phone+"','"+super_address+"')";
            this.jdbcTemplate.update(sql2);
            int super_union_leader_id = superUserDao.findSuperUserIdBySuperUserName(super_user_name);
            String sql3 = "update super_union set super_union_leaderid = '"+super_union_leader_id+"' where super_union_name = '"+super_union_name+"'";
            this.jdbcTemplate.update(sql3);
            data.put("status","1");
            data.put("message","添加成功");
        }else {
            data.put("status", "-1");
            data.put("message", "添加失败");
        }
        data.put("sessionId", session.getId());
        return data;
    }

在实现超市注册和联盟注册的同时查询一个checkstring,防止发生超市或联盟用户名重复的情况。

联盟龙头修改代码:

    @CrossOrigin
    @RequestMapping(value = "/changesuperunionleader",method = RequestMethod.POST)
    public  Map deleteSuperUnion(@RequestBody Object obj,HttpServletRequest request){
        Map para = (Map) obj;
        HttpSession session = request.getSession();
        String super_user_name = (String) para.get("super_user_name");
        String super_union_name = (String) para.get("super_union_name");
        int super_union_leader_id = -1;
        super_union_leader_id = superUserDao.findSuperUserIdBySuperUserName(super_user_name);
        Map data = new HashMap();
        if(super_union_leader_id!=-1){
            String sql = "update super_union set super_union_leaderid = '"+super_union_leader_id+"' where super_union_name = '"+super_union_name+"'";
            this.jdbcTemplate.update(sql);
            data.put("status","1");
            data.put("message","修改成功");
        }else {
            data.put("status", "-1");
            data.put("message", "修改失败");
        }
        data.put("sessionId", session.getId());
        return data;
    }

DAO层代码

@Repository
public interface Admin_SuperUnionDao extends JpaRepository<Admin, Integer> {
    @Query(value = "from Admin_SuperUnion a")
    List<Admin_SuperUnion> findAllSuperUnion();

    @Query(value = "select a.super_union_name from Admin_SuperUnion a")
    List<String> listSuperUnionName();

    @Query(value = "select a.super_union_id from Admin_SuperUnion a where a.super_union_name=?1")
    int findSuperUnionIdBySuperUnionname(String super_union_name);

    @Query(value = "from Admin_SuperUnion a where a.super_union_name like concat('%',:username,'%') ")
    List<SuperUser> findSuperUnionBySuperUnionname(@Param("username")String username);

    @Query(value = "select a.super_union_name from Admin_SuperUnion a where a.super_union_name=?1")
    String checkSuperUnionisexist(String super_user_name);


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值