更新后端,采用Springboot+mybatis
This commit is contained in:
71
src/main/java/com/jsh/erp/service/unit/UnitComponent.java
Normal file
71
src/main/java/com/jsh/erp/service/unit/UnitComponent.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.jsh.erp.service.unit;
|
||||
|
||||
import com.jsh.erp.service.ICommonQuery;
|
||||
import com.jsh.erp.service.app.AppResource;
|
||||
import com.jsh.erp.utils.Constants;
|
||||
import com.jsh.erp.utils.QueryUtils;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service(value = "unit_component")
|
||||
@UnitResource
|
||||
public class UnitComponent implements ICommonQuery {
|
||||
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
|
||||
@Override
|
||||
public Object selectOne(String condition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> select(Map<String, String> map) {
|
||||
return getUnitList(map);
|
||||
}
|
||||
|
||||
private List<?> getUnitList(Map<String, String> map) {
|
||||
String search = map.get(Constants.SEARCH);
|
||||
String name = StringUtil.getInfo(search, "name");
|
||||
String order = QueryUtils.order(map);
|
||||
return unitService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int counts(Map<String, String> map) {
|
||||
String search = map.get(Constants.SEARCH);
|
||||
String name = StringUtil.getInfo(search, "name");
|
||||
return unitService.countUnit(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(String beanJson, HttpServletRequest request) {
|
||||
return unitService.insertUnit(beanJson, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(String beanJson, Long id) {
|
||||
return unitService.updateUnit(beanJson, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return unitService.deleteUnit(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchDelete(String ids) {
|
||||
return unitService.batchDeleteUnit(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkIsNameExist(Long id, String name) {
|
||||
return unitService.checkIsNameExist(id, name);
|
||||
}
|
||||
|
||||
}
|
||||
15
src/main/java/com/jsh/erp/service/unit/UnitResource.java
Normal file
15
src/main/java/com/jsh/erp/service/unit/UnitResource.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.jsh.erp.service.unit;
|
||||
|
||||
import com.jsh.erp.service.ResourceInfo;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author jishenghua qq752718920 2018-10-7 15:26:27
|
||||
*/
|
||||
@ResourceInfo(value = "unit", type = 40)
|
||||
@Inherited
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface UnitResource {
|
||||
}
|
||||
68
src/main/java/com/jsh/erp/service/unit/UnitService.java
Normal file
68
src/main/java/com/jsh/erp/service/unit/UnitService.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package com.jsh.erp.service.unit;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.datasource.entities.Unit;
|
||||
import com.jsh.erp.datasource.entities.UnitExample;
|
||||
import com.jsh.erp.datasource.mappers.UnitMapper;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UnitService {
|
||||
private Logger logger = LoggerFactory.getLogger(UnitService.class);
|
||||
|
||||
@Resource
|
||||
private UnitMapper unitMapper;
|
||||
|
||||
public Unit getUnit(long id) {
|
||||
return unitMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public List<Unit> getUnit() {
|
||||
UnitExample example = new UnitExample();
|
||||
return unitMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public List<Unit> select(String name, int offset, int rows) {
|
||||
return unitMapper.selectByConditionUnit(name, offset, rows);
|
||||
}
|
||||
|
||||
public int countUnit(String name) {
|
||||
return unitMapper.countsByUnit(name);
|
||||
}
|
||||
|
||||
public int insertUnit(String beanJson, HttpServletRequest request) {
|
||||
Unit unit = JSONObject.parseObject(beanJson, Unit.class);
|
||||
return unitMapper.insertSelective(unit);
|
||||
}
|
||||
|
||||
public int updateUnit(String beanJson, Long id) {
|
||||
Unit unit = JSONObject.parseObject(beanJson, Unit.class);
|
||||
unit.setId(id);
|
||||
return unitMapper.updateByPrimaryKeySelective(unit);
|
||||
}
|
||||
|
||||
public int deleteUnit(Long id) {
|
||||
return unitMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public int batchDeleteUnit(String ids) {
|
||||
List<Long> idList = StringUtil.strToLongList(ids);
|
||||
UnitExample example = new UnitExample();
|
||||
example.createCriteria().andIdIn(idList);
|
||||
return unitMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public int checkIsNameExist(Long id, String name) {
|
||||
UnitExample example = new UnitExample();
|
||||
example.createCriteria().andIdNotEqualTo(id).andUnameEqualTo(name);
|
||||
List<Unit> list = unitMapper.selectByExample(example);
|
||||
return list.size();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user