package com.qunzhixinxi.hnqz.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qunzhixinxi.hnqz.admin.entity.WmContract;
import com.qunzhixinxi.hnqz.admin.entity.WmDaHospital;
import com.qunzhixinxi.hnqz.admin.entity.WmWkArticle;
import com.qunzhixinxi.hnqz.admin.mapper.WmContractMapper;
import com.qunzhixinxi.hnqz.admin.service.WmContractService;
import com.qunzhixinxi.hnqz.common.core.util.R;
import com.qunzhixinxi.hnqz.common.data.datascope.DataScope;
import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 档案-合同管理
 *
 * @author Dhy
 * @date 2020-12-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("/wmcontract" )
@Api(value = "wmcontract", tags = "档案-合同管理")
@MapperScan("com.qunzhixinxi.hnqz.admin.mapper")
public class WmContractController {
	private final WmContractService wmContractService;

	/**
	 * 分页查询
	 * @param wmContract 档案-合同管理
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	public R getWmContractPage(Page page ,WmContract wmContract) {
		return R.ok(wmContractService.selectContractList(page,wmContract));
	}

	/**
	 * 通过id查询档案-合同管理
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}" )
	public R getById(Long id) {
		return R.ok(wmContractService.getById(id));
	}

	/**
	 * 通过id删除档案-合同管理
	 * @param  id
	 * @return R
	 */
	@ApiOperation(value = "通过id删除档案-合同管理", notes = "通过id删除档案-合同管理")
	@SysLog("通过id删除档案-合同管理" )
	@GetMapping("/delete" )
	public R removeById(Long id) {
		return R.ok(wmContractService.removeById(id));
	}

	/**
	 * 新增档案-合同管理
	 * @param wmContract 档案-合同管理
	 * @return R
	 */
	@ApiOperation(value = "新增档案-合同管理", notes = "新增档案-合同管理")
	@SysLog("新增档案-合同管理" )
	@PostMapping("/save")
	public R save(@RequestBody WmContract wmContract) {
		wmContract.setCreateTime(LocalDateTime.now());
		wmContract.setDeptId(String.valueOf(SecurityUtils.getUser().getDeptId()));
		return R.ok(wmContractService.save(wmContract));
	}

	/**
	 * 修改档案-合同管理
	 * @param wmContract 档案-合同管理
	 * @return R
	 */
	@ApiOperation(value = "修改档案-合同管理", notes = "修改档案-合同管理")
	@SysLog("修改档案-合同管理" )
	@PostMapping("/update")
	public R updateById(@RequestBody WmContract wmContract) {
		wmContract.setUpdateTime(LocalDateTime.now());
		return R.ok(wmContractService.updateById(wmContract));
	}
}
