package ${packageName}.service.impl.${moduleName};

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.th.demo.model.system.Type;
import com.th.demo.tools.JSONTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ${packageName}.service.${moduleName}.${modelName}Service;
import ${packageName}.mapping.${moduleName}.${modelName}Mapper;
import ${packageName}.model.${moduleName}.${modelName};


@Service("${modelName}Service")
public class ${modelName}ServiceImpl implements ${modelName}Service {
    @Autowired
    ${modelName}Mapper ${modelNameFirstLower}Mapper;
    int num = 0;
    String result=Type.FAIL;

@Override
public String query(int page, int rows) {
PageHelper.startPage(page, rows);
List<${modelName}> list = ${modelNameFirstLower}Mapper.select();
PageInfo<${modelName}> pageInfo = new PageInfo<>(list);
result = JSONTools.toString(pageInfo);
return result;
}


@Override
 public String save(String json,  String userId) {
        ${modelName} ${modelNameFirstLower} = JSON.parseObject(json,${modelName}.class);
         if (${modelNameFirstLower}.getId()==null||${modelNameFirstLower}.getId().equals("")) {
            ${modelNameFirstLower}.setAddId(userId);
            ${modelNameFirstLower}.setAddTime(new Date());
            num = ${modelNameFirstLower}Mapper.insert(${modelNameFirstLower});
            result =JSONTools.toString(num);
        } else {
            ${modelNameFirstLower}.setModifyId(userId);
            ${modelNameFirstLower}.setModifyTime(new Date());
            num = ${modelNameFirstLower}Mapper.updateByPrimaryKey(${modelNameFirstLower});
            result = JSONTools.toString(num);
        }
        return result;
}
  @Override
    public String remove(String id,String userId) {
        num = ${modelNameFirstLower}Mapper.deleteByPrimaryKey(id);
        result = JSONTools.toString(num);
        return result;
    }

}
