package com.persagy.dye.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.persagy.common.utils.DateUtil;
import com.persagy.common.utils.ResponseResult;
import com.persagy.common.utils.ResponseUtil;
import com.persagy.dye.pojo.dto.DyeBasic;
import com.persagy.dye.service.IDyeBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 染色基础表
 *
 * @author yangwanyi
 * @version v1.0.0
 * @company persagy
 * @date 2021-10-25 15:58:56
 */

@RestController
@RequestMapping(value = "/dyeBasic", method = RequestMethod.POST)
public class DyeBasicController {

    @Autowired
    private IDyeBasicService dyeBasicService;

    /**
     * 列表查询
     */
    @RequestMapping(value = "queryDyeBasicList")
    public ResponseResult queryDyeBasicList(@RequestBody DyeBasic dyeBasic) {
        LambdaQueryWrapper<DyeBasic> queryWrapper = new DyeBasic.BuilderQueryWrapper().builder();
        List<DyeBasic> list = this.dyeBasicService.list(queryWrapper);
        if (CollectionUtil.isEmpty(list)) {
            return ResponseUtil.successResult(Lists.newArrayList(), 0L);
        }
        return ResponseUtil.successResult(list, (long) list.size());
    }

    /**
     * 新增
     */
    @RequestMapping(value = "createDyeBasic")
    public ResponseResult createDyeBasic(@RequestBody DyeBasic dyeBasic) {
        dyeBasic.setCreateTime(DateUtil.format(new Date(), DateUtil.FORMAT_DATE_YYYY_MM_DD_HH_MM_SS));
        boolean result = this.dyeBasicService.save(dyeBasic);
        return result ? ResponseUtil.successResult("保存成功") : ResponseUtil.errorResult("保存失败");
    }

    /**
     * 更新
     */
    @RequestMapping(value = "updateDyeBasic")
    public ResponseResult updateDyeBasic(@RequestBody DyeBasic dyeBasic) {
        dyeBasic.setUpdateTime(DateUtil.format(new Date(), DateUtil.FORMAT_DATE_YYYY_MM_DD_HH_MM_SS));
        boolean result = this.dyeBasicService.updateById(dyeBasic);
        return result ? ResponseUtil.successResult("更新成功") : ResponseUtil.errorResult("更新失败");
    }

    /**
     * 逻辑删除
     */
    @RequestMapping(value = "deleteDyeBasic")
    public ResponseResult deleteDyeBasic(@RequestParam String dyeBasicId, @RequestParam String updateUserId) {
        boolean result = this.dyeBasicService.deleteDyeBasicById(dyeBasicId, updateUserId);
        return result ? ResponseUtil.successResult("删除成功") : ResponseUtil.errorResult("删除失败");
    }

}
