package com.hzs.system.home.controller.manage;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.system.home.HoRegionDistribute;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.home.service.IHoRegionDistributeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Description: 全球销售网络分布
 * @Author: yuhui
 * @Time: 2022/10/9 16:57
 * @Classname: SaRegionDistributeController
 * @PackageName: com.hzs.system.home.controller.manage
 */
@Slf4j
@RestController
@RequestMapping("/manage/sa-region-distribute")
public class HoRegionDistributeController extends BaseController {

    @Autowired
    private IHoRegionDistributeService regionDistributeService;


    /**
     * 查询列表
     * @return
     */
    @GetMapping("list")
    public TableDataInfo list(){
        QueryWrapper<HoRegionDistribute> queryWrapper = new QueryWrapper();
        List<HoRegionDistribute> list = regionDistributeService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 新增全球销售网络分布
     * @return
     */
    @PostMapping("save")
    public AjaxResult save(@RequestBody HoRegionDistribute saRegionDistribute){
        saRegionDistribute.setCreationTime(new Date());
        saRegionDistribute.setPkCreator(SecurityUtils.getUserId());
        saRegionDistribute.setPkCountry(SecurityUtils.getPkCountry());
        regionDistributeService.save(saRegionDistribute);
        return AjaxResult.success();
    }

    /**
     * 修改全球销售网络分布
     * @param saRegionDistribute
     * @return
     */
    @PostMapping("update")
    public AjaxResult update(@RequestBody HoRegionDistribute saRegionDistribute){
        saRegionDistribute.setModifiedTime(new Date());
        saRegionDistribute.setPkModified(SecurityUtils.getUserId());
        regionDistributeService.updateById(saRegionDistribute);
        return AjaxResult.success();
    }


    /**
     * 删除全球销售网络分布
     * @param saRegionDistribute
     * @return
     */
    @PostMapping("remove")
    public AjaxResult remove(@RequestBody HoRegionDistribute saRegionDistribute){
        UpdateWrapper<HoRegionDistribute> updateWrapper = new UpdateWrapper();
        updateWrapper.eq("PK_ID",saRegionDistribute.getPkId());
        updateWrapper.set("PK_MODIFIED",SecurityUtils.getUsername());
        updateWrapper.set("MODIFIED_TIME",new Date());
        updateWrapper.set("DEL_FLAG", EDelFlag.DELETE.getValue());
        regionDistributeService.update(updateWrapper);
        return AjaxResult.success();
    }

}
