package com.yeejoin.amos.boot.module.ugp.biz.controller;

import com.yeejoin.amos.boot.module.ugp.api.dto.InstallNoticePageDto;
import com.yeejoin.amos.boot.module.ugp.api.entity.InstallNotice;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.yeejoin.amos.boot.module.ugp.biz.service.impl.InstallNoticeServiceImpl;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.ugp.api.dto.InstallNoticeDto;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.foundation.enumeration.UserType;

/**
 * 安装告知表
 *
 * @author system_generator
 * @date 2022-09-22
 */
@RestController
@Api(tags = "安装告知表Api")
@RequestMapping(value = "/install-notice")
public class InstallNoticeController extends BaseController {

	@Autowired
	InstallNoticeServiceImpl installNoticeServiceImpl;

	/**
	 * 新增安装告知表
	 *
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@PostMapping(value = "/save")
	@ApiOperation(httpMethod = "POST", value = "新增安装告知表", notes = "新增安装告知表")
	public ResponseModel<InstallNoticeDto> save(@RequestBody InstallNoticeDto model) {
		model = installNoticeServiceImpl.createWithModel(model);
		return ResponseHelper.buildResponse(model);
	}

	/**
	 * 根据sequenceNbr更新提交申请
	 *
	 * @param sequenceNbr 主键
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@PutMapping(value = "/{sequenceNbr}")
	@ApiOperation(httpMethod = "PUT", value = "根据sequenceNbr更新提交申请", notes = "根据sequenceNbr更新提交申请")
	public ResponseModel<InstallNoticeDto> updateBySequenceNbrInstallNotice(@RequestBody InstallNoticeDto model, @PathVariable(value = "sequenceNbr") Long sequenceNbr) {
		model.setSequenceNbr(sequenceNbr);
		model.setNoticeStatus("已提交");
		return ResponseHelper.buildResponse(installNoticeServiceImpl.updateWithModel(model));
	}

	/**
	 * 根据sequenceNbr删除
	 *
	 * @param sequenceNbr 主键
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@DeleteMapping(value = "/{sequenceNbr}")
	@ApiOperation(httpMethod = "DELETE", value = "根据sequenceNbr删除安装告知表", notes = "根据sequenceNbr删除安装告知表")
	public ResponseModel<Boolean> deleteBySequenceNbr(HttpServletRequest request, @PathVariable(value = "sequenceNbr") Long sequenceNbr) {
		return ResponseHelper.buildResponse(installNoticeServiceImpl.removeById(sequenceNbr));
	}

	/**
	 * 根据sequenceNbr查询
	 *
	 * @param sequenceNbr 主键
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@GetMapping(value = "/{sequenceNbr}")
	@ApiOperation(httpMethod = "GET", value = "根据sequenceNbr查询单个安装告知表", notes = "根据sequenceNbr查询单个安装告知表")
	public ResponseModel<InstallNoticeDto> selectOne(@PathVariable Long sequenceNbr) {
		return ResponseHelper.buildResponse(installNoticeServiceImpl.queryBySeq(sequenceNbr));
	}
	/**
	 * 列表分页查询
	 *
	 * @param current 当前页
	 * @param current 每页大小
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@GetMapping(value = "/page")
	@ApiOperation(httpMethod = "GET", value = "安装告知表分页查询", notes = "安装告知表分页查询")
	public ResponseModel<Page<InstallNoticeDto>> queryForPage(@RequestParam(value = "current") int current, @RequestParam
			(value = "size") int size) {
		Page<InstallNoticeDto> page = new Page<InstallNoticeDto>();
		page.setCurrent(current);
		page.setSize(size);
		return ResponseHelper.buildResponse(installNoticeServiceImpl.queryForInstallNoticePage(page));
	}

	/**
	 * 列表分页查询
	 *
	 * @param current 当前页
	 * @param current 每页大小
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@GetMapping(value = "/installNoticePage")
	@ApiOperation(httpMethod = "GET", value = "安装告知表分页查询", notes = "安装告知表分页查询")
	public ResponseModel<Page<InstallNoticePageDto>> queryForPage1(@RequestParam(value = "current") int current, @RequestParam
			(value = "size") int size) {
		Page<InstallNoticePageDto> page = new Page<InstallNoticePageDto>();
		page.setCurrent(current);
		page.setSize(size);
		return ResponseHelper.buildResponse(installNoticeServiceImpl.installNoticePage(page));
	}

	/**
	 * 列表全部数据查询
	 *
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@ApiOperation(httpMethod = "GET", value = "安装告知表列表全部数据查询", notes = "安装告知表列表全部数据查询")
	@GetMapping(value = "/list")
	public ResponseModel<List<InstallNoticeDto>> selectForList() {
		return ResponseHelper.buildResponse(installNoticeServiceImpl.queryForInstallNoticeList());
	}

	/**
	 * 查询安装告知申请列表
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@GetMapping(value = "/installApplyList")
	@ApiOperation(httpMethod = "GET", value = "安装告知表分页查询", notes = "安装告知表分页查询")
	public ResponseModel<List<InstallNoticePageDto>> queryForPage1() {
		return ResponseHelper.buildResponse(installNoticeServiceImpl.installNoticeList());
	}

	/**
	 * 根据项目名称和建设单位查询安装告知申请列表
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@GetMapping(value = "/installApplyListByNameUnit")
	@ApiOperation(httpMethod = "GET", value = "安装告知申请表筛选", notes = "安装告知申请表筛选")
	public ResponseModel<List<InstallNoticePageDto>> queryForPageByName(@RequestParam(value = "name") String name, @RequestParam(value = "unit") String unit) {
		return ResponseHelper.buildResponse(installNoticeServiceImpl.selectByName(name, unit));
	}

	/**
	 * 根据主键sequenceNbr查询安装告知申请详情
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@GetMapping ("")
	@ApiOperation(httpMethod = "GET", value = "查询安装告知申请详情", notes = "查询安装告知申请详情")
	public ResponseModel<InstallNoticeDto> installNoticeinfoById(@RequestParam ("sequenceNbr") Long sequenceNbr){
		return ResponseHelper.buildResponse(installNoticeServiceImpl.selectOneById(sequenceNbr));
	}
	/**
	 * 根据sequenceNbr更新
	 *
	 * @param sequenceNbr 主键
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
	@PutMapping(value = "/change/{sequenceNbr}")
	@ApiOperation(httpMethod = "PUT", value = "根据sequenceNbr更新", notes = "根据sequenceNbr更新")
	public ResponseModel<InstallNoticeDto> updateInstallNotice(@RequestBody InstallNoticeDto model, @PathVariable(value = "sequenceNbr") Long sequenceNbr) {
		model.setSequenceNbr(sequenceNbr);
		return ResponseHelper.buildResponse(installNoticeServiceImpl.updateWithModel(model));
	}
}
