package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
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 ${package.Entity}.vo.${entity}Vo;
/**
 * <p>
 * $!{table.comment} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
#if(${kotlin})
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

        }
#else
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
    #set($lowerCaseMapperName=${table.mapperName})
    #set($lowerCaseMapperName=$lowerCaseMapperName.substring(0,1).toLowerCase()+$lowerCaseMapperName.substring(1))

    @Resource
    private ${table.mapperName} ${lowerCaseMapperName};

    /**
     *保存$!{table.comment}
     * @param entity $!{table.comment}业务数据
     * @return
     */
    @Override
    public JSONObject saveT(${entity} entity){
        JSONObject jsonObject = new JSONObject();
        boolean b = super.save(entity);
        jsonObject.set("success",b);
        jsonObject.set("msg",b?"保存成功":"保存失败");
        return jsonObject;
    }
    /**
     *修改$!{table.comment}
     * @param entity $!{table.comment}业务数据
     * @return
     */
    @Override
    public JSONObject update(${entity} entity){
        JSONObject jsonObject = new JSONObject();
        boolean b =  super.updateById(entity);
        jsonObject.set("success",b);
        jsonObject.set("msg",b?"修改成功":"修改失败");
        return jsonObject;
    }
    /**
     *删除$!{table.comment}数据
     * @param id $!{table.comment}主键尖
     * @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;
    }

    /**
     * 按照条件查询$!{table.comment}信息
     * @param pageQuery
     * @throws Exception
     */
    @Override
    public IPage<Map<String,Object>> findPageVo(${entity}Vo pageQuery){
        {
        //条形查询器
        QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
        //分页相关
        Page<${entity}> p =new Page<>(pageQuery.getPage(),pageQuery.getLimit());

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

}
#end
