package ${package}.${pkgName}.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.shoulder.core.dto.response.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.MapUtils;

import ${package}.${pkgName}.entity.${className};
import ${package}.${pkgName}.dao.${className}Dao;
import ${package}.${pkgName}.service.${className}Service;


@Service
public class ${className}ServiceImpl  implements ${className}Service {

    @Autowired
    private ${className}Dao ${lowClassName}Dao;

    /**
     * 添加
     * @param ${lowClassName}
     */
    public int save(${className} ${lowClassName}){
        return ${lowClassName}Dao.save(${lowClassName});
    }

    /**
     * 修改
     * @param ${lowClassName}
     */
    public int update(${className} ${lowClassName}){
        return ${lowClassName}Dao.update(${lowClassName});
    }


    /**
     * 删除
     * @param id
     */
    public int delete(Long id){
        return ${lowClassName}Dao.delete(id);
    }


    /**
     * 列表
     * @param params
     * @return
     */
    public PageResult<${className}> findAll(Map<String, Object> params){
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        if (MapUtils.getInteger(params, "page")!=null && MapUtils.getInteger(params, "limit")!=null)
            PageHelper.startPage(MapUtils.getInteger(params, "page"),MapUtils.getInteger(params, "limit"),true);

        List<${className}> list  =  ${lowClassName}Dao.findAll(params);
        PageInfo<${className}> pageInfo = new PageInfo(list);

        return PageResult.<${className}>builder().data(pageInfo.getList()).code(0).count(pageInfo.getTotal()).build();
    }

}
