package com.fs.app.controller;


import cn.hutool.json.JSONUtil;
import com.fs.app.annotation.Login;
import com.fs.app.param.DoctorEditParam;
import com.fs.app.param.DoctorEditPwdParam;
import com.fs.app.param.DoctorLoginParam;
import com.fs.common.core.domain.R;
import com.fs.common.core.redis.RedisCache;
import com.fs.common.utils.sign.Md5Utils;
import com.fs.his.domain.*;
import com.fs.his.dto.FsExtractDTO;
import com.fs.his.enums.FsExtractTypeEnum;
import com.fs.his.param.*;
import com.fs.his.service.*;
import com.fs.his.vo.FsDoctorArticleListDVO;
import com.fs.his.vo.FsDoctorArticleVO;
import com.fs.his.vo.FsDoctorBillListSVO;
import com.fs.his.vo.FsDoctorExtractListSVO;
import com.fs.sms.service.SmsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;


@Api("医生文章")
@RestController
@RequestMapping(value="/app/doctorArticle")
public class DoctorArticleController extends  AppBaseController {
    @Autowired
    RedisCache redisCache;
    @Autowired
    private IFsDoctorArticleService doctorArticleService;
    @Autowired
    private IFsDoctorArticleCateService articleCateService;

    @ApiOperation("获取文章分类列表")
    @GetMapping("/getDoctorArticleCateList")
    public R getArticleCateList( HttpServletRequest request){
        FsDoctorArticleCate map=new FsDoctorArticleCate();
        map.setIsDel(0);
        List<FsDoctorArticleCate> list=articleCateService.selectFsDoctorArticleCateList(map);
        return R.ok().put("data",list);
    }



    @GetMapping(value = "/getDoctorArticleList")
    @ApiOperation("获取文章列表")
    @Login
    public R getDoctorArticleList(FsDoctorArticleListDParam param)
    {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        param.setDoctorId(Long.parseLong(getDoctorId()));
        List<FsDoctorArticleListDVO> list=doctorArticleService.selectFsDoctorArticleListDVO(param);
        PageInfo<FsDoctorArticleListDVO> listPageInfo=new PageInfo<>(list);

        return R.ok().put("data",listPageInfo);

    }
    @Login
    @GetMapping("/getDoctorArticleByArticleId")
    public R getDoctorArticleByArticleId(@RequestParam("articleId")Long articleId)
    {
        FsDoctorArticleVO article=doctorArticleService.selectFsDoctorArticleByArticleId(articleId);
        return R.ok().put("data",article);
    }
    @Login
    @ApiOperation("新增")
    @PostMapping("/addDoctorArticle")
    public R addDoctorArticle(@Validated @RequestBody FsDoctorArticle param, HttpServletRequest request) throws ParseException {
        param.setDoctorId(Long.parseLong(getDoctorId()));
        param.setViews(0l);
        if(doctorArticleService.insertFsDoctorArticle(param)>0){
            return R.ok();
        }
        else
        {
            return R.error();
        }
    }
    @Login
    @ApiOperation("编辑")
    @PostMapping("/editDoctorArticle")
    public R editDoctorArticle(@Validated @RequestBody FsDoctorArticle param, HttpServletRequest request) throws ParseException {

        if(doctorArticleService.updateFsDoctorArticle(param)>0){
            return R.ok();
        }
        else
        {
            return R.error();
        }
    }

    @Login
    @ApiOperation("删除")
    @PostMapping("/delDoctorArticle")
    public R delStoreNotice(  @RequestBody FsDoctorArticle param, HttpServletRequest request) throws ParseException {

        if(doctorArticleService.deleteFsDoctorArticleByArticleId(param.getArticleId())>0){
            return R.ok();
        }
        else
        {
            return R.error();
        }
    }


}
