给商品选择接口增加商品类别的查询条件

This commit is contained in:
季圣华 2020-12-15 21:38:43 +08:00
parent 0388b8fa86
commit 5ee379241d
6 changed files with 71 additions and 9 deletions

View File

@ -152,7 +152,8 @@ public class MaterialController {
* @return
*/
@GetMapping(value = "/findBySelect")
public JSONObject findBySelect(@RequestParam(value = "q", required = false) String q,
public JSONObject findBySelect(@RequestParam(value = "categoryId", required = false) Long categoryId,
@RequestParam(value = "q", required = false) String q,
@RequestParam("mpList") String mpList,
@RequestParam(value = "depotId", required = false) Long depotId,
@RequestParam("page") Integer currentPage,
@ -161,9 +162,9 @@ public class MaterialController {
JSONObject object = new JSONObject();
try {
Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString());
List<MaterialVo4Unit> dataList = materialService.findBySelectWithBarCode(q, (currentPage-1)*pageSize, pageSize);
List<MaterialVo4Unit> dataList = materialService.findBySelectWithBarCode(categoryId, q, (currentPage-1)*pageSize, pageSize);
String[] mpArr = mpList.split(",");
int total = materialService.findBySelectWithBarCodeCount(q);
int total = materialService.findBySelectWithBarCodeCount(categoryId, q);
object.put("total", total);
JSONArray dataArray = new JSONArray();
//存放数据json数组

View File

@ -37,4 +37,6 @@ public interface MaterialCategoryMapperEx {
List<MaterialCategory> getMaterialCategoryBySerialNo(@Param("serialNo") String serialNo, @Param("id") Long id);
List<MaterialCategory> getMaterialCategoryListByCategoryIds(@Param("parentIds") String[] categoryIds);
List<MaterialCategory> getListByParentId(Long parentId);
}

View File

@ -41,11 +41,13 @@ public interface MaterialMapperEx {
List<MaterialVo4Unit> findByIdWithBarCode(@Param("meId") Long meId);
List<MaterialVo4Unit> findBySelectWithBarCode(@Param("q") String q,
List<MaterialVo4Unit> findBySelectWithBarCode(@Param("idList") List<Long> idList,
@Param("q") String q,
@Param("offset") Integer offset,
@Param("rows") Integer rows);
int findBySelectWithBarCodeCount(@Param("q") String q);
int findBySelectWithBarCodeCount(@Param("idList") List<Long> idList,
@Param("q") String q);
List<MaterialVo4Unit> findByAll(
@Param("name") String name,

View File

@ -46,6 +46,8 @@ public class MaterialService {
@Resource
private MaterialExtendMapperEx materialExtendMapperEx;
@Resource
private MaterialCategoryMapperEx materialCategoryMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
@ -338,26 +340,57 @@ public class MaterialService {
return list;
}
public List<MaterialVo4Unit> findBySelectWithBarCode(String q,Integer offset, Integer rows)throws Exception{
public List<Long> getListByParentId(Long parentId) {
List<Long> idList = new ArrayList<Long>();
List<MaterialCategory> list = materialCategoryMapperEx.getListByParentId(parentId);
idList.add(parentId);
if(list!=null && list.size()>0) {
getIdListByParentId(idList, parentId);
}
return idList;
}
public List<Long> getIdListByParentId(List<Long> idList, Long parentId){
List<MaterialCategory> list = materialCategoryMapperEx.getListByParentId(parentId);
if(list!=null && list.size()>0) {
for(MaterialCategory mc : list){
idList.add(mc.getId());
getIdListByParentId(idList, mc.getId());
}
}
return idList;
}
public List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, Integer offset, Integer rows)throws Exception{
List<MaterialVo4Unit> list =null;
try{
List<Long> idList = new ArrayList<>();
if(categoryId!=null){
Long parentId = categoryId;
idList = getListByParentId(parentId);
}
if(StringUtil.isNotEmpty(q)) {
q = q.replace("'", "");
}
list= materialMapperEx.findBySelectWithBarCode(q, offset, rows);
list= materialMapperEx.findBySelectWithBarCode(idList, q, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public int findBySelectWithBarCodeCount(String q)throws Exception{
public int findBySelectWithBarCodeCount(Long categoryId, String q)throws Exception{
int result=0;
try{
List<Long> idList = new ArrayList<>();
if(categoryId!=null){
Long parentId = categoryId;
idList = getListByParentId(parentId);
}
if(StringUtil.isNotEmpty(q)) {
q = q.replace("'", "");
}
result = materialMapperEx.findBySelectWithBarCodeCount(q);
result = materialMapperEx.findBySelectWithBarCodeCount(idList, q);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);

View File

@ -46,6 +46,10 @@
ofType="com.jsh.erp.datasource.vo.TreeNode" select="getNextNodeTree"/>
</resultMap>
<resultMap id="ResultCategoryMapList" type="com.jsh.erp.datasource.entities.MaterialCategory">
<result column="id" jdbcType="BIGINT" property="id" />
</resultMap>
<sql id="Base_Column_List">
id, name
</sql>
@ -123,4 +127,12 @@
and ifnull(status,'0') !='2'
</select>
<select id="getListByParentId" resultMap="ResultCategoryMapList">
SELECT id FROM jsh_material_category
where 1=1
<if test="parentId != null and parentId !=''">
and parent_id = #{parentId}
</if>
</select>
</mapper>

View File

@ -106,6 +106,12 @@
<if test="q != null">
and (m.name like '%${q}%' or me.bar_code like '%${q}%')
</if>
<if test="idList.size()>0">
and m.category_id in
<foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
and ifnull(m.delete_flag,'0') !='1'
ORDER BY id desc
<if test="offset != null and rows != null">
@ -121,6 +127,12 @@
<if test="q != null">
and (m.name like '%${q}%' or me.bar_code like '%${q}%')
</if>
<if test="idList.size()>0">
and m.category_id in
<foreach collection="idList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
and ifnull(m.delete_flag,'0') !='1'
</select>