package com.goldenwater.slaj.hidd.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.slaj.hidd.domain.ObjHidd;
import com.goldenwater.slaj.hidd.domain.BisOrgMonRepPeri;
import com.goldenwater.slaj.hidd.service.IObjHiddService;
import com.goldenwater.slaj.hidd.service.IBisOrgMonRepPeriService;
import com.goldenwater.slaj.acci.service.impl.AcciNotifyService;

/**
 * 移动端接口
 */
@RestController
@RequestMapping("/hidd/mobile")
public class HiddMobileController extends BaseController {
    @Autowired
    private IObjHiddService objHiddService;

    @Autowired
    private IBisOrgMonRepPeriService bisOrgMonRepPeriService;

    @Autowired
    private AcciNotifyService acciNotifyService;

    /**
     * 移动端隐患列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ObjHidd objHidd) {
        startPage();
        List<ObjHidd> list = objHiddService.selectObjHiddList(objHidd);
        return getDataTable(list);
    }

    /**
     * 移动端隐患新增
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody ObjHidd objHidd) {
        return toAjax(objHiddService.insertObjHidd(objHidd));
    }

    /**
     * 移动端月报新增
     */
    @PostMapping("/saveMonth")
    public AjaxResult saveMonth(@RequestBody BisOrgMonRepPeri bisOrgMonRepPeri) {
        return toAjax(bisOrgMonRepPeriService.insertBisOrgMonRepPeri(bisOrgMonRepPeri));
    }

    /**
     * 移动端月报撤回
     */
    @PostMapping("/saveRevoc")
    public AjaxResult saveRevoc(@RequestBody BisOrgMonRepPeri bisOrgMonRepPeri) {
        bisOrgMonRepPeri.setRepAct("0");
        return toAjax(bisOrgMonRepPeriService.updateBisOrgMonRepPeri(bisOrgMonRepPeri));
    }

    /**
     * 月报催报提醒（向未上报单位发送通知）
     * @param orgGuid 目标单位GUID
     * @param repMonth 报表月份（可选）
     */
    @PostMapping("/pushForward")
    public AjaxResult pushForward(@RequestParam String orgGuid,
                                   @RequestParam(required = false) String repMonth) {
        String title = "隐患月报督促上报信息";
        String content = "隐患月报督促上报信息";
        if (repMonth != null && !repMonth.isEmpty()) {
            content = repMonth + "隐患月报督促上报信息";
        }
        return acciNotifyService.sendNotice(orgGuid, title, content, "hidd");
    }
}
