package com.vci.test; import com.vci.starter.web.annotation.controller.VciUnCheckRight; import com.vci.starter.web.pagemodel.BaseResult; import com.vci.starter.web.pagemodel.Tree; import com.vci.web.service.WebBoServiceI; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Description 测试控制器 * @Author dangsn * @Date 2024/11/14 10:08 */ @RestController @RequestMapping("/dataTestController") public class DataTestController { @Resource private WebBoServiceI boServiceI; /** * 获取产品 * @return */ @VciUnCheckRight @GetMapping("/getProduct") public BaseResult getProduct(){ String sql = "select * from platformbtm_workcontext where workcontexttype = 'product'"; List productList = boServiceI.queryByOnlySqlForMap(sql); BaseResult baseResult = new BaseResult(); baseResult.setSuccess(true); baseResult.setCode(200); baseResult.setData(productList); return baseResult; } /** * 获取ebom信息 * @param parentOid 上级信息 * @return */ @VciUnCheckRight @GetMapping("/getEbomInfo") public BaseResult getEbomInfo(String productNo, String productOid, String parentOid){ if(StringUtils.isBlank(productNo)){ return BaseResult.fail("产品编号为空!"); } if(StringUtils.isBlank(productOid)){ return BaseResult.fail("产品主键为空!"); } BaseResult baseResult = new BaseResult(); List ebomList; if(StringUtils.isBlank(parentOid)){ String sql = "select * from platformbtm_part t where t.ownproduct = '"+productOid+"' and t.code = '"+productNo+"'"; ebomList = boServiceI.queryByOnlySqlForMap(sql); }else{ String sql = "select p.*,e.oid as eoid from platformbtm_part p left join platformlt_ebom e on p.oid = e.t_oid \n" + "where e.f_oid = '"+parentOid+"' and e.workcontextoid = '"+productOid+"' \n" + "and p.islastr = '1' and p.islastv = '1' order by p.code asc"; ebomList = boServiceI.queryByOnlySqlForMap(sql); } List treeList = new ArrayList<>(); if(!CollectionUtils.isEmpty(ebomList)){ for(Map ebom : ebomList){ String oid = ebom.get("OID").toString(); String id = ebom.get("CODE").toString(); String name = ebom.get("NAME").toString(); String revisionvalue = ebom.get("REVISIONVALUE").toString(); String versionrule = ebom.get("VERSIONRULE").toString(); String versionvalue = ebom.get("VERSIONVALUE").toString(); String parttype = ebom.get("PARTTYPE").toString(); String lcStatus = ebom.get("LCSTATUS").toString(); String parttypetext = ""; String lcStatusText = ""; if(parttype.equals("20")){ parttypetext = "产品"; } if(parttype.equals("6")){ parttypetext = "装配件"; } if(parttype.equals("7")){ parttypetext = "零件"; } if(parttype.equals("8")){ parttypetext = "标准件"; } if(lcStatus.equals("Editing")){ lcStatusText = "编辑中"; } if(lcStatus.equals("Published")){ lcStatusText = "已发布"; } Tree tree = new Tree(); tree.setLeaf(false); tree.setExpanded(false); tree.setOid(oid); tree.setId(id); tree.setText(id+" "+name+"["+parttypetext+"]["+revisionvalue+versionrule+versionvalue+"]【"+lcStatusText+"】"); if(StringUtils.isNotBlank(parentOid)){ tree.setParentId(parentOid); } if(ebom.containsKey("EOID")){ Map atrrMap = new HashMap<>(); atrrMap.put("eoid", ebom.get("EOID").toString()); tree.setAttributes(atrrMap); } treeList.add(tree); } } baseResult.setData(treeList); baseResult.setSuccess(true); baseResult.setCode(200); return baseResult; } }