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

import com.yeejoin.amos.boot.module.tcm.biz.service.impl.HistoryDataDealServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

/**
 * @author Administrator
 */
@RestController
@RequestMapping(value = "/history-data")
@Api(tags = "历史数据处理控制器")
public class HistoryDataDealController {

    private HistoryDataDealServiceImpl historyDataDealService;

    public HistoryDataDealController(HistoryDataDealServiceImpl historyDataDealService) {
        this.historyDataDealService = historyDataDealService;
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @PutMapping(value = "/user-permission/update")
    @ApiOperation(httpMethod = "PUT", value = "人员需求2970新增资质后, 检验检测资质存量数据刷库")
    public ResponseModel<Integer> userPermissionUpdate() {
        return ResponseHelper.buildResponse(historyDataDealService.userPermissionUpdate());
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @PutMapping(value = "/user-person-type/update")
    @ApiOperation(httpMethod = "PUT", value = "人员需求2970新增资质后, 人员类型去掉维保，归到作业人员")
    public ResponseModel<Integer> userPersonTypeUpdate() {
        return ResponseHelper.buildResponse(historyDataDealService.userPersonTypeUpdate());
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @PutMapping(value = "/orgCode/update")
    @ApiOperation(httpMethod = "PUT", value = "企业orgCode调整历史数据修复")
    public ResponseModel<Boolean> unitOrgCodeUpdate(@RequestParam String oldOrgCode, @RequestParam String newOrgCode) {
        return ResponseHelper.buildResponse(historyDataDealService.unitOrgCodeUpdate(oldOrgCode, newOrgCode));
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @PutMapping(value = "/handleCompanyHisOrgCode")
    @ApiOperation(httpMethod = "PUT", value = "监管单位层级调整后，业务表（企业、设备、统计等）冗余的所有旧orgCode替换为新orgCode", notes = "监管单位层级调整后，业务表（企业、设备、统计等）冗余的所有旧orgCode替换为新orgCode")
    public ResponseModel<String> handleCompanyHisOrgCode(@RequestParam String newOrgCode, @RequestParam String oldOrgCode) {
        return ResponseHelper.buildResponse(historyDataDealService.handleCompanyHisOrgCode(newOrgCode, oldOrgCode));
    }

}
