package com.sqx.modules.bl.massage.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.bl.massage.entity.MassagePackage;
import com.sqx.modules.bl.massage.service.MassagePackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/massage/package")
@Api(value = "服务包管理", tags = {"服务包管理"})
public class MassagePackageController {

    @Autowired
    private MassagePackageService service;

    @GetMapping("/findPage")
    @ApiOperation("查询按服务包（分页）")
    public Result findPage(MassagePackage massagePackage){
        return service.findPage(massagePackage);
    }

    @PostMapping("/updateSales")
    @ApiOperation("修改销量")
    public Result updateSales(MassagePackage massagePackage){
        service.updateSales(massagePackage);
        return Result.success();
    }

    @PostMapping("/updateEsteemRate")
    @ApiOperation("修改好评")
    public Result updateEsteemRate(MassagePackage massagePackage){
        service.updateEsteemRate(massagePackage);
        return Result.success();
    }

    @PostMapping("/updateCoupon")
    @ApiOperation("修改代金券可用")
    public Result updateCoupon(MassagePackage massagePackage){
        service.updateCoupon(massagePackage);
        return Result.success();
    }

    @PostMapping("/updateVip")
    @ApiOperation("修改VIP可用")
    public Result updateVip(MassagePackage massagePackage){
        service.updateVip(massagePackage);
        return Result.success();
    }

    @PostMapping("/updateNewer")
    @ApiOperation("修改只限新人")
    public Result updateNewer(MassagePackage massagePackage){
        service.updateNewer(massagePackage);
        return Result.success();
    }

    @PostMapping("/updateStatus")
    @ApiOperation("修改状态")
    public Result updateStatus(MassagePackage massagePackage){
        service.updateStatus(massagePackage);
        return Result.success();
    }

    @PostMapping("/add")
    @ApiOperation("添加服务包")
    public Result add(MassagePackage massagePackage){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        massagePackage.setCreateTime(sdf.format(new Date()));
        service.save(massagePackage);
        return Result.success();
    }

    @PostMapping("/modify")
    @ApiOperation("修改服务包")
    public Result modify(MassagePackage massagePackage){
        service.updateById(massagePackage);
        return Result.success();
    }

    @PostMapping("/delete")
    @ApiOperation("删除服务包")
    public Result delete(MassagePackage massagePackage){
        service.delete(massagePackage);
        return Result.success();
    }

}
