package com.unis.crk.basic.service.impl;

import com.unis.crk.basic.entity.WeightPerson;
import com.unis.crk.basic.mapper.WeightPersonMapper;
import com.unis.crk.basic.service.IWeightPersonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import java.util.Map;
import cn.hutool.json.JSONObject;
import com.unis.crk.basic.entity.vo.WeightPersonVo;

import javax.annotation.Resource;

/**
 * <p>
 * 监磅员 服务实现类
 * </p>
 *
 * @author TangSong
 * @since 2023-05-12
 */
@Service
public class WeightPersonServiceImpl extends ServiceImpl<WeightPersonMapper, WeightPerson> implements IWeightPersonService {

    @Resource
    private WeightPersonMapper weightPersonMapper;

    /**
     *保存监磅员
     * @param entity 监磅员业务数据
     * @return
     */
    @Override
    public JSONObject saveT(WeightPerson entity){
        JSONObject jsonObject = new JSONObject();
        boolean b = super.save(entity);
        jsonObject.set("success",b);
        jsonObject.set("msg",b?"保存成功":"保存失败");
        return jsonObject;
    }
    /**
     *修改监磅员
     * @param entity 监磅员业务数据
     * @return
     */
    @Override
    public JSONObject update(WeightPerson entity){
        JSONObject jsonObject = new JSONObject();
        boolean b =  super.updateById(entity);
        jsonObject.set("success",b);
        jsonObject.set("msg",b?"修改成功":"修改失败");
        return jsonObject;
    }
    /**
     *删除监磅员数据
     * @param id 监磅员主键尖
     * @return
     */
    @Override
    public JSONObject delete(String id){
        JSONObject jsonObject = new JSONObject();
        boolean b = false;
        if (StringUtils.isNotBlank(id)){
        b =  super.removeById(id);
        }
        jsonObject.set("success",b);
        jsonObject.set("msg",b?"删除成功":"删除失败");
        return jsonObject;
    }

    /**
     * 按照条件查询监磅员信息
     * @param pageQuery
     * @throws Exception
     */
    @Override
    public IPage<Map<String,Object>> findPageVo(WeightPersonVo pageQuery){
        {
        //条形查询器
        QueryWrapper<WeightPerson> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(pageQuery.getUnitId())) {
            queryWrapper.eq("UNIT_ID", pageQuery.getUnitId());
        }
        //分页相关
        Page<WeightPerson> p =new Page<>(pageQuery.getPage(),pageQuery.getLimit());

        IPage<Map<String,Object>> page = weightPersonMapper.selectMyMapsPage(p,queryWrapper);
        return page;
        }
    }

}
