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

import com.unis.crk.basic.entity.TransportUnit;
import com.unis.crk.basic.mapper.TransportUnitMapper;
import com.unis.crk.basic.service.ITransportUnitService;
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.TransportUnitVo;

import javax.annotation.Resource;

/**
 * <p>
 * 承运单位 服务实现类
 * </p>
 *
 * @author TangSong
 * @since 2023-05-12
 */
@Service
public class TransportUnitServiceImpl extends ServiceImpl<TransportUnitMapper, TransportUnit> implements ITransportUnitService {

    @Resource
    private TransportUnitMapper transportUnitMapper;

    /**
     *保存承运单位
     * @param entity 承运单位业务数据
     * @return
     */
    @Override
    public JSONObject saveT(TransportUnit 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(TransportUnit 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(TransportUnitVo pageQuery){
        {
        //条形查询器
        QueryWrapper<TransportUnit> queryWrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(pageQuery.getUnitId())) {
                queryWrapper.eq("UNIT_ID", pageQuery.getUnitId());
            }
        //分页相关
        Page<TransportUnit> p =new Page<>(pageQuery.getPage(),pageQuery.getLimit());

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

}
