package com.sunda.spmsweb.overseacontroller;


import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsoversea.dto.WhsDumpConfigDTO;
import com.sunda.spmsoversea.dto.WhsDumpConfigQueryDTO;
import com.sunda.spmsoversea.service.IWhsDumpConfigService;
import com.sunda.spmsweb.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * IPO工厂转储配置表 前端控制器
 * </p>
 *
 * @author Hzc
 * @since 2023-02-22
 */
@RestController
@RequestMapping("/whs-dump-config")
@Slf4j
@Api(tags = "IPO工厂转储配置", description = "IPO工厂转储配置")
public class WhsDumpConfigController {

    @Autowired
    IWhsDumpConfigService whsDumpConfigService;


    @RequestMapping("/getWhsDumpConfigPage")
    @ApiOperation(value = "IPO工厂转储配置分页", notes = "IPO工厂转储配置分页\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"current\": 1,\n" +
            "\t\"size\": 20,\n" +
            "\t\"uuid\": \"\",\n" +
            "\t\"werks\": \"\",\n" +
            "\t\"whsLocationCode\": \"\",\n" +
            "\t\"costCenter\": \"\",\n" +
            "\t\"costCenterName\": \"\"\n" +
            "}", httpMethod = "POST")
    public ResponseResult getWhsDumpConfigPage(@RequestBody WhsDumpConfigQueryDTO whsDumpConfigQueryDTO){
        try {
            return ResponseResult.success().add("whsDumpConfigList", whsDumpConfigService.getWhsDumpConfigPage(whsDumpConfigQueryDTO));
        }catch (Exception e){
            log.error("getWhsDumpConfigPage-请求数据失败:"+e.getMessage());
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }


    @RequestMapping("/createOrUpdateWhsDumpConfig")
    @ApiOperation(value = "新建更新IPO工厂转储配置", notes = "新建更新IPO工厂转储配置\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"uuid\": \"\",\n" +
            "\t\"werks\": \"\",\n" +
            "\t\"whsLocationCode\": \"\",\n" +
            "\t\"costCenter\": \"\",\n" +
            "\t\"costCenterName\": \"\"\n" +
            "\t}]\n" +
            "}", httpMethod = "POST")
    public ResponseResult createOrUpdateWhsDumpConfig(@RequestBody WhsDumpConfigDTO whsDumpConfigDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return whsDumpConfigService.createOrUpdateWhsDumpConfig(whsDumpConfigDTO, userId);
        }catch (Exception e){
            log.error("createOrUpdateWhsDumpConfig-请求数据失败:"+e.getMessage());
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/deleteWhsDumpConfig")
    @ApiOperation(value = "删除IPO工厂转储配置", notes = "删除IPO工厂转储配置\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"uuid\": \"\",\n" +
            "\t}]\n" +
            "}", httpMethod = "POST")
    public ResponseResult deleteWhsDumpConfig(@RequestBody WhsDumpConfigDTO whsDumpConfigDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return whsDumpConfigService.deleteWhsDumpConfig(whsDumpConfigDTO, userId);
        }catch (Exception e){
            log.error("deleteWhsDumpConfig-请求数据失败:"+e.getMessage());
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

}
