在數據大屏中需要多表聯合查詢的業務處理,而Jeecgboot提供的生成工具只能滿足最普遍的簡單代碼,mybatis-plus框架使用的QueryWrapper顯然無法滿足多表聯合查詢,需要重寫API接口。
1.新建返回對象的實體類
import lombok.Data;
@Data
public class Vendorcount {
private Integer vendor;
private Integer material;
}
2.mapper層接口
public interface VendorcountMapper extends BaseMapper<vendorcount> {
List<vendorcount> pageByVendor();
}
3.xml中寫入sql
<select id="pageByVendor" resulttype="org.jeecg.modules.demo.vendorquery.entity.Vendorcount">
select count(DISTINCT material13.Vendor) as vendor,count(DISTINCT material13.Material) as material
from material13 INNER JOIN stock on material13.Vendor=stock.create_by and material13.Plant=stock.plant
and material13.Material=stock.partno
</select>
4.service接口
public interface IVendorcountService extends IService<vendorcount> {
List<vendorcount> pageByVendorService();
}
5.serviceImpl
@Service
public class VendorcountServiceImpl extends ServiceImpl<vendorcountmapper, vendorcount=""> implements IVendorcountService {
@Autowired
private VendorcountMapper vendorcountMapper;
@Override
public List<vendorcount> pageByVendorService() {
return vendorcountMapper.pageByVendor();
}
}
6.control層
@Api(tags = "供應商查詢")
@RestController
@RequestMapping("/Vendorcount/vendorcount")
@Slf4j
public class VendorcountController extends JeecgController<vendorcount, ivendorcountservice=""> {
@Autowired
private IVendorcountService vendorcountService;
@AutoLog(value = "供應商查詢-統計個數")
@ApiOperation(value = "供應商查詢-統計個數", notes = "供應商查詢-統計個數")
@GetMapping(value = "/list")
public Result<!--?--> queryVendor(HttpServletRequest req) {
List<vendorcount> pageList = vendorcountService.pageByVendorService();
return Result.ok(pageList);
}
}
7.Shiro配置
// 配置不會被攔截的鏈接
filterChainDefinitionMap.put("/Vendorcount/vendorcount/**", "anon"); //
8.調試API接口
9.前端定時調用接口刷新數據
getAction("/Vendorcount/vendorcount/list").then((res) => {
if (res.success) {
let a = res.result
this.titleItem[0].number.number = [a[0]["material"]]
this.titleItem[1].number.number = [a[0]["vendor"]]
this.titleItem = {
...this.titleItem
}
this.show = false
this.$nextTick(() => {
this.show = true
})
大屏展示
</vendorcount,></vendorcountmapper,>