整理四

管理和购买的逻辑部分,同样是按照已有的框架进行分层,基本上是在调用数据库操作,分为了service层的接口和接口的实现,以及Controller层的调用,以股票管理的为例:
首先是想好都是要做什么,然后service层定义所需要的接口如下:

package com.example.demo.share.service;

import com.example.demo.common.Enums.CommonResult;
import com.example.demo.share.enitiy.BuyTs;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public interface SimShareOp {
    CommonResult seacheShareById(String id);
    CommonResult deleteBuyTsById(String id, String tscode);
    CommonResult addBuyTsById(String id ,String tscode,int tssum );
    CommonResult seachShareByOrderID(String ordId);
}

然后service层中的imp层对接口进行实现:

package com.example.demo.share.service.Imp;

import com.example.demo.common.Enums.CommonResult;
import com.example.demo.share.Dao.ManageDao;
import com.example.demo.share.Dao.UserDao;
import com.example.demo.share.enitiy.BuyTs;
import com.example.demo.share.enitiy.ManageTs;
import com.example.demo.share.service.GetShareService;
import com.example.demo.share.service.SimShareOp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SimShareOpImp implements SimShareOp {
    @Autowired
    ManageDao manageDao;
    @Autowired
    UserDao userDao;
    @Autowired
    GetShareService getShareServiceImp;

    @Override
    public  CommonResult seacheShareById(String id) {
        Map<String,Object> massage= new HashMap<>();
        massage.put("Order",manageDao.selectByUsername(id));
        massage.put("user",userDao.searchById(id));

        return CommonResult.success(massage);
    }

    @Override
    public CommonResult deleteBuyTsById(String id, String tscode) {


        ManageTs manageTs=manageDao.SelectManageTsById(id,tscode);
       //
        //System.out.println(manageTs.getBuyprice()+ "   "+manageTs.getBuyprice()*1.0);
        System.out.println(manageTs.getTssum()+"  "+manageTs.getTssum()*1.0);
        float b=manageTs.getBuyprice()*manageTs.getTssum();
        userDao.upDataForPir(id,b);
        manageDao.deleteManageTsById(id, tscode);

        return CommonResult.success(userDao.searchById(id));
    }

    @Override
    public CommonResult addBuyTsById(String id, String tscode, int tssum) {
        float  buyprice=getShareServiceImp.GetPri(tscode);
        manageDao.addManageTs(new ManageTs(id,tscode,tssum,buyprice));
        userDao.upDataForPir(id,-1*tssum*buyprice);
        return CommonResult.success(userDao.searchById(id));
    }

    @Override
    public CommonResult seachShareByOrderID(String ordId) {
        return CommonResult.success(manageDao.selectById(ordId));
    }
}

然后按照构思好的要做的步骤在controller层调用接口:

package com.example.demo.share.Controller;

import com.example.demo.common.Enums.CommonResult;
import com.example.demo.share.service.SimShareOp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/SimShare")
public class SimShareController {
    @Autowired
    SimShareOp simShareOp;
    @RequestMapping(value = "/AddShare",method = RequestMethod.POST )
    @ResponseBody
    public CommonResult AddShare(@NotNull String useid, String tscode,
                                 @Min(value = 0, message = "数量必须大于0") int tssum
                                 ){
        return simShareOp.addBuyTsById(useid,tscode,tssum);

    }
    @RequestMapping(value = "/DeleShare",method = RequestMethod.GET )
    @ResponseBody
    public CommonResult DeleShare(@NotNull String id,String tscode){
        return simShareOp.deleteBuyTsById(id,tscode);

    }
    @RequestMapping(value = "/GetAllShare",method = RequestMethod.GET )
    @ResponseBody
    public CommonResult ALLShare(@NotNull String id){
        return simShareOp.seacheShareById(id);

    }
    @RequestMapping(value = "/GetShareByOrdId",method = RequestMethod.GET )
    @ResponseBody
    public CommonResult GetShare(@NotNull String id){
        return simShareOp.seachShareByOrderID(id);

    }


}

展开阅读全文

Windows版YOLOv4目标检测实战:训练自己的数据集

04-26
©️2020 CSDN 皮肤主题: 游动-白 设计师: 上身试试 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值